⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 thefile.h

📁 完整的MP3播放器源码
💻 H
字号:
// TheFIle.h : Declaration of the CTheFIle
//
///////////////////////////////////////////////////////////////////////////////
#ifndef __THEFILE_H_
#define __THEFILE_H_

#include "resource.h"       // main symbols

///////////////////////////////////////////////////////////////////////////////
#define BF_SIZE	2048
///////////////////////////////////////////////////////////////////////////////
enum EVERSION	{ MPEG2_LSF, MPEG1 };
enum E_MODE		{ ST, JST, DUAL, MONO };
enum E_SMPLFREQ { E44100, E48000, E32000 };




/////////////////////////////////////////////////////////////////////////////
// CTheFIle
class CTheFIle
{
public:
    CTheFIle():m_file(0),m_nFrameLen(0),m_nSlots(0),
		m_psHDR(reinterpret_cast<SHDR_INFO*>(&m_HdrSignature)),
		m_pdwWalk(0),
		m_pbyWalk(0),
		m_nBitsOffset(0),
		m_HdrSignature(0),
		m_dwSinc(0),
		m_bytesRead(0),
		m_nSubBands(0),
		m_intStereoBound(0),
		m_nReades(0),
		m_offsetBytes(0),
		m_bSingleChMode(0),
		m_bCanRead(0),
        m_crcSum(0xFFFF),m_firstFrame(0),m_filePtr(0)
	{
		
	}

	~CTheFIle()
	{
	    CloseHandle(m_file);
	    m_file = 0;
	}

// ITheFIle
public:
	BOOL	Open(LPCSTR fileName);
	BYTE*	GetFrame(DWORD* pnBytes,
                    DWORD* version,
                    DWORD* mode,
                    DWORD* modeEx,
                    DWORD* frqIdx);
	DWORD	GetBits(int nBits);
	DWORD	GetRealNrOfFrames();
	DWORD	GetFrameLength();
	DWORD	GetLength();
	DWORD	Goto(DWORD newPos);
	DWORD	GetDuration();
	DWORD	GetMilisecPerFrame();
	DWORD	GetTimePerFrame();
	DWORD	GetIntensityStereoBounds();
	DWORD	GetSubBands();
	DWORD	GetFrequency();
	DWORD	GetMode();
	DWORD	GetLayer();
	DWORD	GetVersion();
	DWORD	GetFreqIndex();
	DWORD	GetModeExtension();
	DWORD	GetSlots();
    DWORD   GetSpeed();
	void	Close();

	void	GetFrames(DWORD* minFrm,
                    DWORD* maxFrrm);

		inline DWORD		GetMinFrames() const
	{
        DWORD dwl = 0;
        long length =  GetFileSize(m_file,&dwl);
        long frmLen = m_nFrameLen + 5 - m_psHDR->padding;
        return(length /frmLen);
    }

    DWORD		m_filePtr;	
private:
	void Reset();
	inline int ReadNewFrame()
	{
		DWORD nBytes = 0;
		ReadFile(m_file,m_pBuffer,sizeof(m_pBuffer),&nBytes,0);
		if(nBytes == 0)
		{
			m_nReades = 0;
		}
		else
		{
			//
			//	get 2 pointers on of DWORDS one of bytes at the start of buffer
			//
			m_pdwWalk		= (DWORD*)m_pBuffer;
			m_pbyWalk		=         m_pBuffer;
			m_offsetBytes	= 0;
			m_bCanRead		= FALSE; 
			m_filePtr		+=nBytes;
		}
		return nBytes;
	}

    inline void  AddBits (DWORD bitstring, int length)
    {
		int bitmask = 1 << (length - 1);
		do{
			if (!(m_crcSum & 0x8000) ^ !(bitstring & bitmask))
			{
				m_crcSum <<= 1;
				m_crcSum ^= 0x8005;
			}
			else
				m_crcSum <<= 1;
		}while (bitmask >>= 1);
	}
		 // feed a bitstring to the m_crcSum calculation (0 < length <= 32)
    inline WORD	CheckSum()
    {
        WORD sum = m_crcSum;
        m_crcSum = 0xFFFF;
        return sum;
    }

    //
	BOOL		ParseFileAttributes(int nReads); 
	int			ComputeFrameSize();
	
    inline DWORD		GetMaxFrames() const
	{
        DWORD dwl = 0;
        long length =  GetFileSize(m_file,&dwl);
        long frmLen = m_nFrameLen + 4 - m_psHDR->padding;
        return(length /frmLen);
    }
	
//  Marius C
   	typedef struct
	{
		UINT		notUsed			:1;	//0
		UINT		bOriginal		:1;	//1
		UINT		bCopyRight		:1;	//2
		UINT		notUsed2		:1; //3
		UINT		modeExt			:2; //4..5
		UINT		eMode			:2; //6 7
		UINT		notUsed3		:1;	//8
		UINT		padding			:1; //9
		UINT		eFreq			:2; //10 11 
		UINT		bitRateIdx		:4; //12 13 14 15
		UINT		protect			:1; //16
		UINT		LayerNo			:2; //17 18
		UINT		eVersion		:1; //19
		UINT		restOfB			:11; //20 32
	}SHDR_INFO;

    HANDLE				m_file;
	DWORD*		m_pdwWalk;
	BYTE*		m_pbyWalk;
	BYTE		m_pBuffer[BF_SIZE];
	DWORD		m_nBitsOffset;	
    int			m_frmStartOffset;
	
	//  Marius C
	DWORD		m_HdrSignature;
	SHDR_INFO*  const 	m_psHDR;				
	
	
	DWORD		m_dwSinc;
	DWORD		m_bytesRead;
	int			m_nSubBands;
	int			m_intStereoBound;
	int			m_nFrameLen;
	int			m_nSlots;
	int			m_nReades;
	int			m_offsetBytes;
	BOOL		m_bSingleChMode;
	BOOL		m_bCanRead;	
    WORD        m_crcSum;
/// data tables
	int			m_firstFrame ;
    BOOL        m_closeIt;
	BOOL		m_maby;
	

};


#endif //__THEFILE_H_

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -