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

📄 acelpnet.c

📁 基于EP7312的MP3播放器源代码,包括MCU和PC端代码.
💻 C
📖 第 1 页 / 共 3 页
字号:
        // Return the number of channels in the file.        //        case IOCTL_CODEC_GETCHANNELS:        {            unsigned long *pulChannels;            tANET *pANET;            //            // The first parameter is a pointer to the ACELP.net persistent            // data.            //            pANET = (tANET *)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 = 1;            //            // Success.            //            return(1);        }        //        // Return the length (in milliseconds) of the output file.        //        case IOCTL_CODEC_GETLENGTH:        {            unsigned long *pulLength;            tANET *pANET;            //            // The first parameter is a pointer to the ACELP.net persistent            // data.            //            pANET = (tANET *)ulParam1;            //            // The second parameter is a pointer for the number of            // milliseconds.            //            pulLength = (unsigned long *)ulParam2;            //            // Return the length of the file.            //            *pulLength = pANET->ulTimeLength;            //            // Success.            //            return(1);        }        //        // Return the current position (in milliseconds) within the file.        //        case IOCTL_CODEC_GETTIME:        {            unsigned long *pulTime;            tANET *pANET;            //            // The first parameter is a pointer to the ACELP.net persistent            // data.            //            pANET = (tANET *)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 = pANET->ulTimePos / (pANET->usSampleRate / 1000);            //            // 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 "RIFF".            //            if((pucScratch[0] != 'R') || (pucScratch[1] != 'I') ||               (pucScratch[2] != 'F') || (pucScratch[3] != 'F'))            {                return(0);            }            //            // Make sure that the the third set of four bytes of the file are            // "WAVE".            //            if((pucScratch[8] != 'W') || (pucScratch[9] != 'A') ||               (pucScratch[10] != 'V') || (pucScratch[11] != 'E'))            {                return(0);            }            //            // Make sure that the first chunk of the file is the "fmt " chunk.            //            if((pucScratch[12] != 'f') || (pucScratch[13] != 'm') ||               (pucScratch[14] != 't') || (pucScratch[15] != ' '))            {                return(0);            }            //            // Make sure that the format of the file is ACELP.net.            //            if((pucScratch[20] != 0x30) || (pucScratch[21] != 0x01))            {                return(0);            }            //            // Make sure that the "data" chunk starts where we expect it to.            //            if((pucScratch[54] != 'd') || (pucScratch[55] != 'a') ||               (pucScratch[56] != 't') || (pucScratch[57] != 'a'))            {                return(0);            }            //            // Get the bit rate from the RIFF header.            //            switch(pucScratch[38])            {                //                // The bitrate is 5kbps.                //#ifdef SUPPORT_ACELPNET_5K0                case ACELPNET_5K0:                {                    //                    // We can decode this file.                    //                    return(1);                }#endif                //                // The bitrate is 6.5kbps.                //#ifdef SUPPORT_ACELPNET_6K5                case ACELPNET_6K5:                {                    //                    // We can decode this file.                    //                    return(1);                }#endif                //                // The bitrate is 8.5kbps.                //#ifdef SUPPORT_ACELPNET_8K5                case ACELPNET_8K5:                {                    //                    // We can decode this file.                    //                    return(1);                }#endif                //                // The bitrate is 16kbps.                //#ifdef SUPPORT_ACELPNET_16K0                case ACELPNET_16K0:                {                    //                    // We can decode this file.                    //                    return(1);                }#endif                //                // This is an unknown bitrate, so return an error.                //                default:                {                    return(0);                }            }        }        //        // Prepare the codec to encode or decode a file.        //        case IOCTL_CODEC_OPEN:        {            tANET *pANET;            //            // If we are being asked to encode an ACELP.net file, then return a            // failure since we can only decode ACELP.net.            //            if(ulParam3 & CODEC_OPEN_ENCODE)            {                return(0);            }            //            // The first parameter is a pointer to the ACELP.net persistent            // state.            //            pANET = (tANET *)ulParam1;            //            // Make sure that we have enough memory for this decoder.            //            if((ulParam1 + sizeof(tANET)) > ulExtentOfRAM)            {                return(0);            }            //            // Save the pointer to the file structure.            //            pANET->pFile = (tFile *)ulParam4;            //            // Read the first page of the file.            //            FSRead(pANET->pFile, pANET->pcEncodedData, 512);            //            // Make sure that the first four bytes of the file are "RIFF".            //            if((pANET->pcEncodedData[0] != 'R') ||               (pANET->pcEncodedData[1] != 'I') ||               (pANET->pcEncodedData[2] != 'F') ||               (pANET->pcEncodedData[3] != 'F'))            {                return(0);            }            //            // Make sure that the the third set of four bytes of the file are            // "WAVE".            //            if((pANET->pcEncodedData[8] != 'W') ||               (pANET->pcEncodedData[9] != 'A') ||               (pANET->pcEncodedData[10] != 'V') ||               (pANET->pcEncodedData[11] != 'E'))            {                return(0);            }            //            // Make sure that the first chunk of the file is the "fmt " chunk.            //            if((pANET->pcEncodedData[12] != 'f') ||               (pANET->pcEncodedData[13] != 'm') ||               (pANET->pcEncodedData[14] != 't') ||               (pANET->pcEncodedData[15] != ' '))            {                return(0);            }            //            // Make sure that the format of the file is ACELP.net.            //            if((pANET->pcEncodedData[20] != 0x30) ||               (pANET->pcEncodedData[21] != 0x01))            {                return(0);            }            //            // Make sure that the "data" chunk starts where we expect it to.            //            if((pANET->pcEncodedData[54] != 'd') ||               (pANET->pcEncodedData[55] != 'a') ||               (pANET->pcEncodedData[56] != 't') ||               (pANET->pcEncodedData[57] != 'a'))            {                return(0);            }            //            // Since we've just read the first page of the file, the next read            // will occur at location 512 into the file.            //            pANET->ulFilePos = 512;            //            // Get the length of the ACELP.net file.            //            pANET->ulLength = FSLength(pANET->pFile);            //            // Initially, the 512 bytes previously read into the buffer are            // valid.            //            pANET->usValid = 512;            //            // Make sure the file position and the valid data size are less            // than the file length.            //            if(pANET->ulFilePos > pANET->ulLength)            {                pANET->ulFilePos = pANET->ulLength;                pANET->usValid = pANET->ulLength;            }            //            // The initial time position is zero.            //            pANET->ulTimePos = 0;            //            // Start play from the sixth-second byte of the buffer.            //            pANET->usOffset = 62;            //            // Get the bit rate from the RIFF header.            //            switch(pANET->pcEncodedData[38])            {                //                // The bitrate is 5kbps.                //#ifdef SUPPORT_ACELPNET_5K0                case ACELPNET_5K0:                {                    //                    // Remember the bitrate of the file.                    //                    pANET->usBitRate = 4933;                    //                    // Remember the sample rate of the file.                    //                    pANET->usSampleRate = 8000;                    //                    // Remember the number of samples per frame.                    //                    pANET->usSamplesPerFrame = L_FRAME_5K0;                    //                    // Compute the length of the file in milliseconds.                    //                    pANET->ulTimeLength = (((pANET->ulLength - 62) /                                            BLOCK_ALIGNMENT_5K0) *                                           SAMPLES_PER_FRAME_5K0) / 8;                    //                    // Initialize the ACELP.net decoder.                    //                    init_decoder_5k(&(pANET->sANETInstance));                    //                    // We're done handling this bit rate.                    //                    break;                }#endif                //                // The bitrate is 6.5kbps.                //#ifdef SUPPORT_ACELPNET_6K5                case ACELPNET_6K5:                {                    //                    // Remember the bitrate of the file.                    //                    pANET->usBitRate = 6444;                    //                    // Remember the sample rate of the file.                    //                    pANET->usSampleRate = 8000;                    //                    // Remember the number of samples per frame.                    //                    pANET->usSamplesPerFrame = L_FRAME_6K5;                    //                    // Compute the length of the file in milliseconds.                    //                    pANET->ulTimeLength = (((pANET->ulLength - 62) /                                            BLOCK_ALIGNMENT_6K5) *                                           SAMPLES_PER_FRAME_6K5) / 8;                    //                    // Initialize the ACELP.net decoder.                    //                    init_dec_swt(&(pANET->sANETInstance));                    //                    // We're done handling this bit rate.                    //                    break;                }#endif                //                // The bitrate is 8.5kbps.                //#ifdef SUPPORT_ACELPNET_8K5                case ACELPNET_8K5:                {                    //                    // Remember the bitrate of the file.                    //                    pANET->usBitRate = 8444;                    //                    // Remember the sample rate of the file.                    //                    pANET->usSampleRate = 8000;                    //                    // Remember the number of samples per frame.                    //                    pANET->usSamplesPerFrame = L_FRAME_8K5;                    //                    // Compute the length of the file in milliseconds.                    //                    pANET->ulTimeLength = (((pANET->ulLength - 62) /                                            BLOCK_ALIGNMENT_8K5) *                                           SAMPLES_PER_FRAME_8K5) / 8;                    //                    // Initialize the ACELP.net decoder.                    //                    init_dec_swt(&(pANET->sANETInstance));                    //                    // We're done handling this bit rate.                    //                    break;                }#endif                //                // The bitrate is 16kbps.                //#ifdef SUPPORT_ACELPNET_16K0                case ACELPNET_16K0:                {                    //                    // Remember the bitrate of the file.                    //                    pANET->usBitRate = 16000;                    //                    // Remember the sample rate of the file.                    //                    pANET->usSampleRate = 16000;                    //                    // Remember the number of samples per frame.                    //                    pANET->usSamplesPerFrame = L_FRAME_16K0;                    //                    // Compute the length of the file in milliseconds.                    //                    pANET->ulTimeLength = (((pANET->ulLength - 62) /

⌨️ 快捷键说明

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