Click here to Skip to main content
15,886,199 members
Articles / Desktop Programming / MFC

MPEG Audio Frame Header

Rate me:
Please Sign up or sign in to vote.
4.89/5 (95 votes)
12 Apr 2007LGPL317 min read 896.7K   20.8K   245  
An article about the MPEG audio frame header.
#pragma once

// for XING VBR Header flags
#define FRAMES_FLAG     0x0001
#define BYTES_FLAG      0x0002
#define TOC_FLAG        0x0004
#define VBR_SCALE_FLAG  0x0008

class CMPAFile;

class CVBRHeader
{
public:
	enum VBRHeaderType
	{
		NoHeader,
		XINGHeader,
		VBRIHeader
	};

	CVBRHeader( CMPAFile* pMPAFile, VBRHeaderType HeaderType, DWORD dwOffset );
	~CVBRHeader(void);

	static bool IsVBRHeaderAvailable( CMPAFile* pMPAFile, VBRHeaderType& HeaderType, DWORD& dwOffset );
	bool SeekPoint(float fPercent, DWORD& dwSeekPoint);

	DWORD m_dwBytesPerSec;
	DWORD m_dwBytes;		// total number of bytes
	DWORD m_dwFrames;		// total number of frames

private:
	static DWORD m_dwXINGOffsets[2][2];

	static bool CheckID( CMPAFile* pMPAFile, char ch0, char ch1, char ch2, char ch3, DWORD& dwOffset );
	static bool CheckXING( CMPAFile* pMPAFile, DWORD& dwOffset );
	static bool CheckVBRI( CMPAFile* pMPAFile, DWORD& dwOffset );

	bool ExtractLAMETag( DWORD dwOffset );
	bool ExtractXINGHeader( DWORD dwOffset );	
	bool ExtractVBRIHeader( DWORD dwOffset );

	DWORD SeekPointXING(float fPercent)const ;
	DWORD SeekPointVBRI(float fPercent) const;
	DWORD SeekPointByTimeVBRI(float fEntryTimeMS) const;

	CMPAFile* m_pMPAFile;
public:	
	VBRHeaderType m_HeaderType;
	DWORD m_dwOffset;
	DWORD m_dwQuality;	// quality (0..100)
	int* m_pnToc;				// TOC points for seeking (must be freed)
	DWORD m_dwTableSize;	// size of table (number of entries)	

	// only VBRI
	float m_fDelay;	
	DWORD m_dwTableScale;	// for seeking
	DWORD m_dwBytesPerEntry;
    DWORD m_dwFramesPerEntry;
	DWORD m_dwVersion;
};

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 GNU Lesser General Public License (LGPLv3)


Written By
Web Developer
Germany Germany
Author of the shareware WinCD.

Comments and Discussions