<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<META content="MSHTML 6.00.2900.2769" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV><FONT face=Arial size=2>Mon,</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>You should be calling speex_bits_reset inside the 
loop.&nbsp; This resets some pointers to the beginning of the bit buffer.&nbsp; 
If you don't do this, the pointers will grow indefinitely.&nbsp; Look at 
testenc.c, or at the modified versions that I posted yesterday for the TI 
DSPs.&nbsp; You might want to get the example to run first, then modify it as 
you need.</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>- Jim</FONT></DIV>
<BLOCKQUOTE 
style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
  <DIV style="FONT: 10pt arial">----- Original Message ----- </DIV>
  <DIV 
  style="BACKGROUND: #e4e4e4; FONT: 10pt arial; font-color: black"><B>From:</B> 
  <A title=mowin.dev@gmail.com href="mailto:mowin.dev@gmail.com">Mo Win</A> 
  </DIV>
  <DIV style="FONT: 10pt arial"><B>To:</B> <A title=speex-dev@xiph.org 
  href="mailto:speex-dev@xiph.org">speex-dev@xiph.org</A> </DIV>
  <DIV style="FONT: 10pt arial"><B>Sent:</B> Monday, October 17, 2005 10:31 
  PM</DIV>
  <DIV style="FONT: 10pt arial"><B>Subject:</B> Re: [Speex-dev] Error Executing 
  sampledec in VC++</DIV>
  <DIV><BR></DIV>Hi Steve, thanks for the advice. I placed the appropriate 
  functions outside the while statement but I still get this error at the while 
  loop:<BR><BR>First-chance exception at 0x004010fa in SPXDEC.exe: 0xC0000005: 
  Access violation reading location 0x0000000c.<BR>Unhandled exception at 
  0x004010fa in SPXDEC.exe: 0xC0000005: Access violation reading location 
  0x0000000c.<BR><BR>It looks like the same error. I've attached the code 
  below<BR><BR>Thanks,<BR>Mon<BR><BR>Portion of the revised 
  code:<BR><BR><BR>&nbsp;&nbsp;&nbsp; decstate = speex_decoder_init 
  (&amp;speex_nb_mode);<BR>&nbsp;&nbsp;&nbsp; // Set default options for 
  decoding:<BR>&nbsp;&nbsp;&nbsp; temp = 1;<BR>&nbsp;&nbsp;&nbsp; 
  speex_decoder_ctl(decstate, SPEEX_SET_ENH, 
  &amp;temp);<BR><BR>&nbsp;&nbsp;&nbsp; // Initialize spxbits (structure 
  SpeexBits)<BR>&nbsp;&nbsp;&nbsp; speex_bits_init 
  (&amp;spxbits);<BR><BR>&nbsp;&nbsp;&nbsp; while 
  (!(feof(fo)))&nbsp;&nbsp;&nbsp;&nbsp; // this is where the problem 
  starts<BR>&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  fread (&amp;nbBytes, sizeof(int), 1, 
  fo);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fread (cbits, 1, nbBytes, 
  fo);<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cout &lt;&lt; "1"; // 
  just to see whether the loop 
  iterates<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  speex_bits_read_from (&amp;spxbits, cbits, 
  nbBytes);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; speex_decode 
  (decstate, &amp;spxbits, 
  pcm);<BR><BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Copy 1 frame 
  from float pcm to short spx<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for 
  (n=0; n&lt;FRAME_SIZE; 
  n++)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; spx 
  [n] = pcm [n];<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fwrite (spx, 
  sizeof(short), FRAME_SIZE, fs);<BR><BR>&nbsp;&nbsp;&nbsp; 
  }<BR>&nbsp;&nbsp;&nbsp;&nbsp; // end of&nbsp; loop<BR>&nbsp;&nbsp;&nbsp; // 
  Entire file has been read, decoded and saved<BR><BR>&nbsp;&nbsp;&nbsp; 
  speex_decoder_destroy (decstate);<BR>&nbsp;&nbsp;&nbsp; speex_bits_destroy 
  (&amp;spxbits);<BR>&nbsp;&nbsp;&nbsp; fclose (fo);<BR>&nbsp;&nbsp;&nbsp; 
  fclose (fs);<BR>&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; cout &lt;&lt; "Finished 
  processing!\n";<BR>}<BR><BR>
  <DIV><SPAN class=gmail_quote>On 10/18/05, <B class=gmail_sendername>Steve 
  Russell</B> &lt;<A 
  href="mailto:srussell@innernet.net">srussell@innernet.net</A>&gt; 
