<div dir="rtl"><div dir="ltr">hi</div><div dir="ltr">we are trying to decode speech that was encoded on a ds'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 "stdafx.h"</div><div dir="ltr">#include <iostream></div><div dir="ltr">#include <stdio.h></div><div dir="ltr">#include "speex.h"</div>
<div dir="ltr">#include "speex_bits.h"</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(& 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,&temp);</div>
<div dir="ltr"><span class="Apple-tab-span" style="white-space:pre">        </span>speex_bits_init(&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("mode com1: baud=38400 parity=n data=8 stop=1");//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("com1:", "w+" );</div>
<div dir="ltr"><span class="Apple-tab-span" style="white-space:pre">        </span>FILE *mic1 = fopen("mic.txt" , "wt");</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(&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, &bits, output);</div><div dir="ltr"><span class="Apple-tab-span" style="white-space:pre">                                </span>for (j=0;j<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] >> 12) & 0x000F); </div>
<div dir="ltr"><span class="Apple-tab-span" style="white-space:pre">                                        </span>out_ascii[j*4+1]=hex2ascii((out[j] >> 8) & 0x000F);</div><div dir="ltr"><span class="Apple-tab-span" style="white-space:pre">                                        </span>out_ascii[j*4+2]=hex2ascii((out[j] >> 4) & 0x000F);</div>
<div dir="ltr"><span class="Apple-tab-span" style="white-space:pre">                                        </span>out_ascii[j*4+3]=hex2ascii(out[j] & 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<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">
"<i>Unhandled exception at 0x1000b65a in new_speex.exe: 0xC0000005: Access violation reading location 0xccccccfc.</i>"</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>