[Speex-dev] Error Executing sampledec in VC++

Mo Win mowin.dev at gmail.com
Mon Oct 17 19:31:24 PDT 2005


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:

First-chance exception at 0x004010fa in SPXDEC.exe: 0xC0000005: Access
violation reading location 0x0000000c.
Unhandled exception at 0x004010fa in SPXDEC.exe: 0xC0000005: Access
violation reading location 0x0000000c.

It looks like the same error. I've attached the code below

Thanks,
Mon

Portion of the revised code:


decstate = speex_decoder_init (&speex_nb_mode);
// Set default options for decoding:
temp = 1;
speex_decoder_ctl(decstate, SPEEX_SET_ENH, &temp);

// Initialize spxbits (structure SpeexBits)
speex_bits_init (&spxbits);

while (!(feof(fo))) // this is where the problem starts
{
fread (&nbBytes, sizeof(int), 1, fo);
fread (cbits, 1, nbBytes, fo);

cout << "1"; // just to see whether the loop iterates

speex_bits_read_from (&spxbits, cbits, nbBytes);
speex_decode (decstate, &spxbits, pcm);


// Copy 1 frame from float pcm to short spx
for (n=0; n<FRAME_SIZE; n++)
spx [n] = pcm [n];

fwrite (spx, sizeof(short), FRAME_SIZE, fs);

}
// end of loop
// Entire file has been read, decoded and saved

speex_decoder_destroy (decstate);
speex_bits_destroy (&spxbits);
fclose (fo);
fclose (fs);

cout << "Finished processing!\n";
}

On 10/18/05, Steve Russell <srussell at innernet.net> wrote:
>
> Mon,
>  Here is feedback that I got concerning the access violation, i.e. the
> failure of the while loop below. Does this solve the problem?
>  Steve
>  My guess is that speex_decoder_init() should be outside the while()..
> loop
> as speex_decoder_destroy() is also outside.
>
> ----- Original Message -----
> *From:* Mo Win <mowin.dev at gmail.com>
> *To:* speex-dev at xiph.org
> *Sent:* Monday, October 17, 2005 8:05 AM
> *Subject:* [Speex-dev] Error Executing sampledec in VC++
>
> 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 - First-chance
> exception in sampledec.exe : 0xC0000005: Access Violation. Has anyone
> encountered this / does anyone know how to deal with it? by the way,
> sampleenc executed perfectly...
>
> 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..
>
> In gratitude,
> Mon
>
> (Below is my code. it's almost exactly like sampleenc except I read a file
> stream instead of stdin)
>
> #include "speex/speex.h"
>
> #include <stdio.h>
> #include <iostream.h>
>
> void main ()
> {
> // Definitions
> #define FRAME_SIZE 160
> #define FIXED_POINT
>
>  // Variable Declarations
> FILE *fo, *fs;
> short spx [FRAME_SIZE];
> float pcm [FRAME_SIZE];
> char cbits [200];
> int nbBytes, n, temp;
>
> void *decstate;
> SpeexBits spxbits;
>
>
> // Program starts here:
> cout << "Starting spxdec...\n";
> fo = fopen("samp.spx","rb");
>
> if (fo == NULL)
> cout << "Error!\n";
> else
> cout << "Okay!\n";
>
> fs = fopen ("pcmfile", "wb");
>
> if (fs == NULL)
> cout << "Error creating file!\n";
> else
> cout << "File created!\n";
>
>
> while (!(feof(fo)))
> {
> decstate = speex_decoder_init (&speex_nb_mode);
>
> // Set default options for decoding:
> temp = 1;
> speex_decoder_ctl(decstate, SPEEX_SET_ENH, &temp);
>
>
> // Initialize spxbits (structure SpeexBits)
> speex_bits_init (&spxbits);
>
>
> fread (&nbBytes, sizeof(int), 1, fo);
> fread (cbits, 1, nbBytes, fo);
>
> cout << "1"; // just to see whether the loop iterates
>
> speex_bits_read_from (&spxbits, cbits, nbBytes);
> speex_decode (decstate, &spxbits, pcm);
>
>
> // Copy 1 frame from float pcm to short spx
> for (n=0; n<FRAME_SIZE; n++)
> spx [n] = pcm [n];
>
> fwrite (spx, sizeof(short), FRAME_SIZE, fs);
>
> }
> // end of loop
> // Entire file has been read, decoded and saved
>
> speex_decoder_destroy (decstate);
> speex_bits_destroy (&spxbits);
> fclose (fo);
> fclose (fs);
>
> cout << "Finished processing!\n";
> }
>
>  ------------------------------
>
> _______________________________________________
> Speex-dev mailing list
> Speex-dev at xiph.org
> http://lists.xiph.org/mailman/listinfo/speex-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.xiph.org/pipermail/speex-dev/attachments/20051018/11754124/attachment.html


More information about the Speex-dev mailing list