📄 mp3_decode.c
字号:
/*
********************************************************************************
* Copyright (C),2004-2005, tonyzyz, Fuzhou Rockchip Co.,Ltd.
* All Rights Reserved
* V1.00
* FileName : Mp3_Decode.c
* Author : tonyzyz
* Description:
* History :
* <author> <time> <version> <desc>
* tonyzyz 05/09/17 1.0 ORG
*
********************************************************************************
*/
#define _IN_MP3_DECODE
#include <Creg.h>
#include "Macro.h"
#include "Memap.h"
#include "MsgDef.h"
#include "Global.h"
#include "Resource.h"
#include "MP3DecodeGlobal.h"
#include "MP3DecodeStruct.h"
#include "Mp3ApiStruct.h"
#include "Config.h"
#include "Audio.h"
#include "Message.h"
#include "Byte2Word.h"
#include "MP3DecodeAsm.h"
#include "Subspecanal.h"
extern void MP3_Init_MP3(MP3_DECODER_STRUCT *MP3DecodeStruct);
extern void MP3_FrameDecode(unsigned int *pBuffer, frame_params *FrameParams, MP3_DECODER_STRUCT *MP3DecodeStruct);
void ClearPcmData(void);
void ClearPcmData(void);
void MP3DecodeOutputEnable(void);
void MP3DecodeOutputDisable(unsigned int bEnd);
MP3_DECODER_STRUCT MP3Obj __attribute__((section(".mp3_bss, \"aw\"")));
frame_params MP3FrameParams __attribute__((section(".mp3_bss, \"aw\"")));
al_table alloc_table __attribute__((section(".mp3_bss, \"aw\"")));
//******************************************************************************
/*------------------------------------------------------------------------------
Function:
Input:
Output:
------------------------------------------------------------------------------*/
__attribute__((section(".mp3_text,\"ax\"")))
void PCMOutBufferChange(void)
{
Mp3PlayFlag.bc.bPcmBufEmpty = 1;
write_mem32(DMAR_SAR2,(((unsigned long)(pPCMOutputBuf) << 1) & 0x0001ffff) + (unsigned long)0x40000);
write_mem32(DMAR_DAR2,(unsigned long)(I2DSP_TXDB) << 1);
write_mem32(DMAR_CTL2,0x00100125);
write_mem32(DMAR_CTL2+2,PCMOutBufferLength<<1);
write_mem32(DMAR_CFG2,0x00000040);
write_mem32(DMAR_CFG2+2,0x00001004);
write_mem32(DMAR_DmaCfgReg,0x00000001);
write_mem32(DMAR_MaskBlock,0x00000404);
write_mem32(DMAR_ChEnReg,0x00000404);
BitrateCount ++ ;
StroboscopeCount ++;
AVI_MP3_DECODE_REQ;
}
/*------------------------------------------------------------------------------
Function:
Input :
Output :
------------------------------------------------------------------------------*/
__attribute__((section(".mp3_text,\"ax\"")))
void ClearPcmData(void)
{
int *pData;
int i;
PCMOutBufferLength = 576;
if(MP3FrameParams.header.lay == 1) PCMOutBufferLength = 384;
else if((MP3FrameParams.header.version != MPEG_PHASE2_LSF) || (MP3FrameParams.header.lay !=3))
{PCMOutBufferLength = 1152;}
pPCMOutputBuf = pMP3DecodeOutputBuf;
pData = pMP3DecodeOutputBuf;
for(i = (PCMOutBufferLength << 1); i > 0 ; i--)
*pData++ = 0;//i*56+1;
Mp3PlayFlag.bc.bPcmBufFull = 1;
}
/*------------------------------------------------------------------------------
Function:
:
:
Input :
Output :
------------------------------------------------------------------------------*/
__attribute__((section(".mp3_text,\"ax\"")))
void FillPcmData(void)
{
unsigned int l = 576;
PCMOutBufferLength = 576;
if(MP3FrameParams.header.lay == 1){ l = 384 ; PCMOutBufferLength = 384; }
else if((MP3FrameParams.header.version != MPEG_PHASE2_LSF) || (MP3FrameParams.header.lay !=3))
{PCMOutBufferLength = 1152;}
pPCMOutputBuf = pMP3DecodeOutputBuf;
if(MP3FrameParams.stereo == 2)
{
PCMBufferDataChangeStereo(pMP3DecodeOutputBuf,pPCMOutputBuf,l);
if(MP3FrameParams.header.lay != 1)
{
if((MP3FrameParams.header.version != MPEG_PHASE2_LSF) || (MP3FrameParams.header.lay !=3))
PCMBufferDataChangeStereo(pMP3DecodeOutputBuf+2304,pPCMOutputBuf+2304,l);
}
}
else
{
PCMBufferDataChangeMono(pMP3DecodeOutputBuf,pPCMOutputBuf+l*2,l);
if(MP3FrameParams.header.lay != 1)
{
if((MP3FrameParams.header.version != MPEG_PHASE2_LSF) || (MP3FrameParams.header.lay !=3))
PCMBufferDataChangeMono(pMP3DecodeOutputBuf+2304,pPCMOutputBuf+2304+l*2,l);
}
}
Mp3PlayFlag.bc.bPcmBufFull = 1;
}
/*------------------------------------------------------------------------------
Function:
Input :
Output :
------------------------------------------------------------------------------*/
__attribute__((section(".mp3_text,\"ax\"")))
void MP3DecodeOutputEnable(void)
{
bitclear_creg(%imask,15);
MP3DecodeBadFrameCount = 0;
write_mem(I2DSP_DPCTRL,0x0001); //Tx FIFO Reset
write_mem(I2DSP_TXCOM, 0x0006); //Tx enable,I2Dsp enable,DMA request Enable
write_mem32(DMAR_ClearBlock,0x00000004);
write_mem32(DMAR_SAR2,(((unsigned long)(pPCMOutputBuf) << 1) & 0x0001ffff) + (unsigned long)0x40000);
write_mem32(DMAR_DAR2,(unsigned long)(I2DSP_TXDB) << 1);
write_mem32(DMAR_CTL2,0x00100125);
write_mem32(DMAR_CTL2+2,PCMOutBufferLength<<1);
write_mem32(DMAR_CFG2,0x00000040);
write_mem32(DMAR_CFG2+2,0x00001004);
write_mem32(DMAR_DmaCfgReg,0x00000001);
write_mem32(DMAR_MaskBlock,0x00000404);
write_mem32(DMAR_ChEnReg,0x00000404);
SystemInfo.bc.bSysIdleEn = 0;
#if(FLASHROM_TYPE == _MLC_)
MlcDataRefresh(); // hjl 2006-12-7
#endif
bitset_creg(%imask,15);
}
/*------------------------------------------------------------------------------
Function: ????IIS??MP3??????????
Input : ??
Output : ??
------------------------------------------------------------------------------*/
__attribute__((section(".mp3_text,\"ax\"")))
void MP3DecodeOutputDisable(unsigned int bEnd)
{
unsigned int TimeOut;
#ifdef LCD_MEMORY_DEV
while(DmaFillImage2LcdFlag);
#endif
MusicCodecMute(1);
bitclear_creg(%imask,15);
//------------------------------------------------------------
//wait DMA Transmite End
TimeOut = 0;
while((read_mem(DMAR_StatusBlock) & 0x0004) == 0) {
delay_nops(480);
if (++TimeOut > 1024) break;
}
write_mem32(DMAR_ClearBlock,0x00000004);
write_mem32(DMAR_ChEnReg,0x00000400);
//------------------------------------------------------------
//wait I2DSP Transmite End
TimeOut = 0;
while((read_mem(I2DSP_STATUS) & 0x01) == 0) {
delay_nops(480);
if (++TimeOut > 1024) break;
}
Delay1Ms(4);
write_mem(I2DSP_TXCOM, 0x0000);
write_mem(I2DSP_DPCTRL,0x0001); //Tx FIFO Reset
//------------------------------------------------------------
if (bEnd) {
AVI_MP3_DECODE_REQ_CLR;
AVI_MP3_DECODE_DISABLE;
write_mem32(DMAR_MaskBlock,0x00000400);
}
SystemInfo.bc.bSysIdleEn = 1;
SysIdleCounter = 0;
//------------------------------------------------------------
bitset_creg(%imask,15);
}
/*------------------------------------------------------------------------------
Function:
Input :
Output :
------------------------------------------------------------------------------*/
__attribute__((section(".mp3_text,\"ax\"")))
void MP3DecodeStart(void)
{
int i;
PCMOutBufferLength = 1152;
for(i = APPLICATION_INPUT_BUF_LENGTH - 1; i >= 0; i --)
*(ApplicationInputBufferStart + i) = 0;
for(i = (PCM_OUT_BUF_LENGTH << 1) - 1; i >= 0; i --)
*(FirstPCMOutAddress + i) = 0;
Mp3PlayFlag.bc.bPcmBufFull = 0;
Mp3PlayFlag.bc.bPcmBufEmpty = 1;
Mp3SamplingFreqSet(MusicPlayInfo.Freq);
Mp3CpuFreqSet(MusicPlayInfo.Freq);
DecodeEqSet();
Mp3PlayFlag.bc.bMP3DecodeEnable = 0;
if(MusicPlayInfo.PlayState == MUSIC_DECODE_PLAY) {
MP3DecodeOutputEnable();
Mp3PlayFlag.bc.bMP3DecodeEnable = 1;
} else {
if ((Sys2InitFlag.bc.bGameModuleInitEnable != 0) || (CurrCpuFreq != 51)) {
bitclear_creg(%imask,5);
SystemInfo.bc.bSysIdleEn = 1;
SysIdleCounter = 0;
bitset_creg(%imask,5);
}
}
Mp3PlayFlag.bc.bMP3DecodeInit = 1;
PostFun1Message(MSG_FUNCTION1_MUSIC_MP3,MSG_FUNCTION1_MP3_PLAY,0,0,0/*,0,0,0*/);
}
/*------------------------------------------------------------------------------
Function:
Input :
Output :
------------------------------------------------------------------------------*/
__attribute__((section(".mp3_text,\"ax\"")))
void Mp3DecodeEnd(void)
{
Mp3PlayFlag.bc.bMP3DecodeEnable = 0;
if(Mp3PlayFlag.bc.bPcmBufEmpty)
{
Mp3PlayFlag.bc.bPcmBufEmpty = 0;
MP3DecodeOutputDisable(1);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -