<html><body><div style="color:#000; background-color:#fff; 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: 14pt;"><div style="font-family: times new roman, new york, times, serif; font-size: 12pt;"><div id="yiv691098271"><div><div style="color:#000;background-color:#fff;font-family:times new roman, new york, times, serif;font-size:14pt;"><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&lt;stdio.h&gt;<br>#include"intel16.h"<br>#include &lt;speex/speex.h&gt;</div><div><br>#define FRAME_SIZE 160<br>#define MAX_NB_BYTES 25<br>SpeexBits bits;<br>void *enc_state;<br>int quality=4;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>int
 nbBytes;<br>int byte_ptr;<br>int frame_size;<br>short frame[FRAME_SIZE];&nbsp; <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&lt;160;z++)<br>&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp; frame[z]=intel_theme[z];&nbsp; //array of short from "intel16" header file<br>&nbsp;&nbsp;&nbsp; }<br>&nbsp;printf("\n =================================== \n");<br><br>&nbsp;for( z=0;z&lt;160;z++)<br>&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf("%i",frame[z]);<br>&nbsp;&nbsp;&nbsp; printf ("&nbsp; ");<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br><br>/*===============================ENCODING==============================================*/<br><br>&nbsp;&nbsp;&nbsp;&nbsp; speex_bits_init(&amp;bits);<br>&nbsp;&nbsp;&nbsp;&nbsp; enc_state = speex_encoder_init(&amp;speex_nb_mode);<br>&nbsp;&nbsp;&nbsp;&nbsp;
 speex_encoder_ctl(enc_state,SPEEX_GET_FRAME_SIZE,&amp;frame_size);<br>&nbsp;&nbsp;&nbsp;&nbsp; speex_encoder_ctl(enc_state,SPEEX_SET_QUALITY,&amp;quality);<br>&nbsp;&nbsp;&nbsp;&nbsp; speex_bits_reset(&amp;bits);<br>&nbsp;<br>//-----------TWO CALLS FOR ENCODING-------------------<br>&nbsp;&nbsp;&nbsp;&nbsp; speex_encode_int(enc_state, frame, &amp;bits);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // encoding from frame to &amp;bits<br>&nbsp;&nbsp;&nbsp;&nbsp; nbBytes = speex_bits_write(&amp;bits, outBuffer, MAX_NB_BYTES); //writing from &amp;bits to outBuffer<br>//----------------------------------------------------<br>&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp;&nbsp; speex_bits_destroy(&amp;bits);<br>&nbsp;&nbsp;&nbsp;&nbsp; speex_encoder_destroy(enc_state);&nbsp;&nbsp;&nbsp; <br><br>printf("\n outBuffer: ");<br>for(z=0;z&lt;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(&amp;decBits);<br>dec_state=speex_decoder_init(&amp;speex_nb_mode);<br>speex_decoder_ctl(dec_state, SPEEX_GET_FRAME_SIZE, &amp;frame_size);<br><br>//-----------TWO CALLS FOR DECODING-------------------<br>speex_bits_read_from(&amp;decBits,outBuffer,nbBytes);<br>speex_decode_int(dec_state,&amp;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&lt;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 ("&nbsp; ");</span><br style="font-weight:bold;"><span style="font-weight:bold;">}</span><br style="font-weight:bold;"><br>speex_bits_destroy(&amp;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&nbsp; -512&nbsp; 16384&nbsp; 512&nbsp; -768&nbsp; -2048&nbsp; -1280&nbsp; 256&nbsp; -1024&nbsp; 12288&nbsp; 0&nbsp; 8192&nbsp; 253&nbsp; 256&nbsp; -768&nbsp; 12288&nbsp; 0&nbsp; -16&nbsp; -768&nbsp;
 -512&nbsp; -1&nbsp; 0&nbsp; -512&nbsp; -768&nbsp; -1536&nbsp; -512&nbsp; -512&nbsp; -768&nbsp; 16384&nbsp; 0&nbsp; 8192&nbsp; -512&nbsp; 16384&nbsp; 512&nbsp; -768&nbsp; -2048&nbsp; -1280&nbsp; 256&nbsp; -1024&nbsp; 12288&nbsp; 0&nbsp; 8192&nbsp; 253&nbsp; 256&nbsp; -768&nbsp; 12288&nbsp; 0&nbsp; -16&nbsp; -768&nbsp; -512&nbsp; -1&nbsp; 0&nbsp; -512&nbsp; -768&nbsp; -1536&nbsp; -512&nbsp; -512&nbsp; -768&nbsp; 16384&nbsp; 0&nbsp; 8192&nbsp; -512&nbsp; 16384&nbsp; 512&nbsp; -768&nbsp; -2048&nbsp; -1280&nbsp; 256&nbsp; -1024&nbsp; 12288&nbsp; 0&nbsp; 8192&nbsp; 253&nbsp; 256&nbsp; -768&nbsp; 12288&nbsp; 0&nbsp; -16&nbsp; -768&nbsp; -512&nbsp; -1&nbsp; 0&nbsp; -512&nbsp; -768&nbsp; -1536&nbsp; -512&nbsp; -512&nbsp; -768&nbsp; 16384&nbsp; 0&nbsp; 8192&nbsp; -512&nbsp; 16384&nbsp; 512&nbsp; -768&nbsp; -2048&nbsp; -1280&nbsp; 256&nbsp; -1024&nbsp; 12288&nbsp; 0&nbsp; 8192&nbsp; 253&nbsp; 256&nbsp; -768&nbsp; 12288&nbsp; 0&nbsp; -16&nbsp; -768&nbsp; -512&nbsp;
 -1&nbsp; 0&nbsp; -512&nbsp; -768&nbsp; -1536&nbsp; -512&nbsp; -512&nbsp; -768&nbsp; 16384&nbsp; 0&nbsp; 8192&nbsp; -512&nbsp; 16384&nbsp; 512&nbsp; -768&nbsp; -2048&nbsp; -1280&nbsp; 256&nbsp; -1024&nbsp; 12288&nbsp; 0&nbsp; 8192&nbsp; 253&nbsp; 256&nbsp; -768&nbsp; 12288&nbsp; 0&nbsp; -16&nbsp; -768&nbsp; -512&nbsp; -1&nbsp; 0&nbsp; -512&nbsp; -768&nbsp; -1536&nbsp; -512&nbsp; -512&nbsp; -768&nbsp; 16384&nbsp; 0&nbsp; -1&nbsp; 0&nbsp; -512&nbsp; -768&nbsp; -1536&nbsp; -512&nbsp; -512&nbsp; -768&nbsp; 16384&nbsp; -1&nbsp; <br>&nbsp;=================================== <br><br>&nbsp;outBuffer: �9�p�C��m�Cx6��<br>&nbsp;<br>//the decoded frame .totally different<br>&nbsp;BUFFER DECODED BACK <br>0&nbsp; 0&nbsp; 0&nbsp; 0&nbsp; 0&nbsp; 0&nbsp; 0&nbsp; 0&nbsp; 0&nbsp; 0&nbsp; 0&nbsp; 0&nbsp; 0&nbsp; 0&nbsp; 0&nbsp; 0&nbsp; 0&nbsp; 0&nbsp; 0&nbsp; 0&nbsp; 0&nbsp; 0&nbsp; 0&nbsp; 0&nbsp; 0&nbsp; 0&nbsp; 0&nbsp; 0&nbsp; 0&nbsp; 0&nbsp; 0&nbsp;
 0&nbsp; 0&nbsp; 0&nbsp; 0&nbsp; 0&nbsp; 0&nbsp; 0&nbsp; 0&nbsp; 0&nbsp; 0&nbsp; 0&nbsp; 0&nbsp; 0&nbsp; 0&nbsp; 0&nbsp; 0&nbsp; 0&nbsp; 0&nbsp; 0&nbsp; 0&nbsp; 0&nbsp; 0&nbsp; 0&nbsp; 0&nbsp; 0&nbsp; 0&nbsp; 0&nbsp; 0&nbsp; 0&nbsp; 0&nbsp; 0&nbsp; 0&nbsp; 0&nbsp; 0&nbsp; 0&nbsp; 0&nbsp; 0&nbsp; 0&nbsp; 0&nbsp; 0&nbsp; 0&nbsp; 0&nbsp; 0&nbsp; 0&nbsp; 0&nbsp; 0&nbsp; 0&nbsp; 0&nbsp; 0&nbsp; 2838&nbsp; -3982&nbsp; 4801&nbsp; -4136&nbsp; 432&nbsp; -1945&nbsp; 610&nbsp; 1035&nbsp; -1090&nbsp; 2752&nbsp; -558&nbsp; 1431&nbsp; -2320&nbsp; -1016&nbsp; 789&nbsp; 5084&nbsp; -2395&nbsp; -2916&nbsp; -225&nbsp; -311&nbsp; -703&nbsp; 586&nbsp; 1110&nbsp; -557&nbsp; -1152&nbsp; 1096&nbsp; 229&nbsp; 425&nbsp; 5825&nbsp; -933&nbsp; 3922&nbsp; -6289&nbsp; 7423&nbsp; -6636&nbsp; -793&nbsp; -2123&nbsp; -354&nbsp; 991&nbsp; -1947&nbsp; 3958&nbsp; -1070&nbsp; 1380&nbsp; -2120&nbsp; -2777&nbsp; -679&nbsp; 9010&nbsp; -2451&nbsp; -4210&nbsp; -1845&nbsp; 229&nbsp; -1687&nbsp;
 317&nbsp; 1443&nbsp; -1355&nbsp; -2818&nbsp; 214&nbsp; 721&nbsp; -313&nbsp; 9997&nbsp; -60&nbsp; 3489&nbsp; -5953&nbsp; 9277&nbsp; -6990&nbsp; -2716&nbsp; -1642&nbsp; -792&nbsp; 477&nbsp; -2417&nbsp; 5801&nbsp; -1200&nbsp; 1055&nbsp; -1744&nbsp; -2927&nbsp; -2053&nbsp; 10273&nbsp; -1913&nbsp; -4342&nbsp; -2718&nbsp; 427&nbsp; <br>&nbsp;nbBytes: 20<br>&nbsp;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></body></html>