关于AMR编解码函数代码问题请教【3GPP给出的代码学习遇到问题】

teleinfor 2012-01-06 01:20:11
如果你研究过AMR编解码,并且参考了3gpp给出的source code,请指点迷津。谢谢了!

详细请参考下面附代码。问题:
Decoder_Interface_Decode(destate, analysis, synth, 0)函数负责解码工作,这里analysis输入数据是具体的AMR FRAME数据还是保存为.amr文件之后的文件frame数据呢?我一直没看明白。

根据这个规范的说明,这个示例编解码代码都是操作的文件,并且考虑了不同的文件存储格式。我就搞不懂了,不知道他到底编解码的时候输出和输入是单纯的AMR FRAME DATA(即是网络上RTP真正承载的数据),还是指的保存为文件后附加上文件保存信息时候的storage frame格式数据呢?

具体解码器代码如下(具体的全代码请到3GPP TS26.104获取):

/*
* main
*
*
* Function:
* Speech decoder main program
*
* Usage: decoder bitstream_file synthesis_file
*
* Format for ETSI bitstream file:
* 1 word (2-byte) for the TX frame type
* 244 words (2-byte) containing 244 bits.
* Bit 0 = 0x0000 and Bit 1 = 0x0001
* 1 word (2-byte) for the mode indication
* 4 words for future use, currently written as zero
*
* Format for 3GPP bitstream file:
* Holds mode information and bits packed to octets.
* Size is from 1 byte to 31 bytes.
*
* Format for synthesis_file:
* Speech is written to a 16 bit 8kHz file.
*
* ETSI bitstream file format is defined using ETSI as preprocessor
* definition
* Returns:
* 0
*/
int main (int argc, char * argv[]){

FILE * file_speech, *file_analysis;

short synth[160];
int frames = 0;
int * destate;
int read_size;
#ifndef ETSI
unsigned char analysis[32];
enum Mode dec_mode;
#ifdef IF2
short block_size[16]={ 12, 13, 15, 17, 18, 20, 25, 30, 5, 0, 0, 0, 0, 0, 0, 0 };
#else
char magic[8];
short block_size[16]={ 12, 13, 15, 17, 19, 20, 26, 31, 5, 0, 0, 0, 0, 0, 0, 0 };
#endif
#else
short analysis[250];
#endif

/* Process command line options */
if (argc == 3){

file_speech = fopen(argv[2], "wb");
if (file_speech == NULL){
fprintf ( stderr, "%s%s%s\n","Use: ",argv[0], " input.file output.file " );
return 1;
}

file_analysis = fopen(argv[1], "rb");
if (file_analysis == NULL){
fprintf ( stderr, "%s%s%s\n","Use: ",argv[0], " input.file output.file " );
fclose(file_speech);
return 1;
}

}
else {
fprintf ( stderr, "%s%s%s\n","Use: ",argv[0], " input.file output.file " );
return 1;
}
Copyright();
/* init decoder */
destate = Decoder_Interface_init();

#ifndef ETSI
#ifndef IF2
/* read and verify magic number */
fread( magic, sizeof( char ), strlen( AMR_MAGIC_NUMBER ), file_analysis );
if ( strncmp( magic, AMR_MAGIC_NUMBER, strlen( AMR_MAGIC_NUMBER ) ) ) {
fprintf( stderr, "%s%s\n", "Invalid magic number: ", magic );
fclose( file_speech );
fclose( file_analysis );
return 1;
}
#endif
#endif

#ifndef ETSI

/* find mode, read file */
while (fread(analysis, sizeof (unsigned char), 1, file_analysis ) > 0)
{
#ifdef IF2
dec_mode = analysis[0] & 0x000F;
#else
dec_mode = (analysis[0] >> 3) & 0x000F;
#endif
read_size = block_size[dec_mode];

fread(&analysis[1], sizeof (char), read_size, file_analysis );
#else

read_size = 250;
/* read file */
while (fread(analysis, sizeof (short), read_size, file_analysis ) > 0)
{
#endif

frames ++;

/* call decoder */
Decoder_Interface_Decode(destate, analysis, synth, 0);

fwrite( synth, sizeof (short), 160, file_speech );
}

Decoder_Interface_exit(destate);

fclose(file_speech);
fclose(file_analysis);
fprintf ( stderr, "\n%s%i%s\n","Decoded ", frames, " frames.");

return 0;
}
...全文
275 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
JACKLI2012 2012-12-19
  • 打赏
  • 举报
回复
楼主可否将AMR编解码的全部源码发给我一份?最近我也刚刚开始接触AMR,先谢谢啦。我邮箱:458463197@qq.com。

2,543

社区成员

发帖
与我相关
我的任务
社区描述
专题开发/技术/项目 多媒体/流媒体开发
社区管理员
  • 多媒体/流媒体开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