Play sound file

Mar 7, 2009 at 6:22pm
I need a way to play a sound file in the background when the C program is running.I'm using windows. How to play a midi file would be sufficient. And please I need a code snippet , not some link to a 10 page site that I won't understand.
Mar 7, 2009 at 9:43pm
Use this API Function in windows.h

 
PlaySound("C:\\SOUNDS\\BELLS.WAV", NULL, SND_ASYNC);


Source: http://www.dreamincode.net/forums/showtopic18352.htm

This may not play large .wav files. (more than about 1MB)

Edit: More on the PlaySound function
http://msdn.microsoft.com/en-us/library/ms712879.aspx
Last edited on Mar 7, 2009 at 9:47pm
Mar 8, 2009 at 7:25am
Okay, I suppose I could just convert all the sound files that I want to play int .wav format. Thanks for the help.
Mar 8, 2009 at 7:41am
Do you know how to convert a midi file into a .wav file while keeping it less than 1MB?(I seem to have a problem in that my converter transforms a 10 KB midi file into .wav file larger than 1 MB even under the worst possible quality).
Mar 8, 2009 at 8:09am
This might work:

http://manuals.opensound.com/developer/softsynth.c.html

but there's no percussion

You might also want to convert into another format ogg, mp3, etc. There are APIs for those
Last edited on Mar 8, 2009 at 8:11am
Mar 8, 2009 at 8:29am
I read the entire page, I didn't understand a word, and I don't even know the purpose you gave the link for.
But how do you play other formats?(I mean what are the functions?)
Last edited on Mar 8, 2009 at 8:30am
Mar 8, 2009 at 7:18pm
The playsound function works(sorry for the stupid comment that I just deleted). But I still need either a way to convert my sound files to small sized .wav files, or the functions that can play ogg, mp3... .Thank you in advance.
Mar 8, 2009 at 9:08pm
Just use Win32 MM apis to play MP3, WMA, etc...
Mar 8, 2009 at 9:30pm
"Just use Win32 MM apis to play MP3, WMA, etc... "
A code snippet like the one in the first reply would be great.(I don't really know what the parameters mean or if there is a return value nor do I really care to know, I'll just copy the code snippet and paste it inside my code and also keep it for later use.)
Mar 9, 2009 at 12:20am
If you are not willing to learn then forget programming.
Mar 9, 2009 at 6:12am
"If you are not willing to learn then forget programming."
Understanding how to play sound files is the least important thing I can think of in C programming. I'm the first in my class in programming and I know everything essential to writing a c program, and playing sound files is merely decoration, that's why I said I didn't care to understand what the parameters mean. I guess I won't be expecting any help anymore.
Topic archived. No new replies allowed.