?? g721.c
字號:
//****************************************************************************//// G721.C - Codec interface driver for the G.721 encoder/decoder.//// Copyright (c) 1999,2000,2001 Cirrus Logic, Inc.////****************************************************************************#include "globals.h"#ifdef SUPPORT_G721#include "adpcm/g72x.h"#include "buffer/buffer.h"#include "src/src.h"//****************************************************************************//// The name of this codec.////****************************************************************************static const unsigned short pusCodecName[] ={ 'G', '7', '2', '1', 'G', '.', '7', '2', '1', ' ', 'A', 'D', 'P', 'C', 'M', '\0'};//****************************************************************************//// A structure which defines the persistent state of the G.721 encoder/// decoder.////****************************************************************************typedef struct{ // // The file from which we read data when decoding or to which we write data // when encoding. // tFile *pFile; // // The buffer which holds the encoded G.721 audio. // char pcEncodedData[512 + 128]; // // The buffer which holds the 8000Hz PCM audio stream. // short psSRCData[512 + NUMTAPS - 1]; // // The buffer which holds the 44100Hz PCM audio stream when encoding. // short psRawData[4096 + NUMTAPS - 1]; // // The persistent state of the G.721 encoder/decoder. // struct g72x_state sG721; // // The buffer from which we read the PCM audio stream when encoding or to // which we write the PCM audio stream when decoding. // BufferState *pBuffer; // // The length of the encoded G.721 file. // unsigned long ulLength; // // The number of bytes in pcEncodedData which contain valid encoded // G.721 audio. // unsigned short usValid; // // The offset into pcEncodedData of the next G.721 sample to be processed. // unsigned short usOffset; // // The length of the file in milliseconds. // unsigned long ulTimeLength; // // The number of G.721 samples that have been processed, either decoded and // played via the DAI interface or recorded via the DAI interface and // encoded. // unsigned long ulTimePos; // // The current offset into the G.721 file, indicating the number of // bytes which have been read from the file into the encoded data buffer. // unsigned long ulFilePos;} tG721;//****************************************************************************//// The codec plug-in entry point for the G.721 encoder/decoder.////****************************************************************************unsigned longG721Ioctl(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; // // The second parameter is a pointer for the name. // ppusName = (unsigned short **)ulParam2; // // There is no way to store the artist name in a G.721 file. // *ppusName = 0; // // Success. // return(1); } // // Return the name of the song // case IOCTL_CODEC_GETTITLE: { unsigned short **ppusName; // // The second parameter is a pointer for the name. // ppusName = (unsigned short **)ulParam2; // // There is no way to store the song title in a G.721 file. // *ppusName = 0; // // Success. // return(1); } // // Return the bitrate at which this file is encoded. // case IOCTL_CODEC_GETBITRATE: { unsigned long *pulBitRate; // // The second parameter is a pointer for the bitrate. // pulBitRate = (unsigned long *)ulParam2; // // The bitrate of G.721 is 32kbps. // *pulBitRate = 32000; // // Success. // return(1); } // // Return the sample rate at which this file is encoded. // case IOCTL_CODEC_GETSAMPLERATE: { unsigned long *pulSampleRate; // // The second parameter is a pointer for the sample rate. // pulSampleRate = (unsigned long *)ulParam2; // // The sample rate of this G.721 codec is 8kHz. // *pulSampleRate = 8000; // // Success. // return(1); } // // Return the number of channels in the file. // case IOCTL_CODEC_GETCHANNELS: { unsigned long *pulChannels; // // The second parameter is a pointer for the number of channels. // pulChannels = (unsigned long *)ulParam2; // // The file contains only a single channel. // *pulChannels = 1; // // Success. // return(1); } // // Return the length (in milliseconds) of the file. // case IOCTL_CODEC_GETLENGTH: { unsigned long *pulLength; tG721 *pG721; // // The first parameter is a pointer ot the G.721 persistent data. // pG721 = (tG721 *)ulParam1; // // The second parameter is a pointer for the number of // milliseconds. // pulLength = (unsigned long *)ulParam2; // // Return the length of the file. // *pulLength = pG721->ulTimeLength; // // Success. // return(1); } // // Return the current position (in milliseconds) within the file. // case IOCTL_CODEC_GETTIME: { unsigned long *pulTime; tG721 *pG721; // // The first parameter is a pointer to the G.721 persistent data. // pG721 = (tG721 *)ulParam1; // // The second parameter is a pointer for the number of // milliseconds. // pulTime = (unsigned long *)ulParam2; // // Determine the time based on the sample rate. // *pulTime = pG721->ulTimePos / 8; // // Success. // return(1); } // // Determine if the given file can be decoded. // case IOCTL_CODEC_QUERY: { tFile *pFile; unsigned char *pucScratch; // // The second parameter is the file to be checked. // pFile = (tFile *)ulParam2; // // The third parameters is a 512 byte scratch buffer. // pucScratch = (unsigned char *)ulParam3; // // Read the first 512 bytes from the file. // FSRead(pFile, pucScratch, 512); // // Make sure that the first four bytes of the file are "G721". // if((pucScratch[0] != 'G') || (pucScratch[1] != '7') || (pucScratch[2] != '2') || (pucScratch[3] != '1')) { return(0); } // // We can decode this file. // return(1); } // // Prepare the codec to encode or decode a file. // case IOCTL_CODEC_OPEN: { tG721 *pG721; // // The first parameter is a pointer to the G.721 persistent state. // pG721 = (tG721 *)ulParam1; // // Make sure that we have enough memory for this decoder. // if(((unsigned long)pG721 + sizeof(tG721)) > ulExtentOfRAM) { return(0); } // // Initialize the G.721 decoder. // g72x_init_state(&(pG721->sG721)); // // Save the pointer to the file structure. // pG721->pFile = (tFile *)ulParam4; // // See if we should encode or decode. // if(ulParam3 & CODEC_OPEN_ENCODE) { // // The first four bytes of the file are "G721" to indicate that // this is a G.721 file. // pG721->pcEncodedData[0] = 'G'; pG721->pcEncodedData[1] = '7'; pG721->pcEncodedData[2] = '2'; pG721->pcEncodedData[3] = '1'; // // There are four bytes in the output buffer. // pG721->usValid = 4; // // The initial time position and length is zero. // pG721->ulTimePos = pG721->ulTimeLength = 0; // // The first write in the file will occur at position 0. // pG721->ulFilePos = 0; // // The initial length of the file is zero. // pG721->ulLength = 0; } else { // // Read the first page of the file. // FSRead(pG721->pFile, pG721->pcEncodedData, 512); // // Make sure that the first four bytes of the file are "G721". // if((pG721->pcEncodedData[0] != 'G') || (pG721->pcEncodedData[1] != '7') || (pG721->pcEncodedData[2] != '2') || (pG721->pcEncodedData[3] != '1')) { return(0); } // // Since we've just read the first page of the file, the next // read will occur at location 512 into the file. // pG721->ulFilePos = 512; // // Get the length of the G.721 file. // pG721->ulLength = FSLength(pG721->pFile); // // Initially, the 512 bytes previously read into the buffer are // valid. // pG721->usValid = 512; // // Make sure the file position and the valid data size are less // than the file length. // if(pG721->ulFilePos > pG721->ulLength) { pG721->ulFilePos = pG721->ulLength; pG721->usValid = pG721->ulLength; }
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -