[Speex-dev] Decoding only a certain frame results in different values than when decoding the entire file
    Hermann Weber 
    hermie.weber at gmx.de
       
    Thu Dec 22 11:55:18 PST 2011
    
    
  
To make it complete, here is the code that I am using to encode a large 
file:
int __stdcall SpxEncode(unsigned char* inBuf, unsigned char* outBuf, 
unsigned int inlen)
{
     //char *testFile;
     //FILE *ftest;
     //testFile = "test";
     //ftest = fopen(testFile, "wb");
     //fwrite(inBuf,1,inlen,ftest);
     //take every 320 bytes
     //copy every short to float array, and make sure to put null in 
unused area
     float input[MAX_FRAME_SIZE];
     char cbits[MAX_FRAME_BYTES];
     unsigned int inBufpos = 0, j, outBufpos = 0;
     short *sinBuf;
     sinBuf = (short*) inBuf;
     do
     {
         j = 0;
         do
             {
             //copy to float array
             input[j] = sinBuf[inBufpos];
             inBufpos++; j++;
             }
         while ((inBufpos % 160 != 0) && (inBufpos != (inlen/2)));
         //fill the rest with null
         if (inBufpos == (inlen/2))
             for (j=(inBufpos%160); j<160; j++)    input[j] = 0;
         speex_bits_reset(&bits);
         speex_encode(encstate, input, &bits);
         /*Copy the bits to an array of char that can be written*/
         speex_bits_write(&bits, cbits, MAX_FRAME_BYTES);
         for (j=0; j<62; j++)
             {
             outBuf[outBufpos] = cbits[j];
             outBufpos++;
             }
     }
     while (inBufpos != (inlen/2));
     //fwrite(outBuf, 1, outBufpos, ftest);
     //fclose(ftest);
     return 42;
}
    
    
More information about the Speex-dev
mailing list