Thread: [Win32] MP3 Playback

  1. #1
    Registered User
    Join Date
    Mar 2005
    Posts
    69

    [Win32] MP3 Playback

    As far as i've undestood,for playing an MP3 file using waveOut functions i have to proceed as with the WAV files,but with the difference that it must be passed , to the waveOutOpen function , a WAVEFORMATEXTENSIBLE structure rather than a WAVEFORMATEX one

    Code:
    typedef struct {
      WAVEFORMATEX  Format;
      union {
        WORD  wValidBitsPerSample;
        WORD  wSamplesPerBlock;
        WORD  wReserved;
      } Samples;
      DWORD   dwChannelMask; 
      GUID    SubFormat;
    } WAVEFORMATEXTENSIBLE, *PWAVEFORMATEXTENSIBLE;
    in WAVEFORMATEX i set the wFormatTag field on WAVE_FORMAT_EXTENSIBLE rather than WAVE_FORMAT_PCM and
    cbSize = sizeof(WAVEFORMATEXTENSIBLE)

    The other fields of both structs have to be initialized as described in MSDN and almost all of them specify the audio signal characteristics,such as bits per sample,frequency etc...

    My problem is the SubFormat field of WAVEFORMATEXTENSIBLE struct,which is the GUID of the MP3 format,i guess

    How i obtain such a GUID? I searched google with "mp3 guid",but nothing

    P.S. If you have the GUID give me it directly

  2. #2
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    I'm afraid you're under a misconception. Under no circumstances is waveOut* capable of directly playing compressed audio. WAVEFORMATEXTENSIBLE is for unusual sample formats, but they're still raw audio data.

    You have to use some other API to decode the MP3 data.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  3. #3
    Registered User
    Join Date
    Mar 2004
    Posts
    220
    You might want to try the MCI API.

    Check it out at: http://www.gamedev.net/reference/art...rticle2053.asp
    OS: Windows XP Pro CE
    IDE: VS .NET 2002
    Preferred Language: C++.

  4. #4
    Registered User
    Join Date
    Mar 2005
    Posts
    69
    Quote Originally Posted by Tronic
    You might want to try the MCI API.

    Check it out at: http://www.gamedev.net/reference/art...rticle2053.asp
    Ah ok,thank you

    But MCI has a limitation,it cannot play two or more tracks at the same time,like you would do with waveOut and WAV files...i have to write a videogame with all musics and sounds in mp3 format and,as you know,sound effects in a game are played together most times,or there is a music track playing in background together with temporary sound effects,noises...

    i'll try looking for other apis

  5. #5
    Registered User
    Join Date
    Mar 2004
    Posts
    220
    Sorry I couldn't find anything better for you. I used an API for this a while back, but I forgot what it was called. I used it in conjunction with OpenAL, so it did some nifty tricks with 3D sound.

    Multi-track sound though...I honestly have no idea about that.
    OS: Windows XP Pro CE
    IDE: VS .NET 2002
    Preferred Language: C++.

  6. #6
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    Check into using DirectSound. I think this can do what you want.

  7. #7
    Registered User
    Join Date
    Mar 2005
    Posts
    69
    Quote Originally Posted by bithub
    Check into using DirectSound. I think this can do what you want.
    DirectSound uses the same Win32 structures used with waveOut* functions ( WAVEFORMATEX,...) so it doesn't support MP3

    Perhaps i can load the MP3 file in memory,then convert it to WAV format before reproduction,using DirectShow or other APIs and then play it

    Can DirectShow convert MP3 -> WAV ?

    Tronic,did you use those unknown APIs to convert the MP3s to WAV before sending them to OpenAL for reproduction?
    Try to remember their name

  8. #8
    Registered User
    Join Date
    Mar 2005
    Location
    Mountaintop, Pa
    Posts
    1,058
    Perhaps this tutorial can be of some help?

    DirectShow tutorial

    Part II should be able to play MP3

  9. #9
    Registered User
    Join Date
    Mar 2005
    Posts
    69
    Found it!!

    This is a Win32 function for converting from an MP3 stream to a WAV audio buffer,that can be used for reproduction with waveOut* (which can also reproduce several tracks together)

    http://64.233.183.104/search?q=cache...EGLAYER3&hl=it

    DirectShow is no longer necessary

  10. #10
    Registered User
    Join Date
    Mar 2004
    Posts
    220
    Yay. I guess I don't have to exercise my poor memory skillz after all XD.
    OS: Windows XP Pro CE
    IDE: VS .NET 2002
    Preferred Language: C++.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. which Portable mp3 player?
    By Raihana in forum A Brief History of Cprogramming.com
    Replies: 27
    Last Post: 01-09-2004, 07:58 AM
  2. MP3 to WAVE and WAVE to MP3 conversion
    By Blizzarddog in forum C++ Programming
    Replies: 8
    Last Post: 01-01-2004, 08:32 PM
  3. mp3 players vs mp3 cd players
    By Geo-Fry in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 12-06-2003, 09:22 PM
  4. Mp3
    By gvector1 in forum C# Programming
    Replies: 15
    Last Post: 07-08-2003, 05:48 PM