Click here to Skip to main content
15,891,708 members
Articles / Desktop Programming / MFC

Converting Wav file to MP3 or other format using DirectShow

Rate me:
Please Sign up or sign in to vote.
4.84/5 (49 votes)
30 Jul 2002CPOL3 min read 701.5K   22.2K   188  
Simple class to convert stereo 44 kHz, 16 bit wav file to another format, including MP3. The class shows how to use DirectShow API for audio conversion.
// DSEncoder.h: interface for the CDSEncoder class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_DSENCODER_H__598FE0B2_9419_4E96_A5A9_FDF6E6480EBF__INCLUDED_)
#define AFX_DSENCODER_H__598FE0B2_9419_4E96_A5A9_FDF6E6480EBF__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include "dshow.h"
#include "DSCodec.h"

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;
};

#endif // !defined(AFX_DSENCODER_H__598FE0B2_9419_4E96_A5A9_FDF6E6480EBF__INCLUDED_)

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) G. LABOURE
France France
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions