[Speex-dev] problem: The decoded frame is not as the original one
Arthurc
arthurc99 at yahoo.com
Sun Mar 11 19:59:55 PDT 2012
1. Sound encoding and decoding is a lossy process.
2. To determine that it is working correctly, you either play it back or look at he wave form.
Arthur
On 2012年3月12日, at 上午1:17, Mashal al-shboul <shboul8989 at yahoo.com> wrote:
> Hi All,
> i need your help in determining the problem in the following sample code (taken from speex manual) for fixed point encoding.
> i tested encoding a 160 sample frame and then decoding it back But The problem is that the decoded frame is totally different from the original frame(see output below).What is the possible reason for this?.thanks for any help
>
> #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];
> /*===========END ===============================*/
>
>
> 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 (" ");
> }
>
> /*===============================ENCODING==============================================*/
>
> 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);
>
> //-----------TWO CALLS FOR ENCODING-------------------
> 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");
> /*===============================END OF ENCODING=========================================*/
>
>
> /*===============================DECODING==============================================*/
>
> speex_bits_init(&decBits);
> dec_state=speex_decoder_init(&speex_nb_mode);
> speex_decoder_ctl(dec_state, SPEEX_GET_FRAME_SIZE, &frame_size);
>
> //-----------TWO CALLS FOR DECODING-------------------
> 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:
> //the original frame
> 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 -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 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 -1 0 -512 -768 -1536 -512 -512 -768 16384 -1
> ===================================
>
> outBuffer: ╴9╴p╴C╴╴m╴Cx6╴╴
>
> //the decoded frame .totally different
> 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 -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 -2451 -4210 -1845 229 -1687 317 1443 -1355 -2818 214 721 -313 9997 -60 3489 -5953 9277 -6990 -2716 -1642 -792 477 -2417 5801 -1200 1055 -1744 -2927 -2053 10273 -1913 -4342 -2718 427
> nbBytes: 20
> frame_size= 160
>
>
>
>
>
>
>
> _______________________________________________
> Speex-dev mailing list
> Speex-dev at xiph.org
> http://lists.xiph.org/mailman/listinfo/speex-dev
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.xiph.org/pipermail/speex-dev/attachments/20120312/14e207f5/attachment-0001.htm
More information about the Speex-dev
mailing list