Hi all. I'm trying to decode speex using version 1.1.10's libspeex with
fixed_point enabled. copied the sample in the manual (1.1.11) with
minor revisions. While running the program, encountered this warning:<br><br>"Packet is larger than allocated buffer : 38"
<br><br>when calling <span style="font-weight: bold;">speex_bits_read_from (&bits, cbits, nBytes)</span><br><br>then my program terminated unexpectedly with errors (<span style="font-style: italic;">Unhandled exception at 0x10225e1f (
msvcr80d.dll) in sampleDEC.exe: 0xC0000005: Access violation reading location 0x645c3a63</span>.)<br><br>I
declared cbits as char *cbits [500]. nBytes is 38, bit rate is 15000
bps. I'm decoding a 'speex' file created using a program much like
sampleENC. Can anyone tell me what is wrong and how I can correct the
problem? Thank you. For your reference I'm attaching the code. Please
feel free to ask me questions if the information I provided is lacking.
By the way, I am compiling for Windows using VS2005 Beta2.
<br><br>Thanks,<br>Mon<br><br><span style="font-family: courier new,monospace;">#define FIXED_POINT</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
int main (int argc, char ** argv)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">{</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
printf ("sampleDEC.exe started!\n"); /**/</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> int nBytes, FrameSize, BitRate;
</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> FILE *fin, *fout;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
char *inFile, *outFile, *PEnhancement;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> short out [500];</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> char cbits [500];</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> void *state;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> SpeexBits bits;</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
state = speex_decoder_init (&speex_nb_mode);</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> speex_decoder_ctl (state, SPEEX_GET_FRAME_SIZE, &FrameSize);
</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> inFile = argv [1];</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> outFile = argv [2];</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> PEnhancement = argv [3];</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> fout = fopen (outFile, "w");</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
if (fout == NULL)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> {</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
printf ("Error creating file\n");</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> return 1;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> }</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> printf ("Successfully opened %s for writing! \n", outFile); /**/
</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> fin = fopen (inFile, "rb");</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> if (fin == NULL)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> {</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> printf ("Error opening file\n");</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> return 1;
</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> }</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> printf ("Successfully opened %s for decoding!\n\n", inFile); /**/
</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> </span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> fseek (fin,(sizeof(char))*12+sizeof(int),SEEK_SET); // because of the way I encoded a PCM file
</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> speex_decoder_ctl (state, SPEEX_GET_BITRATE, &BitRate);</span>
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> printf ("decoding... BIT RATE: %i\n",BitRate);</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> switch (*PEnhancement)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> { // Here I use BitRate to toggle Perceptual Enhancement
</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> case 'Y':</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
BitRate = 1;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> break;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
case 'y':</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> BitRate = 1;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
break;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> case 'N':</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
BitRate = 0;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> break;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
case 'n':</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> BitRate = 0;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
break;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> default:</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
BitRate = 1;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> break;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
}</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> speex_decoder_ctl (state, SPEEX_SET_ENH, &BitRate);</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> BitRate = 0; // Henceforth BitRate is used to count the number of frames decoded</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> while (1)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> {
</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> fread(&nBytes, sizeof(int), 1, fin);</span><span style="font-family: courier new,monospace;"></span><span style="font-family: courier new,monospace;">
</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> </span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> if (feof(fin))
</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> break;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> fread(cbits, sizeof(char), nBytes, fin);</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> speex_bits_read_from(&bits, cbits, nBytes);</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> speex_decode_int(state, &bits, out);</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> fwrite(out, sizeof(short), FrameSize, fout);</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
BitRate++; </span><span style="font-family: courier new,monospace;"></span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> }</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> printf ("nBytes is %i.\n",nBytes);</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
printf ("Decoded %i frames\n",BitRate);</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> speex_encoder_destroy(state);
</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> speex_bits_destroy(&bits);</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> fclose (fin);</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> fclose(fout);</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> return 0;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">}</span>
<br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><br>