Re: Playing an MP3 file using WaveOut functions
- From: "Alessandro Angeli [MVP::DS/MF]" <nobody@xxxxxxxxxxxxxxxxxx>
- Date: Tue, 10 Oct 2006 01:13:20 +0200
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
.
- Follow-Ups:
- Re: Playing an MP3 file using WaveOut functions
- From: Punit Kaur
- Re: Playing an MP3 file using WaveOut functions
- From: Punit Kaur
- Re: Playing an MP3 file using WaveOut functions
- Prev by Date: Re: What simple open-source audio library do you recommend?
- Next by Date: Re: Trouble with asf reader output pin configuration
- Previous by thread: Re: Selecting Audio Default Device, using winapi
- Next by thread: Re: Playing an MP3 file using WaveOut functions
- Index(es):
Relevant Pages
|