From 16ca18b9b087fffb7fec386115e759e334a629ad Mon Sep 17 00:00:00 2001 From: Jean-Marc Valin Date: Wed, 18 Jun 2008 23:44:48 +1000 Subject: [PATCH] Automatically choosing the overlap based on the frame size. --- libcelt/celt.c | 2 +- libcelt/celt.h | 2 +- libcelt/dump_modes.c | 11 +++++------ libcelt/modes.c | 28 ++++++++++++++++++---------- libcelt/modes.h | 2 +- libcelt/testcelt.c | 21 ++++++++++----------- tools/celtdec.c | 2 +- tools/celtenc.c | 2 +- 8 files changed, 38 insertions(+), 32 deletions(-) diff --git a/libcelt/celt.c b/libcelt/celt.c index ab5163f7..b575c3aa 100644 --- a/libcelt/celt.c +++ b/libcelt/celt.c @@ -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); diff --git a/libcelt/celt.h b/libcelt/celt.h index 114c3709..27456ab5 100644 --- a/libcelt/celt.h +++ b/libcelt/celt.h @@ -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. diff --git a/libcelt/dump_modes.c b/libcelt/dump_modes.c index de4e062c..0de1c19a 100644 --- a/libcelt/dump_modes.c +++ b/libcelt/dump_modes.c @@ -231,12 +231,11 @@ int main(int argc, char **argv) m = malloc(nb*sizeof(CELTMode*)); for (i=0;ienergy_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; diff --git a/libcelt/modes.h b/libcelt/modes.h index 52855156..a3066b04 100644 --- a/libcelt/modes.h +++ b/libcelt/modes.h @@ -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" diff --git a/libcelt/testcelt.c b/libcelt/testcelt.c index 6e33a39e..3f9b5a4f 100644 --- a/libcelt/testcelt.c +++ b/libcelt/testcelt.c @@ -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 \n"); + fprintf (stderr, "Usage: testcelt \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<