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

Steve Russell srussell at innernet.net
Mon Oct 17 19:44:35 PDT 2005


Mon,

Here is an additional post that came to me regarding your trouble.  In the meantime, I will take your latest comments and see what more feedback we can get.  I don't know what it is, and I haven't taken the time in the last few months to try again to get Speex going inside C++, but something about it has been much more difficult for me to grasp than both mmio and Ogg Vorbis.

(That's not a criticism!  I appreciate all the "free" efforts involved.)

Steve

steve,

your speex decoding code looks ok, only you have to be sure that you have
the spx file encoded correctly as well. the point is the problem could also
be caused by the source file being read and if you are at all reading it
correctly.

what i'll probably do here is:

1. check the encoding code to validate the integrity of the spx file
2. check the decoding code if the sizes are being read correctly.

the spx file here shows a certain formatting structure where each item =
size+data, so i assume this is a variable bitrate (VBR) encoding where item
sizes could be of any value. to make it easier you can also do CBR, where
your speex data are encoded on a constant bitrate.  this will make debugging
easier for starters until you know what the problem is.

regards,
ronald
  ----- Original Message ----- 
  From: Mo Win 
  To: speex-dev at xiph.org 
  Cc: Steve Russell 
  Sent: Monday, October 17, 2005 10:31 PM
  Subject: Re: [Speex-dev] Error Executing sampledec in VC++


  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 
      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/20051017/38ce337c/attachment-0001.htm


More information about the Speex-dev mailing list