1. alogorithm to convert MIDI to Wav

Hello ,

I was searching for an algorithm to convert a MIDI file to Wav file .
can any of you can help me with that ..

Thanks & regards,
Raghavendra M L

new topic     » topic index » view message » categorize

2. Re: alogorithm to convert MIDI to Wav

Raghavendra M L wrote:

> I was searching for an algorithm to convert a
> MIDI file to Wav file. can any of you can help
> me with that ..

This isn't entirely trivial. MIDI specifies information about the state of a
musical keyboard, such as:

   instrument number 42 was selected on channel 7
   the c3 key for channel 2 was hit at a velocity of 32
   the expression pedal 2 for channel number 5 was pressed
   the pitch bend wheel for channel 2 was moved 12 units
   the c3 key for channel 12 was released

The General MIDI (GM) specifies a specific mapping of instruments. For
example, instrument 1 is a Grand Piano, instrument 9 is a Celesta, etc. So
to create a waveform, the general algorithm would be:

   what waveform would instrument X generate at pitch Y?

Again, note that there's no information about an instrument specified in
MIDI - just the state of a musical keyboard's keys, pedals and levers. It's
up to the MIDI player to supply that data.

This is typically solved by storing digital samples (looped waves) in a
lookup wavetable. Since the timbre of an instrument changes over it's range
(that is, the spectral composition of a low note is much different for a low
note than a high note), an instrument is typically multisampled. That is,
several waves are captured over it's range. Since it takes a lot of storage
to capture a sample, it's not practical to sample each and every pitch of
the instrument. Instead, most instruments have samples spread across the
instrument, from a couple notes to a couple octaves. If the pitch D4 is
selected and the closest sample is Bb3, it's the job of the software to
scale the pitch of the Bb3 sample to D4.

Scaling a sample is done by writing out every nth sample point. For example,
if you write out every 2nd sample point of a sample, you effectively double
it's pitch, and raise it by an octave. The best samplers will interpolate
missing sample points from the data, typically with a quartic spline.

In addition to instruments being sampled over the pitch range, they are
often sampled over the velocity range, since playing an instrument harder
will also change the timbre, in addition to changing the volume.

The sample player typically applies some sort of ADSR envelope
(attack/decay/sustain/release) to the waveform to make it more natural
sounding. For example, one instrument might fade away, while another might
just end abruptly when a MIDI note off event is received.

For more information on converting samples to sound, you might want to look
at MOD players. Pete coded on a while back in assembly for Euphoria, but he
might still have the 'pure' Euphoria code.

You can find free collections of General MIDI samples on the internet in
SoundFont, DLS and Inst formats, ranging in size from 512K all the way up to
80Meg. These files are typically a pain to parse; you can find information
about them in Wotsit's File Formats (do a Web search).

Hope this answered your question.

-- David Cuny

new topic     » goto parent     » topic index » view message » categorize

3. Re: alogorithm to convert MIDI to Wav

David ,

yes .. it was a very comprehensive answer to my question

Thanks a lot ,
Raghu

David Cuny wrote:

> Raghavendra M L wrote:
>
> > I was searching for an algorithm to convert a
> > MIDI file to Wav file. can any of you can help
> > me with that ..
>
> This isn't entirely trivial. MIDI specifies information about the state of a
> musical keyboard, such as:
>
>    instrument number 42 was selected on channel 7
>    the c3 key for channel 2 was hit at a velocity of 32
>    the expression pedal 2 for channel number 5 was pressed
>    the pitch bend wheel for channel 2 was moved 12 units
>    the c3 key for channel 12 was released
>
> The General MIDI (GM) specifies a specific mapping of instruments. For
> example, instrument 1 is a Grand Piano, instrument 9 is a Celesta, etc. So
> to create a waveform, the general algorithm would be:
>
>    what waveform would instrument X generate at pitch Y?
>
> Again, note that there's no information about an instrument specified in
> MIDI - just the state of a musical keyboard's keys, pedals and levers. It's
> up to the MIDI player to supply that data.
>
> This is typically solved by storing digital samples (looped waves) in a
> lookup wavetable. Since the timbre of an instrument changes over it's range
> (that is, the spectral composition of a low note is much different for a low
> note than a high note), an instrument is typically multisampled. That is,
> several waves are captured over it's range. Since it takes a lot of storage
> to capture a sample, it's not practical to sample each and every pitch of
> the instrument. Instead, most instruments have samples spread across the
> instrument, from a couple notes to a couple octaves. If the pitch D4 is
> selected and the closest sample is Bb3, it's the job of the software to
> scale the pitch of the Bb3 sample to D4.
>
> Scaling a sample is done by writing out every nth sample point. For example,
> if you write out every 2nd sample point of a sample, you effectively double
> it's pitch, and raise it by an octave. The best samplers will interpolate
> missing sample points from the data, typically with a quartic spline.
>
> In addition to instruments being sampled over the pitch range, they are
> often sampled over the velocity range, since playing an instrument harder
> will also change the timbre, in addition to changing the volume.
>
> The sample player typically applies some sort of ADSR envelope
> (attack/decay/sustain/release) to the waveform to make it more natural
> sounding. For example, one instrument might fade away, while another might
> just end abruptly when a MIDI note off event is received.
>
> For more information on converting samples to sound, you might want to look
> at MOD players. Pete coded on a while back in assembly for Euphoria, but he
> might still have the 'pure' Euphoria code.
>
> You can find free collections of General MIDI samples on the internet in
> SoundFont, DLS and Inst formats, ranging in size from 512K all the way up to
> 80Meg. These files are typically a pain to parse; you can find information
> about them in Wotsit's File Formats (do a Web search).
>
> Hope this answered your question.
>
> -- David Cuny

new topic     » goto parent     » topic index » view message » categorize

4. Re: alogorithm to convert MIDI to Wav

At 01:49 PM 3/29/2000 +0530, you wrote:
>Hello ,
>
>I was searching for an algorithm to convert a MIDI file to Wav file .
>can any of you can help me with that ..
>
>Thanks & regards,
>Raghavendra M L

While David Cuny's answer would be of help if you wanted to actually
create a program to process MIDI files, there may be an easier way
if your soundcard supports full-duplex playback and record.

If it does, you should be able to run an audio cable directly from the
line-in port on your soundcard to the line-in port.  You can then play
the midi file using any midi software, such as MS MediaPlayer, and
record it using any recording software, such as MS Sound Recorder.
Both of these can be found in Start/Programs/Accessories/Entertainment.

You will also be able to do this under any other OS such as Linux, so
long as your soundcard and drivers support playback and record
simultaneously (full-duplex), and you have the proper software.

Granted, this isn't a perfect solution, but it should tide you over until
something better comes along.

James Powell

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu