Re: Playing an MP3 file using WaveOut functions



Punit Kaur wrote:

Can someone explain me the steps to write a program that
would take an mp3 file as input and play it using Waveout
functions. I nkow that Waveout function plays from a
buffer. How do I convert the mp3 files to the
appropriately formatted buffer that waveout functions can
understand and play the audio?

I tried using the PlaySound function directly on the mp3
files but it is giving problems by cutting off the last
few seconds of the audio file. Hence I decided to shift
to Waveout option.

You need to decompress the MP3 stream to PCM before passing
the PCM buffers to waveOut. One way to do that is to use the
acmStream functions with the system's MP3 codec. Since an
MP3 file is a raw MP3 stream, you can just read the file
without any parsing and pass the blocks directly to
acmStreamConvert().

However, since you need to properly configure the ACM
decoder using an MPEGLAYER3WAVEFORMAT structure, you either
must know in advance the exact format of the MP3 file or you
need to parse the MP3 frame header to gather the values to
fill in the structure.

If your MP3 files contain ID3 tags, you should also skip the
tags, especially if they are ID3v2 tags that contains large
blocks of data, like JPEG images.

You can find instructions on all of this in my FAQ (see my
signature below). You can read about ID3 on
http://en.wikipedia.org/wiki/ID3.

If you want something that does all of the above for you,
you can use the WMSyncReader or WMReader objects documented
in the WindowsMediaFormat SDK. The WM reader objects are
supposed to only read ASF files, but they also support MP3
ones and will parse, skip and decode the MP3 for you.

If you want something that does all of the above and also
actually plays the audio, you can use DirectShow. The
default audio rendering filter in DirectShow is DirectSound,
but you can manually choose the other system's filter based
on waveOut.

The MPEGVideo MCI driver will also play MP3 files for you
(in fact, it is an MCI wrapper for DirectShow).


--
// Alessandro Angeli
// MVP :: DirectShow / MediaFoundation
// a dot angeli at psynet dot net
// http://www.riseoftheants.com/mmx/faq.htm



.



Relevant Pages

  • Re: 80040154
    ... I am using window media control in my project to play mp3, ... some mp3 file in my project play but some give "Unspecified Error" ... > specific AVI or you have a bad install of the codec. ...
    (microsoft.public.windowsmedia.player)
  • Re: problems getting mp3 files to play
    ... You have to long a path/file name to the linked MP3. ... I downloaded MP3 files from Amazon and added one of them to a slide ... I can right click on the speaker and select Play Sound and the MP3 file ...
    (microsoft.public.powerpoint)
  • Re: problems getting mp3 files to play
    ... I downloaded MP3 files from Amazon and added one of them to a slide using ... I can right click on the speaker and select Play Sound and the MP3 file ...
    (microsoft.public.powerpoint)
  • Re: .wav to .mp3 ACM Conversion
    ... My code converts to mp3 file with the following ... the expected sound output. ... drivers by changing priorities 4rm device manager. ...
    (microsoft.public.win32.programmer.mmedia)
  • RE: problems getting mp3 files to play
    ... Put both the ppt and mp3 into the folder. ... I can right click on the speaker and select Play Sound and the MP3 file plays ...
    (microsoft.public.powerpoint)