📄 d_mp3.c
字号:
//#################################################
// NX5858 MP3 Demo program
// Contents : MP3 Codec Function
// Hardware model : NX5858 Demo Board
// Main CPU : STANDARD 8032
// Compiler : Keil uVision2
//
// Copyrigt : NEXIA Device. INC
// Date : 2005. 8.20
// Last modifier : 2005. .
// File name : d_mp3.c
//#################################################
#include "dec_extern.h"
code unsigned short SamplingFrequency[3]={11025, 12000, 8000};
code unsigned char BitRate[15][2] =
{ //MPGE2 MPEG1
{ 0 , 0 },
{ 8/2, 32/2 },
{ 16/2, 40/2 },
{ 24/2, 48/2 },
{ 32/2, 56/2 },
{ 40/2, 64/2 },
{ 48/2, 80/2 },
{ 56/2, 96/2 },
{ 64/2, 112/2 },
{ 80/2, 128/2 },
{ 96/2, 160/2 },
{ 112/2, 192/2 },
{ 128/2, 224/2 },
{ 144/2, 256/2 },
{ 160/2, 320/2 }
};
code UINT8 mpeg_cnt[15][2] =
{ // MPEG2, MPEG1
{ 0x00, 0x00 }, // Free, Free
{ 0x02, 0x08 }, // 8 32
{ 0x04, 0x0a }, // 16 40
{ 0x06, 0x0c }, // 24 48
{ 0x08, 0x0e }, // 32 56
{ 0x0a, 0x10 }, // 40 64
{ 0x0c, 0x14 }, // 48 80
{ 0x0e, 0x18 }, // 56 96
{ 0x10, 0x1c }, // 64 112
{ 0x14, 0x20 }, // 80 128
{ 0x18, 0x28 }, // 96 160
{ 0x1c, 0x30 }, // 112 192
{ 0x20, 0x38 }, // 128 224
{ 0x24, 0x40 }, // 144 256
{ 0x28, 0x50 } // 160 320
};
void Mp3_Reset(void)
{
//[5]:pwm [4]:register [3]:common [2]:encoder [1]:mp3 [0]:wma
write_XDATA(MP3_SOFT_RESET, 0x18); //if 0 set , reset
}
void Mp3_Mute_Off(void)
{
write_XDATA(AUDIO_CODEC_CONTROL, 0x00);
}
void Mp3_Mute_On(void)
{
write_XDATA(AUDIO_CODEC_CONTROL, 0x02);
}
void Decoder_Encoder_Stop(void)
{
write_XDATA(MP3_WMA_CODEC_CONTROL, 0x00); //audio codec clock enable
}
void MP3_Decoder_Start(void)
{
write_XDATA(FRAME_LENGTH_MODE, 0x03);
write_XDATA(MP3_WMA_CODEC_CONTROL, 0x06);
}
void Vol_mono_set(UINT8 vol)
{
write_XDATA(DECODER_L2L_VOLUME, vol);
write_XDATA(DECODER_L2R_VOLUME, vol);
write_XDATA(DECODER_R2L_VOLUME, 0x7f);
write_XDATA(DECODER_R2R_VOLUME, 0x7f);
}
void Vol_stereo_set(UINT8 vol)
{
write_XDATA(DECODER_L2L_VOLUME, vol);
write_XDATA(DECODER_L2R_VOLUME, 0x7f);
write_XDATA(DECODER_R2L_VOLUME, 0x7f);
write_XDATA(DECODER_R2R_VOLUME, vol);
}
void check_MP3_header()
{
xdata UINT8 pre_header2=0xff;
xdata HEADER1_STATUS header1;
xdata HEADER2_STATUS header2;
xdata HEADER3_STATUS header3;
xdata _header *pHeader = &FILE_INFO.HEADER;
if(!(read_XDATA(MP3_INTERRUPT_STATUS)&0x01)){
return;
}
write_XDATA(MP3_INTERRUPT_STATUS, 0xFF);
header1.byte = read_XDATA(DECODER_HEADER_STATUS1);
header2.byte = read_XDATA(DECODER_HEADER_STATUS2);
header3.byte = read_XDATA(DECODER_HEADER_STATUS3);
if(header1.bc.reserved != 7)
return;
if(header1.bc.Mpeg == 1)
return;
if(header1.bc.Layer != 1)
return;
if((header2.bc.BitRate) == 0x0F)
return;
if((pre_header2 & 0xf0) == (header2.byte & 0xf0))
return;
pre_header2 = header2.byte;
//MPEG1
if(header1.bc.Mpeg==3)
{
pHeader->Mpeg=1;
pHeader->SamplingFreq = SamplingFrequency[header2.bc.SamplingFrequency]<<2;//*4
}
//MPEG2
if(header1.bc.Mpeg==2)
{
pHeader->Mpeg=0;
pHeader->SamplingFreq = SamplingFrequency[header2.bc.SamplingFrequency]<<1;//*2
}
//else MPEG2.5
if(header1.bc.Mpeg==0)
{
pHeader->Mpeg=0;
pHeader->SamplingFreq = SamplingFrequency[header2.bc.SamplingFrequency];
}
pHeader->BitRate = (UINT16)BitRate[header2.bc.BitRate][pHeader->Mpeg]<<1;//*2
if(pHeader->BitRate == 0){
// prevent incorrect stream, divide by 0
return;
}
if(!vbr_bitrate)
pHeader->BufcntInSec = mpeg_cnt[header2.bc.BitRate][pHeader->Mpeg];
if(!vbr_bitrate)
// pHeader->TotalTimeInSec = (File_Size>>9) / pHeader->BufcntInSec;
pHeader->TotalTimeInSec = (((File_Size>>9) / pHeader->BufcntInSec)*128)/125;
switch(header3.bc.Mode){
case 0:
case 2:
pHeader->stereo=1;//stereo
break;
case 1://joint stereo
pHeader->stereo=1;//
break;
case 3:
pHeader->stereo=0;//mono
break;
}
}
void Volume_Setting(UINT8 vol)
{
if(FILE_INFO.HEADER.stereo) Vol_stereo_set(vol);
else Vol_mono_set(vol);
}
/*
void EQ_set(UINT8 base, UINT8 treble, UINT8 prescale)
{
write_XDATA(DECODER_BASS, base);
write_XDATA(DECODER_TREBLE, treble);
write_XDATA(DECODER_PRESCALE, prescale);
}
*/
void EqulizerBand_Set(void){
write_XDATA(0xfa33, 0x10);
write_XDATA(0xfa34, 0x10);
write_XDATA(0xfa35, 0x10);
write_XDATA(0xfa36, 0x10);
write_XDATA(0xfa37, 0x10);
write_XDATA(0xfa38, 0x10);
write_XDATA(0xfa39, 0x10);
write_XDATA(0xfa3a, 0x10);
write_XDATA(0xfa3b, 0x10);
write_XDATA(0xfa3c, 0x10);
write_XDATA(0xfa31, 0x98);//EQ sensetive
write_XDATA(0xfa02, 0xf0);
write_XDATA(0xfa61,0x04);
}
///////////////////////////////////////////////////////
// CODEC EQ = 0dB, ADJUST WOLFSON CODEC EQ.
///////////////////////////////////////////////////////
code UINT8 EQ_PRESCALE[7]={0x16,0x14,0x15,0x16,0x17,0x15,0x16};
code UINT8 EQ_ARRAY[7][10]={
{0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10},//Normal
{0x11,0x0f,0x0e,0x0d,0x11,0x11,0x10,0x10,0x0c,0x0c},//Rock
{0x12,0x11,0x0d,0x0c,0x0b,0x0d,0x10,0x11,0x12,0x12},//pop
{0x10,0x10,0x10,0x0d,0x0d,0x0d,0x10,0x0e,0x0c,0x0c},//Jazz
{0x10,0x0a,0x0a,0x0d,0x10,0x10,0x10,0x10,0x0e,0x0e},//Classic
{0x10,0x10,0x10,0x0d,0x0c,0x0e,0x0b,0x0e,0x10,0x10},//Live
{0x11,0x0c,0x0b,0x0f,0x11,0x11,0x10,0x10,0x0c,0x0c},//Dance
};
void Band10_Sensetive(UINT8 value){
data UINT8 i;
idata UINT16 nx_addr = DECODER_EQ_BAND0;
xdata UINT8* pband = &(EQ_ARRAY[value]);
write_XDATA(DECODER_PRESCALE, EQ_PRESCALE[value]);//EQ sensetive
for(i=0; i<10; i++)
write_XDATA(nx_addr++, *pband++);//EQ sensetive
}
// max 596mV volume value 25
void EQ_mode_set(UINT8 EQ_Mode)
{
if(EQ_Mode < EQ_3D){
// if(EQ_Mode == 0){
// write_XDATA(SOUND_EFFECT_CTRL, 0x80);//EQ sensetive
// }
Band10_Sensetive(EQ_Mode);
// if(EQ_Mode)
// write_XDATA(SOUND_EFFECT_CTRL, 0x98);//EQ sensetive
#ifdef CLASS_D_AMP
#else
Codec_EQ_Set(0x0F, 0x0F);
#endif
}
if(EQ_Mode == EQ_3D){
Band10_Sensetive(EQ_FLAT);
#ifdef CLASS_D_AMP
#else
Codec_EQ_Set(0x09, 0x09);//EQ 0db
Codec_3D_Set(aud_3d);
#endif
}
#ifndef CLASS_D_AMP
else
Codec_3D_Exit();
#endif
write_XDATA(SOUND_EFFECT_CTRL, 0x98);//EQ sensetive
}
/*
void UserEQ(UINT8 user_eq_value[3])
{
// write_XDATA(DECODER_PRESCALE_VOLUME, 0x1f-user_eq_value[1]);
Codec_EQ_Set(0x0e-user_eq_value[0], 0x0e-user_eq_value[2], aud_3d);
}*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -