[CELT-dev] uint decode error on visual studio...

Jean-Marc Valin jean-marc.valin at usherbrooke.ca
Wed Mar 3 16:26:45 PST 2010


In general, that error message means a corrupted packet. I *very rare* 
cases, it could be a bug in CELT or a compile problem, but I haven't 
encountered such case for more than a year now.

	Jean-Marc

On 2010-03-03 14:38, Torgeir Hagland wrote:
> Is this a common warning? The decoder doesn't return an error on it, but
> I see it a lot in my test application on windows. It is non existent on
> my linux box. I haven't tried mingw yet.
>
> please note that I'm using visual studio 2008 w/the vcproj that Bjoern
> Rasmussen made for 0.5.2 (w/some file references removed) at the moment
> and it is giving a lot of C4554 warnings "'operator' : check operator
> precedence for possible error; use parentheses to clarify precedence",
> especially where the EC_CODE_* macros are used. I would have to agree
> with msdev, it would be nice to have precedence clarified.
>
> The idea of my app below is that I take a raw mono 16-bit little endian
> signed PCM, Celt it, then immediately turn it back into the same PCM
> format again. However my output file clearly suffers from "uint decode
> error" on windows, but on linux it's just peachy.
>
>
> #include <stdlib.h>
> #include <stdio.h>
> #include <string.h>
>
> #include <libcelt/celt.h>
>
> int gBitRate=128000;
> int gFrameSize=256;
> int gSampleRate=44100;
> int gNrChannels=1;
>
> int main(int argc, char* argv[])
> {
> const char* inputfilename="..\\input_mono.snd";
> const char* encodedfilename="..\\encoded_mono.celt";
> const char* outputfilename="..\\output_mono.snd";
>
> FILE* encodedfile=0;
>
> FILE* inputfile=fopen(inputfilename,"rb");
> if(!inputfile)
> {
> printf("ERROR opening %s for reading\n",inputfilename);
> return -1;
> }
>
> encodedfile=fopen(encodedfilename,"wb");
> if(!encodedfile)
> {
> printf("ERROR opening %s for writing\n",encodedfilename);
> return -1;
> }
>
> FILE* outputfile=fopen(outputfilename,"wb");
> if(!outputfile)
> {
> printf("ERROR opening %s for writing\n",outputfilename);
> return -1;
> }
>
> int bytes_per_packet = ((gBitRate*gFrameSize/gSampleRate+4)/8)*gNrChannels;
>
> int error=0;
> celt_int16*
> pcmbuffer=(celt_int16*)malloc(sizeof(celt_int16)*gFrameSize*gNrChannels);
> unsigned char* encodedbuffer=(unsigned char*)malloc(bytes_per_packet);
> CELTMode* mode=celt_mode_create(gSampleRate,gFrameSize,&error);
> if(mode==NULL || error!=CELT_OK)
> {
> printf("ERROR: celt_mode_create %s\n",celt_strerror(error));
> return -1;
> }
> int offset=0;
> int res=0;
>
> CELTEncoder* encoder=celt_encoder_create(mode,gNrChannels,&error);
> if(encoder==NULL || error!=CELT_OK)
> {
> printf("ERROR: celt_encoder_create %s\n",celt_strerror(error));
> return -1;
> }
>
> while((res=fread(pcmbuffer,sizeof(celt_int16)*gFrameSize*gNrChannels,1,inputfile))==1)
> {
> int ret=celt_encode(encoder,pcmbuffer,NULL,encodedbuffer,bytes_per_packet);
> if(ret<0)
> {
> printf("ERROR: celt_encode %s\n",celt_strerror(ret));
> return -1;
> }
> else if(ret!=bytes_per_packet)
> {
> printf("ERROR: celt_encode got %d bytes, expected %d\n",ret,
> bytes_per_packet);
> return -1;
> }
> else
> {
> if(fwrite(encodedbuffer,bytes_per_packet,sizeof(unsigned
> char),encodedfile)!=1)
> {
> printf("ERROR: failed writing bytes to %s\n",encodedfilename);
> return -1;
> }
> else
> {
> printf("writing offset: %d, size %d\n",offset,bytes_per_packet);
> offset+=bytes_per_packet;
> }
> }
> }
> fclose(inputfile);
> fclose(encodedfile);
>
> celt_encoder_destroy(encoder);
> celt_mode_destroy(mode);
>
> CELTMode* mode2=celt_mode_create(gSampleRate,gFrameSize,&error);
> if(mode2==NULL || error!=CELT_OK)
> {
> printf("ERROR: celt_mode_create 2 %s\n",celt_strerror(error));
> return -1;
> }
>
> encodedfile=fopen(encodedfilename,"rb");
> if(!encodedfile)
> {
> printf("ERROR opening %s for reading\n",encodedfilename);
> return -1;
> }
>
> CELTDecoder* decoder=celt_decoder_create(mode2,gNrChannels,&error);
> if(decoder==NULL || error!=CELT_OK)
> {
> printf("ERROR: celt_decoder_create %s\n",celt_strerror(error));
> return -1;
> }
>
>
> fseek(encodedfile,0,2);
> int filesize=ftell(encodedfile);
> fseek(encodedfile,0,0);
> offset=0;
> while((res=fread(encodedbuffer,bytes_per_packet,1,encodedfile))==1)
> {
> printf("reading offset: %d, size %d,
> %.2f\n",offset,bytes_per_packet,((float)offset/(float)filesize)*100.0f);
> offset+=bytes_per_packet;
>
> int ret=celt_decode(decoder,encodedbuffer,bytes_per_packet,pcmbuffer);
> if(ret!=CELT_OK)
> {
> printf("ERROR: celt_decode %s\n",celt_strerror(ret));
> return -1;
> }
> else
> {
> fwrite(pcmbuffer,sizeof(celt_int16)*gFrameSize*gNrChannels,1,outputfile);
> }
> }
>
> fclose(outputfile);
> fclose(encodedfile);
>
> celt_decoder_destroy(decoder);
>
> celt_mode_destroy(mode2);
>
> free(pcmbuffer);
> free(encodedbuffer);
> }
>
>
>
> _______________________________________________
> celt-dev mailing list
> celt-dev at xiph.org
> http://lists.xiph.org/mailman/listinfo/celt-dev



More information about the celt-dev mailing list