📄 acelpnet.c
字号:
BLOCK_ALIGNMENT_16K0) * SAMPLES_PER_FRAME_16K0) / 16; // // Initialize the ACELP.net decoder. // init_decod_wb(&(pANET->sANETInstance)); // // We're done handling this bit rate. // break; }#endif // // This is an unknown bitrate, so return an error. // default: { return(0); } } // // There is no output buffer. // pANET->pOutput = 0; // // Success. // return(1); } // // Set the output buffer for the decoder. // case IOCTL_CODEC_SETBUFFER: { tANET *pANET; // // The first parameter is a pointer to the ACELP.net persistent // state. // pANET = (tANET *)ulParam1; // // The second parameter is a pointer to the output buffer. // pANET->pOutput = (BufferState *)ulParam2; // // Provide the output buffer with our data buffers. // BufferSetBuffer(pANET->pOutput, pANET->psPCM, pANET->psPCM, (pANET->usSamplesPerFrame * 4)); // // Success. // return(1); } // // Determine if the next frame of data can be decoded. // case IOCTL_CODEC_CAN_DECODE: { tANET *pANET; // // The first parameter is a pointer to the ACELP.net persistent // state. // pANET = (tANET *)ulParam1; // // See if there is space available for decoding the next frame. // if(BufferSpaceAvailable(pANET->pOutput) < (pANET->usSamplesPerFrame * 2)) { // // There is not enough space available, so we can not decode // the next frame. // return(0); } // // We can decode the next frame. // return(1); } // // Decode data. // case IOCTL_CODEC_DECODE: { tANET *pANET; short *psLeft, *psRight; long lLength; // // The first parameter is a pointer to the ACELP.net persistent // state. // pANET = (tANET *)ulParam1; // // See if we've reached the end of the file. // if((pANET->usValid == pANET->usOffset) && (pANET->ulFilePos == pANET->ulLength)) { return(0); } // // Wait until there is space in the output buffer. This tells us // when it is OK to write more data into the output buffer. // while(BufferSpaceAvailable(pANET->pOutput) < (pANET->usSamplesPerFrame * 2)) { // // Busy wait until space is available. // } // // Get the write pointer for the output buffer. // BufferGetWritePointer(pANET->pOutput, &psLeft, &psRight, &lLength); // // Call the appropriate decoder based on the bitrate. // switch(pANET->usBitRate) { // // Decode a 5kbps stream. //#ifdef SUPPORT_ACELPNET_5K0 case 4933: { // // Call the 5kbps decoder. // lLength = Decode5k0(pANET, psLeft); // // We're done handling this stream. // break; }#endif // // Decode a 6.5kbps stream. //#ifdef SUPPORT_ACELPNET_6K5 case 6444: { // // Call the 6.5kbps decoder. // lLength = Decode6k5(pANET, psLeft); // // We're done handling this stream. // break; }#endif // // Decode a 8.5kbps stream. //#ifdef SUPPORT_ACELPNET_8K5 case 8444: { // // Call the 8.5kbps decoder. // lLength = Decode8k5(pANET, psLeft); // // We're done handling this stream. // break; }#endif // // Decode at 16kbps stream. //#ifdef SUPPORT_ACELPNET_16K0 case 16000: { // // Call the 16kbps decoder. // lLength = Decode16k0(pANET, psLeft); // // We're done handling this stream. // break; }#endif } // // Update the output buffer write pointer. // BufferUpdateWritePointer(pANET->pOutput, lLength); // // Increment the time. // pANET->ulTimePos += lLength; // // See if we need to read more data from the file. // if(((pANET->usValid - pANET->usOffset) < 64) && (pANET->ulFilePos != pANET->ulLength)) { // // Copy the tail of the buffer to the beginning. // memcpy(pANET->pcEncodedData, pANET->pcEncodedData + (pANET->usOffset & ~3), pANET->usValid - (pANET->usOffset & ~3)); // // Read the next 512 bytes from the file. // FSRead(pANET->pFile, pANET->pcEncodedData + pANET->usValid - (pANET->usOffset & ~3), 512); // // Update the buffer pointers. // if((pANET->ulLength - pANET->ulFilePos) < 512) { pANET->usValid += pANET->ulLength - pANET->ulFilePos - (pANET->usOffset & ~3); } else { pANET->usValid += 512 - (pANET->usOffset & ~3); } pANET->usOffset &= 3; // // Update the position within the file. // pANET->ulFilePos += 512; if(pANET->ulFilePos > pANET->ulLength) { pANET->ulFilePos = pANET->ulLength; } } // // Success. // return(1); } // // Encode a frame of data. // case IOCTL_CODEC_CAN_ENCODE: case IOCTL_CODEC_ENCODE: { // // We don't support encode, so return an error. // return(0); } // // Seek to the specified time position. // case IOCTL_CODEC_SEEK: { tANET *pANET; // // The first parameter is a pointer to the ACELP.net persistent // state. // pANET = (tANET *)ulParam1; // // Make sure that the specified time is valid. // if(ulParam2 > pANET->ulTimeLength) { ulParam2 = pANET->ulTimeLength; } // // Compute the seek position based on the bitrate. // switch(pANET->usBitRate) { // // The bitrate is 5kbps. //#ifdef SUPPORT_ACELPNET_5K0 case 4933: { // // Convert the seek point from time to bytes. // pANET->ulFilePos = ((ulParam2 / MS_PER_FRAME_TOTAL_5K0) * BLOCK_ALIGNMENT_5K0) + 62; // // Convert the seek point from bytes to samples. // pANET->ulTimePos = ((pANET->ulFilePos - 62) / BLOCK_ALIGNMENT_5K0) * SAMPLES_PER_FRAME_5K0; // // Initialize the ACELP.net decoder. // init_decoder_5k(&(pANET->sANETInstance)); // // We're done handling this bitrate. // break; }#endif // // The bitrate is 6.5kbps. //#ifdef SUPPORT_ACELPNET_6K5 case 6444: { // // Convert the seek point from time to bytes. // pANET->ulFilePos = ((ulParam2 / MS_PER_FRAME_TOTAL_6K5) * BLOCK_ALIGNMENT_6K5) + 62; // // Convert the seek point from bytes to samples. // pANET->ulTimePos = ((pANET->ulFilePos - 62) / BLOCK_ALIGNMENT_6K5) * SAMPLES_PER_FRAME_6K5; // // Initialize the ACELP.net decoder. // init_dec_swt(&(pANET->sANETInstance)); // // We're done handling this bitrate. // break; }#endif // // The bitrate is 8.5kbps. //#ifdef SUPPORT_ACELPNET_8K5 case 8444: { // // Convert the seek point from time to bytes. // pANET->ulFilePos = ((ulParam2 / (MS_PER_FRAME_TOTAL_8K5 * 2)) * (BLOCK_ALIGNMENT_8K5 * 2)) + 62; // // Convert the seek point from bytes to samples. // pANET->ulTimePos = ((pANET->ulFilePos - 62) / (BLOCK_ALIGNMENT_8K5 * 2)) * (SAMPLES_PER_FRAME_8K5 * 2); // // Initialize the ACELP.net decoder. // init_dec_swt(&(pANET->sANETInstance)); // // We're done handling this bitrate. // break; }#endif // // The bitrate is 16kbps. //#ifdef SUPPORT_ACELPNET_16K0 case 16000: { // // Convert the seek point from time to bytes. // pANET->ulFilePos = ((ulParam2 / (MS_PER_FRAME_TOTAL_16K0 * 2)) * (BLOCK_ALIGNMENT_16K0 * 2)) + 62; // // Convert the seek point from bytes to samples. // pANET->ulTimePos = ((pANET->ulFilePos - 62) / (BLOCK_ALIGNMENT_16K0 * 2)) * (SAMPLES_PER_FRAME_16K0 * 2); // // Initialize the ACELP.net decoder. // init_decod_wb(&(pANET->sANETInstance)); // // We're done handling this bitrate. // break; }#endif } // // Seek to the specified position. // FSSeek(pANET->pFile, pANET->ulFilePos & ~511); // // Read the next 512 bytes from the file. // FSRead(pANET->pFile, pANET->pcEncodedData, 512); // // Update the buffer pointers. // if((pANET->ulLength - pANET->ulFilePos) < 512) { pANET->usValid = pANET->ulLength - pANET->ulFilePos; } else { pANET->usValid = 512; } pANET->usOffset = pANET->ulFilePos & 511; // // Update the position within the file. // pANET->ulFilePos = (pANET->ulFilePos + 512) & ~511; if(pANET->ulFilePos > pANET->ulLength) { pANET->ulFilePos = pANET->ulLength; } // // Success. // return(1); } // // Cleanup after the codec. // case IOCTL_CODEC_CLOSE: { // // There's nothing to do, so return success. // return(1); } // // We should never get here, but just in case... // default: { // // Return a failure. // return(0); } }}#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -