?? layer3.c
字號:
/***********************************************
copyright by Haia Tech
www.haia2004.com
************************************************/
//#include <stdio.h>
//#include <stdlib.h>
#include "common.h"
#include "decode.h"
unsigned int totpos=0;
unsigned char buf[BITSTREAM_BUFSIZE];
unsigned int frameNum=0,x4;
extern Bit_stream_struc bs;
frame_params fr_ps;
struct Granule grle[2][2];
short *pcm_dat;
short led;
extern unsigned short *mp3_dat;
extern unsigned int buf_byte_idx;
//FILE *file_p;
void mp3()
{
// FILE *musicout;
III_side_info_t III_side_info;
III_scalefac_t III_scalefac;
layer info;
short pcm_sample[2][SSLIMIT][SBLIMIT];
int i,j,k;
/*
char *filename1="d:\\arm_app\\encode_mp3\\10.mp3";
char *filename2="d:\\arm_app\\encode_mp3\\out.pcm" ;
if ((musicout = fopen(filename2, "w+b")) == NULL) {
printf ("Could not create \"%s\".\n", filename2);
exit(1);
}
if ((file_p = fopen(filename1, "rb")) == NULL) {
printf("Could not find \"%s\".\n", filename1);
exit(1);
}
*/
mp3_dat=(unsigned short *)0x0c030000;
pcm_dat=(short *)0x0c100000;
fr_ps.header = &info;
open_bit_stream_r();
frameNum=0;
totpos=0;
buf_byte_idx=0;
while(!bs.eobs) {
//嘗試幀同步
if (!seek_sync(SYNC_WORD)) {
// printf("\nFrame cannot be located\n");
break;
}
//解碼幀頭
decode_info( );
//將fr_ps.header中的信息解讀到fr_ps的相關域中
hdr_to_frps();
//輸出相關信息
// printf("\r%05lu", frameNum);
frameNum++;
if(led)
{
led=0;
*(unsigned int *)0x1d20044=0xff; //LED is Off
}
else
{
led=1;
*(unsigned int *)0x1d20044=0xf7; //LED is ON
}
if(frameNum>500) break;
if (info.error_protection)
buffer_CRC();
switch (info.lay) {
case 3:
{
int nSlots, main_data_end, flush_main;
int bytes_to_discard, gr, ch;
static int frame_start = 0;
//取Side信息
III_get_side_info(&III_side_info);
nSlots = main_data_slots();
//讀主數據(Audio Data)
for (; nSlots > 0; nSlots--) /* read main data. */
hputbuf((unsigned char) getbit(8));
main_data_end = totpos / 8; /*of privious frame*/
if ( flush_main=(totpos % bitsPerSlot) )
{
hgetbits((int)(bitsPerSlot - flush_main));
main_data_end ++;
}
bytes_to_discard = frame_start - main_data_end - III_side_info.main_data_begin ;
/* 最多=1 */
if( main_data_end > BITSTREAM_BUFSIZE )
{
frame_start -= BITSTREAM_BUFSIZE;
rewindNbytes( BITSTREAM_BUFSIZE); // totpos-=4096*8
}
frame_start += main_data_slots();
if (bytes_to_discard < 0) {
// printf("Not enough main data to decode frame %d. Frame discarded.\n",
// frameNum - 1);
break;
}
for (; bytes_to_discard > 0; bytes_to_discard--)
hgetbits(8);
for (gr=0;gr<2;gr++)
{
// double hybridIn[2][SBLIMIT][SSLIMIT];/* Hybrid filter input */
SS hybridIn[2];
//主解碼
for (ch=0; ch<fr_ps.stereo; ch++)
{
int is[SBLIMIT][SSLIMIT]; /*保存量化數據 頻率線*/
int part2_start;
part2_start=totpos;
//獲取比例因子
III_get_scale_factors(&III_scalefac,&III_side_info, gr, ch);
//Huffman解碼
III_hufman_decode(&grle[ch][gr],part2_start,is);
//逆量化采樣
III_dequantize_sample(is, hybridIn[ch], &III_scalefac, &grle[ch][gr], ch);
}
//兩個聲道處理完,進行立體聲處理
III_stereo(hybridIn, &III_scalefac, &grle[0][gr]);
for (ch=0; ch<fr_ps.stereo; ch++)
{
III_reorder(hybridIn[ch], &grle[ch][gr]);
//反混疊處理
III_antialias(hybridIn[ch],&grle[ch][gr]);
//IMDCT 加窗 疊加
Granule_imdct(&grle[ch][gr], ch, hybridIn[ch]);
//多相頻率倒置 X(-1)
Granule_freqinverse(hybridIn[ch]);
}
//多相合成
if(fr_ps.stereo == 2)
Granule_subband_synthesis2(hybridIn[0],hybridIn[1],pcm_sample);
else // 單聲道處理
Granule_subband_synthesis( 0,hybridIn[0],pcm_sample);
// Granule_subband_synthesis( 1,hybridIn[1],pcm_sample);
/* Output PCM sample points for one granule(顆粒). */
// fwrite(pcm_sample,2,SBLIMIT*SSLIMIT*2,musicout);
for(i=0;i<2;i++)
for(j=0;j<SSLIMIT;j++)
for(k=0;k<SBLIMIT;k++)
{
*pcm_dat=pcm_sample[i][j][k];
pcm_dat++;
}
}
}
break;
default:
// printf("\nOnly layer III supported!\n");
// exit(1);
break;
}
}
// fclose(file_p);
// fclose(musicout);
// printf("\nDecoding done.\n");
*(unsigned int *)0x1d20044=0xff; //LED is Off
while(1);
return;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -