資源簡介
在CCS上測試通過的MP3解碼代碼,可結合5509和AIC23來實現音頻解碼和編碼,適合初學者。

代碼片段和文件信息
#include?
#include?
#include?
#include?“common.h“
char?*layer_names[3]?=?{?“I“?“II“?“III“?};
int?bitrate[3][15]?=?{
{0326496128160192224256288320352384416448}
{0324856648096112128160192224256320384}
{032404856648096112128160192224256320}
};
double??s_freq[4]?=?{44.1?48?32?0};
char?*mode_names[4]?=?{?“stereo“?“j-stereo“?“dual-ch“?“single-ch“?};
FILE?*OpenTableFile(char?*name)
{
char?fulname[80];
FILE?*f;
fulname[0]?=?‘\0‘;
strcat(fulname?name);
if(?(f=fopen(fulname“r“))==NULL?)?{
fprintf(stderr“\nOpenTable:?could?not?find?%s\n“?fulname);
????}
????return?f;
}
void?WriteHdr(frame_params?*fr_ps)
{
layer?*info?=?fr_ps->header;
printf(“HDR:??sync=FFF?id=%X?layer=%X?ep=%X?br=%X?sf=%X?pd=%X?“
info->version?info->lay?!info->error_protection
info->bitrate_index?info->sampling_frequency?info->padding);
printf(“pr=%X?m=%X?js=%X?c=%X?o=%X?e=%X\n“
info->extension?info->mode?info->mode_ext
info->copyright?info->original?info->emphasis);
printf(“layer=%s?tot?bitrate=%d?sfrq=%.1f?mode=%s?“
layer_names[info->lay-1]?bitrate[info->lay-1][info->bitrate_index]
s_freq[info->sampling_frequency]?mode_names[info->mode]);
printf(“sblim=%d?jsbd=%d?ch=%d\n“
fr_ps->sblimit?fr_ps->jsbound?fr_ps->stereo);
}
void?*mem_alloc(unsigned?long?block?char?*item)
{
void?*ptr;
ptr?=?(void?*)malloc((unsigned?long)block);
if?(ptr?!=?NULL)
memset(ptr?0?block);
else{
printf(“Unable?to?allocate?%s\n“?item);
exit(0);
}
return?ptr;
}
/*open?and?initialize?the?buffer;?*/
void?alloc_buffer(Bit_stream_struc?*bs?int?size)
{
bs->buf?=?(unsigned?char?*)?mem_alloc(size*sizeof(unsigned?char)?“buffer“);
bs->buf_size?=?size;
}
void?desalloc_buffer(Bit_stream_struc?*bs)
{
free(bs->buf);
}
/*?open?the?device?to?read?the?bit?stream?from?it?*/
void?open_bit_stream_r(Bit_stream_struc?*bs?char?*bs_filenam?int?size)
{
register?unsigned?char?flag?=?1;
if?((bs->pt?=?fopen(bs_filenam?“rb“))?==?NULL)?{
printf(“Could?not?find?\“%s\“.\n“?bs_filenam);
exit(1);
}
bs->format?=?BINARY;
alloc_buffer(bs?size);
bs->buf_byte_idx=0;
bs->buf_bit_idx=0;
bs->totbit=0;
bs->mode?=?READ_MODE;
bs->eob?=?FALSE;
bs->eobs?=?FALSE;
}
void?close_bit_stream_r(Bit_stream_struc?*bs)
{
fclose(bs->pt);
desalloc_buffer(bs);
}
/*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?end_bs(Bit_stream_struc?*bs)
{
??return(bs->eobs);
}
/*return?the?current?bit?stream?length?(in?bits)*/
unsigned?long?sstell(Bit_stream_struc?*bs)
{
??return(bs->totbit);
}
void?refill_buffer(Bit_stream_struc?*bs)
{
register?int?i=bs->buf_size-2-bs->buf_byte_idx;
register?unsigned?long?n=1;
while?((i>=0)?&&?(!bs->eob))?{
n=fread(&bs->buf[
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2011-11-03?20:30??MP3\
?????目錄???????????0??2011-11-24?21:08??MP3\mp3code\
?????目錄???????????0??2011-11-24?20:08??MP3\mp3code\Debug\
?????文件???????29381??2011-11-24?20:07??MP3\mp3code\Debug\common.obj
?????文件??????114039??2011-11-24?20:08??MP3\mp3code\Debug\decode.obj
?????文件???????23221??2011-11-24?20:08??MP3\mp3code\Debug\huffman.obj
?????文件???????23574??2011-11-24?20:25??MP3\mp3code\Debug\la
?????文件???????32277??2011-11-24?20:08??MP3\mp3code\Debug\mp3code.map
?????文件??????292886??2011-11-24?20:08??MP3\mp3code\Debug\mp3code.out
?????文件?????????248??2011-11-24?20:25??MP3\mp3code\Debug.lkf
?????文件????????1810??2011-11-24?20:08??MP3\mp3code\cc_build_Debug.log
?????文件????????7463??1999-01-28?13:27??MP3\mp3code\common.c
?????文件????????4036??1999-01-28?13:59??MP3\mp3code\common.h
?????文件???????29640??2011-11-24?20:09??MP3\mp3code\decode.c
?????文件????????1673??2011-11-24?20:25??MP3\mp3code\decode.h
?????文件????????6006??1999-01-28?09:20??MP3\mp3code\huffman.c
?????文件????????2089??1999-01-28?09:19??MP3\mp3code\huffman.h
?????文件????????5394??2011-11-24?21:08??MP3\mp3code\la
?????目錄???????????0??2011-11-24?20:07??MP3\mp3code\mp3code.CS_\
?????文件????????3072??2011-11-24?20:07??MP3\mp3code\mp3code.CS_\FILE.CDX
?????文件????????2556??2011-11-24?21:08??MP3\mp3code\mp3code.CS_\FILE.DBF
?????文件????????4378??2011-11-24?20:07??MP3\mp3code\mp3code.CS_\FILE.FPT
?????文件??????346624??2011-11-24?21:08??MP3\mp3code\mp3code.CS_\SYMBOL.CDX
?????文件??????275289??2011-11-24?21:08??MP3\mp3code\mp3code.CS_\SYMBOL.DBF
?????文件??????571346??2011-11-24?21:08??MP3\mp3code\mp3code.CS_\SYMBOL.FPT
?????文件?????????759??2011-11-24?19:00??MP3\mp3code\mp3code.cmd
?????文件????????3536??2011-11-24?21:26??MP3\mp3code\mp3code.paf2
?????文件????????1177??2011-11-24?16:15??MP3\mp3code\mp3code.pjt
?????文件???????12620??2011-11-24?21:26??MP3\mp3code\mp3code.sbl
評論
共有 條評論