It's lossy encoding.<br><br><div class="gmail_quote">On Mon, Mar 12, 2012 at 1:17 AM, Mashal al-shboul <span dir="ltr"><<a href="mailto:shboul8989@yahoo.com">shboul8989@yahoo.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="HOEnZb"><div class="h5"><div><div style="font-size:14pt;font-family:times new roman,new york,times,serif">
<div style="font-family:times new roman,new york,times,serif;font-size:14pt"><div style="font-family:times new roman,new york,times,serif;font-size:12pt"><div><div><div style="font-size:14pt;font-family:times new roman,new york,times,serif">
<div>Hi All,</div><div>i need your help in determining the problem in the following sample code (taken from speex manual) for fixed point encoding.</div><div>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<br>
</div><div><br></div><div>#include<stdio.h><br>#include"intel16.h"<br>#include <speex/speex.h></div><div><br>#define FRAME_SIZE 160<br>#define MAX_NB_BYTES 25<br>SpeexBits bits;<br>void *enc_state;<br>
int quality=4;Â Â Â Â Â Â <br>int
nbBytes;<br>int byte_ptr;<br>int frame_size;<br>short frame[FRAME_SIZE];Â <br>char outBuffer[20];<br><br>SpeexBits decBits;<br>void *dec_state;<br>short
decFrame[FRAME_SIZE];<br>/*===========END ===============================*/<br><br><br>int z=0;<br>int frame_size;<br><br><br>int main (int argc,char **argv)<br>{<br>for( z=0;z<160;z++)<br>Â Â Â {<br>Â Â Â frame[z]=intel_theme[z];Â //array of short from "intel16" header file<br>
   }<br> printf("\n =================================== \n");<br><br> for( z=0;z<160;z++)<br>   {<br>       printf("%i",frame[z]);<br>   printf (" ");<br>       }<br><br>/*===============================ENCODING==============================================*/<br>
<br>Â Â Â Â speex_bits_init(&bits);<br>Â Â Â Â enc_state = speex_encoder_init(&speex_nb_mode);<br>Â Â Â Â
speex_encoder_ctl(enc_state,SPEEX_GET_FRAME_SIZE,&frame_size);<br>Â Â Â Â speex_encoder_ctl(enc_state,SPEEX_SET_QUALITY,&quality);<br>Â Â Â Â speex_bits_reset(&bits);<br>Â <br>//-----------TWO CALLS FOR ENCODING-------------------<br>
    speex_encode_int(enc_state, frame, &bits);               // encoding from frame to &bits<br>    nbBytes = speex_bits_write(&bits, outBuffer, MAX_NB_BYTES); //writing from &bits to outBuffer<br>//----------------------------------------------------<br>
    <br>    speex_bits_destroy(&bits);<br>    speex_encoder_destroy(enc_state);   <br><br>printf("\n outBuffer: ");<br>for(z=0;z<20;z++)<br>{<br>printf("%c",outBuffer[z]);<br>}<br>printf("\n
\n");<br>/*===============================END OF ENCODING=========================================*/<br><br><br>/*===============================DECODING==============================================*/<br><br>speex_bits_init(&decBits);<br>
dec_state=speex_decoder_init(&speex_nb_mode);<br>speex_decoder_ctl(dec_state, SPEEX_GET_FRAME_SIZE, &frame_size);<br><br>//-----------TWO CALLS FOR DECODING-------------------<br>speex_bits_read_from(&decBits,outBuffer,nbBytes);<br>
speex_decode_int(dec_state,&decBits,decFrame);<br>//----------------------------------------------------<br>printf("\n BUFFER DECODED BACK \n");<br><span style="font-weight:bold"></span></div><div><span style="font-weight:bold"><br>
</span></div><div><span style="font-weight:bold">for(z=0;z<160;z++)</span><br style="font-weight:bold"><span style="font-weight:bold">{</span><br style="font-weight:bold"><span style="font-weight:bold">printf("%i",decFrame[z]);</span><br style="font-weight:bold">
<span style="font-weight:bold">printf ("Â ");</span><br style="font-weight:bold"><span style="font-weight:bold">}</span><br style="font-weight:bold"><br>speex_bits_destroy(&decBits);<br>speex_decoder_destroy(dec_state);<br>
/*===============================END OF DECODING==============================================*/<br>printf("\n nbBytes: ");<br>printf("%i",nbBytes);<br>printf("\n frame_size= ");<br>printf("%i",frame_size);<br>
printf ("\n");<br>//-----------------<br>printf("end of run!");<br><br>return 0;<br>}</div><div><br></div><div><span style="font-weight:bold">OUTPUT:</span></div><div>//the original frame<br><span style="font-weight:bold"></span></div>
<div>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Â <br>
 =================================== <br><br> outBuffer: �9�p�C��m�Cx6��<br> <br>//the decoded frame .totally different<br> BUFFER DECODED BACK <br>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Â <br>Â nbBytes: 20<br>Â frame_size= 160<br>
<br><span style="font-weight:bold"></span></div><div><br><span style="font-weight:bold"></span></div><div><br><span style="font-weight:bold"></span></div><div><br><span style="font-weight:bold"></span></div><div><br><span style="font-weight:bold"></span></div>
<div><span style="font-weight:bold"></span></div></div></div></div><br><br> </div> </div> </div></div></div></div><br>_______________________________________________<br>
Speex-dev mailing list<br>
<a href="mailto:Speex-dev@xiph.org">Speex-dev@xiph.org</a><br>
<a href="http://lists.xiph.org/mailman/listinfo/speex-dev" target="_blank">http://lists.xiph.org/mailman/listinfo/speex-dev</a><br>
<br></blockquote></div><br>