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

📄 pwav.c

📁 瑞星微公司RK27XX系列芯片的SDK开发包
💻 C
📖 第 1 页 / 共 3 页
字号:
                    pPCM->FrameOutputLeft[i] = 0;
                    pPCM->FrameOutputRight[i] = 0;
                    pPCM->psLeft[i] = 0;
                    pPCM->psRight[i] = 0;
                }

                for (i = 0;i < INFO_BYTE_SIZE;i++)
                {
                    pINFO.Artist[i] = 0;
                    pINFO.Name[i] = 0;
                    pINFO.Product[i] = 0;
                    pINFO.Genre[i] = 0;
                }

                pPCM->N_remain = 0;
                pPCM->N_GeneratedSample = 0;
                if (VideoPlaying) // add by hwg for mjpg, 08/04/24
                {
                    isErr = InitADPCMDecoder(pPCM);
                }
                else
                {
                    isErr = InitPCMDecoder(pPCM);
//20080104 modify sdk
                    //Bug Fix: Dec 27,2007, By Vincent Hisung
                    if (pPCM->usByteRate != 0)
                        pPCM->ulTimeLength = 1000 * (long long)RKFIO_FLength(pRawFileCache) / (long long) pPCM->usByteRate ;
                }
                //----------------------------------------

                //设置缓冲区
                {
                    unsigned long size;

                    pPCM->pOutput = (BufferState *) & sPlayBuffer;

                    if (pPCM->wFormatTag == WAVE_FORMAT_DVI_ADPCM)
                        size = WAV_IMAMAX_PCM_LENGTH;
                    else
                        if (pPCM->wFormatTag == WAVE_FORMAT_PCM)
                            size = pPCM->usSamplesPerBlock;
                        else
                            size = pPCM->usSamplesPerBlock;

                    msadpcm_outsize = size * 2;
                    if (pPCM->ucChannels == 2)
                    {
                        BufferSetBuffer(pPCM->pOutput, pPCM->FrameOutputLeft, pPCM->FrameOutputRight, size * 4);//size*4
                        poutLeft = pPCM->FrameOutputLeft;
                        poutRight = pPCM->FrameOutputRight;
                    }
                    else
                    {
                        BufferSetBuffer(pPCM->pOutput, pPCM->FrameOutputLeft, pPCM->FrameOutputLeft, size * 4); //size*4
                        poutLeft = pPCM->FrameOutputLeft;
                        poutRight = poutLeft;
                    }
                }

                /*
                 poutLeft = pPCM->FrameOutputLeft;
                 poutRight=pPCM->FrameOutputRight;
                 */
                OutLength = pPCM->usSamplesPerBlock;

                return(isErr);
            }

        case SUBFN_CODEC_GETCAPTUREBUFFER:
            {
                tPCM *pPCM;
                short **ppsBuffer;
                long *plLength;

                pPCM = (tPCM *)ulParam1;

                *(unsigned long *)ulParam2 = (unsigned long)poutLeft;//pPCM->FrameOutputLeft;
                *(unsigned long *)ulParam3 = (unsigned long)poutRight;//pPCM->FrameOutputRight;
                *(unsigned long *)ulParam4 = (unsigned long)OutLength;

                return(1);
            }

        case SUBFN_CODEC_DECODE:
            {
                tPCM *pPCM;
                short *psLeft, *psRight;
                long lLength, lBlockSize;
                long ret;
                short *ptr;
                char *char_ptr;
                unsigned int Counter = 0;
                pPCM = (tPCM *)ulParam1;

                switch (pPCM->wFormatTag)
                {
                    case WAVE_FORMAT_ADPCM:
                        {
                            int i;

                            //pPCM->pOutput->psLeft = pPCM->FrameOutputLeft;
                            //pPCM->pOutput->psRight = pPCM->FrameOutputRight;

                            long tmp = 0;
//20080104 modify sdk

                            //--------------------------------
                            if ((pPCM->ulLength) == 0)
                                return 0;

                            if ((pPCM->usOffset) >= (pPCM->ulLength))
                                return 0;

                            if (pPCM->usValid < (pPCM->usOffset & ~3))
                                return 0;
                            //--------------------------------
                            if (pPCM->ucChannels == 1)
                            {
                                //pPCM->pOutput->psRight = pPCM->FrameOutputLeft;
                                poutRight = pPCM->FrameOutputLeft;
                            }
                            else
                            {
                                //pPCM->pOutput->psRight = pPCM->FrameOutputRight;
                                poutRight = pPCM->FrameOutputRight;
                            }
                            //得到缓冲区内已有数据量
                            while (1)
                            {
                                tmp = BufferDataAvailable(pPCM->pOutput);

                                //若数据量足够,可进行输出
                                if (tmp >= msadpcm_outsize)//2036*2
                                {
                                    BufferGetReadPointer(pPCM->pOutput, &poutLeft, &poutRight, &tmp);
                                    BufferUpdateReadPointer(pPCM->pOutput, msadpcm_outsize);//2036*2
                                    {
                                        OutLength = msadpcm_outsize;//2036*2;
                                    }
                                    // Success
                                    return(1); //解满缓冲区后再返回
                                }
                                else
                                {
                                    ret = MSADPCM_FORMAT(pPCM);
                                    if (ret > 0)
                                        BufferUpdateWritePointer(pPCM->pOutput, ret, 0);
                                    else
                                        return 0;
                                }
                            }

                            return(0);
                        }

                    case WAVE_FORMAT_IMA_ADPCM:
                        {
                            int i;
//20080104 modify sdk

                            //--------------------------------
                            if ((pPCM->ulLength) == 0)
                                return 0;

                            if ((pPCM->usOffset) >= (pPCM->ulLength))
                                return 0;

                            if (pPCM->usValid < (pPCM->usOffset & ~3))
                                return 0;
                            //--------------------------------

                            ret = IMAADPCM_FORMAT(pPCM);

                            if (ret > 0)
                                OutLength = ret;
                            //pPCM->pOutput->psLeft = pPCM->FrameOutputLeft;

                            poutLeft = pPCM->FrameOutputLeft;

                            if (pPCM->ucChannels == 1)
                            {
                                //pPCM->pOutput->psRight = pPCM->FrameOutputLeft;
                                poutRight = pPCM->FrameOutputLeft;
                            }
                            else
                            {
                                //pPCM->pOutput->psRight = pPCM->FrameOutputRight;
                                poutRight = pPCM->FrameOutputRight;
                            }



                            if (ret != 0)
                                ret = 1;
                            else
                                ret = 0;

                            return(ret);
                        }

                    case WAVE_FORMAT_PCM:
                        {
                            int i;

                            if ((pPCM->ulLength) == 0)
                                return 0;

                            if ((pPCM->usOffset) >= (pPCM->ulLength))
                                return 0;

                            if (pPCM->usValid == 0)
                                return 0;
                            psLeft = pPCM->FrameOutputLeft;
                            psRight = pPCM->FrameOutputRight;

                            if (pPCM->uBitsPerSample == 16)
                            {

                                lBlockSize = (pPCM->usSamplesPerBlock << pPCM->ucChannels);
                            }
                            else
                                if (pPCM->uBitsPerSample == 8)
                                {

                                    lBlockSize = (pPCM->usSamplesPerBlock * pPCM->ucChannels);
                                }


                            pPCM->usValid = RKFIO_FRead(pRawFileCache, pPCM->pucEncodedData, lBlockSize);


                            pPCM->usOffset += pPCM->usValid;

                            //16位量化
                            if (pPCM->uBitsPerSample == 16)
                            {
                                ptr = (short *)pPCM->pucEncodedData;
                                if (pPCM->ucChannels == 1)
                                {
                                    for (i = 0; i < lBlockSize / 2 ; i++)
                                    {
                                        *psLeft  = *ptr++ ;
                                        *psRight++ = *psLeft++;
                                    }
                                }
                                else
                                {
                                    for (i = 0; i < lBlockSize / 2 ; i++)
                                    {
                                        if (i % 2 == 0) // L,R,L,R
                                        {
                                            *psLeft++ = *ptr++ ;  //LLL
                                        }
                                        else
                                        {
                                            *psRight++ = *ptr++ ; //RRR
                                        }
                                    }
                                }
                            }
                            else
                                //8位量化
                                if (pPCM->uBitsPerSample == 8)
                                {
                                    char_ptr = (char *)pPCM->pucEncodedData;

                                    if (pPCM->ucChannels == 1)  //mono
                                    {

                                        for (i = 0; i < lBlockSize ; i++)
                                        {
                                            *psLeft  = (short)(((*char_ptr) - 0x80) << 8);//Convert 8BIT(per sample) to 16BIT(per sample)
                                            char_ptr++ ;

                                            *psRight++ = *psLeft++;
                                        }

                                    }
                                    else  //stereo
                                    {
                                        for (i = 0 ; i < lBlockSize ; i++)
                                        {
                                            // L,R,L,R
                                            if (i % 2 == 0)
                                            {
                                                *psLeft  = (short)(((*char_ptr) - 0x80) << 8);
                                                char_ptr++ ;  //LLL
                                                psLeft++;
                                            }

                                            else
                                            {
                                                *psRight  = (short)(((*char_ptr) - 0x80) << 8);
                                                char_ptr++ ;//RRR
                                                psRight++;

                                            }
                                        }
                                    }
                                }
                                else
                                    //不支持的量化位数
                                    return 0;



                            OutLength = pPCM->usSamplesPerBlock;
                            //--------------------------------------------

                            if (pPCM->uBitsPerSample == 16)
                            {
                                pPCM->ulTimePos += (lBlockSize >> pPCM->ucChannels);
                            }
                            else
                                if (pPCM->uBitsPerSample == 8)
                                {
                                    pPCM->ulTimePos += (lBlockSize >> (pPCM->ucChannels - 1));
                                }

                            //若已到文件结尾则解码结束
                            if (pPCM->usValid < lBlockSize)
                            {
                                return 0;
                            }


                            return 1;
                        }
                    default:
                        return 0; //error.
                }
            }

            //#ifdef ADPCM_ENC_INCLUDE
        case SUBFN_CODEC_ENCODE:
            {

                short *psLeft, *psRight;
                unsigned char *encodetemp;

⌨️ 快捷键说明

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