<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">I'm not sure if anyone is experienced with this but i'm having very strange issues with implementing speex in my iOS application.&nbsp;<div><br></div><div>I have written a encode and decode function basically exactly like the example files online. To process audio I am using an iOS VoiceProcessingIO Audio Unit which is set at 16bit pcm with 8000 sample rate. After buffering 320 bytes of PCM audio I feed it into my encode function set at quality 10 (comes out to about 62 bytes of compressed audio). Then after sending it across the net I buffer 62 byte chunks and feed them into the decode function for playback. Unfortunately playback is strange as it sounds very distorted and robotic, although I can clearly recognize what was said and the encode and decode functions go through without any errors. I bypassed the speex functions and just sent uncompressed PCM using the same app and its crystal clear. Where am I going wrong here? Anyone got any suggestions?</div><div><br></div><div>My code is as follows</div><div><br></div><div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; color: rgb(120, 73, 42); ">#define AUDIO_QUALITY <span style="color: #252bd8">10</span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; color: rgb(120, 73, 42); ">#define FRAME_SIZE <span style="color: #252bd8">160</span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; color: rgb(120, 73, 42); ">#define COMP_FRAME_SIZE <span style="color: #252bd8">62</span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; min-height: 13px; "><br></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; min-height: 13px; "><br></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; "><span style="color: #ba2da2">char</span> *encodeSpeexWithBuffer(<span style="color: #4f8187">spx_int16_t</span> *buffer, <span style="color: #ba2da2">int</span> *insize) {</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; ">&nbsp; &nbsp; <span style="color: #4f8187">SpeexBits</span> bits;</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; ">&nbsp; &nbsp; <span style="color: #ba2da2">void</span> *enc_state;</div><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; min-height: 13.0px">&nbsp; &nbsp;&nbsp;</p><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; ">&nbsp; &nbsp; <span style="color: #ba2da2">char</span> *outputBuffer = (<span style="color: #ba2da2">char</span> *)<span style="color: #3d1e81">malloc</span>(<span style="color: #78492a">COMP_FRAME_SIZE</span>);</div><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; min-height: 13.0px">&nbsp;&nbsp; &nbsp;<br class="webkit-block-placeholder"></p><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; color: rgb(49, 89, 94); "><span style="color: #000000">&nbsp; &nbsp; </span>speex_bits_init<span style="color: #000000">(&amp;bits);</span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; ">&nbsp; &nbsp; enc_state = <span style="color: #31595e">speex_encoder_init</span>(&amp;<span style="color: #4f8187">speex_nb_mode</span>);</div><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; min-height: 13.0px">&nbsp;&nbsp; &nbsp;<br class="webkit-block-placeholder"></p><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; ">&nbsp; &nbsp; <span style="color: #ba2da2">int</span> quality = <span style="color: #78492a">AUDIO_QUALITY</span>;</div><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; min-height: 13.0px">&nbsp;&nbsp; &nbsp;<br class="webkit-block-placeholder"></p><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; ">&nbsp; &nbsp; <span style="color: #31595e">speex_encoder_ctl</span>(enc_state, <span style="color: #78492a">SPEEX_SET_QUALITY</span>, &amp;quality);</div><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; min-height: 13.0px">&nbsp;&nbsp; &nbsp;<br class="webkit-block-placeholder"></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; min-height: 13.0px">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br class="webkit-block-placeholder"></p><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; color: rgb(49, 89, 94); "><span style="color: #000000">&nbsp; &nbsp; </span>speex_bits_reset<span style="color: #000000">(&amp;bits);</span></div><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; min-height: 13.0px">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;<br class="webkit-block-placeholder"></p><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; ">&nbsp; &nbsp; <span style="color: #31595e">speex_encode_int</span>(enc_state, buffer, &amp;bits);</div><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; min-height: 13.0px">&nbsp;&nbsp; &nbsp;<br class="webkit-block-placeholder"></p><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; min-height: 13px; "><br></div><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; min-height: 13.0px">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;<br class="webkit-block-placeholder"></p><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; ">&nbsp; &nbsp; *insize = <span style="color: #31595e">speex_bits_write</span>(&amp;bits, outputBuffer, <span style="color: #78492a">COMP_FRAME_SIZE</span>);</div><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; min-height: 13.0px">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br class="webkit-block-placeholder"></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; min-height: 13.0px">&nbsp;&nbsp; &nbsp;<br class="webkit-block-placeholder"></p><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; color: rgb(49, 89, 94); "><span style="color: #000000">&nbsp; &nbsp; </span>speex_bits_destroy<span style="color: #000000">(&amp;bits);</span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; color: rgb(49, 89, 94); "><span style="color: #000000">&nbsp; &nbsp; </span>speex_encoder_destroy<span style="color: #000000">(enc_state);</span></div><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; min-height: 13.0px">&nbsp;&nbsp; &nbsp;<br class="webkit-block-placeholder"></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; min-height: 13.0px">&nbsp;&nbsp; &nbsp;<br class="webkit-block-placeholder"></p><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; ">&nbsp; &nbsp; <span style="color: #ba2da2">return</span> outputBuffer;</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; ">}</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; min-height: 13px; "><br></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; "><span style="color: #ba2da2">short</span> *decodeSpeexWithBuffer(<span style="color: #ba2da2">char</span> *buffer) {</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; ">&nbsp; &nbsp; <span style="color: #4f8187">SpeexBits</span> bits;</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; ">&nbsp; &nbsp; <span style="color: #ba2da2">void</span> *dec_state;</div><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; min-height: 13.0px">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;<br class="webkit-block-placeholder"></p><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; color: rgb(49, 89, 94); "><span style="color: #000000">&nbsp; &nbsp; </span>speex_bits_init<span style="color: #000000">(&amp;bits);</span></div><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; min-height: 13.0px">&nbsp;&nbsp; &nbsp;<br class="webkit-block-placeholder"></p><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; ">&nbsp; &nbsp; dec_state = <span style="color: #31595e">speex_decoder_init</span>(&amp;<span style="color: #4f8187">speex_nb_mode</span>);</div><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; min-height: 13.0px">&nbsp;&nbsp; &nbsp;<br class="webkit-block-placeholder"></p><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; ">&nbsp; &nbsp; <span style="color: #ba2da2">short</span> *outTemp = (<span style="color: #ba2da2">short</span> *)<span style="color: #3d1e81">malloc</span>(<span style="color: #78492a">FRAME_SIZE</span> * <span style="color: #252bd8">2</span>);</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; min-height: 13px; "><br></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; ">&nbsp; &nbsp; <span style="color: #31595e">speex_bits_read_from</span>(&amp;bits, buffer, <span style="color: #78492a">COMP_FRAME_SIZE</span>);</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; ">&nbsp; &nbsp; <span style="color: #31595e">speex_decode_int</span>(dec_state, &amp;bits, outTemp);</div><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; min-height: 13.0px">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;<br class="webkit-block-placeholder"></p><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; color: rgb(49, 89, 94); "><span style="color: #000000">&nbsp; &nbsp; </span>speex_decoder_destroy<span style="color: #000000">(dec_state);</span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; color: rgb(49, 89, 94); "><span style="color: #000000">&nbsp; &nbsp; </span>speex_bits_destroy<span style="color: #000000">(&amp;bits);</span></div><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; min-height: 13.0px">&nbsp;&nbsp; &nbsp;<br class="webkit-block-placeholder"></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; min-height: 13.0px">&nbsp;&nbsp; &nbsp;<br class="webkit-block-placeholder"></p><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; ">&nbsp; &nbsp; <span style="color: #ba2da2">return</span> outTemp;</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; ">}</div></div><div><br></div></body></html>