我需要你的帮助来确定以下示例代码中的问题(取自speex手册)以进行定点编码。 我测试了160个样本帧的编码,然后将其解码回来但问题是解码后的帧与原始帧完全不同(请参阅下面评论中的输出)。这可能是什么原因?谢谢任何帮助< / p>
#include<stdio.h>
#include"intel16.h"
#include <speex/speex.h>
#define FRAME_SIZE 160
#define MAX_NB_BYTES 25
SpeexBits bits;
void *enc_state;
int quality=4;
int nbBytes;
int byte_ptr;
int frame_size;
short frame[FRAME_SIZE];
char outBuffer[20];
SpeexBits decBits;
void *dec_state;
short decFrame[FRAME_SIZE];
int z=0;
int frame_size;
int main (int argc,char **argv)
{
for( z=0;z<160;z++)
{
frame[z]=intel_theme[z]; //array of short from "intel16" header file
}
printf("\n =================================== \n");
for( z=0;z<160;z++)
{
printf("%i",frame[z]);
printf (" ");
}
speex_bits_init(&bits);
enc_state = speex_encoder_init(&speex_nb_mode);
speex_encoder_ctl(enc_state,SPEEX_GET_FRAME_SIZE,&frame_size);
speex_encoder_ctl(enc_state,SPEEX_SET_QUALITY,&quality);
speex_bits_reset(&bits);
speex_encode_int(enc_state, frame, &bits);
// encoding from frame to &bits
nbBytes = speex_bits_write(&bits, outBuffer, MAX_NB_BYTES);
//writing from &bits to outBuffer
//----------------------------------------------------
speex_bits_destroy(&bits);
speex_encoder_destroy(enc_state);
printf("\n outBuffer: ");
for(z=0;z<20;z++)
{
printf("%c",outBuffer[z]);
}
printf("\n \n");
//-----------DECODING-------------------
speex_bits_init(&decBits);
dec_state=speex_decoder_init(&speex_nb_mode);
speex_decoder_ctl(dec_state, SPEEX_GET_FRAME_SIZE, &frame_size);
speex_bits_read_from(&decBits,outBuffer,nbBytes);
speex_decode_int(dec_state,&decBits,decFrame);
//----------------------------------------------------
printf("\n BUFFER DECODED BACK \n");
for(z=0;z<160;z++)
{
printf("%i",decFrame[z]);
printf (" ");
}
speex_bits_destroy(&decBits);
speex_decoder_destroy(dec_state);
/*==========END OF DECODING==============*/
printf("\n nbBytes: ");
printf("%i",nbBytes);
printf("\n frame_size= ");
printf("%i",frame_size);
printf ("\n");
//-----------------
printf("end of run!");
return 0;
}
答案 0 :(得分:0)
Speex是一款有损编解码器。这意味着解码器的输出通常与编码器的输入略有不同。由于允许Speex稍微更改数据,因此可以更多地压缩数据。
http://www.speex.org/docs/manual/speex-manual/node4.html#SECTION00413000000000000000