wrote:</SPAN>
  <BLOCKQUOTE class=gmail_quote 
  style="PADDING-LEFT: 1ex; MARGIN: 0pt 0pt 0pt 0.8ex; BORDER-LEFT: rgb(204,204,204) 1px solid">
    <DIV><FONT face=Arial size=4>Mon,</FONT></DIV>
    <DIV><FONT face=Arial size=4></FONT>&nbsp;</DIV>
    <DIV><FONT face=Arial size=4>Here is&nbsp;feedback that I got concerning the 
    access violation, i.e. the failure of the while loop below.&nbsp; Does this 
    solve the problem?</FONT></DIV>
    <DIV><FONT face=Arial size=4></FONT>&nbsp;</DIV>
    <DIV><FONT face=Arial size=4>Steve</FONT></DIV>
    <DIV><FONT face=Arial size=4></FONT>&nbsp;</DIV>
    <DIV>My guess is that speex_decoder_init() should be outside the while().. 
    loop<BR>as speex_decoder_destroy() is also outside.</DIV>
    <BLOCKQUOTE 
    style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: rgb(0,0,0) 2px solid; MARGIN-RIGHT: 0px"><SPAN 
      class=q>
      <DIV 
      style="FONT: 10pt arial; font-size-adjust: none; font-stretch: normal">----- 
      Original Message ----- </DIV>
      <DIV 
      style="BACKGROUND: rgb(228,228,228) 0% 50%; FONT: 10pt arial; font-size-adjust: none; font-stretch: normal; moz-background-clip: initial; moz-background-origin: initial; moz-background-inline-policy: initial"><B>From:</B> 
      <A title=mowin.dev@gmail.com 
      onclick="return top.js.OpenExtLink(window,event,this)" 
      href="mailto:mowin.dev@gmail.com" target=_blank>Mo Win</A> </DIV>
      <DIV 
      style="FONT: 10pt arial; font-size-adjust: none; font-stretch: normal"><B>To:</B> 
      <A title=speex-dev@xiph.org 
      onclick="return top.js.OpenExtLink(window,event,this)" 
      href="mailto:speex-dev@xiph.org" target=_blank>speex-dev@xiph.org</A> 
      </DIV>
      <DIV 
      style="FONT: 10pt arial; font-size-adjust: none; font-stretch: normal"><B>Sent:</B> 
      Monday, October 17, 2005 8:05 AM</DIV>
      <DIV 
      style="FONT: 10pt arial; font-size-adjust: none; font-stretch: normal"><B>Subject:</B> 
      [Speex-dev] Error Executing sampledec in VC++</DIV>
      <DIV><BR></DIV></SPAN>
      <DIV><SPAN class=q id=q_10700a0bc525377c_2>hey guys, I just compiled an 
      application similar to sampledec.c (for speex 1.1.10) and it was fine but 
      when I executed it, the app exited without doing anything. I'm using MS VC 
      6.0 and this was all I got -<SPAN style="FONT-WEIGHT: bold"> First-chance 
      exception in sampledec.exe : 0xC0000005: Access Violation. </SPAN>Has 
      anyone encountered this / does anyone know how to deal with it? by the 
      way, sampleenc executed perfectly... <BR><BR>When I removed the "while" 
      loop in sampledec, the program executed fine (I placed printf's to check 
      which lines were executed). I also tried running the loop only once 
      (erasing only the while statement and retaining the code within it) and it 
      worked fine again. Something seems to be happening during loop iteration 
      that causes the program to terminate abnormally.. any clues? thanks very 
      much for any tip..<BR><BR>In gratitude,<BR>Mon<BR><BR>(Below is my code. 
      it's almost exactly like sampleenc except I read a file stream instead of 
      stdin)<BR><BR>#include "speex/speex.h"<BR><BR>#include 
      &lt;stdio.h&gt;<BR>#include &lt;iostream.h&gt;<BR><BR>void main 
      ()<BR>{<BR>&nbsp;&nbsp;&nbsp; <SPAN style="COLOR: rgb(153,255,153)">// 
      Definitions</SPAN><BR>&nbsp;&nbsp;&nbsp; #define FRAME_SIZE 
      160<BR>&nbsp;&nbsp;&nbsp; #define 
      FIXED_POINT<BR><BR>&nbsp;&nbsp;&nbsp;<SPAN 
      style="COLOR: rgb(153,255,153)"> // Variable 
      Declarations</SPAN><BR>&nbsp;&nbsp;&nbsp; FILE *fo, 
      *fs;<BR>&nbsp;&nbsp;&nbsp; short spx [FRAME_SIZE];<BR>&nbsp;&nbsp;&nbsp; 
      float pcm [FRAME_SIZE];<BR>&nbsp;&nbsp;&nbsp; char cbits 
      [200];<BR>&nbsp;&nbsp;&nbsp; int nbBytes, n, 
      temp;<BR><BR>&nbsp;&nbsp;&nbsp; void *decstate;<BR>&nbsp;&nbsp;&nbsp; 
      SpeexBits spxbits;<BR><BR><BR>&nbsp;&nbsp;&nbsp; <SPAN 
      style="COLOR: rgb(153,255,153)">// Program starts 
      here:</SPAN><BR>&nbsp;&nbsp;&nbsp; cout &lt;&lt; "Starting 
      spxdec...\n";<BR>&nbsp;&nbsp;&nbsp; fo = 
      fopen("samp.spx","rb");<BR><BR>&nbsp;&nbsp;&nbsp; if (fo == 
      NULL)<BR>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; cout &lt;&lt; 
      "Error!\n";<BR>&nbsp;&nbsp;&nbsp; else<BR>&nbsp;&nbsp;&nbsp; 
      &nbsp;&nbsp;&nbsp; cout &lt;&lt; "Okay!\n";<BR><BR>&nbsp;&nbsp;&nbsp; fs = 
      fopen ("pcmfile", "wb");<BR><BR>&nbsp;&nbsp;&nbsp; if (fs == 
      NULL)<BR>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; cout &lt;&lt; "Error 
      creating file!\n";<BR>&nbsp;&nbsp;&nbsp; else<BR>&nbsp;&nbsp;&nbsp; 
      &nbsp;&nbsp;&nbsp; cout &lt;&lt; "File 
      created!\n";<BR><BR><BR>&nbsp;&nbsp;&nbsp; while 
      (!(feof(fo)))<BR>&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp; decstate = 
      speex_decoder_init (&amp;speex_nb_mode);<BR><BR>&nbsp;&nbsp;&nbsp; // Set 
      default options for decoding:<BR>&nbsp;&nbsp;&nbsp; temp = 
      1;<BR>&nbsp;&nbsp;&nbsp; speex_decoder_ctl(decstate, SPEEX_SET_ENH, 
      &amp;temp);<BR><BR><BR>&nbsp;&nbsp;&nbsp; // Initialize spxbits (structure 
      SpeexBits)<BR>&nbsp;&nbsp;&nbsp; speex_bits_init 
      (&amp;spxbits);<BR><BR><BR>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; fread 
      (&amp;nbBytes, sizeof(int), 1, fo);<BR>&nbsp;&nbsp;&nbsp; 
      &nbsp;&nbsp;&nbsp; fread (cbits, 1, nbBytes, 
      fo);<BR><BR>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; cout &lt;&lt; "1"; // 
      just to see whether the loop iterates<BR><BR>&nbsp;&nbsp;&nbsp; 
      &nbsp;&nbsp;&nbsp; speex_bits_read_from (&amp;spxbits, cbits, 
      nbBytes);<BR>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; speex_decode (decstate, 
      &amp;spxbits, pcm);<BR><BR><BR>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 
      Copy 1 frame from float pcm to short spx<BR>&nbsp;&nbsp;&nbsp; 
      &nbsp;&nbsp;&nbsp; for (n=0; n&lt;FRAME_SIZE; n++)<BR>&nbsp;&nbsp;&nbsp; 
      &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; spx [n] = pcm 
      [n];<BR><BR>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; fwrite (spx, 
      sizeof(short), FRAME_SIZE, fs);<BR><BR>&nbsp;&nbsp;&nbsp; 
      }<BR>&nbsp;&nbsp;&nbsp; &nbsp;// end of&nbsp; loop<BR>&nbsp;&nbsp;&nbsp; 
      // Entire file has been read, decoded and saved<BR><BR>&nbsp;&nbsp;&nbsp; 
      speex_decoder_destroy (decstate);<BR>&nbsp;&nbsp;&nbsp; speex_bits_destroy 
      (&amp;spxbits);<BR>&nbsp;&nbsp;&nbsp; fclose (fo);<BR>&nbsp;&nbsp;&nbsp; 
      fclose (fs);<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; cout &lt;&lt; 
      "Finished processing!\n";<BR>}<BR><BR></SPAN></DIV><SPAN class=q>
      <P></P>
      <HR>

      <P></P>_______________________________________________<BR>Speex-dev 
      mailing list<BR><A onclick="return top.js.OpenExtLink(window,event,this)" 
      href="mailto:Speex-dev@xiph.org" 
      target=_blank>Speex-dev@xiph.org</A><BR><A 
      onclick="return top.js.OpenExtLink(window,event,this)" 
      href="http://lists.xiph.org/mailman/listinfo/speex-dev" 
      target=_blank>http://lists.xiph.org/mailman/listinfo/speex-dev</A><BR>
      <P></P></SPAN></BLOCKQUOTE></BLOCKQUOTE></DIV><BR>
  <P>
  <HR>

  <P></P>_______________________________________________<BR>Speex-dev mailing 
  list<BR>Speex-dev@xiph.org<BR>http://lists.xiph.org/mailman/listinfo/speex-dev<BR></BLOCKQUOTE></BODY></HTML>