Yet another step towards variable frame size
This commit is contained in:
parent
0475267e62
commit
073d0bc925
4 changed files with 58 additions and 49 deletions
|
@ -472,7 +472,7 @@ void quant_bands(const CELTMode *m, int start, celt_norm * restrict X, const cel
|
||||||
int curr_balance, curr_bits;
|
int curr_balance, curr_bits;
|
||||||
|
|
||||||
N = M*eBands[i+1]-M*eBands[i];
|
N = M*eBands[i+1]-M*eBands[i];
|
||||||
BPbits = m->bits;
|
BPbits = m->bits[FULL_FRAME(m)];
|
||||||
|
|
||||||
if (encode)
|
if (encode)
|
||||||
tell = ec_enc_tell(enc_dec, BITRES);
|
tell = ec_enc_tell(enc_dec, BITRES);
|
||||||
|
@ -552,7 +552,7 @@ void quant_bands_stereo(const CELTMode *m, int start, celt_norm *_X, const celt_
|
||||||
|
|
||||||
X = _X+M*eBands[i];
|
X = _X+M*eBands[i];
|
||||||
Y = X+M*eBands[m->nbEBands+1];
|
Y = X+M*eBands[m->nbEBands+1];
|
||||||
BPbits = m->bits;
|
BPbits = m->bits[FULL_FRAME(m)];
|
||||||
|
|
||||||
N = M*eBands[i+1]-M*eBands[i];
|
N = M*eBands[i+1]-M*eBands[i];
|
||||||
tell = ec_enc_tell(enc, BITRES);
|
tell = ec_enc_tell(enc, BITRES);
|
||||||
|
@ -789,7 +789,7 @@ void unquant_bands_stereo(const CELTMode *m, int start, celt_norm *_X, const cel
|
||||||
|
|
||||||
X = _X+M*eBands[i];
|
X = _X+M*eBands[i];
|
||||||
Y = X+M*eBands[m->nbEBands+1];
|
Y = X+M*eBands[m->nbEBands+1];
|
||||||
BPbits = m->bits;
|
BPbits = m->bits[FULL_FRAME(m)];
|
||||||
|
|
||||||
N = M*eBands[i+1]-M*eBands[i];
|
N = M*eBands[i+1]-M*eBands[i];
|
||||||
tell = ec_dec_tell(dec, BITRES);
|
tell = ec_dec_tell(dec, BITRES);
|
||||||
|
|
|
@ -328,11 +328,11 @@ static void compute_mdcts(const CELTMode *mode, int shortBlocks, celt_sig * rest
|
||||||
const int C = CHANNELS(_C);
|
const int C = CHANNELS(_C);
|
||||||
if (C==1 && !shortBlocks)
|
if (C==1 && !shortBlocks)
|
||||||
{
|
{
|
||||||
const mdct_lookup *lookup = MDCT(mode);
|
const mdct_lookup *lookup = &mode->mdct[FULL_FRAME(mode)];
|
||||||
const int overlap = OVERLAP(mode);
|
const int overlap = OVERLAP(mode);
|
||||||
clt_mdct_forward(lookup, in, out, mode->window, overlap);
|
clt_mdct_forward(lookup, in, out, mode->window, overlap);
|
||||||
} else {
|
} else {
|
||||||
const mdct_lookup *lookup = MDCT(mode);
|
const mdct_lookup *lookup = &mode->mdct[FULL_FRAME(mode)];
|
||||||
const int overlap = OVERLAP(mode);
|
const int overlap = OVERLAP(mode);
|
||||||
int N = FRAMESIZE(mode);
|
int N = FRAMESIZE(mode);
|
||||||
int B = 1;
|
int B = 1;
|
||||||
|
@ -342,7 +342,7 @@ static void compute_mdcts(const CELTMode *mode, int shortBlocks, celt_sig * rest
|
||||||
SAVE_STACK;
|
SAVE_STACK;
|
||||||
if (shortBlocks)
|
if (shortBlocks)
|
||||||
{
|
{
|
||||||
lookup = &mode->shortMdct;
|
lookup = &mode->mdct[0];
|
||||||
N = mode->shortMdctSize;
|
N = mode->shortMdctSize;
|
||||||
B = shortBlocks;
|
B = shortBlocks;
|
||||||
}
|
}
|
||||||
|
@ -378,7 +378,7 @@ static void compute_inv_mdcts(const CELTMode *mode, int shortBlocks, celt_sig *X
|
||||||
{
|
{
|
||||||
int j;
|
int j;
|
||||||
if (transient_shift==0 && C==1 && !shortBlocks) {
|
if (transient_shift==0 && C==1 && !shortBlocks) {
|
||||||
const mdct_lookup *lookup = MDCT(mode);
|
const mdct_lookup *lookup = &mode->mdct[FULL_FRAME(mode)];
|
||||||
clt_mdct_backward(lookup, X, out_mem+C*(MAX_PERIOD-N-N4), mode->window, overlap);
|
clt_mdct_backward(lookup, X, out_mem+C*(MAX_PERIOD-N-N4), mode->window, overlap);
|
||||||
} else {
|
} else {
|
||||||
VARDECL(celt_word32, x);
|
VARDECL(celt_word32, x);
|
||||||
|
@ -387,7 +387,7 @@ static void compute_inv_mdcts(const CELTMode *mode, int shortBlocks, celt_sig *X
|
||||||
int N2 = N;
|
int N2 = N;
|
||||||
int B = 1;
|
int B = 1;
|
||||||
int n4offset=0;
|
int n4offset=0;
|
||||||
const mdct_lookup *lookup = MDCT(mode);
|
const mdct_lookup *lookup = &mode->mdct[FULL_FRAME(mode)];
|
||||||
SAVE_STACK;
|
SAVE_STACK;
|
||||||
|
|
||||||
ALLOC(x, 2*N, celt_word32);
|
ALLOC(x, 2*N, celt_word32);
|
||||||
|
@ -395,7 +395,7 @@ static void compute_inv_mdcts(const CELTMode *mode, int shortBlocks, celt_sig *X
|
||||||
|
|
||||||
if (shortBlocks)
|
if (shortBlocks)
|
||||||
{
|
{
|
||||||
lookup = &mode->shortMdct;
|
lookup = &mode->mdct[0];
|
||||||
N2 = mode->shortMdctSize;
|
N2 = mode->shortMdctSize;
|
||||||
B = shortBlocks;
|
B = shortBlocks;
|
||||||
n4offset = N4;
|
n4offset = N4;
|
||||||
|
|
|
@ -325,27 +325,15 @@ CELTMode *celt_mode_create(celt_int32 Fs, int frame_size, int *error)
|
||||||
mode->mdctSize = frame_size;
|
mode->mdctSize = frame_size;
|
||||||
mode->ePredCoef = QCONST16(.8f,15);
|
mode->ePredCoef = QCONST16(.8f,15);
|
||||||
|
|
||||||
if (frame_size > 640 && (frame_size%16)==0)
|
if (frame_size >= 640 && (frame_size%16)==0)
|
||||||
{
|
{
|
||||||
mode->nbShortMdcts = 8;
|
mode->nbShortMdcts = 8;
|
||||||
} else if (frame_size > 384 && (frame_size%8)==0)
|
} else if (frame_size >= 320 && (frame_size%8)==0)
|
||||||
{
|
{
|
||||||
mode->nbShortMdcts = 4;
|
mode->nbShortMdcts = 4;
|
||||||
} else if (frame_size > 384 && (frame_size%10)==0)
|
} else if (frame_size >= 120 && (frame_size%4)==0)
|
||||||
{
|
|
||||||
mode->nbShortMdcts = 5;
|
|
||||||
} else if (frame_size > 256 && (frame_size%6)==0)
|
|
||||||
{
|
|
||||||
mode->nbShortMdcts = 3;
|
|
||||||
} else if (frame_size > 256 && (frame_size%8)==0)
|
|
||||||
{
|
|
||||||
mode->nbShortMdcts = 4;
|
|
||||||
} else if (frame_size > 64 && (frame_size%4)==0)
|
|
||||||
{
|
{
|
||||||
mode->nbShortMdcts = 2;
|
mode->nbShortMdcts = 2;
|
||||||
} else if (frame_size > 128 && (frame_size%6)==0)
|
|
||||||
{
|
|
||||||
mode->nbShortMdcts = 3;
|
|
||||||
} else
|
} else
|
||||||
{
|
{
|
||||||
mode->nbShortMdcts = 1;
|
mode->nbShortMdcts = 1;
|
||||||
|
@ -384,7 +372,12 @@ CELTMode *celt_mode_create(celt_int32 Fs, int frame_size, int *error)
|
||||||
#endif
|
#endif
|
||||||
mode->window = window;
|
mode->window = window;
|
||||||
|
|
||||||
mode->bits = (const celt_int16 **)compute_alloc_cache(mode, 1, mode->nbShortMdcts);
|
for (i=0;(1<<i)<=mode->nbShortMdcts;i++)
|
||||||
|
{
|
||||||
|
/* FIXME: Do something for i==0 */
|
||||||
|
if (i!=0)
|
||||||
|
mode->bits[i] = (const celt_int16 **)compute_alloc_cache(mode, 1, 1<<i);
|
||||||
|
}
|
||||||
if (mode->bits==NULL)
|
if (mode->bits==NULL)
|
||||||
goto failure;
|
goto failure;
|
||||||
|
|
||||||
|
@ -397,16 +390,18 @@ CELTMode *celt_mode_create(celt_int32 Fs, int frame_size, int *error)
|
||||||
mode->logN = logN;
|
mode->logN = logN;
|
||||||
#endif /* !STATIC_MODES */
|
#endif /* !STATIC_MODES */
|
||||||
|
|
||||||
clt_mdct_init(&mode->mdct, 2*mode->mdctSize);
|
for (i=0;(1<<i)<=mode->nbShortMdcts;i++)
|
||||||
|
{
|
||||||
clt_mdct_init(&mode->shortMdct, 2*mode->shortMdctSize);
|
clt_mdct_init(&mode->mdct[i], 2*mode->shortMdctSize<<i);
|
||||||
|
if ((mode->mdct[i].trig==NULL)
|
||||||
mode->prob = quant_prob_alloc(mode);
|
|
||||||
if ((mode->mdct.trig==NULL) || (mode->shortMdct.trig==NULL)
|
|
||||||
#ifndef ENABLE_TI_DSPLIB55
|
#ifndef ENABLE_TI_DSPLIB55
|
||||||
|| (mode->mdct.kfft==NULL) || (mode->shortMdct.kfft==NULL)
|
|| (mode->mdct[i].kfft==NULL)
|
||||||
#endif
|
#endif
|
||||||
|| (mode->prob==NULL))
|
)
|
||||||
|
goto failure;
|
||||||
|
}
|
||||||
|
mode->prob = quant_prob_alloc(mode);
|
||||||
|
if (mode->prob==NULL)
|
||||||
goto failure;
|
goto failure;
|
||||||
|
|
||||||
mode->marker_start = MODEVALID;
|
mode->marker_start = MODEVALID;
|
||||||
|
@ -424,7 +419,7 @@ failure:
|
||||||
|
|
||||||
void celt_mode_destroy(CELTMode *mode)
|
void celt_mode_destroy(CELTMode *mode)
|
||||||
{
|
{
|
||||||
int i;
|
int i, m;
|
||||||
const celt_int16 *prevPtr = NULL;
|
const celt_int16 *prevPtr = NULL;
|
||||||
if (mode == NULL)
|
if (mode == NULL)
|
||||||
{
|
{
|
||||||
|
@ -445,18 +440,24 @@ void celt_mode_destroy(CELTMode *mode)
|
||||||
}
|
}
|
||||||
mode->marker_start = MODEFREED;
|
mode->marker_start = MODEFREED;
|
||||||
#ifndef STATIC_MODES
|
#ifndef STATIC_MODES
|
||||||
if (mode->bits!=NULL)
|
for (m=0;(1<<m)<=mode->nbShortMdcts;m++)
|
||||||
{
|
{
|
||||||
for (i=0;i<mode->nbEBands;i++)
|
/* FIXME: Do something for i==0 */
|
||||||
|
if (m==0)
|
||||||
|
continue;
|
||||||
|
if (mode->bits[m]!=NULL)
|
||||||
{
|
{
|
||||||
if (mode->bits[i] != prevPtr)
|
for (i=0;i<mode->nbEBands;i++)
|
||||||
{
|
{
|
||||||
prevPtr = mode->bits[i];
|
if (mode->bits[m][i] != prevPtr)
|
||||||
celt_free((int*)mode->bits[i]);
|
{
|
||||||
}
|
prevPtr = mode->bits[m][i];
|
||||||
|
celt_free((int*)mode->bits[m][i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
celt_free((celt_int16**)mode->bits[m]);
|
||||||
celt_free((celt_int16**)mode->bits);
|
}
|
||||||
celt_free((celt_int16*)mode->eBands);
|
celt_free((celt_int16*)mode->eBands);
|
||||||
celt_free((celt_int16*)mode->allocVectors);
|
celt_free((celt_int16*)mode->allocVectors);
|
||||||
|
|
||||||
|
@ -464,8 +465,9 @@ void celt_mode_destroy(CELTMode *mode)
|
||||||
celt_free((celt_int16*)mode->logN);
|
celt_free((celt_int16*)mode->logN);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
clt_mdct_clear(&mode->mdct);
|
for (i=0;(1<<i)<=mode->nbShortMdcts;i++)
|
||||||
clt_mdct_clear(&mode->shortMdct);
|
clt_mdct_clear(&mode->mdct[i]);
|
||||||
|
|
||||||
quant_prob_free(mode->prob);
|
quant_prob_free(mode->prob);
|
||||||
mode->marker_end = MODEFREED;
|
mode->marker_end = MODEFREED;
|
||||||
celt_free((CELTMode *)mode);
|
celt_free((CELTMode *)mode);
|
||||||
|
|
|
@ -40,6 +40,8 @@
|
||||||
#include "mdct.h"
|
#include "mdct.h"
|
||||||
#include "pitch.h"
|
#include "pitch.h"
|
||||||
|
|
||||||
|
#define MAX_CONFIG_SIZES 4
|
||||||
|
|
||||||
#define CELT_BITSTREAM_VERSION 0x8000000c
|
#define CELT_BITSTREAM_VERSION 0x8000000c
|
||||||
|
|
||||||
#ifdef STATIC_MODES
|
#ifdef STATIC_MODES
|
||||||
|
@ -64,8 +66,6 @@
|
||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define MDCT(mode) (&(mode)->mdct)
|
|
||||||
|
|
||||||
#ifndef OVERLAP
|
#ifndef OVERLAP
|
||||||
#define OVERLAP(mode) ((mode)->overlap)
|
#define OVERLAP(mode) ((mode)->overlap)
|
||||||
#endif
|
#endif
|
||||||
|
@ -93,22 +93,29 @@ struct CELTMode {
|
||||||
int nbAllocVectors; /**< Number of lines in the matrix below */
|
int nbAllocVectors; /**< Number of lines in the matrix below */
|
||||||
const celt_int16 *allocVectors; /**< Number of bits in each band for several rates */
|
const celt_int16 *allocVectors; /**< Number of bits in each band for several rates */
|
||||||
|
|
||||||
const celt_int16 * const *bits; /**< Cache for pulses->bits mapping in each band */
|
const celt_int16 * const *(bits[MAX_CONFIG_SIZES]); /**< Cache for pulses->bits mapping in each band */
|
||||||
|
|
||||||
/* Stuff that could go in the {en,de}coder, but we save space this way */
|
/* Stuff that could go in the {en,de}coder, but we save space this way */
|
||||||
mdct_lookup mdct;
|
mdct_lookup mdct[MAX_CONFIG_SIZES];
|
||||||
|
|
||||||
const celt_word16 *window;
|
const celt_word16 *window;
|
||||||
|
|
||||||
int nbShortMdcts;
|
int nbShortMdcts;
|
||||||
int shortMdctSize;
|
int shortMdctSize;
|
||||||
mdct_lookup shortMdct;
|
|
||||||
|
|
||||||
int *prob;
|
int *prob;
|
||||||
const celt_int16 *logN;
|
const celt_int16 *logN;
|
||||||
celt_uint32 marker_end;
|
celt_uint32 marker_end;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static inline int FULL_FRAME(const CELTMode *m)
|
||||||
|
{
|
||||||
|
int i=0;
|
||||||
|
while (1<<i < m->nbShortMdcts)
|
||||||
|
i++;
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
int check_mode(const CELTMode *mode);
|
int check_mode(const CELTMode *mode);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue