[Speex-dev] Decoding only a certain frame results in different values than when decoding the entire file

Hermann Weber hermie.weber at gmx.de
Wed Dec 21 15:03:24 PST 2011


Sorry, it seems I have only replied to Lakhdar, not to the newsgroup.
Below is my reply to Lakhdar, and I would like to make it more clear 
now, using some pseudo values for simplicity:

I read bytes 1 to 124 from my encoded spx file.
I decode themt and get the values:
---Frame 1----
-293
-8234
2134
17
---Frame 2----
-9323
-732
189
2329

Both frames are just perfect as I need them.

But now when I read bytes 63 to 125 from my encoded spx and decode it, I 
get the values
732
9273
-799
-723

This is weird because I expected to get the encoded values
-9323
-732
189
2329

I hope I could explain it well.
Am I missing something here?

Thank you very much.
Hermann



Hi Lakhdar,

I am not sure if I do anything wrong with the dec state memory.
Could you perhaps take a look at what I am (perhaps wrongly) doing?

int __stdcall SpxDecode(unsigned char* DinBuf, float* DoutBuf, unsigned 
int Dinlen)
{

     //char *testFile;
     //FILE *ftest;
     //testFile = "test2";
     //ftest = fopen(testFile, "wb");
     //fwrite(inBuf,1,inlen,ftest);
     //fwrite(outBuf, 1, outBufpos, ftest);
     //fclose(ftest);

     //take every 62 bytes
     //decode, then write to outbuf

     char cbits[MAX_FRAME_BYTES];
     float output[MAX_FRAME_SIZE];
     short out[MAX_FRAME_SIZE];
     unsigned int i,j;

     unsigned char* tout; tout = (unsigned char*)&out;

     for (i=0; i<(Dinlen/62); i++)
         {
         for (j=0;j<62;j++)    cbits[j] = DinBuf[(i*62)+j];

         speex_bits_read_from(&bits, cbits, 62);
         speex_decode(decstate, &bits, output);

         for (j=0;j<160;j++) DoutBuf[j+(i*160)] = output[j];
         }

     return 43;
}

Btw, just if you wondering what I am doing... I am feeding (62 * 
NumberOfFramesThatIWantToRead) bytes from VB6 and return it as a float 
array.

Greetings,
Hermann

Am 21.12.2011 15:26, schrieb Lakhdar Bourokba:
 > Hi Hermann,
 > Could it be your decoder state memory that is not longer sync ?
 > When a decoder processes a frame, it uses that frame and its memory 
state (affected by the previous frames) to generate the output samples. 
If you skip the previous frames, the decoder state memory will not be 
the same (as when you do full decoding) which causes the output to be 
different.
 > I hope this helps.
 > L.
 >
 >
 > On Wed, Dec 21, 2011 at 5:17 AM, Hermann Weber <hermie.weber at gmx.de> 
wrote:
 >
 >     Hello!
 >
 >     I am still using version 1.0.4.
 >
 >     When I have encoded a larger file and then only want to decode 
only one
 >     frame from it (for example the 2nd frame), is there anything special
 >     that I have to keep in mind?
 >
 >     I thought that I could simply read the bytes from the encoded 
file for
 >     example from the start position of the 2nd frame and then decode 
it. I
 >     did that, and I can play it play, but the values in the decoded 2nd
 >     frame are different than they are when I decode the entire file 
and then
 >     look at the values for the 2nd frame.
 >     I hope I could explain it well.
 >
 >     I noticed that there is a pattern in the beginning of the encoded 
file,
 >     and I am not sure if I have to take it into account somehow.
 >
 >     It would be nice if someone could tell me if something comes to 
his/her
 >     mind that I might be doing wrong.
 >
 >     Thank you very much.
 >
 >     Hermann
 >     _______________________________________________
 >     Speex-dev mailing list
 >     Speex-dev at xiph.org
 >     http://lists.xiph.org/mailman/listinfo/speex-dev
 >
 >


Hello!

I am still using version 1.0.4.

When I have encoded a larger file and then only want to decode only one 
frame from it (for example the 2nd frame), is there anything special 
that I have to keep in mind?

I thought that I could simply read the bytes from the encoded file for 
example from the start position of the 2nd frame and then decode it. I 
did that, and I can play it play, but the values in the decoded 2nd 
frame are different than they are when I decode the entire file and then 
look at the values for the 2nd frame.
I hope I could explain it well.

I noticed that there is a pattern in the beginning of the encoded file, 
and I am not sure if I have to take it into account somehow.

It would be nice if someone could tell me if something comes to his/her 
mind that I might be doing wrong.

Thank you very much.

Hermann


More information about the Speex-dev mailing list