Click here to Skip to main content
15,886,833 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.9K   20.8K   245  
An article about the MPEG audio frame header.
#include "StdAfx.h"
#include ".\apetag.h"

CAPETag* CAPETag::FindTag(CMPAStream* pStream, bool bAppended, DWORD dwBegin, DWORD dwEnd)
{
	DWORD dwOffset;

	if (!bAppended)
	{
		// stands at the beginning of file (complete header is 32 bytes)
		dwOffset = dwBegin;
	}
	else
	{
		// stands at the end of the file (complete footer is 32 bytes)
		dwOffset = dwEnd - 32;		
	}
	BYTE* pBuffer = pStream->ReadBytes(8, dwOffset, false);

	if (memcmp("APETAGEX", pBuffer, 8) == 0)
		return new CAPETag(pStream, bAppended, dwOffset);
	return NULL;
}

CAPETag::CAPETag(CMPAStream* pStream, bool bAppended, DWORD dwOffset) :
	CTag(pStream, _T("APE"), bAppended, dwOffset)
{
	dwOffset += 8;
	DWORD dwVersion = pStream->ReadLEValue(4, dwOffset);
	
	// first byte is version number
	m_fVersion = dwVersion/1000.0f;
	
	// get size
	m_dwSize = pStream->ReadLEValue(4, dwOffset);

	/*DWORD dwNumItems = */pStream->ReadLEValue(4, dwOffset);

	// only valid for version 2
	DWORD dwFlags = pStream->ReadLEValue(4, dwOffset);
	bool bHeader, bFooter;
	if (m_fVersion > 1.0f)
	{
		bHeader = dwFlags >> 31 & 0x1;
		bFooter = dwFlags >> 30 & 0x1;
	}
	else
	{
		bHeader = false;
		bFooter = true;
	}

	if (bHeader)
		m_dwSize += 32;	// add header

	if (bAppended)
		m_dwOffset -= (m_dwSize - 32);
}

CAPETag::~CAPETag(void)
{
}

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