|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
|
Announcements
Chapters
Services
Feature Zones
|
IntroductionThis article explains how to use the DirectShow API for simple audio conversion, particularly Wav to MP3 conversion. Audio codecs in the DirectShow API are of three type : native codecs, ACM codecs, and DMO (DirectX Media Object) codecs. There are only few audio native codecs for audio compression. For MP3
encoding, the only one that I've found is the LAME
DirectShow wrapper from Elecard. Most MP3 encoders are in the ACM (Audio
Compression Manager) format, wich was introduced with the Windows Multimedia
API. The GraphBuilder and other filters
The graph consist of five filters:
Important noteThe WAV Dest filter is not included in standard filters, but need to be compiled from the DirectX SDK (SDK_root\Samples\Multimedia\DirectShow\Filters\WavDest). For convenience, the compiled WAV Dest filter is included in the demo zip, but you have to register it by RegSrv32 wavdest.ax. ACM codecs and the ACM Wrapper filterAll of the ACM codecs are listed in DirectShow in the Audio Compressors
Filter Category ( Note : Depending of your configuration, several ACM codecs for a same format can be installed on your computer. This can be the case for MP3 codecs. You set priority or deactivate some of them by the use of control panel, as show in the following figure.
The DeviceEnumerator or how to browse ACM codecsThe Device Enumerator must be used to retrieve an instance of an ACM codec.
It returns the codecs list by the Configuring the ACM codec with IAMStreamConfig interfaceOnce the desired codec is instantiated, we can obtain an
Note : For some codecs (including MP3), the call to
The classesCDSEncoder
class CDSEncoder : public CArray<CDSCodec*, CDSCodec*> { public: void BuildGraph(CString szSrcFileName, CString szDestFileName, int nCodec, int nFormat); CDSEncoder(); virtual ~CDSEncoder(); protected: void BuildCodecArray(); HRESULT AddFilterByClsid(IGraphBuilder *pGraph, LPCWSTR wszName, const GUID& clsid, IBaseFilter **ppF); BOOL SetFilterFormat(AM_MEDIA_TYPE* pStreamFormat, IBaseFilter* pBaseFilter); IGraphBuilder *m_pGraphBuilder; }; As CDSCodec
class CDSCodec : public CArray<CDSCodecFormat*, CDSCodecFormat*> { public: CDSCodec(); virtual ~CDSCodec(); CString m_szCodecName; IMoniker *m_pMoniker; void BuildCodecFormatArray(); }; As CDSCodecFormat
class CDSCodecFormat { public: WORD BitsPerSample(); DWORD BytesPerSec(); DWORD SamplesPerSecond(); WORD NumberOfChannels(); CDSCodecFormat(); virtual ~CDSCodecFormat(); public: AM_MEDIA_TYPE* m_pMediaType; }; Known issuesErrors CheckingThe article goal is to demonstrate the use of DirectShow for simple audio conversion. These classes are not as safe as they have to be. Please keep this in mind if you plan to use it in a production environment. Source Wav formatThere are no sampling conversion, so you can only generate 44 kHz output files if you use 44 kHz Wav. Windows MediaWindows Media format can be used only with a certificate that can be obtained by the Windows Media SDK from Microsoft.
|
||||||||||||||||||||||