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

📄 codec.c

📁 基于EP7312的MP3播放器源代码,包括MCU和PC端代码.
💻 C
📖 第 1 页 / 共 3 页
字号:
            return(-1);        }        //        // Determine the codec type based on the format tag.        //        switch(pucData[ulOffset + 8] + (pucData[ulOffset + 9] << 8))        {            //            // This file is a MS ADPCM file.            //#ifdef SUPPORT_MSADPCM            case 0x02:            {                return(CODEC_MSADPCM);            }#endif            //            // This file is an MP3 file.            //#ifdef SUPPORT_MP3            case 0x55:            {                return(CODEC_MP3);            }#endif            //            // This file is an ACELP.net file.            //#ifdef SUPPORT_ACELPNET            case 0x130:            {                return(CODEC_ACELPNET);            }#endif            //            // This file is a WMA file.            //#ifdef SUPPORT_WMA            case 0x160:            case 0x161:            {                return(CODEC_WMA);            }#endif            //            // This is an unknown format, so we can not decode this file.            //            default:            {                return(-1);            }        }    }    //    // It is not a RIFF file, so see if it is an ASF file.    //    else if(CodecIsASFFile(pFile, pucData) == 1)    {        //        // Find the stream format chunk.        //        ulOffset = CodecFindASFChunk(pFile, pucData, pucStreamFormatGUID);        //        // If the stream format chunk does not exist, then this is an invalid        // file and we will not be able to decode it.        //        if(ulOffset == -1)        {            return(-1);        }        //        // The format tag starts 62 bytes into the stream format chunk.        //        ulOffset += 62;        //        // If the format tag does not start in the currently read portion of        // the file, then we need to read more data from the file.        //        if(ulOffset >= 512)        {            //            // Decrement the offset by the number of bytes that we are reading.            //            ulOffset -= 512;            //            // Read the next portion of the file.            //            FSRead(pFile, pucData, 512);        }        //        // Get the first byte of the format tag.        //        ulRet = pucData[ulOffset];        //        // See if the first byte of the format tag is at the end of the buffer.        //        if(ulOffset == 511)        {            //            // Read the next portion of the file.            //            FSRead(pFile, pucData, 512);            //            // Get the second byte of the format tag.            //            ulRet |= pucData[0] << 8;        }        else        {            //            // Get the second byte of the format tag from the buffer.            //            ulRet |= pucData[ulOffset + 1] << 8;        }        //        // Determine the codec type based on the format tag.        //        switch(ulRet)        {            //            // This file is a WMA file.            //#ifdef SUPPORT_WMA            case 0x160:            case 0x161:            {                return(CODEC_WMA);            }#endif            //            // This is an unknown format, so we can not decode this file.            //            default:            {                return(-1);            }        }    }    //    // It is not an ASF file, so query each decoder.    //    else    {        //        // Check each decoder and see if any of them can decode the file.        //        for(ulOffset = 0; ulOffset < NUMCODECS; ulOffset++)        {            //            // Query this codec.            //            ulRet = CodecQuery(ulOffset, pFile, pucData);            //            // Seek back to the beginning of the file.            //            FSSeek(pFile, 0);            //            // Stop searching if this codec can decode the file.            //            if(ulRet != -1)            {                return(ulOffset);            }        }    }    //    // We couldn't determine which codec to use, so return an error.    //    return(-1);}//****************************************************************************//// CodecQuery determines if a codec is able to decode the given file.////****************************************************************************unsigned longCodecQuery(unsigned long ulCodec, tFile *pFile, unsigned char *pucScratch){    unsigned long ulOffset = 0;    //    // If a codec number was not specified, then determine the codec to be used    // by parsing the file.    //    if(ulCodec == -1)    {        //        // Determine if there is a codec which can decode this file.        //        ulCodec = DetermineCodec(pFile, pucScratch);        if(ulCodec == -1)        {            return(-1);        }    }    //    // See if this is a RIFF file; if so, get the starting offset of the "data"    // chunk.    //    IsRIFFFile(pFile, pucScratch, &ulOffset);    //    // Pass the query request to the entry pointer for the codec.    //    if((pfnIoctl[ulCodec])(IOCTL_CODEC_QUERY, 0, (unsigned long)pFile,                           (unsigned long)pucScratch, ulOffset) == 1)    {        //        // Return the codec which can decode this file.        //        return(ulCodec);    }    //    // This codec can not decode this file, so return a failure.    //    return(-1);}//****************************************************************************//// CodecOpen opens a codec.  For decoders, the type of the current file is// determined and used to determine the codec to open.  For encoders, the// specified codec is opened.////****************************************************************************unsigned longCodecOpen(unsigned long ulCodec, unsigned long ulFlags, tFile *pFile){    unsigned long ulRet, ulOffset = 0;    //    // If there is already a codec opened, then return a failure.    //    if(sCodec.bCodecOpen)    {        return(0);    }    //    // Make sure that a valid set of flags were specified.    //    if(!(ulFlags & (CODEC_OPEN_ENCODE | CODEC_OPEN_DECODE)) ||       ((ulFlags & (CODEC_OPEN_ENCODE | CODEC_OPEN_DECODE)) ==        (CODEC_OPEN_ENCODE | CODEC_OPEN_DECODE)))    {        return(0);    }    //    // Determine the type of the file if this is a request for a decoder.    //    if(ulFlags & CODEC_OPEN_DECODE)    {        //        // If a codec number was not specified, then determine the codec to be        // used by parsing the file.        //        if(ulCodec == -1)        {            //            // Determine the codec to use.            //            ulCodec = DetermineCodec(pFile, (unsigned char *)ulEndOfRAM);            //            // If we could not determine the codec to use, then return a            // failure.            //            if(ulCodec == -1)            {                return(0);            }        }        //        // See if this is a RIFF file; if so, get the starting offset of the        // "data" chunk.        //        IsRIFFFile(pFile, (unsigned char *)ulEndOfRAM, &ulOffset);    }    else    {        //        // If a codec number was not specified, then find the first codec that        // can encode.        //        if(ulCodec == -1)        {            //            // Loop through all the available codecs.            //            for(ulCodec = 0; ulCodec < NUMCODECS; ulCodec++)            {                //                // Open this codec.                //                if(CodecOpen(ulCodec, CODEC_OPEN_ENCODE, pFile))                {                    break;                }            }            //            // If we found a codec, then close it now.            //            if(ulCodec != NUMCODECS)            {                //                // Close the codec.                //                CodecClose();                //                // Seek back to the beginning of the file.                //                FSSeek(pFile, 0);            }        }    }    //    // Make sure that a valid codec was specified.    //    if(ulCodec >= NUMCODECS)    {        return(0);    }    //    // Pass the open request to the entry point for the codec.    //    ulRet = (pfnIoctl[ulCodec])(IOCTL_CODEC_OPEN, ulEndOfRAM, ulOffset,                                ulFlags, (unsigned long)pFile);    //    // If the open succeeded, then keep track of the fact that a codec is    // opened.    //    if(ulRet)    {        //        // A codec is opened.        //        sCodec.bCodecOpen = 1;        //        // The codec which is opened.        //        sCodec.ucCodec = ulCodec;        //        // The flags specified when the codec was opened.        //        sCodec.ucFlags = ulFlags;    }    //    // Return the result to the caller.    //    return(ulRet);}//****************************************************************************//// CodecGetIndex returns the codec number of the current codec.  This can then// be used on subsequent calls to CodecOpen for the given file, avoiding the// codec determination process.////****************************************************************************unsigned longCodecGetIndex(unsigned long *pulIndex){    //    // If there is not a codec opened, then return an error.    //    if(!sCodec.bCodecOpen)    {        return(0);    }    //    // Return the current codec number.    //    *pulIndex = sCodec.ucCodec;    //    // Success.    //    return(1);}//****************************************************************************//// CodecGetName gets the name of the current codec.  The first four characters// of the string returned are the short name of the codec, and the remaining// characters are the full name of the codec.////****************************************************************************unsigned longCodecGetName(const unsigned short **ppusName){    //    // If there is not a codec opened, then return an error.    //    if(!sCodec.bCodecOpen)    {        return(0);    }    //    // Pass the codec name request to the entry point for the specified codec.    //    return((pfnIoctl[sCodec.ucCodec])(IOCTL_CODEC_GETNAME, ulEndOfRAM,                                      (unsigned long)ppusName, 0, 0));}//****************************************************************************//// CodecGetNameByIndex gets the name of the specified codec.  The first four// characters of the string returned are the short name of the codec, and the// remaining characters are the full name of the codec.//

⌨️ 快捷键说明

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