<div dir="rtl"><div dir="ltr">hi</div><div dir="ltr">we are trying to decode speech that was encoded on a ds&#39;pic with a NB 8 Kb/sec.</div><div dir="ltr"> we wrote a simple program using the API speex lib 1.2 beta 3:</div>
<div dir="ltr"><br></div><div dir="ltr"><br></div><div dir="ltr">#include &quot;stdafx.h&quot;</div><div dir="ltr">#include &lt;iostream&gt;</div><div dir="ltr">#include &lt;stdio.h&gt;</div><div dir="ltr">#include &quot;speex.h&quot;</div>
<div dir="ltr">#include &quot;speex_bits.h&quot;</div><div dir="ltr">using namespace std;</div><div dir="ltr">char hex2ascii(char toconv);</div><div dir="ltr">#define FRAME_SIZE 160</div><div dir="ltr">#define nbBytes 20</div>
<div dir="ltr">int main(int argc, _TCHAR* argv[])</div><div dir="ltr">{</div><div dir="ltr"><span class="Apple-tab-span" style="white-space:pre">        </span>int mode = 3;<span class="Apple-tab-span" style="white-space:pre">        </span></div>
<div dir="ltr"><span class="Apple-tab-span" style="white-space:pre">        </span>int i=0,j=0;<span class="Apple-tab-span" style="white-space:pre">                </span></div><div dir="ltr"><span class="Apple-tab-span" style="white-space:pre">        </span>char ch=0;</div>
<div dir="ltr"><span class="Apple-tab-span" style="white-space:pre">        </span>int in=0,temp=0;</div><div dir="ltr"><span class="Apple-tab-span" style="white-space:pre">        </span>char out_ascii[640]={0};</div><div dir="ltr"><span class="Apple-tab-span" style="white-space:pre">        </span>float output[FRAME_SIZE];//the originals 160 words in float</div>
<div dir="ltr"><span class="Apple-tab-span" style="white-space:pre">        </span>short out[FRAME_SIZE];//the originals 160 words</div><div dir="ltr"><span class="Apple-tab-span" style="white-space:pre">        </span>char cbits[nbBytes];</div>
<div dir="ltr"><span class="Apple-tab-span" style="white-space:pre">        </span>void *state;//hold the state of the decoder</div><div dir="ltr"><span class="Apple-tab-span" style="white-space:pre">        </span>SpeexMode speex_nb_mode;</div>
<div dir="ltr"><span class="Apple-tab-span" style="white-space:pre">        </span>SpeexBits bits;</div><div dir="ltr"><span class="Apple-tab-span" style="white-space:pre">        </span>state=decoder_init_func(&amp; speex_nb_mode);//initializing a speex decoder</div>
<div dir="ltr"><span class="Apple-tab-span" style="white-space:pre">        </span></div><div dir="ltr"><span class="Apple-tab-span" style="white-space:pre">        </span></div><div dir="ltr"><span class="Apple-tab-span" style="white-space:pre">        </span>speex_decoder_ctl(state,SPEEX_SET_MODE,&amp;temp);</div>
<div dir="ltr"><span class="Apple-tab-span" style="white-space:pre">        </span>speex_bits_init(&amp;bits); </div><div dir="ltr"><br></div><div dir="ltr"><br></div><div dir="ltr">we get the data throw RS232, and convert the decoded (supose to be the original or close to it) to ASCII, so we can simply play it in MATLAB: </div>
<div dir="ltr"><br></div><div dir="ltr">system(&quot;mode com1: baud=38400 parity=n data=8 stop=1&quot;);//opening the rs232</div><div dir="ltr"><div dir="ltr"><br></div><div dir="ltr"><span class="Apple-tab-span" style="white-space:pre">        </span>FILE* mic=fopen(&quot;com1:&quot;, &quot;w+&quot; );</div>
<div dir="ltr"><span class="Apple-tab-span" style="white-space:pre">        </span>FILE *mic1 = fopen(&quot;mic.txt&quot; , &quot;wt&quot;);</div><div dir="ltr"><span class="Apple-tab-span" style="white-space:pre">        </span></div>
<div dir="ltr"><span class="Apple-tab-span" style="white-space:pre">        </span>while(1)</div><div dir="ltr"><span class="Apple-tab-span" style="white-space:pre">        </span>{</div><div dir="ltr"><span class="Apple-tab-span" style="white-space:pre">        </span>if (feof( mic ) == 0){</div>
<div dir="ltr"><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span>cbits[i]=fgetc(mic);</div><div dir="ltr"><span class="Apple-tab-span" style="white-space:pre">        </span>if(i==20)</div>
<div dir="ltr"><span class="Apple-tab-span" style="white-space:pre">                        </span>{</div><div dir="ltr"><span class="Apple-tab-span" style="white-space:pre">                                </span>speex_bits_read_from(&amp;bits, cbits, nbBytes); </div><div dir="ltr">
<span class="Apple-tab-span" style="white-space:pre">                                </span>i=0;</div><div dir="ltr"><span class="Apple-tab-span" style="white-space:pre">                                </span>speex_decode(state, &amp;bits, output);</div><div dir="ltr"><span class="Apple-tab-span" style="white-space:pre">                                </span>for (j=0;j&lt;FRAME_SIZE;j++)</div>
<div dir="ltr"><span class="Apple-tab-span" style="white-space:pre">                                </span>{</div><div dir="ltr"><span class="Apple-tab-span" style="white-space:pre">                                        </span>out[j]=output[j];</div><div dir="ltr"><span class="Apple-tab-span" style="white-space:pre">                                        </span>out_ascii[j*4]=hex2ascii((out[j] &gt;&gt; 12) &amp; 0x000F); </div>
<div dir="ltr"><span class="Apple-tab-span" style="white-space:pre">                                        </span>out_ascii[j*4+1]=hex2ascii((out[j] &gt;&gt; 8) &amp; 0x000F);</div><div dir="ltr"><span class="Apple-tab-span" style="white-space:pre">                                        </span>out_ascii[j*4+2]=hex2ascii((out[j] &gt;&gt; 4) &amp; 0x000F);</div>
<div dir="ltr"><span class="Apple-tab-span" style="white-space:pre">                                        </span>out_ascii[j*4+3]=hex2ascii(out[j]  &amp; 0x000F);</div><div dir="ltr"><span class="Apple-tab-span" style="white-space:pre">                                </span>}</div>
<div dir="ltr"><span class="Apple-tab-span" style="white-space:pre">                                </span>fputs(out_ascii,mic1);<span class="Apple-tab-span" style="white-space:pre">        </span></div><div dir="ltr"><span class="Apple-tab-span" style="white-space:pre">                        </span>}</div>
<div dir="ltr"><span class="Apple-tab-span" style="white-space:pre">        </span>else{</div><div dir="ltr"><span class="Apple-tab-span" style="white-space:pre">                                </span>i++;</div><div dir="ltr"><span class="Apple-tab-span" style="white-space:pre">        </span>}</div>
<div dir="ltr"><span class="Apple-tab-span" style="white-space:pre">        </span>}</div><div dir="ltr"><br></div><div dir="ltr"><span class="Apple-tab-span" style="white-space:pre">        </span>fclose( mic );</div><div dir="ltr"><span class="Apple-tab-span" style="white-space:pre">        </span>fclose( mic1 );</div>
<div dir="ltr"><span class="Apple-tab-span" style="white-space:pre">        </span></div><div dir="ltr"><span class="Apple-tab-span" style="white-space:pre">        </span>return 0;</div><div dir="ltr">}</div><div dir="ltr"><br></div><div dir="ltr">
char hex2ascii(char toconv)</div><div dir="ltr">{</div><div dir="ltr"><span class="Apple-tab-span" style="white-space:pre">        </span>if (toconv&lt;0x0A) </div><div dir="ltr"><span class="Apple-tab-span" style="white-space:pre">        </span>{</div>
<div dir="ltr"><span class="Apple-tab-span" style="white-space:pre">                </span>toconv += 0x30;</div><div dir="ltr"><span class="Apple-tab-span" style="white-space:pre">        </span>}</div><div dir="ltr"><span class="Apple-tab-span" style="white-space:pre">        </span>else </div>
<div dir="ltr"><span class="Apple-tab-span" style="white-space:pre">        </span>{</div><div dir="ltr"><span class="Apple-tab-span" style="white-space:pre">                </span>toconv += 0x37;</div><div dir="ltr"><span class="Apple-tab-span" style="white-space:pre">        </span>}</div>
<div dir="ltr"><span class="Apple-tab-span" style="white-space:pre">        </span></div><div dir="ltr">return (toconv);</div><div dir="ltr">}</div><div><br></div></div><div dir="ltr">the program give as an error message:</div><div dir="ltr">
&quot;<i>Unhandled exception at 0x1000b65a in new_speex.exe: 0xC0000005: Access violation reading location 0xccccccfc.</i>&quot;</div><div dir="ltr"><br></div><div dir="ltr">we dont undersand why, maybe we are not on the correct NB mode?</div>
<div dir="ltr">we need help!</div><div dir="ltr"><br></div><div dir="ltr">thanks</div><div dir="ltr">shlomo and eitan</div><div dir="ltr">EE students in israel<br clear="all"><br><br></div>
</div>