Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Midi2Wav (win32 API)

0 views
Skip to first unread message

werasm

unread,
Mar 7, 2006, 3:25:56 AM3/7/06
to
Hi all,

I would like (for the heck of it, mostly), a little program that
converts MIDI files to WAV files. Basically I need to load the MIDI
file and convert it to WAV without sound loss. I suppose it is
possible, as I know of programs that do just this.

Apart from for the heck of it, I do have a reason. My wife composed a
school anthem. A friend of hers used her Yamaha "Portable Grand" to
create the music, and now I have files (only 3 of them) in MIDI format
that require conversion to WAV format so that we can give supply the
school with a backtrack. I've searched for freeware to perform this
once off, but I have not found any allowing me to record the entire
song without paying. I then thought that it would be a nice challenge
to write - seeing that programming is my hobby and my profession. I
would at least impress my wife :-). Therefore, any of you media gurus
willing to put me on my way? My language of choice, btw, is C++, I
would therefore prefer trying it using WIN32 API.

Kind regards,

Werner

werasm

unread,
Mar 7, 2006, 4:27:21 AM3/7/06
to
Hi again,

Forgot to mention, the platform is XP or Win2000. :-)

Chris P. [MVP]

unread,
Mar 7, 2006, 9:19:56 AM3/7/06
to

There's an easy way and a hard way as I see it.

The easy way is to use the PC to playback the MIDI track and at the same
time record the output by setting the Record mixer to "Stereo Mix" or "What
U Hear". You can use Media Player and a software Recorder, no software
writing required.

The hard way would be to create your own MIDI renderer which is incredibly
complex as it involves synthesizing each of the instruments. The build in
windows MIDI renderer goes directly to the audio output and they don't give
you any hooks to intercept the data before it hits the sound card.

For the reason I would strongly recommend option A. You could even do it
in code with a few MCI commands to play the MIDI and record the WAV,
automatically stopping on completion. DirectShow is also a viable option
by it is a little more complex.

-Chris
--
http://www.chrisnet.net/code.htm
http://www.avdevforum.com/AV

Alessandro Angeli [MVP::DS/MF]

unread,
Mar 7, 2006, 6:29:06 PM3/7/06
to
Chris P. [MVP] wrote:

> The build in windows MIDI
> renderer goes directly to the audio output and they don't
> give you any hooks to intercept the data before it hits
> the sound card.

You can always create your own hooks in C, but for small set
of files your option A still seems preferable.


--
// Alessandro Angeli
// MVP :: DirectShow / MediaFoundation
// a dot angeli at psynet dot net


werasm

unread,
Mar 8, 2006, 2:45:18 AM3/8/06
to

Chris P. [MVP] wrote:
> On 7 Mar 2006 00:25:56 -0800, werasm wrote:
>
> > Hi all,
> >
> > I would like (for the heck of it, mostly), a little program that
> > converts MIDI files to WAV files. Basically I need to load the MIDI
> > file and convert it to WAV without sound loss. I suppose it is
> > possible, as I know of programs that do just this.
> There's an easy way and a hard way as I see it.
>
> The easy way is to use the PC to playback the MIDI track and at the same
> time record the output by setting the Record mixer to "Stereo Mix" or "What
> U Hear". You can use Media Player and a software Recorder, no software
> writing required.

Maybe I'll try this to get the job done


>
> The hard way would be to create your own MIDI renderer which is incredibly
> complex as it involves synthesizing each of the instruments. The build in
> windows MIDI renderer goes directly to the audio output and they don't give
> you any hooks to intercept the data before it hits the sound card.
>

Ok, I'll skip this. I was hoping to intercept the MIDI output data, and
hoping that some conversion functions existed before streaming it into
WAV.

> For the reason I would strongly recommend option A. You could even do it
> in code with a few MCI commands to play the MIDI and record the WAV,
> automatically stopping on completion. DirectShow is also a viable option
> by it is a little more complex.

I'll try playing with MCI commands and DirectShow for the kicks. Any
good examples, or should MSDN be sufficient?

Regards,

W

rn

unread,
Mar 8, 2006, 2:48:46 AM3/8/06
to
Install QuickTime from Apple (and the SDK).

Use the ConvertMovieToFile() and related functions to convert the MIDI file
to an AIFF file, then convert the AIFF file to a regular wave file.

You can't covert a MIDI file directly to a wave file, you need to go via a
temporary aiff file.

It will use the sounds from the QuickTime synth, which (I guess) is based on
the

same Roland GM sounds as Windows uses

Works fine in my app

Rolf

"werasm" <w_e...@telkomsa.net> skrev i meddelandet
news:1141719956.2...@i39g2000cwa.googlegroups.com...

Chris P. [MVP]

unread,
Mar 8, 2006, 9:56:57 AM3/8/06
to
On 7 Mar 2006 23:45:18 -0800, werasm wrote:

>
> Ok, I'll skip this. I was hoping to intercept the MIDI output data, and
> hoping that some conversion functions existed before streaming it into
> WAV.

Reading MIDI data from file is relatively easy, and sending it to the MIDI
renderer is pretty easy too. There just aren't efficient methods to
capture the output of the renderer or a nice conversion function.



>
> I'll try playing with MCI commands and DirectShow for the kicks. Any
> good examples, or should MSDN be sufficient?

MCI commands are pretty simple and the documentation should be enough for
that. A few google searches will usually show up enough examples.

DirectShow is a far bit more involved but a lot more fun, it's like playing
with lego's only the lego's blow up on you when you do something wrong. :)
The language of choice for DirectShow is C++, it is possible to work with
it in other languages such as C# but you need enough C++ knowledge to
compile samples and read the code.

It's easiest to start with the Summer 2004 DirectX SDK, it has the most
complete samples and includes project files.

Reading of the newsgroups microsoft.public.win32.programmer.directx.audio
and microsoft.public.win32.programmer.directx.video and required including
the google archives. A book helps but it seems the best book on the topic
is now out of print, Mark Pesce's "Programming Microsoft DirectShow for
Digital Video and Television" and is now selling for $60 used.
There's some good info at these sites:
http://tmhare.mvps.org/faqs.htm
http://www.avdevforum.com/av
http://www.gdcl.co.uk/
http://www.limegreensocks.com/DShow/


For your particular case you would need 2 separate filter graphs. One for
the playback and one for the capture.

Playback built by RenderFile():
FileSource(midi file) -> MIDI Parser -> MIDI Out Device

For capture you need:
Audio capture source -> WaveDest (sample) -> File Writer

It should be enough to slap these filters into a graph and call Render on
the first output pin.

0 new messages