我需要您的幫助來確定下面的示例代碼(從speex手冊中獲取)用於固定點編碼的問題。 我測試了160個樣本幀的編碼,然後將其解碼回來。但問題是,解碼後的幀與原始幀完全不同(請參閱下面的註釋輸出內容)。這是什麼原因?感謝您的任何幫助Speex解碼的幀不是原始幀
#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;
}
OUTPUT: //原始幀 1 -512 16384 512 -768 -2048 -1280 -1024 256 12288 0 8192 253 256 -768 12288 0 -16 -768 -512 -1 0 - 512 -768 -1536 -512 -512 -768 16384 0 8192 -512 16384 512 -768 -2048 -1280 256 -1024 12288 0 8192 253 256 -768 12288 0 -16 -768 -512 -1 0 -512 -768 - 1536 -512 -512 -768 16384 0 8192 -512 16384 512 -768 -2048 -1280 256 -1024 12288 0 8192 253 256 -768 12288 0 -16 -768 -512 -1 0 -512 -768 -1536 -512 - 512 -768 -4136 – 2012-03-11 07:02:04
//解碼後的幀。完全不同 緩衝器解碼後退 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2838 -3982 4801 -4136 432 -1945 610 1035 -1090 2752 -558 1431 -2320 - 1016 789 5084 -2395 -2916 -225 -311 -703 586 1110 -557 -1152 1096 229 425 5825 -933 3922 -6289 7423 -6636 -793 -2123 -354 991 -1947 3958 -1070 1380 -2120 -2777 -679 9010 – 2012-03-11 07:11:02
看到我對這個問題的回答:http://stackoverflow.com/a/10048755/273501 – 2012-04-06 20:21:51