Commit 53fb0f77 authored by Jean-Marc Valin's avatar Jean-Marc Valin
Browse files

Handling auto-detecting of frame size in decoder

parent cf60e7ad
......@@ -62,20 +62,19 @@ int main(int argc, char *argv[])
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;
}
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 @@ int main(int argc, char *argv[])
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 @@ int main(int argc, char *argv[])
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);
......
......@@ -120,6 +120,14 @@ int opus_decode(OpusDecoder *st, const unsigned char *data,
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 @@ int opus_decode(OpusDecoder *st, const unsigned char *data,
for (i=0;i<frame_size*st->channels;i++)
pcm[i] += pcm_celt[i];
}
return celt_ret;
return celt_ret<0 ? celt_ret : audiosize;
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment