More work on variable frame size (getting rid of FRAMESIZE() )

This commit is contained in:
Jean-Marc Valin 2010-05-07 07:45:18 -04:00
parent 017fa85775
commit ce4dd367c2
10 changed files with 28 additions and 33 deletions

View file

@ -53,7 +53,7 @@ void compute_band_energies(const CELTMode *m, const celt_sig *X, celt_ener *bank
int i, c, N;
const celt_int16 *eBands = m->eBands;
const int C = CHANNELS(_C);
N = FRAMESIZE(m);
N = M*m->eBands[m->nbEBands+1];
for (c=0;c<C;c++)
{
for (i=0;i<m->nbEBands;i++)
@ -92,7 +92,7 @@ void normalise_bands(const CELTMode *m, const celt_sig * restrict freq, celt_nor
int i, c, N;
const celt_int16 *eBands = m->eBands;
const int C = CHANNELS(_C);
N = FRAMESIZE(m);
N = M*m->eBands[m->nbEBands+1];
for (c=0;c<C;c++)
{
i=0; do {
@ -116,7 +116,7 @@ void compute_band_energies(const CELTMode *m, const celt_sig *X, celt_ener *bank
int i, c, N;
const celt_int16 *eBands = m->eBands;
const int C = CHANNELS(_C);
N = FRAMESIZE(m);
N = M*m->eBands[m->nbEBands+1];
for (c=0;c<C;c++)
{
for (i=0;i<m->nbEBands;i++)
@ -138,7 +138,7 @@ void compute_noise_energies(const CELTMode *m, const celt_sig *X, const celt_wor
int i, c, N;
const celt_int16 *eBands = m->eBands;
const int C = CHANNELS(_C);
N = FRAMESIZE(m);
N = M*m->eBands[m->nbEBands+1];
for (c=0;c<C;c++)
{
for (i=0;i<m->nbEBands;i++)
@ -161,7 +161,7 @@ void normalise_bands(const CELTMode *m, const celt_sig * restrict freq, celt_nor
int i, c, N;
const celt_int16 *eBands = m->eBands;
const int C = CHANNELS(_C);
N = FRAMESIZE(m);
N = M*m->eBands[m->nbEBands+1];
for (c=0;c<C;c++)
{
for (i=0;i<m->nbEBands;i++)
@ -195,7 +195,7 @@ void denormalise_bands(const CELTMode *m, const celt_norm * restrict X, celt_sig
int i, c, N;
const celt_int16 *eBands = m->eBands;
const int C = CHANNELS(_C);
N = FRAMESIZE(m);
N = M*m->eBands[m->nbEBands+1];
if (C>2)
celt_fatal("denormalise_bands() not implemented for >2 channels");
for (c=0;c<C;c++)
@ -220,7 +220,7 @@ void denormalise_bands(const CELTMode *m, const celt_norm * restrict X, celt_sig
}
}
int compute_pitch_gain(const CELTMode *m, const celt_sig *X, const celt_sig *P, int norm_rate, int *gain_id, int _C, celt_word16 *gain_prod)
int compute_pitch_gain(const CELTMode *m, const celt_sig *X, const celt_sig *P, int norm_rate, int *gain_id, int _C, celt_word16 *gain_prod, int M)
{
int j, c;
celt_word16 g;
@ -228,7 +228,7 @@ int compute_pitch_gain(const CELTMode *m, const celt_sig *X, const celt_sig *P,
const int C = CHANNELS(_C);
celt_word32 Sxy=0, Sxx=0, Syy=0;
int len = m->pitchEnd;
const int N = FRAMESIZE(m);
int N = M*m->eBands[m->nbEBands+1];
#ifdef FIXED_POINT
int shift = 0;
celt_word32 maxabs=0;
@ -313,7 +313,7 @@ int compute_pitch_gain(const CELTMode *m, const celt_sig *X, const celt_sig *P,
}
}
void apply_pitch(const CELTMode *m, celt_sig *X, const celt_sig *P, int gain_id, int pred, int _C)
void apply_pitch(const CELTMode *m, celt_sig *X, const celt_sig *P, int gain_id, int pred, int _C, int M)
{
int j, c, N;
celt_word16 gain;
@ -321,7 +321,7 @@ void apply_pitch(const CELTMode *m, celt_sig *X, const celt_sig *P, int gain_id,
const int C = CHANNELS(_C);
int len = m->pitchEnd;
N = FRAMESIZE(m);
N = M*m->eBands[m->nbEBands+1];
gain = ADD16(QCONST16(.5f,14), MULT16_16_16(QCONST16(.05f,14),gain_id));
delta = PDIV32_16(gain, len);
if (pred)
@ -385,7 +385,7 @@ int folding_decision(const CELTMode *m, celt_norm *X, celt_word16 *average, int
const int C = CHANNELS(_C);
const celt_int16 * restrict eBands = m->eBands;
N0 = FRAMESIZE(m);
N0 = M*m->eBands[m->nbEBands+1];
for (c=0;c<C;c++)
{

View file

@ -73,9 +73,9 @@ void denormalise_bands(const CELTMode *m, const celt_norm * restrict X, celt_sig
* @param gains Gain computed for each pitch band (returned)
* @param bank Square root of the energy for each band
*/
int compute_pitch_gain(const CELTMode *m, const celt_sig *X, const celt_sig *P, int norm_rate, int *gain_id, int _C, celt_word16 *gain_prod);
int compute_pitch_gain(const CELTMode *m, const celt_sig *X, const celt_sig *P, int norm_rate, int *gain_id, int _C, celt_word16 *gain_prod, int M);
void apply_pitch(const CELTMode *m, celt_sig *X, const celt_sig *P, int gain_id, int pred, int _C);
void apply_pitch(const CELTMode *m, celt_sig *X, const celt_sig *P, int gain_id, int pred, int _C, int M);
int folding_decision(const CELTMode *m, celt_norm *X, celt_word16 *average, int *last_decision, int _C, int M);

View file

@ -334,7 +334,7 @@ static void compute_mdcts(const CELTMode *mode, int shortBlocks, celt_sig * rest
} else {
const mdct_lookup *lookup = &mode->mdct[LM];
const int overlap = OVERLAP(mode);
int N = FRAMESIZE(mode);
int N = mode->shortMdctSize<<LM;
int B = 1;
int b, c;
VARDECL(celt_word32, x);
@ -371,7 +371,7 @@ static void compute_inv_mdcts(const CELTMode *mode, int shortBlocks, celt_sig *X
{
int c, N4;
const int C = CHANNELS(_C);
const int N = FRAMESIZE(mode);
const int N = mode->shortMdctSize<<LM;
const int overlap = OVERLAP(mode);
N4 = (N-overlap)>>1;
for (c=0;c<C;c++)
@ -687,7 +687,7 @@ int celt_encode_float(CELTEncoder * restrict st, const celt_sig * pcm, celt_sig
SAVE_STACK;
ALLOC(x_lp, (2*N-2*N4)>>1, celt_word16);
pitch_downsample(in, x_lp, 2*N-2*N4, N, C, &st->xmem, &st->pitch_buf[MAX_PERIOD>>1]);
pitch_search(st->mode, x_lp, st->pitch_buf, 2*N-2*N4, MAX_PERIOD-(2*N-2*N4), &pitch_index, &st->xmem);
pitch_search(st->mode, x_lp, st->pitch_buf, 2*N-2*N4, MAX_PERIOD-(2*N-2*N4), &pitch_index, &st->xmem, M);
RESTORE_STACK;
}
@ -699,11 +699,11 @@ int celt_encode_float(CELTEncoder * restrict st, const celt_sig * pcm, celt_sig
if (has_pitch)
{
compute_mdcts(st->mode, 0, st->out_mem+pitch_index*C, pitch_freq, C, LM);
has_pitch = compute_pitch_gain(st->mode, freq, pitch_freq, norm_rate, &gain_id, C, &st->gain_prod);
has_pitch = compute_pitch_gain(st->mode, freq, pitch_freq, norm_rate, &gain_id, C, &st->gain_prod, M);
}
if (has_pitch)
apply_pitch(st->mode, freq, pitch_freq, gain_id, 1, C);
apply_pitch(st->mode, freq, pitch_freq, gain_id, 1, C, M);
compute_band_energies(st->mode, freq, bandE, C, M);
for (i=0;i<st->mode->nbEBands*C;i++)
@ -904,7 +904,7 @@ int celt_encode_float(CELTEncoder * restrict st, const celt_sig * pcm, celt_sig
CELT_MOVE(st->out_mem, st->out_mem+C*N, C*(MAX_PERIOD+st->overlap-N));
if (has_pitch)
apply_pitch(st->mode, freq, pitch_freq, gain_id, 0, C);
apply_pitch(st->mode, freq, pitch_freq, gain_id, 0, C, M);
compute_inv_mdcts(st->mode, shortBlocks, freq, transient_time, transient_shift, st->out_mem, C, LM);
@ -1311,7 +1311,7 @@ static void celt_decode_lost(CELTDecoder * restrict st, celt_word16 * restrict p
pitch_downsample(st->out_mem, pitch_buf, MAX_PERIOD, MAX_PERIOD,
C, mem0, mem1);
pitch_search(st->mode, pitch_buf+((MAX_PERIOD-len)>>1), pitch_buf, len,
MAX_PERIOD-len-100, &pitch_index, &tmp);
MAX_PERIOD-len-100, &pitch_index, &tmp, 1<<LM);
pitch_index = MAX_PERIOD-len-pitch_index;
st->last_pitch_index = pitch_index;
} else {
@ -1596,7 +1596,7 @@ int celt_decode_float(CELTDecoder * restrict st, const unsigned char *data, int
CELT_MOVE(st->decode_mem, st->decode_mem+C*N, C*(DECODE_BUFFER_SIZE+st->overlap-N));
if (has_pitch)
apply_pitch(st->mode, freq, pitch_freq, gain_id, 0, C);
apply_pitch(st->mode, freq, pitch_freq, gain_id, 0, C, M);
for (i=0;i<M*st->mode->eBands[start];i++)
freq[i] = 0;

View file

@ -95,8 +95,6 @@ extern "C" {
#define CELT_RESET_STATE_REQUEST 8
#define CELT_RESET_STATE CELT_RESET_STATE_REQUEST
/** GET the frame size used in the current mode */
#define CELT_GET_FRAME_SIZE 1000
/** GET the lookahead used in the current mode */
#define CELT_GET_LOOKAHEAD 1001
/** GET the sample rate used in the current mode */

View file

@ -61,9 +61,6 @@ int celt_mode_info(const CELTMode *mode, int request, celt_int32 *value)
return CELT_INVALID_MODE;
switch (request)
{
case CELT_GET_FRAME_SIZE:
*value = mode->mdctSize;
break;
case CELT_GET_LOOKAHEAD:
*value = mode->overlap;
break;
@ -350,7 +347,7 @@ CELTMode *celt_mode_create(celt_int32 Fs, int frame_size, int *error)
/* Overlap must be divisible by 4 */
if (mode->nbShortMdcts > 1)
mode->overlap = ((frame_size/mode->nbShortMdcts)>>2)<<2;
mode->overlap = (mode->shortMdctSize>>2)<<2;
else
mode->overlap = (frame_size>>3)<<2;

View file

@ -148,11 +148,11 @@ void pitch_downsample(const celt_sig * restrict x, celt_word16 * restrict x_lp,
}
void pitch_search(const CELTMode *m, const celt_word16 * restrict x_lp, celt_word16 * restrict y, int len, int max_pitch, int *pitch, celt_sig *xmem)
void pitch_search(const CELTMode *m, const celt_word16 * restrict x_lp, celt_word16 * restrict y, int len, int max_pitch, int *pitch, celt_sig *xmem, int M)
{
int i, j;
const int lag = MAX_PERIOD;
const int N = FRAMESIZE(m);
const int N = M*m->eBands[m->nbEBands+1];
int best_pitch[2]={0};
VARDECL(celt_word16, x_lp4);
VARDECL(celt_word16, y_lp4);

View file

@ -43,6 +43,6 @@
void pitch_downsample(const celt_sig * restrict x, celt_word16 * restrict x_lp, int len, int end, int _C, celt_sig * restrict xmem, celt_word16 * restrict filt_mem);
void pitch_search(const CELTMode *m, const celt_word16 * restrict x_lp, celt_word16 * restrict y, int len, int max_pitch, int *pitch, celt_sig *xmem);
void pitch_search(const CELTMode *m, const celt_word16 * restrict x_lp, celt_word16 * restrict y, int len, int max_pitch, int *pitch, celt_sig *xmem, int M);
#endif

View file

@ -126,7 +126,6 @@ int main(int argc, char *argv[])
celt_encoder_ctl(enc,CELT_SET_COMPLEXITY(complexity));
}
celt_mode_info(mode, CELT_GET_FRAME_SIZE, &frame_size);
in = (celt_int16*)malloc(frame_size*channels*sizeof(celt_int16));
out = (celt_int16*)malloc(frame_size*channels*sizeof(celt_int16));
while (!feof(fin))

View file

@ -322,7 +322,8 @@ static CELTDecoder *process_header(ogg_packet *op, celt_int32 enh_enabled, celt_
return NULL;
}
celt_mode_info(*mode, CELT_GET_FRAME_SIZE, frame_size);
/*celt_mode_info(*mode, CELT_GET_FRAME_SIZE, frame_size);*/
*frame_size = header.frame_size;
*granule_frame_size = *frame_size;
if (!*rate)

View file

@ -500,7 +500,7 @@ int main(int argc, char **argv)
snprintf(vendor_string, sizeof(vendor_string), "Encoded with CELT %s (bitstream: %d)\n",CELT_VERSION,bitstream);
comment_init(&comments, &comments_length, vendor_string);
celt_mode_info(mode, CELT_GET_FRAME_SIZE, &frame_size);
/*celt_mode_info(mode, CELT_GET_FRAME_SIZE, &frame_size);*/
celt_header_init(&header, mode, chan);
header.nb_channels = chan;