Thread: Playing music

  1. #1
    Cheesy Poofs! PJYelton's Avatar
    Join Date
    Sep 2002
    Location
    Boulder
    Posts
    1,728

    Playing music

    I am really unsure of how to do this using Win32 API. I have a few classical music .mp3's that I want to be running in the background of a game I am writing. Anyone know how I can load music (preferably an mp3) to play in my windows program? I can't seem to find any useful tutorials unfort...

  2. #2
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    try PlaySound() for wav files.
    MP3 will need some other format. AFAIK DirectPlay.

    this will loop a wav file from the current folder until you call it again with a NULL for the filename

    PlaySound(szSoundFileName ,NULL ,SND_ASYNC |SND_LOOP | SND_FILENAME);

    else look at the WOM (windows open media) layer.

    this gives full control as msg's as posted as to the progress of the sound as it plays (needed in a mp3 player)

    Look at the waveOut......() functions ie waveOutOpen(), waveOutGetPosition, waveOutPrepareHeader()

  3. #3
    Cheesy Poofs! PJYelton's Avatar
    Join Date
    Sep 2002
    Location
    Boulder
    Posts
    1,728
    Thanks for the help, I'll look into those functions. Just one more (likely very stupid) question. Is there any way to convert an mp3 into a .wav file? It doesn't matter to me if quality suffers, unless it is very considerable.

  4. #4
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,829
    To convert an .mp3 to a .wav you will need a mp3 decoder, some people call them mp3 rippers, but a true ripper is a .cda -> .wav tool. There are numerous .mp3 decoders around.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  5. #5
    verbose cat
    Join Date
    Jun 2003
    Posts
    209
    Originally posted by PJYelton
    Thanks for the help, I'll look into those functions. Just one more (likely very stupid) question. Is there any way to convert an mp3 into a .wav file? It doesn't matter to me if quality suffers, unless it is very considerable.
    Not a stupid question at all. Do a search on "sound file converters" on one of the big search engines and you'll turn up alot of programs.

    Actually converting an mp3 into a .wav would probably not lose any quality but would make the resulting file REEEELY big (unless the .mp3 is extremely small).

    The mp3 format is a compressed format and relies on tricks that can cause some quality loss (sort of like a .jpg image) while the .wav format is more like raw sound data (sort of like a .bmp image). A 2-3 minute .mp3 file might take 3-4 MB (depending on the quality) whereas the .wav created from that could be considerably larger. Making a 2-3 minute .wav from a very high quality source (like a CD) could be 20+ MB! Depending on how good the .mp3 is you could cut that in half or more (and the converter you use may have other options to set as well).

    If you can find a way to play the .mp3 files, I would say keep that format for the game, but that is my opinion. This would also allow people to put their own .mp3 files in the program directory for custom music (if you want to allow that...).

  6. #6
    Cheesy Poofs! PJYelton's Avatar
    Join Date
    Sep 2002
    Location
    Boulder
    Posts
    1,728
    Yeah, I found out the hard way on that one. My 3 MB mp3's suddenly turned into 37 MB wav files which obviously makes using them a little impractical. I'm still working on using the mp3 in my game although its proven to be a little difficult at the moment...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Is AOL music crazy?
    By joeprogrammer in forum A Brief History of Cprogramming.com
    Replies: 9
    Last Post: 03-24-2006, 07:24 PM
  2. Playing music
    By adr in forum Windows Programming
    Replies: 13
    Last Post: 12-31-2005, 03:23 PM
  3. playing music in C++
    By dutch's finest in forum C++ Programming
    Replies: 3
    Last Post: 02-21-2005, 05:57 PM
  4. Playing Music in C#
    By Smoose777 in forum C# Programming
    Replies: 9
    Last Post: 06-06-2002, 04:11 PM
  5. Playing Music
    By Quantrizi in forum A Brief History of Cprogramming.com
    Replies: 11
    Last Post: 05-11-2002, 07:47 PM