ref: 53fb0f775ed86a7883e8136208d81af234333f06
parent: cf60e7adec7ad575884fbdb058876fce969fa15e
author: Jean-Marc Valin <[email protected]>
date: Mon Jan 31 10:56:38 EST 2011
Handling auto-detecting of frame size in decoder
--- a/src/opus_dec.c
+++ b/src/opus_dec.c
@@ -62,10 +62,10 @@
short *in, *out;
int mode=MODE_HYBRID;
double bits=0;
- if (argc != 6 && argc != 7)
+ if (argc != 5 && argc != 6)
{
- fprintf (stderr, "Usage: test_opus <rate (kHz)> <channels> <frame size> "
- " <bytes per packet> [<VBR rate (kb/s)>] [<packet loss rate>] "
+ fprintf (stderr, "Usage: test_opus <rate (kHz)> <channels> "
+ "[<packet loss rate>] "
"<input> <output>\n");
return 1;
}
@@ -72,10 +72,9 @@
rate = atoi(argv[1]);
channels = atoi(argv[2]);
- frame_size = atoi(argv[3]);
if (argc >= 7)
- loss = atoi(argv[4]);
+ loss = atoi(argv[3]);
inFile = argv[argc-2];
fin = fopen(inFile, "rb");
@@ -94,7 +93,7 @@
dec = opus_decoder_create(rate, channels);
- out = (short*)malloc(frame_size*channels*sizeof(short));
+ out = (short*)malloc(960*channels*sizeof(short));
while (!stop)
{
len = ((fgetc(fin)<<8)&0xFF00) | (fgetc(fin)&0xFF);
@@ -102,11 +101,11 @@
break;
bits += len*8;
err = fread(data, 1, len, fin);
- opus_decode(dec, rand()%100<loss ? NULL : data, len, out, frame_size);
- count++;
+ frame_size = opus_decode(dec, rand()%100<loss ? NULL : data, len, out, 960);
+ count+=frame_size;
fwrite(out, sizeof(short), frame_size*channels, fout);
}
- fprintf (stderr, "average bit-rate: %f kb/s\n", bits*rate/(frame_size*(double)count));
+ fprintf (stderr, "average bit-rate: %f kb/s\n", bits*rate/((double)count));
opus_decoder_destroy(dec);
fclose(fin);
fclose(fout);
--- a/src/opus_decoder.c
+++ b/src/opus_decoder.c
@@ -120,6 +120,14 @@
ec_dec_init(&dec,&buf);
}
+ if (audiosize > frame_size)
+ {
+ fprintf(stderr, "PCM buffer too small");
+ return -1;
+ } else {
+ frame_size = audiosize;
+ }
+
if (st->mode != MODE_CELT_ONLY)
{
DecControl.API_sampleRate = st->Fs;
@@ -188,7 +196,7 @@
for (i=0;i<frame_size*st->channels;i++)
pcm[i] += pcm_celt[i];
}
- return celt_ret;
+ return celt_ret<0 ? celt_ret : audiosize;
}