Added a check to make sure the encoder signal matches that of the decoder

This commit is contained in:
Jean-Marc Valin 2008-01-29 08:17:50 +11:00
parent 38b6d479a4
commit 4618eee092

View file

@ -33,19 +33,25 @@
#include "celt.h" #include "celt.h"
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <math.h>
#define FRAME_SIZE 256 #define FRAME_SIZE 256
#define CHANNELS 1 #define CHANNELS 1
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
int i;
char *inFile, *outFile; char *inFile, *outFile;
FILE *fin, *fout; FILE *fin, *fout;
short in[FRAME_SIZE*CHANNELS]; short in[FRAME_SIZE*CHANNELS];
short out[FRAME_SIZE*CHANNELS];
CELTEncoder *enc; CELTEncoder *enc;
CELTDecoder *dec; CELTDecoder *dec;
int len; int len;
char data[1024]; char data[1024];
double rmsd = 0;
int count = 0;
inFile = argv[1]; inFile = argv[1];
fin = fopen(inFile, "rb"); fin = fopen(inFile, "rb");
@ -62,21 +68,30 @@ int main(int argc, char *argv[])
len = celt_encode(enc, in, data, 32); len = celt_encode(enc, in, data, 32);
//printf ("\n"); //printf ("\n");
//printf ("%d\n", len); //printf ("%d\n", len);
#if 1 /* This is to simulate packet loss */
/* this is to simulate packet loss */
if (rand()%100==-1) if (rand()%100==-1)
celt_decode(dec, NULL, len, in); celt_decode(dec, NULL, len, out);
else else
celt_decode(dec, data, len, in); celt_decode(dec, data, len, out);
//printf ("\n"); //printf ("\n");
#endif for (i=0;i<FRAME_SIZE*CHANNELS;i++)
fwrite(in, sizeof(short), FRAME_SIZE*CHANNELS, fout); rmsd += (in[i]-out[i])*1.0*(in[i]-out[i]);
count++;
fwrite(out, sizeof(short), FRAME_SIZE*CHANNELS, fout);
} }
celt_encoder_destroy(enc); celt_encoder_destroy(enc);
celt_decoder_destroy(dec); celt_decoder_destroy(dec);
fclose(fin); fclose(fin);
fclose(fout); fclose(fout);
if (rmsd > 0)
{
rmsd = sqrt(rmsd/(1.0*FRAME_SIZE*CHANNELS*count));
fprintf (stderr, "Error: encoder doesn't match decoder\n");
fprintf (stderr, "RMS mismatch is %f\n", rmsd);
return 1;
} else {
fprintf (stderr, "Encoder matches decoder!!\n");
}
return 0; return 0;
} }