<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.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";}
span.estilodeemail19
        {mso-style-type:personal;
        font-family:"calibri","sans-serif";
        color:windowtext;}
span.estilodeemail20
        {mso-style-type:personal-reply;
        font-family:"calibri","sans-serif";
        color:#1f497d;}
.msochpdefault
        {mso-style-type:export-only;
        font-size:10.0pt;}
@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"><span style="color:#1F497D">Dear Community,  </span></p>
<p class="MsoNormal"><span style="color:#1F497D"> &nbsp; </span></p>
<p class="MsoNormal"><span style="color:#1F497D">I have got it to work now.  </span></p>
<p class="MsoNormal"><span style="color:#1F497D">However, sound is very noisy. It seems that it is overflowing my DAC.  </span></p>
<p class="MsoNormal"><span style="color:#1F497D">We use a 10-bit DAC and it seems that Speex is decoding values to a 16-bit PCM buffer.  </span></p>
<p class="MsoNormal"><span style="color:#1F497D">Looking at the decoded buffer, I can see values very close 0 (some negative ones, some positive ones, but very close to 0).  </span></p>
<p class="MsoNormal"><span style="color:#1F497D"> &nbsp; </span></p>
<p class="MsoNormal"><span style="color:#1F497D">Is there any proper way to rescale decoded samples from 16-bit to 8-bit (or 10-bit at most)?  </span></p>
<p class="MsoNormal"><span style="color:#1F497D"> &nbsp; </span></p>
<p class="MsoNormal"><span style="color:#1F497D">Thank you!  </span></p>
<p class="MsoNormal"><span style="color:#1F497D"> &nbsp; </span></p>
<div>
<p class="MsoNormal"><span style="color:#1F497D;mso-fareast-language:PT-BR"><img width="200" height="130" id="_x0000_i1026" src="cid:image001.jpg@01CF907D.B928BC00" alt="Descrição: Mauricio Cirelli">  </span></p>
<p class="MsoNormal"><span style="color:#1F497D;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="color:#1F497D;mso-fareast-language:PT-BR"> &nbsp; </span></p>
</div>
<p class="MsoNormal"><span style="color:#1F497D"> &nbsp; </span></p>
<div>
<div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0cm 0cm 0cm">
<p class="MsoNormal"><b><span style="font-size:10.0pt;font-family:&quot;Tahoma&quot;,&quot;sans-serif&quot;;mso-fareast-language:PT-BR">De:</span></b><span style="font-size:10.0pt;font-family:&quot;Tahoma&quot;,&quot;sans-serif&quot;;mso-fareast-language:PT-BR"> Mauricio Cirelli
<br>
<b>Enviada em:</b> terça-feira, 24 de junho de 2014 15:23<br>
<b>Para:</b> 'speex-dev@xiph.org'<br>
<b>Assunto:</b> Speex Decoding Issue  </span></p>
</div>
</div>
<p class="MsoNormal"> &nbsp; </p>
<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@01CF907D.B928BC00" 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>