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>
decstate = speex_decoder_init (&speex_nb_mode);<br>
// Set default options for decoding:<br>
temp = 1;<br>
speex_decoder_ctl(decstate, SPEEX_SET_ENH, &temp);<br>
<br>
// Initialize spxbits (structure SpeexBits)<br>
speex_bits_init (&spxbits);<br>
<br>
while (!(feof(fo))) // this is where the problem starts<br>
{<br>
fread (&nbBytes, sizeof(int), 1, fo);<br>
fread (cbits, 1, nbBytes, fo);<br>
<br>
cout << "1"; // just to see whether the loop iterates<br>
<br>
speex_bits_read_from (&spxbits, cbits, nbBytes);<br>
speex_decode (decstate, &spxbits, pcm);<br>
<br>
<br>
// Copy 1 frame from float pcm to short spx<br>
for (n=0; n<FRAME_SIZE; n++)<br>
spx [n] = pcm [n];<br>
<br>
fwrite (spx, sizeof(short), FRAME_SIZE, fs);<br>
<br>
}<br>
// end of loop<br>
// Entire file has been read, decoded and saved<br>
<br>
speex_decoder_destroy (decstate);<br>
speex_bits_destroy (&spxbits);<br>
fclose (fo);<br>
fclose (fs);<br>
<br>
cout << "Finished processing!\n";<br>
}<br><br><div><span class="gmail_quote">On 10/18/05, <b class="gmail_sendername">Steve Russell</b> <<a href="mailto:srussell@innernet.net">srussell@innernet.net</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div><font face="Arial" size="4">Mon,</font></div>
<div><font face="Arial" size="4"></font> </div>
<div><font face="Arial" size="4">Here is feedback that I got concerning the
access violation, i.e. the failure of the while loop below. Does this
solve the problem?</font></div>
<div><font face="Arial" size="4"></font> </div>
<div><font face="Arial" size="4">Steve</font></div>
<div><font face="Arial" size="4"></font> </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="border-left: 2px solid rgb(0, 0, 0); padding-right: 0px; padding-left: 5px; margin-left: 5px; margin-right: 0px;"><span class="q">
<div style="font-family: arial; font-style: normal; font-variant: normal; font-weight: normal; font-size: 10pt; line-height: normal; font-size-adjust: none; font-stretch: normal;">----- Original Message ----- </div>
<div style="background: rgb(228, 228, 228) none repeat scroll 0% 50%; -moz-background-clip: initial; -moz-background-origin: initial; -moz-background-inline-policy: initial; font-family: arial; font-style: normal; font-variant: normal; font-weight: normal; font-size: 10pt; line-height: normal; font-size-adjust: none; font-stretch: normal;">
<b>From:</b>
<a title="mowin.dev@gmail.com" href="mailto:mowin.dev@gmail.com" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">Mo Win</a>
</div>
<div style="font-family: arial; font-style: normal; font-variant: normal; font-weight: normal; font-size: 10pt; line-height: normal; font-size-adjust: none; font-stretch: normal;"><b>To:</b> <a title="speex-dev@xiph.org" href="mailto:speex-dev@xiph.org" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">
speex-dev@xiph.org</a> </div>
<div style="font-family: arial; font-style: normal; font-variant: normal; font-weight: normal; font-size: 10pt; line-height: normal; font-size-adjust: none; font-stretch: normal;"><b>Sent:</b> Monday, October 17, 2005 8:05
AM</div>
<div style="font-family: arial; font-style: normal; font-variant: normal; font-weight: normal; font-size: 10pt; line-height: normal; 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 <stdio.h><br>#include
<iostream.h><br><br>void main ()<br>{<br> <span style="color: rgb(153, 255, 153);">// Definitions</span><br>
#define FRAME_SIZE 160<br> #define
FIXED_POINT<br><br> <span style="color: rgb(153, 255, 153);"> //
Variable Declarations</span><br> FILE *fo,
*fs;<br> short spx [FRAME_SIZE];<br> float
pcm [FRAME_SIZE];<br> char cbits
[200];<br> int nbBytes, n, temp;<br><br>
void *decstate;<br> SpeexBits
spxbits;<br><br><br> <span style="color: rgb(153, 255, 153);">// Program starts
here:</span><br> cout << "Starting
spxdec...\n";<br> fo =
fopen("samp.spx","rb");<br><br> if (fo ==
NULL)<br> cout <<
"Error!\n";<br> else<br>
cout << "Okay!\n";<br><br> fs =
fopen ("pcmfile", "wb");<br><br> if (fs ==
NULL)<br> cout << "Error creating
file!\n";<br> else<br>
cout << "File created!\n";<br><br><br> while
(!(feof(fo)))<br> {<br> decstate =
speex_decoder_init (&speex_nb_mode);<br><br> // Set
default options for decoding:<br> temp =
1;<br> speex_decoder_ctl(decstate, SPEEX_SET_ENH,
&temp);<br><br><br> // Initialize spxbits (structure
SpeexBits)<br> speex_bits_init
(&spxbits);<br><br><br> fread
(&nbBytes, sizeof(int), 1, fo);<br>
fread (cbits, 1, nbBytes, fo);<br><br>
cout << "1"; // just to see whether the loop
iterates<br><br> speex_bits_read_from
(&spxbits, cbits, nbBytes);<br>
speex_decode (decstate, &spxbits, pcm);<br><br><br>
// Copy 1 frame from float pcm to short
spx<br> for (n=0; n<FRAME_SIZE;
n++)<br> spx [n] = pcm
[n];<br><br> fwrite (spx, sizeof(short),
FRAME_SIZE, fs);<br><br> }<br> //
end of loop<br> // Entire file has been read, decoded
and saved<br><br> speex_decoder_destroy
(decstate);<br> speex_bits_destroy
(&spxbits);<br> fclose (fo);<br>
fclose (fs);<br> <br> cout <<
"Finished processing!\n";<br>}<br><br>
</span></div><span class="q"><p>
</p><hr>
<p></p>_______________________________________________<br>Speex-dev mailing
list<br><a href="mailto:Speex-dev@xiph.org" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">Speex-dev@xiph.org</a><br><a href="http://lists.xiph.org/mailman/listinfo/speex-dev" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">
http://lists.xiph.org/mailman/listinfo/speex-dev</a><br><p></p></span></blockquote>
</blockquote></div><br>