【发布时间】:2012-04-07 04:21:51
【问题描述】:
我需要您的帮助来确定以下定点编码示例代码(取自 speex 手册)中的问题。 我测试了对 160 个样本帧进行编码,然后将其解码,但问题是解码后的帧与原始帧完全不同(请参阅下面的评论中的输出)。这可能是什么原因?感谢任何帮助
#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 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 -1536 -512 -78 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 -52 768 -4136
-
//解码后的帧.完全不同的BUFFER DECODED BACK 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 -2320 -1016 789 5084 -2395 -2916 -2916 -225 -311 -703 586 586 586 1110 -557 -557 -1157 -1152 1096 229 429 429 429 425555555555555555555555555555555555555555555555555555555555558825588255882558825588255882558825588255882558825太平洋-793 -2123 -354 991 -1947 3958 -1070 1380 -2120 -2777 -679 9010
-
查看我对这个问题的回答:stackoverflow.com/a/10048755/273501
-
你是如何解决解码帧开头的这些 000000000000 的?我目前正在解决这个特殊问题。?在此先感谢...
标签: c compression frame encode speex