MP3_Common.c
上传用户:kingbiz
上传日期:2022-06-24
资源大小:2524k
文件大小:3k
- /*============================================================================*/
- /*============================================================================*/
- /*============================================================================*/
- #include "mp3_common.h"
- /*============================================================================*/
- /*============================================================================*/
- static char *mode_names[4] = { "stereo", "j-stereo", "dual-ch", "single-ch" };
- static char *layer_names[3] = { "I", "II", "III" };
- static S16 buffer[BUFFER_SIZE];
- /*============================================================================*/
- /*============================================================================*/
- /* open the device to read the bit stream from it */
- void open_bit_stream_r()
- {
- bs.buf =buffer;
- bs.read_ptr =0;
- bs.write_ptr =0;
- bs.bit_len =8;
- bs.totbit =0;
- bs.eof = FALSE;
- bs.eobs = FALSE;
- // quest_stream(&bs.write_ptr);
- }
- /*return the status of the bit stream*/
- /* returns 1 if end of bit stream was reached */
- /* returns 0 if end of bit stream was not reached */
- int seek_sync(unsigned int sync)
- {
- unsigned int aligning;
- unsigned int val;
- aligning = bs.totbit%ALIGNING;
- if (aligning)
- getbit((int)(ALIGNING-aligning)); //字节对齐
- val = getbit(12);
- while( ((val&0xfff)!= sync) && (!bs.eobs))
- {
- val<<=ALIGNING;
- val|=getbit(ALIGNING);
- }
- if (bs.eobs)
- return(0);
- else
- return(1);
- }
- int js_bound(int lay, int m_ext)
- {
- static int jsb_table[3][4] = {
- { 4, 8, 12, 16 },
- { 4, 8, 12, 16},
- { 0, 4, 8, 16}
- }; /* lay+m_e -> jsbound */
- // if(lay<1 || lay >3 || m_ext<0 || m_ext>3) {
- // fprintf(stderr, "js_bound bad layer/modext (%d/%d)n", lay, m_ext);
- // exit(1);
- // }
- return(jsb_table[lay-1][m_ext]);
- }
- /* interpret data in hdr str to fields in fr_ps */
- void hdr_to_frps()
- {
- layer *hdr = fr_ps.header; /* (or pass in as arg?) */
- fr_ps.actual_mode = hdr->mode;
- fr_ps.stereo = (hdr->mode == MPG_MD_MONO) ? 1 : 2;
- fr_ps.sblimit = SBLIMIT;
- if(hdr->mode == MPG_MD_JOINT_STEREO)
- fr_ps.jsbound = js_bound(hdr->lay, hdr->mode_ext);
- else
- fr_ps.jsbound = fr_ps.sblimit;
- }
-
- int putmask[9]={0x0, 0x1, 0x3, 0x7, 0xf, 0x1f, 0x3f, 0x7f, 0xff};
- /*read N bit from the bit stream */
- //#define MIN(A, B) ((A) < (B) ? (A) : (B))
- U32 getbit(int N)
- {
- U32 val;
- U32 temp;
- int j;
- int i;
- /////
-
- j =N;
- val =0;
-
- if(N>MAX_LENGTH)
- {
- DbgUart_Printf("nwrong length!");
- }
- ///
-
- bs.totbit+=j;
- while(j>0)
- {
- if(!bs.bit_len)
- {
- bs.bit_len=8;
- if(++bs.read_ptr>=mp3_dat_size)
- { //mp3的长度
- DbgUart_Printf("bs.read_ptr=%08XH(%d)n",bs.read_ptr,bs.read_ptr);
- bs.eobs=1;
- }
- }
- i=MIN(bs.bit_len,j);
- //temp=mp3_data[bs.read_ptr]&putmask[bs.bit_len];
- temp=mp3_src[bs.read_ptr]&putmask[bs.bit_len];
- bs.bit_len-=i;
- j-=i;
- temp>>=bs.bit_len;
- val|=(temp<<j);
- }
- return val;
- }
- /*
- void quest_stream(unsigned int *ptr)
- {
- ptr=ptr;
- }
- */