0

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 in a comment).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];

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: //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 -4136 – Mashal al-shboul Mar 11 '12 at 07:02
  • //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 – Mashal al-shboul Mar 11 '12 at 07:11
  • See my answer to this question: http://stackoverflow.com/a/10048755/273501 – Thilo Köhler Apr 06 '12 at 20:21
  • how did you solve these 000000000000 at the beginning of decoded frame? I am messing up with this particular problem currently.? thanks in advance... – guness Jan 26 '13 at 03:07

1 Answers1

0

Speex is a lossy codec. That means that the output from the decoder will usually be a little different than the input to the encoder. Because Speex is allowed to change the data a little bit, it can compress the data more.

http://www.speex.org/docs/manual/speex-manual/node4.html#SECTION00413000000000000000

rob mayoff
  • 375,296
  • 67
  • 796
  • 848
  • Thank you for replying.Do you mean that decoding back a frame will result in different one from the encoded?..to the degree of the major difference shown above (in the comments, BUFFER DECODED BACK)? is there a method to ensure that Speex works correctly? – Mashal al-shboul Mar 11 '12 at 11:23
  • Don't put your output in comments. Edit your question and paste it in there, formatted as code. – rob mayoff Mar 11 '12 at 18:37
  • i can't exceed max character limits! – Mashal al-shboul Mar 12 '12 at 18:27