Commit 16ca18b9 authored by Jean-Marc Valin's avatar Jean-Marc Valin
Browse files

Automatically choosing the overlap based on the frame size.

parent 9d1decd1
......@@ -373,7 +373,7 @@ int celt_encode(CELTEncoder * restrict st, celt_int16_t * restrict pcm, unsigned
transient_time = -1;
maxR = 0;
}
if (maxR > 10)
if (maxR > 30)
{
float gain_1;
ec_enc_bits(&st->enc, 1, 1);
......
......@@ -108,7 +108,7 @@ typedef struct CELTMode CELTMode;
@param error Returned error code (if NULL, no error will be returned)
@return A newly created mode
*/
EXPORT CELTMode *celt_mode_create(celt_int32_t Fs, int channels, int frame_size, int lookahead, int *error);
EXPORT CELTMode *celt_mode_create(celt_int32_t Fs, int channels, int frame_size, int *error);
/** Destroys a mode struct. Only call this after all encoders and decoders
using this mode are destroyed as well.
......
......@@ -231,12 +231,11 @@ int main(int argc, char **argv)
m = malloc(nb*sizeof(CELTMode*));
for (i=0;i<nb;i++)
{
int Fs, ch, frame, overlap;
Fs = atoi(argv[4*i+1]);
ch = atoi(argv[4*i+2]);
frame = atoi(argv[4*i+3]);
overlap = atoi(argv[4*i+4]);
m[i] = celt_mode_create(Fs, ch, frame, overlap, NULL);
int Fs, ch, frame;
Fs = atoi(argv[3*i+1]);
ch = atoi(argv[3*i+2]);
frame = atoi(argv[3*i+3]);
m[i] = celt_mode_create(Fs, ch, frame, NULL);
}
file = fopen("static_modes.c", "w");
dump_modes(file, m, nb);
......
......@@ -270,7 +270,7 @@ static void compute_energy_allocation_table(CELTMode *mode)
mode->energy_alloc = alloc;
}
CELTMode *celt_mode_create(celt_int32_t Fs, int channels, int frame_size, int lookahead, int *error)
CELTMode *celt_mode_create(celt_int32_t Fs, int channels, int frame_size, int *error)
{
int i;
#ifdef STDIN_TUNING
......@@ -335,24 +335,33 @@ CELTMode *celt_mode_create(celt_int32_t Fs, int channels, int frame_size, int lo
*error = CELT_BAD_ARG;
return NULL;
}
if (lookahead < 32 || lookahead > frame_size)
{
celt_warning("The overlap must be between 32 and the frame size");
if (error)
*error = CELT_BAD_ARG;
return NULL;
}
res = (Fs+frame_size)/(2*frame_size);
mode = celt_alloc(sizeof(CELTMode));
mode->Fs = Fs;
mode->overlap = lookahead;
mode->mdctSize = frame_size;
mode->nbChannels = channels;
mode->eBands = compute_ebands(Fs, frame_size, &mode->nbEBands);
compute_pbands(mode, res);
mode->ePredCoef = QCONST16(.8f,15);
if (frame_size <= 64)
{
mode->nbShortMdcts = 1;
} else if (frame_size <= 256)
{
mode->nbShortMdcts = 2;
} else if (frame_size <= 384)
{
mode->nbShortMdcts = 3;
} else {
mode->nbShortMdcts = 4;
}
if (mode->nbShortMdcts > 1)
mode->overlap = frame_size/mode->nbShortMdcts;
else
mode->overlap = frame_size/2;
compute_allocation_table(mode, res);
/*printf ("%d bands\n", mode->nbEBands);*/
......@@ -380,7 +389,6 @@ CELTMode *celt_mode_create(celt_int32_t Fs, int channels, int frame_size, int lo
mdct_init(&mode->mdct, 2*mode->mdctSize);
mode->fft = pitch_state_alloc(MAX_PERIOD);
mode->nbShortMdcts = 4;
mode->shortMdctSize = mode->mdctSize/mode->nbShortMdcts;
mdct_init(&mode->shortMdct, 2*mode->shortMdctSize);
mode->shortWindow = mode->window;
......
......@@ -39,7 +39,7 @@
#include "psy.h"
#include "pitch.h"
#define CELT_BITSTREAM_VERSION 0x80000002
#define CELT_BITSTREAM_VERSION 0x80000003
#ifdef STATIC_MODES
#include "static_modes.h"
......
......@@ -51,26 +51,25 @@ int main(int argc, char *argv[])
celt_int32_t frame_size, channels;
int bytes_per_packet;
unsigned char data[1024];
int rate, overlap;
int rate;
#if !(defined (FIXED_POINT) && defined(STATIC_MODES))
int i;
double rmsd = 0;
#endif
int count = 0;
int skip;
celt_int32_t skip;
celt_int16_t *in, *out;
if (argc != 9 && argc != 8)
if (argc != 8 && argc != 7)
{
fprintf (stderr, "Usage: testcelt <rate> <channels> <frame size> <overlap> <bytes per packet> <input> <output>\n");
fprintf (stderr, "Usage: testcelt <rate> <channels> <frame size> <bytes per packet> <input> <output>\n");
return 1;
}
rate = atoi(argv[1]);
channels = atoi(argv[2]);
frame_size = atoi(argv[3]);
overlap = atoi(argv[4]);
skip = overlap;
mode = celt_mode_create(rate, channels, frame_size, overlap, NULL);
mode = celt_mode_create(rate, channels, frame_size, NULL);
celt_mode_info(mode, CELT_GET_LOOKAHEAD, &skip);
if (mode == NULL)
{
......@@ -78,20 +77,20 @@ int main(int argc, char *argv[])
return 1;
}
bytes_per_packet = atoi(argv[5]);
bytes_per_packet = atoi(argv[4]);
if (bytes_per_packet < 0 || bytes_per_packet > 200)
{
fprintf (stderr, "bytes per packet must be between 10 and 200\n");
return 1;
}
inFile = argv[6];
inFile = argv[5];
fin = fopen(inFile, "rb");
if (!fin)
{
fprintf (stderr, "Could not open input file %s\n", argv[6]);
return 1;
}
outFile = argv[7];
outFile = argv[6];
fout = fopen(outFile, "wb+");
if (!fout)
{
......@@ -141,7 +140,7 @@ int main(int argc, char *argv[])
data[rand()%8] ^= 1<<rand()%8;
#endif
/* This is to simulate packet loss */
if (argc==9 && rand()%1000<atoi(argv[8]))
if (argc==9 && rand()%1000<atoi(argv[7]))
/*if (errors && (errors%2==0))*/
celt_decode(dec, NULL, len, out);
else
......
......@@ -298,7 +298,7 @@ static CELTDecoder *process_header(ogg_packet *op, celt_int32_t enh_enabled, cel
fprintf (stderr, "Unsupported number of channels: %d\n", header.nb_channels);
return NULL;
}
*mode = celt_mode_create(header.sample_rate, header.nb_channels, header.frame_size, header.overlap, NULL);
*mode = celt_mode_create(header.sample_rate, header.nb_channels, header.frame_size, NULL);
if (*mode == NULL)
{
fprintf (stderr, "Mode initialization failed.\n");
......
......@@ -455,7 +455,7 @@ int main(int argc, char **argv)
fprintf (stderr, "Only mono and stereo are supported\n");
return 1;
}
mode = celt_mode_create(rate, chan, 256, 128, NULL);
mode = celt_mode_create(rate, chan, 256, NULL);
if (!mode)
return 1;
celt_mode_info(mode, CELT_GET_FRAME_SIZE, &frame_size);
......
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