<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Generator" content="Microsoft Word 14 (filtered medium)">
<!--[if !mso]><style>v\:* {behavior:url(#default#VML);}
o\:* {behavior:url(#default#VML);}
w\:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}
</style><![endif]--><style><!--

@font-face
        {font-family:calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
@font-face
        {font-family:verdana;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
@font-face
        {font-family:webdings;
        panose-1:5 3 1 2 1 5 9 6 7 3;}

p.msonormal, li.msonormal, div.msonormal
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"calibri","sans-serif";
        mso-fareast-language:en-us;}
a:link, span.msohyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.msohyperlinkfollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
p.msoacetate, li.msoacetate, div.msoacetate
        {mso-style-priority:99;
        mso-style-link:"texto de balão char";
        margin:0cm;
        margin-bottom:.0001pt;
        font-size:8.0pt;
        font-family:"tahoma","sans-serif";
        mso-fareast-language:en-us;}
span.estilodeemail17
        {mso-style-type:personal-compose;
        font-family:"calibri","sans-serif";
        color:windowtext;}
span.textodebalochar
        {mso-style-name:"texto de balão char";
        mso-style-priority:99;
        mso-style-link:"texto de balão";
        font-family:"tahoma","sans-serif";}
.msochpdefault
        {mso-style-type:export-only;
        font-family:"calibri","sans-serif";
        mso-fareast-language:en-us;}
@page wordsection1
        {size:612.0pt 792.0pt;
        margin:70.85pt 3.0cm 70.85pt 3.0cm;}
div.wordsection1
        {page:wordsection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal">Dear Speex community,  </p>
<p class="MsoNormal"> &nbsp; </p>
<p class="MsoNormal"><span>I am having problems to get the Speex Decoding API to work properly in our project.  </span></p>
<p class="MsoNormal"><span> &nbsp; </span></p>
<p class="MsoNormal"><span>I am working in an embedded project with a very limited RAM and Flash memory and would like to use Speex encoded files to save memory while having good voice sounds in our speakers.  </span></p>
<p class="MsoNormal"><span>I have developed a Windows-based tool to convert WAV files to Speex files in packets of 160 bytes (we are using only the narrowband mode). Those packets are written into a C file which we compile and embed in our custom
 hardware (ARM-based microcontroller). I am attaching one of such C source files with speex encoded bytes for reference, which consists of 61 encoded packets. I am also attaching the original WAV file.  </span></p>
<p class="MsoNormal"><span> &nbsp; </span></p>
<p class="MsoNormal"><span>In our application, we are trying to decode the embedded list of packets and playback using the microcontroller DA converter. Here I paste the function which handles this task:  </span></p>
<p class="MsoNormal"><span> &nbsp; </span></p>
<p class="MsoNormal"><i><span style="font-size:10.0pt;font-family:&quot;Courier New&quot;">&nbsp; SpeexBits bits;
  </span></i></p>
<p class="MsoNormal"><i><span style="font-size:10.0pt;font-family:&quot;Courier New&quot;">&nbsp;&nbsp;void *dec_state;
  </span></i></p>
<p class="MsoNormal"><i><span style="font-size:10.0pt;font-family:&quot;Courier New&quot;">&nbsp;&nbsp;int idx = 0;  </span></i></p>
<p class="MsoNormal"><i><span style="font-size:10.0pt;font-family:&quot;Courier New&quot;">&nbsp; // 160 decoded &#8220;samples&#8221;  </span></i></p>
<p class="MsoNormal"><i><span style="font-size:10.0pt;font-family:&quot;Courier New&quot;">&nbsp; short output_frame[SPEEX_NB_FRAME_SIZE];  </span></i></p>
<p class="MsoNormal"><i><span style="font-size:10.0pt;font-family:&quot;Courier New&quot;">&nbsp;
  </span></i></p>
<p class="MsoNormal"><i><span style="font-size:10.0pt;font-family:&quot;Courier New&quot;">&nbsp;&nbsp;// Getting the timer period from the Sample Rate of the original WAV file  </span></i></p>
<p class="MsoNormal"><i><span style="font-size:10.0pt;font-family:&quot;Courier New&quot;">&nbsp; float periodSec = 1.0f / (float) pstAudioBuffer-&gt;u.spx-&gt;dwSampleRate;  </span></i></p>
<p class="MsoNormal"><i><span style="font-size:10.0pt;font-family:&quot;Courier New&quot;">&nbsp; unsigned int periodMicroSec = (unsigned int) (periodSec * 1000000.0f);  </span></i></p>
<p class="MsoNormal"><i><span style="font-size:10.0pt;font-family:&quot;Courier New&quot;">&nbsp;
  </span></i></p>
<p class="MsoNormal"><i><span style="font-size:10.0pt;font-family:&quot;Courier New&quot;">&nbsp;&nbsp;// Initialization  </span></i></p>
<p class="MsoNormal"><i><span style="font-size:10.0pt;font-family:&quot;Courier New&quot;">&nbsp; speex_bits_init(&amp;bits);
  </span></i></p>
<p class="MsoNormal"><i><span style="font-size:10.0pt;font-family:&quot;Courier New&quot;">&nbsp;&nbsp;dec_state = speex_decoder_init(&amp;speex_nb_mode);
  </span></i></p>
<p class="MsoNormal"><i><span style="font-size:10.0pt;font-family:&quot;Courier New&quot;">&nbsp;&nbsp;  </span></i></p>
<p class="MsoNormal"><i><span style="font-size:10.0pt;font-family:&quot;Courier New&quot;">&nbsp;&nbsp;// Configures the output timer to generate IRQs every &lt;periodMicroSec&gt; microseconds  </span></i></p>
<p class="MsoNormal"><i><span style="font-size:10.0pt;font-family:&quot;Courier New&quot;">&nbsp; pstAudioDriverInterface-&gt;configure_output_timer(periodMicroSec);  </span></i></p>
<p class="MsoNormal"><i><span style="font-size:10.0pt;font-family:&quot;Courier New&quot;">&nbsp;
  </span></i></p>
<p class="MsoNormal"><i><span style="font-size:10.0pt;font-family:&quot;Courier New&quot;">&nbsp;&nbsp;// Configures the DAC for audio playback  </span></i></p>
<p class="MsoNormal"><i><span style="font-size:10.0pt;font-family:&quot;Courier New&quot;">&nbsp; pstAudioDriverInterface-&gt;configure_dac(pstAudioBuffer-&gt;u.spx-&gt;dwSampleRate);  </span></i></p>
<p class="MsoNormal"><i><span style="font-size:10.0pt;font-family:&quot;Courier New&quot;"> &nbsp; </span></i></p>
<p class="MsoNormal"><i><span style="font-size:10.0pt;font-family:&quot;Courier New&quot;">&nbsp; // Playback loop, for each packet in the List  </span></i></p>
<p class="MsoNormal"><i><span style="font-size:10.0pt;font-family:&quot;Courier New&quot;">&nbsp; for(idx = 0; idx &lt; pstAudioBuffer-&gt;u.spx-&gt;dwTotalChunks; idx&#43;&#43;)  </span></i></p>
<p class="MsoNormal"><i><span style="font-size:10.0pt;font-family:&quot;Courier New&quot;">&nbsp; {  </span></i></p>
<p class="MsoNormal"><i><span style="font-size:10.0pt;font-family:&quot;Courier New&quot;">&nbsp;&nbsp;&nbsp; speex_bits_reset(&amp;bits);  </span></i></p>
<p class="MsoNormal"><i><span style="font-size:10.0pt;font-family:&quot;Courier New&quot;">&nbsp;&nbsp;&nbsp; speex_bits_read_from(&amp;bits, pstAudioBuffer-&gt;u.spx-&gt;pstChunkList[idx]-&gt;pbyBuffer, pstAudioBuffer-&gt;u.spx-&gt;pstChunkList[idx]-&gt;dwChunkSize);
  </span></i></p>
<p class="MsoNormal"><i><span style="font-size:10.0pt;font-family:&quot;Courier New&quot;">&nbsp;&nbsp;&nbsp;&nbsp;while(speex_decode_int(dec_state, &amp;bits, output_frame) != -1);  </span></i></p>
<p class="MsoNormal"><i><span style="font-size:10.0pt;font-family:&quot;Courier New&quot;">&nbsp;&nbsp;&nbsp; // Sends each decoded sample to the DAC at the specified TIMER IRQ period  </span></i></p>
<p class="MsoNormal"><i><span style="font-size:10.0pt;font-family:&quot;Courier New&quot;">&nbsp;&nbsp;&nbsp; pstAudioDriverInterface-&gt;write_buffer(output_frame, sizeof(output_frame));  </span></i></p>
<p class="MsoNormal"><i><span style="font-size:10.0pt;font-family:&quot;Courier New&quot;">&nbsp; }  </span></i></p>
<p class="MsoNormal"><i><span style="font-size:10.0pt;font-family:&quot;Courier New&quot;">&nbsp;
  </span></i></p>
<p class="MsoNormal"><i><span style="font-size:10.0pt;font-family:&quot;Courier New&quot;">&nbsp;&nbsp;// Freeing memory  </span></i></p>
<p class="MsoNormal"><i><span style="font-size:10.0pt;font-family:&quot;Courier New&quot;">&nbsp; speex_bits_destroy(&amp;bits);
  </span></i></p>
<p class="MsoNormal"><i><span style="font-size:10.0pt;font-family:&quot;Courier New&quot;">&nbsp;&nbsp;speex_decoder_destroy(dec_state);  </span></i></p>
<p class="MsoNormal"><i><span style="font-size:10.0pt;font-family:&quot;Courier New&quot;"> &nbsp; </span></i></p>
<p class="MsoNormal"><i><span style="font-size:10.0pt;font-family:&quot;Courier New&quot;"> &nbsp; </span></i></p>
<p class="MsoNormal"><span>Everything I get is a very noise &#8220;hiss&#8221; output. When we playback a RAW PCM file or a WAV file in our hardware, it is perfectly clear and sounds good. However, due to hardware limitations, we cannot proceed with raw WAV
 files.  </span></p>
<p class="MsoNormal"><span> &nbsp; </span></p>
<p class="MsoNormal"><span>Any help would be very appreciated.  </span></p>
<p class="MsoNormal"><span> &nbsp; </span></p>
<p class="MsoNormal"><span>Thanks in advance.  </span></p>
<p class="MsoNormal"><span> &nbsp; </span></p>
<p class="MsoNormal"><span style="mso-fareast-language:PT-BR"><img width="200" height="130" id="Imagem_x0020_1" src="cid:image001.jpg@01CF8FBF.2B637EA0" alt="Descrição: Mauricio Cirelli">  </span></p>
<p class="MsoNormal"><span style="mso-fareast-language:PT-BR"> &nbsp; </span></p>
<p class="MsoNormal"><b><span style="font-size:8.0pt;font-family:&quot;Verdana&quot;,&quot;sans-serif&quot;;color:#595959;mso-fareast-language:PT-BR">AVISO LEGAL</span></b><span style="font-size:8.0pt;font-family:&quot;Verdana&quot;,&quot;sans-serif&quot;;color:#595959;mso-fareast-language:PT-BR">:
 As informações contidas nesta mensagem e nos arquivos anexados são para uso restrito, sendo seu sigilo protegido por lei, não havendo ainda garantia legal quanto à integridade de seu conteúdo. Caso não seja o destinatário, por favor, desconsidere essa mensagem.
 O uso indevido dessas informações será tratado conforme as normas da empresa e a legislação em vigor.<br>
&nbsp;<br>
</span><b><span style="font-size:8.0pt;font-family:&quot;Verdana&quot;,&quot;sans-serif&quot;;color:#595959;mso-fareast-language:PT-BR">LEGAL ADVICE:</span></b><span style="font-size:8.0pt;font-family:&quot;Verdana&quot;,&quot;sans-serif&quot;;color:#595959;mso-fareast-language:PT-BR">
 The information in this e-mail and in the attached files are confidential and may be legally privileged. There is no legal guarantee as regards the reliability of said information. If you are not the intended recipient please disregard the content thereof.
 The unduly use of this information is subject to the rules of the company and the legislation in force.  </span></p>
<p class="MsoNormal" style="margin-left:35.4pt"><b><span style="font-size:18.0pt;font-family:Webdings;color:teal;mso-fareast-language:PT-BR"> &nbsp; </span></b></p>
<p class="MsoNormal" style="margin-left:35.4pt"><b><span style="font-size:18.0pt;font-family:Webdings;color:teal;mso-fareast-language:PT-BR">P</span></b><span style="font-size:8.0pt;font-family:&quot;Verdana&quot;,&quot;sans-serif&quot;;color:#595959;mso-fareast-language:PT-BR">
</span><span style="font-size:8.0pt;font-family:&quot;Verdana&quot;,&quot;sans-serif&quot;;color:#595959;mso-fareast-language:PT-BR">Economize papel, só imprima em caso de real necessidade, a natureza agradece.  </span></p>
<p class="MsoNormal"><span style="mso-fareast-language:PT-BR"> &nbsp; </span></p>
<p class="MsoNormal"> &nbsp; </p>
</div>
</body>
</html>