Windows Phone 8是否支持amr-nb音频格式?我们可以在Windows Phone 8中将amr-nb转换为pcm吗?
答案 0 :(得分:2)
我已经正确地完成了这项工作。您可以按照以下步骤操作:
创建c ++运行时项目
将amr-nb代码插入到c ++运行时项目
和代码
int DecodeAMRFileToWAVEFile(const char* pchAMRFileName, const char* pchWAVEFilename)
{
FILE* fpamr = NULL;
FILE* fpwave = NULL;
char magic[8];
void * destate;
int nFrameCount = 0;
int stdFrameSize;
unsigned char stdFrameHeader;
unsigned char amrFrame[MAX_AMR_FRAME_SIZE];
short pcmFrame[PCM_FRAME_SIZE];
fpamr = fopen(pchAMRFileName, "rb");
if ( fpamr==NULL ) return 0;
// 检查amr文件头
fread(magic, sizeof(char), strlen(AMR_MAGIC_NUMBER), fpamr);
if (strncmp(magic, AMR_MAGIC_NUMBER, strlen(AMR_MAGIC_NUMBER)))
{
fclose(fpamr);
return 0;
}
// 创建并初始化WAVE文件
fpwave = fopen(pchWAVEFilename, "wb");
WriteWAVEFileHeader(fpwave, nFrameCount);
/* init decoder */
destate = Decoder_Interface_init();
// 读第一帧 - 作为参考帧
memset(amrFrame, 0, sizeof(amrFrame));
memset(pcmFrame, 0, sizeof(pcmFrame));
ReadAMRFrameFirst(fpamr, amrFrame, &stdFrameSize, &stdFrameHeader);
// 解码一个AMR音频帧成PCM数据
Decoder_Interface_Decode(destate, amrFrame, pcmFrame, 0);
nFrameCount++;
fwrite(pcmFrame, sizeof(short), PCM_FRAME_SIZE, fpwave);
// 逐帧解码AMR并写到WAVE文件里
while(1)
{
memset(amrFrame, 0, sizeof(amrFrame));
memset(pcmFrame, 0, sizeof(pcmFrame));
if (!ReadAMRFrame(fpamr, amrFrame, stdFrameSize, stdFrameHeader)) break;
// 解码一个AMR音频帧成PCM数据 (8k-16b-单声道)
Decoder_Interface_Decode(destate, amrFrame, pcmFrame, 0);
nFrameCount++;
fwrite(pcmFrame, sizeof(short), PCM_FRAME_SIZE, fpwave);
}
Decoder_Interface_exit(destate);
fclose(fpamr);
fclose(fpwave);
// 重写WAVE文件头
fpwave = fopen(pchWAVEFilename, "r+");
WriteWAVEFileHeader(fpwave, nFrameCount);
fclose(fpwave);
return nFrameCount;
}
评论用中文写成:D