📄 wma.c
字号:
//****************************************************************************//// WMA.C - Codec interface driver for the MSAudio decoder.//// Copyright (c) 1999,2000,2001 Cirrus Logic, Inc.////****************************************************************************#include "globals.h"#ifdef SUPPORT_WMA#include "wma/include/WMA_DEC_EMB_ARM.h"#include "buffer/buffer.h"#include "src/src.h"//****************************************************************************//// The name of this codec.////****************************************************************************static const unsigned short pusCodecName[] ={ 'W', 'M', 'A', ' ', 'W', 'i', 'n', 'd', 'o', 'w', 's', ' ', 'M', 'e', 'd', 'i', 'a', '(', 't', 'm', ')', ' ', 'A', 'u', 'd', 'i', 'o', '\0'};//****************************************************************************//// The GUID of the security chunk in a DRM protected file.////****************************************************************************static const unsigned char pucSecurityGUID[16] ={ 0xfb, 0xb3, 0x11, 0x22, 0x23, 0xbd, 0xd2, 0x11, 0xb4, 0xb7, 0x00, 0xa0, 0xc9, 0x55, 0xfc, 0x6e};//****************************************************************************//// The size of the output buffer that will be used.////****************************************************************************#define WMA_MAX_PCM_LENGTH 1536//****************************************************************************//// A structure which defines the persistent state of the WMA decoder.////****************************************************************************typedef struct{ // // The persistent internal state of the WMA decoder library. This must be // the first member of this structure. // tWMAFileState sWMAState; // // The file from which we read data. // tFile *pFile; // // A buffer to contain the WMA file contents // unsigned char pucWMAData[1024]; // // The offset of the data currently in the pucWMAData buffer. // tWMA_U32 dwOffset; // // The length of the data currently in the pucWMAData buffer. // tWMA_U32 dwLength; // // Buffers to contain the decoded WMA audio. // short psLeft[WMA_MAX_PCM_LENGTH + NUMTAPS - 1]; short psRight[WMA_MAX_PCM_LENGTH + NUMTAPS - 1]; // // The buffer to which we write decoded WMA audio. // BufferState *pOutput; // // The number of samples that have been played. // tWMA_U32 dwTimePos; // // The sample rate of the decoded PCM data. // tWMA_U32 dwSampleRate; // // The file header information structure. // tWMAFileHeader sWMAHeader; // // The file content descriptor structure. // tWMAFileContDesc sWMADesc; // // A buffer to contain the song title. // unsigned short pusTitle[64]; // // A buffer to contain the song author. // unsigned short pusAuthor[64]; // // A boolean that is true when there is more PCM data to be decoded for // the current WMA frame. // tWMA_U32 bMorePCMToGenerate;} tWMA;//****************************************************************************//// WMADebugMessage is called by the WMA decoder to display a human readable// error message intended for the developer, not the end user.////****************************************************************************voidWMADebugMessage(const char *pszFmt, ...){ // // Do nothing. //}//****************************************************************************//// Microsoft insists upon releasing debug versions of their code...////****************************************************************************void__assert(void){ // // Do nothing. //}//****************************************************************************//// Microsoft can't figure out how to #ifdef out the calls the malloc that the// embedded version of the WMA library never makes since it never takes those// code paths.////****************************************************************************void *malloc(void){ // // Return a NULL pointer, since we do not support memory allocation. This // is making a bold assumption that Microsoft actually checks the returned // value... // return(0);}//****************************************************************************//// WMAFileCBGetLicenseData is called by the WMA decoder when it needs to read// more bytes from the license file.////****************************************************************************tWMA_U32WMAFileCBGetLicenseData(tWMAFileState *psState, tWMA_U32 dwOffset, tWMA_U32 dwNumBytes, unsigned char **ppData){ // // We don't support a separate license file, so return zero bytes. // return(0);}//****************************************************************************//// WMAFileCBGetData is called by the WMA decoder when it needs to read more// data for decoding the file.////****************************************************************************tWMA_U32WMAFileCBGetData(tWMAFileState *psState, tWMA_U32 dwOffset, tWMA_U32 dwNumBytes, unsigned char **ppData){ tWMA *pWMA; tWMA_U32 dwIndex; // // Get a pointer to the persistent state structure. // pWMA = (tWMA *)psState; // // Make sure that the requested read is not for too many bytes. // if(dwNumBytes > WMA_MAX_DATA_REQUESTED) { return(0); } // // Determine if the requested data already exists in the buffer. // if((dwOffset >= pWMA->dwOffset) && ((dwOffset + dwNumBytes) < (pWMA->dwOffset + pWMA->dwLength))) { // // The requested data already exists in the buffer, so do not read it // from the file system. // *ppData = pWMA->pucWMAData + (dwOffset - pWMA->dwOffset); // // Return the number of bytes "read". // return(dwNumBytes); } // // Return the offset into the buffer of the requested byte of file data. // This could be non-zero since we only read on 512 byte boundaries from // the filesystem. // dwIndex = dwOffset & 0x1ff; // // Return a pointer to the buffer containing the newly read file data. // *ppData = pWMA->pucWMAData + dwIndex; // // Seek to the 512 byte boundary in the file before the requested file // position. // FSSeek(pWMA->pFile, dwOffset & ~0x1ff); // // Read the requested number of bytes from the file. // FSRead(pWMA->pFile, pWMA->pucWMAData, (dwNumBytes + dwIndex + 511) & ~0x1ff); // // Keep track of the portion of the file that is currently in the buffer. // pWMA->dwOffset = dwOffset & ~0x1ff; pWMA->dwLength = (dwNumBytes + dwIndex + 511) & ~0x1ff; // // Return the number of bytes read (i.e. requested). // return(dwNumBytes);}//****************************************************************************//// The codec plug-in entry point for the WMA decoder.////****************************************************************************unsigned longWMAIoctl(unsigned long ulIoctl, unsigned long ulParam1, unsigned long ulParam2, unsigned long ulParam3, unsigned long ulParam4){ // // Determine what to do based on the specified IOCTL. // switch(ulIoctl) { // // Return the name for this codec. // case IOCTL_CODEC_GETNAME: { const unsigned short **ppusName; // // The secod parameter is a pointer for the name. // ppusName = (const unsigned short **)ulParam2; // // Return the name of this codec. The first four characters are // the short name and the string starting at the fifth character // is the long name. // *ppusName = pusCodecName; // // Success. // return(1); } // // Return the name of the artist. // case IOCTL_CODEC_GETARTIST: { unsigned short **ppusName; tWMA *pWMA; // // The first parameter is a pointer to the WMA persistent data. // pWMA = (tWMA *)ulParam1; // // The second parameter is a pointer for the name. // ppusName = (unsigned short **)ulParam2; // // Return the name of the artist. // *ppusName = pWMA->pusAuthor; // // Success. // return(1); } // // Return the name of the song // case IOCTL_CODEC_GETTITLE: { unsigned short **ppusName; tWMA *pWMA; // // The first parameter is a pointer to the WMA persistent data. // pWMA = (tWMA *)ulParam1; // // The second parameter is a pointer for the name. // ppusName = (unsigned short **)ulParam2; // // Return the name of the song. // *ppusName = pWMA->pusTitle; // // Success. // return(1); } // // Return the bitrate at which this file is encoded. // case IOCTL_CODEC_GETBITRATE: { unsigned long *pulBitRate; tWMA *pWMA; // // The first parameter is a pointer to the WMA persistent data. // pWMA = (tWMA *)ulParam1; // // The second parameter is a pointer for the bitrate. // pulBitRate = (unsigned long *)ulParam2; // // Return the average bitrate of the file. // *pulBitRate = pWMA->sWMAHeader.bitrate; // // Success. // return(1); } // // Return the sample rate at which this file is encoded. // case IOCTL_CODEC_GETSAMPLERATE: { unsigned long *pulSampleRate; tWMA *pWMA; // // The first parameter is a pointer to the WMA persistent data. // pWMA = (tWMA *)ulParam1; // // The second parameter is a pointer for the sample rate. // pulSampleRate = (unsigned long *)ulParam2; // // Return the sample rate of the file. // *pulSampleRate = pWMA->dwSampleRate; // // Success. // return(1); } // // Return the number of channels in the file. // case IOCTL_CODEC_GETCHANNELS: { unsigned long *pulChannels; tWMA *pWMA; // // The first parameter is a pointer to the WMA persistent data. // pWMA = (tWMA *)ulParam1; // // The second parameter is a pointer for the number of channels. // pulChannels = (unsigned long *)ulParam2; // // Return the number of channels in the file. // *pulChannels = pWMA->sWMAHeader.num_channels; // // Success. // return(1); } // // Return the length (in milliseconds) of the file. // case IOCTL_CODEC_GETLENGTH: { unsigned long *pulLength; tWMA *pWMA; // // The first parameter is a pointer to the WMA persistent data. // pWMA = (tWMA *)ulParam1; // // The second parameter is a pointer for the number of // milliseconds. // pulLength = (unsigned long *)ulParam2; // // Return the length of the file. // *pulLength = pWMA->sWMAHeader.duration; // // Success. // return(1); } // // Return the current position (in milliseconds) within the file. // case IOCTL_CODEC_GETTIME: { unsigned long *pulTime; tWMA *pWMA; // // The first parameter is a pointer to the WMA persistent data. // pWMA = (tWMA *)ulParam1; // // The second parameter is a pointer for the number of // milliseconds. // pulTime = (unsigned long *)ulParam2; // // Determine the time based on the sample rate.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -