diff --git a/libcelt/bands.c b/libcelt/bands.c index 07495506..bdb34d45 100644 --- a/libcelt/bands.c +++ b/libcelt/bands.c @@ -48,7 +48,7 @@ #ifdef FIXED_POINT /* Compute the amplitude (sqrt energy) in each of the bands */ -void compute_band_energies(const CELTMode *m, const celt_sig *X, celt_ener *bank, int _C) +void compute_band_energies(const CELTMode *m, const celt_sig *X, celt_ener *bank, int _C, int M) { int i, c, N; const celt_int16 *eBands = m->eBands; @@ -62,18 +62,18 @@ void compute_band_energies(const CELTMode *m, const celt_sig *X, celt_ener *bank celt_word32 maxval=0; celt_word32 sum = 0; - j=eBands[i]; do { + j=M*eBands[i]; do { maxval = MAX32(maxval, X[j+c*N]); maxval = MAX32(maxval, -X[j+c*N]); - } while (++j 0) { int shift = celt_ilog2(maxval)-10; - j=eBands[i]; do { + j=M*eBands[i]; do { sum = MAC16_16(sum, EXTRACT16(VSHR32(X[j+c*N],shift)), EXTRACT16(VSHR32(X[j+c*N],shift))); - } while (++jnbEBands] = EPSILON+VSHR32(EXTEND32(celt_sqrt(sum)),-shift); @@ -87,7 +87,7 @@ void compute_band_energies(const CELTMode *m, const celt_sig *X, celt_ener *bank } /* Normalise each band such that the energy is one. */ -void normalise_bands(const CELTMode *m, const celt_sig * restrict freq, celt_norm * restrict X, const celt_ener *bank, int _C) +void normalise_bands(const CELTMode *m, const celt_sig * restrict freq, celt_norm * restrict X, const celt_ener *bank, int _C, int M) { int i, c, N; const celt_int16 *eBands = m->eBands; @@ -102,16 +102,16 @@ void normalise_bands(const CELTMode *m, const celt_sig * restrict freq, celt_nor shift = celt_zlog2(bank[i+c*m->nbEBands])-13; E = VSHR32(bank[i+c*m->nbEBands], shift); g = EXTRACT16(celt_rcp(SHL32(E,3))); - j=eBands[i]; do { + j=M*eBands[i]; do { X[j+c*N] = MULT16_16_Q15(VSHR32(freq[j+c*N],shift-1),g); - } while (++jnbEBands); } } #else /* FIXED_POINT */ /* Compute the amplitude (sqrt energy) in each of the bands */ -void compute_band_energies(const CELTMode *m, const celt_sig *X, celt_ener *bank, int _C) +void compute_band_energies(const CELTMode *m, const celt_sig *X, celt_ener *bank, int _C, int M) { int i, c, N; const celt_int16 *eBands = m->eBands; @@ -123,7 +123,7 @@ void compute_band_energies(const CELTMode *m, const celt_sig *X, celt_ener *bank { int j; celt_word32 sum = 1e-10; - for (j=eBands[i];jnbEBands] = sqrt(sum); /*printf ("%f ", bank[i+c*m->nbEBands]);*/ @@ -133,7 +133,7 @@ void compute_band_energies(const CELTMode *m, const celt_sig *X, celt_ener *bank } #ifdef EXP_PSY -void compute_noise_energies(const CELTMode *m, const celt_sig *X, const celt_word16 *tonality, celt_ener *bank, int _C) +void compute_noise_energies(const CELTMode *m, const celt_sig *X, const celt_word16 *tonality, celt_ener *bank, int _C, int M) { int i, c, N; const celt_int16 *eBands = m->eBands; @@ -145,7 +145,7 @@ void compute_noise_energies(const CELTMode *m, const celt_sig *X, const celt_wor { int j; celt_word32 sum = 1e-10; - for (j=eBands[i];jnbEBands] = sqrt(sum); /*printf ("%f ", bank[i+c*m->nbEBands]);*/ @@ -156,7 +156,7 @@ void compute_noise_energies(const CELTMode *m, const celt_sig *X, const celt_wor #endif /* Normalise each band such that the energy is one. */ -void normalise_bands(const CELTMode *m, const celt_sig * restrict freq, celt_norm * restrict X, const celt_ener *bank, int _C) +void normalise_bands(const CELTMode *m, const celt_sig * restrict freq, celt_norm * restrict X, const celt_ener *bank, int _C, int M) { int i, c, N; const celt_int16 *eBands = m->eBands; @@ -168,7 +168,7 @@ void normalise_bands(const CELTMode *m, const celt_sig * restrict freq, celt_nor { int j; celt_word16 g = 1.f/(1e-10f+bank[i+c*m->nbEBands]); - for (j=eBands[i];jeBands; @@ -184,13 +184,13 @@ void renormalise_bands(const CELTMode *m, celt_norm * restrict X, int _C) for (c=0;ceBands[m->nbEBands+1], Q15ONE, eBands[i+1]-eBands[i], 1); + renormalise_vector(X+M*eBands[i]+c*M*eBands[m->nbEBands+1], Q15ONE, M*eBands[i+1]-M*eBands[i], 1); } while (++inbEBands); } } /* De-normalise the energy to produce the synthesis from the unit-energy bands */ -void denormalise_bands(const CELTMode *m, const celt_norm * restrict X, celt_sig * restrict freq, const celt_ener *bank, int _C) +void denormalise_bands(const CELTMode *m, const celt_norm * restrict X, celt_sig * restrict freq, const celt_ener *bank, int _C, int M) { int i, c, N; const celt_int16 *eBands = m->eBands; @@ -208,14 +208,14 @@ void denormalise_bands(const CELTMode *m, const celt_norm * restrict X, celt_sig { int j, end; celt_word32 g = SHR32(bank[i+c*m->nbEBands],1); - j=eBands[i]; - end = eBands[i+1]; + j=M*eBands[i]; + end = M*eBands[i+1]; do { *f++ = SHL32(MULT16_32_Q15(*x, g),2); x++; } while (++jnbEBands];inbEBands+1];i++) + for (i=M*eBands[m->nbEBands];inbEBands+1];i++) *f++ = 0; } } @@ -341,7 +341,7 @@ void apply_pitch(const CELTMode *m, celt_sig *X, const celt_sig *P, int gain_id, #ifndef DISABLE_STEREO -static void stereo_band_mix(const CELTMode *m, celt_norm *X, celt_norm *Y, const celt_ener *bank, int stereo_mode, int bandID, int dir) +static void stereo_band_mix(const CELTMode *m, celt_norm *X, celt_norm *Y, const celt_ener *bank, int stereo_mode, int bandID, int dir, int M) { int i = bandID; const celt_int16 *eBands = m->eBands; @@ -364,7 +364,7 @@ static void stereo_band_mix(const CELTMode *m, celt_norm *X, celt_norm *Y, const a1 = DIV32_16(SHL32(EXTEND32(left),14),norm); a2 = dir*DIV32_16(SHL32(EXTEND32(right),14),norm); } - for (j=0;jmax_val) @@ -448,7 +448,7 @@ int folding_decision(const CELTMode *m, celt_norm *X, celt_word16 *average, int } /* Quantisation of the residual */ -void quant_bands(const CELTMode *m, int start, celt_norm * restrict X, const celt_ener *bandE, int *pulses, int shortBlocks, int fold, int resynth, int total_bits, int encode, void *enc_dec) +void quant_bands(const CELTMode *m, int start, celt_norm * restrict X, const celt_ener *bandE, int *pulses, int shortBlocks, int fold, int resynth, int total_bits, int encode, void *enc_dec, int M) { int i, j, remaining_bits, balance; const celt_int16 * restrict eBands = m->eBands; @@ -458,7 +458,7 @@ void quant_bands(const CELTMode *m, int start, celt_norm * restrict X, const cel SAVE_STACK; B = shortBlocks ? m->nbShortMdcts : 1; - ALLOC(_norm, eBands[m->nbEBands+1], celt_norm); + ALLOC(_norm, M*eBands[m->nbEBands+1], celt_norm); norm = _norm; balance = 0; @@ -471,7 +471,7 @@ void quant_bands(const CELTMode *m, int start, celt_norm * restrict X, const cel int curr_balance, curr_bits; - N = eBands[i+1]-eBands[i]; + N = M*eBands[i+1]-M*eBands[i]; BPbits = m->bits; if (encode) @@ -502,18 +502,18 @@ void quant_bands(const CELTMode *m, int start, celt_norm * restrict X, const cel { int spread = fold ? B : 0; if (encode) - alg_quant(X+eBands[i], eBands[i+1]-eBands[i], q, spread, resynth, enc_dec); + alg_quant(X+M*eBands[i], N, q, spread, resynth, enc_dec); else - alg_unquant(X+eBands[i], eBands[i+1]-eBands[i], q, spread, enc_dec); + alg_unquant(X+M*eBands[i], N, q, spread, enc_dec); } else { if (resynth) - intra_fold(m, start, eBands[i+1]-eBands[i], norm, X+eBands[i], eBands[i], B); + intra_fold(m, start, N, norm, X+M*eBands[i], M*eBands[i], B, M); } if (resynth) { celt_word16 n; - n = celt_sqrt(SHL32(EXTEND32(eBands[i+1]-eBands[i]),22)); - for (j=eBands[i];jeBands; @@ -533,7 +533,7 @@ void quant_bands_stereo(const CELTMode *m, int start, celt_norm *_X, const celt_ SAVE_STACK; B = shortBlocks ? m->nbShortMdcts : 1; - ALLOC(_norm, eBands[m->nbEBands+1], celt_norm); + ALLOC(_norm, M*eBands[m->nbEBands+1], celt_norm); norm = _norm; balance = 0; @@ -550,11 +550,11 @@ void quant_bands_stereo(const CELTMode *m, int start, celt_norm *_X, const celt_ int qalloc; celt_norm * restrict X, * restrict Y; - X = _X+eBands[i]; - Y = X+eBands[m->nbEBands+1]; + X = _X+M*eBands[i]; + Y = X+M*eBands[m->nbEBands+1]; BPbits = m->bits; - N = eBands[i+1]-eBands[i]; + N = M*eBands[i+1]-M*eBands[i]; tell = ec_enc_tell(enc, BITRES); if (i != start) balance -= tell; @@ -575,7 +575,7 @@ void quant_bands_stereo(const CELTMode *m, int start, celt_norm *_X, const celt_ if (qb>14) qb = 14; - stereo_band_mix(m, X, Y, bandE, qb==0, i, 1); + stereo_band_mix(m, X, Y, bandE, qb==0, i, 1, M); mid = renormalise_vector(X, Q15ONE, N, 1); side = renormalise_vector(Y, Q15ONE, N, 1); @@ -715,7 +715,7 @@ void quant_bands_stereo(const CELTMode *m, int start, celt_norm *_X, const celt_ alg_quant(X, N, q1, spread, resynth, enc); } else { if (resynth) - intra_fold(m, start, eBands[i+1]-eBands[i], norm, X, eBands[i], B); + intra_fold(m, start, N, norm, X, M*eBands[i], B, M); } if (q2 > 0) { int spread = fold ? B : 0; @@ -737,16 +737,16 @@ void quant_bands_stereo(const CELTMode *m, int start, celt_norm *_X, const celt_ mid = (1.f/32768)*imid; side = (1.f/32768)*iside; #endif - n = celt_sqrt(SHL32(EXTEND32(eBands[i+1]-eBands[i]),22)); + n = celt_sqrt(SHL32(EXTEND32(N),22)); for (j=0;jeBands; @@ -769,7 +769,7 @@ void unquant_bands_stereo(const CELTMode *m, int start, celt_norm *_X, const cel SAVE_STACK; B = shortBlocks ? m->nbShortMdcts : 1; - ALLOC(_norm, eBands[m->nbEBands+1], celt_norm); + ALLOC(_norm, M*eBands[m->nbEBands+1], celt_norm); norm = _norm; balance = 0; @@ -787,11 +787,11 @@ void unquant_bands_stereo(const CELTMode *m, int start, celt_norm *_X, const cel int qalloc; celt_norm * restrict X, * restrict Y; - X = _X+eBands[i]; - Y = X+eBands[m->nbEBands+1]; + X = _X+M*eBands[i]; + Y = X+M*eBands[m->nbEBands+1]; BPbits = m->bits; - N = eBands[i+1]-eBands[i]; + N = M*eBands[i+1]-M*eBands[i]; tell = ec_dec_tell(dec, BITRES); if (i != start) balance -= tell; @@ -836,7 +836,7 @@ void unquant_bands_stereo(const CELTMode *m, int start, celt_norm *_X, const cel iside = bitexact_cos(16384-itheta); delta = (N-1)*(log2_frac(iside,BITRES+2)-log2_frac(imid,BITRES+2))>>2; } - n = celt_sqrt(SHL32(EXTEND32(eBands[i+1]-eBands[i]),22)); + n = celt_sqrt(SHL32(EXTEND32(N),22)); #if 1 if (N==2) @@ -928,7 +928,7 @@ void unquant_bands_stereo(const CELTMode *m, int start, celt_norm *_X, const cel int spread = fold ? B : 0; alg_unquant(X, N, q1, spread, dec); } else - intra_fold(m, start, eBands[i+1]-eBands[i], norm, X, eBands[i], B); + intra_fold(m, start, N, norm, X, M*eBands[i], B, M); if (q2 > 0) { int spread = fold ? B : 0; @@ -936,7 +936,7 @@ void unquant_bands_stereo(const CELTMode *m, int start, celt_norm *_X, const cel } else for (j=0;jmode->nbShortMdcts; SAVE_STACK; if (check_encoder(st) != CELT_OK) @@ -697,13 +698,13 @@ int celt_encode_float(CELTEncoder * restrict st, const celt_sig * pcm, celt_sig if (has_pitch) apply_pitch(st->mode, freq, pitch_freq, gain_id, 1, C); - compute_band_energies(st->mode, freq, bandE, C); + compute_band_energies(st->mode, freq, bandE, C, M); for (i=0;imode->nbEBands*C;i++) bandLogE[i] = amp2Log(bandE[i]); /* Band normalisation */ - normalise_bands(st->mode, freq, X, bandE, C); - if (!shortBlocks && !folding_decision(st->mode, X, &st->tonal_average, &st->fold_decision, C)) + normalise_bands(st->mode, freq, X, bandE, C, M); + if (!shortBlocks && !folding_decision(st->mode, X, &st->tonal_average, &st->fold_decision, C, M)) has_fold = 0; /* Don't use intra energy when we're operating at low bit-rate */ @@ -713,7 +714,7 @@ int celt_encode_float(CELTEncoder * restrict st, const celt_sig * pcm, celt_sig else st->delayedIntra = 0; - NN = st->mode->eBands[st->mode->nbEBands]; + NN = M*st->mode->eBands[st->mode->nbEBands]; if (shortBlocks && !transient_shift) { celt_word32 sum[8]={1,1,1,1,1,1,1,1}; @@ -757,7 +758,7 @@ int celt_encode_float(CELTEncoder * restrict st, const celt_sig * pcm, celt_sig } while (mmode->nbShortMdcts-1); #endif if (mdct_weight_shift) - mdct_shape(st->mode, X, mdct_weight_pos+1, st->mode->nbShortMdcts, N, st->mode->nbShortMdcts, mdct_weight_shift, C, 0); + mdct_shape(st->mode, X, mdct_weight_pos+1, st->mode->nbShortMdcts, N, st->mode->nbShortMdcts, mdct_weight_shift, C, 0, M); } @@ -865,16 +866,16 @@ int celt_encode_float(CELTEncoder * restrict st, const celt_sig * pcm, celt_sig for (i=0;imode->nbEBands;i++) offsets[i] = 0; bits = nbCompressedBytes*8 - ec_enc_tell(&enc, 0) - 1; - compute_allocation(st->mode, start, offsets, bits, pulses, fine_quant, fine_priority, C); + compute_allocation(st->mode, start, offsets, bits, pulses, fine_quant, fine_priority, C, M); quant_fine_energy(st->mode, start, bandE, st->oldBandE, error, fine_quant, &enc, C); /* Residual quantisation */ if (C==1) - quant_bands(st->mode, start, X, bandE, pulses, shortBlocks, has_fold, resynth, nbCompressedBytes*8, 1, &enc); + quant_bands(st->mode, start, X, bandE, pulses, shortBlocks, has_fold, resynth, nbCompressedBytes*8, 1, &enc, M); #ifndef DISABLE_STEREO else - quant_bands_stereo(st->mode, start, X, bandE, pulses, shortBlocks, has_fold, resynth, nbCompressedBytes*8, &enc); + quant_bands_stereo(st->mode, start, X, bandE, pulses, shortBlocks, has_fold, resynth, nbCompressedBytes*8, &enc, M); #endif quant_energy_finalise(st->mode, start, bandE, st->oldBandE, error, fine_quant, fine_priority, nbCompressedBytes*8-ec_enc_tell(&enc, 0), &enc, C); @@ -887,11 +888,11 @@ int celt_encode_float(CELTEncoder * restrict st, const celt_sig * pcm, celt_sig if (mdct_weight_shift) { - mdct_shape(st->mode, X, 0, mdct_weight_pos+1, N, st->mode->nbShortMdcts, mdct_weight_shift, C, 1); + mdct_shape(st->mode, X, 0, mdct_weight_pos+1, N, st->mode->nbShortMdcts, mdct_weight_shift, C, 1, M); } /* Synthesis */ - denormalise_bands(st->mode, X, freq, bandE, C); + denormalise_bands(st->mode, X, freq, bandE, C, M); CELT_MOVE(st->out_mem, st->out_mem+C*N, C*(MAX_PERIOD+st->overlap-N)); @@ -1459,6 +1460,7 @@ int celt_decode_float(CELTDecoder * restrict st, const unsigned char *data, int int mdct_weight_pos=0; int gain_id=0; int start=0; + const int M=st->mode->nbShortMdcts; SAVE_STACK; if (check_decoder(st) != CELT_OK) @@ -1530,7 +1532,7 @@ int celt_decode_float(CELTDecoder * restrict st, const unsigned char *data, int offsets[i] = 0; bits = len*8 - ec_dec_tell(&dec, 0) - 1; - compute_allocation(st->mode, start, offsets, bits, pulses, fine_quant, fine_priority, C); + compute_allocation(st->mode, start, offsets, bits, pulses, fine_quant, fine_priority, C, M); /*bits = ec_dec_tell(&dec, 0); compute_fine_allocation(st->mode, fine_quant, (20*C+len*8/5-(ec_dec_tell(&dec, 0)-bits))/C);*/ @@ -1545,20 +1547,20 @@ int celt_decode_float(CELTDecoder * restrict st, const unsigned char *data, int /* Decode fixed codebook and merge with pitch */ if (C==1) - quant_bands(st->mode, start, X, bandE, pulses, shortBlocks, has_fold, 1, len*8, 0, &dec); + quant_bands(st->mode, start, X, bandE, pulses, shortBlocks, has_fold, 1, len*8, 0, &dec, M); #ifndef DISABLE_STEREO else - unquant_bands_stereo(st->mode, start, X, bandE, pulses, shortBlocks, has_fold, len*8, &dec); + unquant_bands_stereo(st->mode, start, X, bandE, pulses, shortBlocks, has_fold, len*8, &dec, M); #endif unquant_energy_finalise(st->mode, start, bandE, st->oldBandE, fine_quant, fine_priority, len*8-ec_dec_tell(&dec, 0), &dec, C); if (mdct_weight_shift) { - mdct_shape(st->mode, X, 0, mdct_weight_pos+1, N, st->mode->nbShortMdcts, mdct_weight_shift, C, 1); + mdct_shape(st->mode, X, 0, mdct_weight_pos+1, N, st->mode->nbShortMdcts, mdct_weight_shift, C, 1, M); } /* Synthesis */ - denormalise_bands(st->mode, X, freq, bandE, C); + denormalise_bands(st->mode, X, freq, bandE, C, M); CELT_MOVE(st->decode_mem, st->decode_mem+C*N, C*(DECODE_BUFFER_SIZE+st->overlap-N)); @@ -1566,7 +1568,7 @@ int celt_decode_float(CELTDecoder * restrict st, const unsigned char *data, int if (has_pitch) apply_pitch(st->mode, freq, pitch_freq, gain_id, 0, C); - for (i=0;imode->eBands[start];i++) + for (i=0;imode->eBands[start];i++) freq[i] = 0; /* Compute inverse MDCTs */ diff --git a/libcelt/modes.c b/libcelt/modes.c index 7447a5c4..9cd408a9 100644 --- a/libcelt/modes.c +++ b/libcelt/modes.c @@ -119,14 +119,13 @@ static const int band_allocation[BARK_BANDS*BITALLOC_SIZE] = static celt_int16 *compute_ebands(celt_int32 Fs, int frame_size, int nbShortMdcts, int *nbEBands) { - int min_bins = 2; celt_int16 *eBands; int i, res, min_width, lin, low, high, nBark, offset=0; - if (min_bins < nbShortMdcts) - min_bins = nbShortMdcts; + frame_size /= nbShortMdcts; + nbShortMdcts = 1; res = (Fs+frame_size)/(2*frame_size); - min_width = min_bins*res; + min_width = res; /* Find the number of critical bands supported by our sampling rate */ for (nBark=1;nBark= min_width) break; - low = (bark_freq[lin]+res*min_bins/2)/(res*min_bins); + low = (bark_freq[lin]+res/2)/res; high = nBark-lin; *nbEBands = low+high; eBands = celt_alloc(sizeof(celt_int16)*(*nbEBands+2)); @@ -148,21 +147,21 @@ static celt_int16 *compute_ebands(celt_int32 Fs, int frame_size, int nbShortMdct /* Linear spacing (min_width) */ for (i=0;i0) offset = eBands[low-1]*res - bark_freq[lin-1]; /* Spacing follows critical bands */ for (i=0;i eBands[*nbEBands+1]) eBands[*nbEBands] = eBands[*nbEBands+1]; @@ -170,10 +169,10 @@ static celt_int16 *compute_ebands(celt_int32 Fs, int frame_size, int nbShortMdct { if (eBands[i+1]-eBands[i] < eBands[i]-eBands[i-1]) { - eBands[i] -= (2*eBands[i]-eBands[i-1]-eBands[i+1]+nbShortMdcts)/(2*nbShortMdcts)*nbShortMdcts; + eBands[i] -= (2*eBands[i]-eBands[i-1]-eBands[i+1])/2; } } - /*for (i=0;i<*nbEBands+1;i++) + /*for (i=0;i<=*nbEBands+1;i++) printf ("%d ", eBands[i]); printf ("\n"); exit(1);*/ @@ -181,7 +180,7 @@ static celt_int16 *compute_ebands(celt_int32 Fs, int frame_size, int nbShortMdct return eBands; } -static void compute_allocation_table(CELTMode *mode, int res) +static void compute_allocation_table(CELTMode *mode, int res, int M) { int i, j, nBark; celt_int16 *allocVectors; @@ -209,7 +208,7 @@ static void compute_allocation_table(CELTMode *mode, int res) low = bark_freq[j]; high = bark_freq[j+1]; - edge = mode->eBands[eband+1]*res; + edge = M*mode->eBands[eband+1]*res; while (edge <= high && eband < mode->nbEBands) { celt_int32 num; @@ -227,7 +226,7 @@ static void compute_allocation_table(CELTMode *mode, int res) /* Move to next eband */ current = 0; eband++; - edge = mode->eBands[eband+1]*res; + edge = M*mode->eBands[eband+1]*res; } current += alloc; } @@ -361,7 +360,7 @@ CELTMode *celt_mode_create(celt_int32 Fs, int frame_size, int *error) else mode->overlap = (frame_size>>3)<<2; - compute_allocation_table(mode, res); + compute_allocation_table(mode, res, mode->nbShortMdcts); if (mode->allocVectors==NULL) goto failure; @@ -378,7 +377,7 @@ CELTMode *celt_mode_create(celt_int32 Fs, int frame_size, int *error) #endif mode->window = window; - mode->bits = (const celt_int16 **)compute_alloc_cache(mode, 1); + mode->bits = (const celt_int16 **)compute_alloc_cache(mode, 1, mode->nbShortMdcts); if (mode->bits==NULL) goto failure; @@ -387,7 +386,7 @@ CELTMode *celt_mode_create(celt_int32 Fs, int frame_size, int *error) goto failure; for (i=0;inbEBands;i++) - logN[i] = log2_frac(mode->eBands[i+1]-mode->eBands[i], BITRES); + logN[i] = log2_frac(mode->nbShortMdcts*(mode->eBands[i+1]-mode->eBands[i]), BITRES); mode->logN = logN; #endif /* !STATIC_MODES */ diff --git a/libcelt/rate.c b/libcelt/rate.c index 762aeba7..016e249a 100644 --- a/libcelt/rate.c +++ b/libcelt/rate.c @@ -46,7 +46,7 @@ #ifndef STATIC_MODES -celt_int16 **compute_alloc_cache(CELTMode *m, int C) +celt_int16 **compute_alloc_cache(CELTMode *m, int C, int M) { int i, prevN; int error = 0; @@ -60,8 +60,8 @@ celt_int16 **compute_alloc_cache(CELTMode *m, int C) prevN = -1; for (i=0;inbEBands;i++) { - int N = C*(eBands[i+1]-eBands[i]); - if (N == prevN && eBands[i] < m->pitchEnd) + int N = C*M*(eBands[i+1]-eBands[i]); + if (N == prevN && M*eBands[i] < m->pitchEnd) { bits[i] = bits[i-1]; } else { @@ -102,7 +102,7 @@ celt_int16 **compute_alloc_cache(CELTMode *m, int C) -static inline void interp_bits2pulses(const CELTMode *m, int start, int *bits1, int *bits2, int total, int *bits, int *ebits, int *fine_priority, int len, int _C) +static inline void interp_bits2pulses(const CELTMode *m, int start, int *bits1, int *bits2, int total, int *bits, int *ebits, int *fine_priority, int len, int _C, int M) { int psum; int lo, hi; @@ -145,7 +145,7 @@ static inline void interp_bits2pulses(const CELTMode *m, int start, int *bits1, int N, d; int offset; - N=m->eBands[j+1]-m->eBands[j]; + N=M*(m->eBands[j+1]-m->eBands[j]); /* Compensate for the extra DoF in stereo */ d=(C*N+ ((C==2 && N>2) ? 1 : 0))<logN[j]; @@ -173,7 +173,7 @@ static inline void interp_bits2pulses(const CELTMode *m, int start, int *bits1, RESTORE_STACK; } -void compute_allocation(const CELTMode *m, int start, int *offsets, int total, int *pulses, int *ebits, int *fine_priority, int _C) +void compute_allocation(const CELTMode *m, int start, int *offsets, int total, int *pulses, int *ebits, int *fine_priority, int _C, int M) { int lo, hi, len, j; const int C = CHANNELS(_C); @@ -216,7 +216,7 @@ void compute_allocation(const CELTMode *m, int start, int *offsets, int total, i if (bits2[j] < 0) bits2[j] = 0; } - interp_bits2pulses(m, start, bits1, bits2, total, pulses, ebits, fine_priority, len, C); + interp_bits2pulses(m, start, bits1, bits2, total, pulses, ebits, fine_priority, len, C, M); RESTORE_STACK; } diff --git a/libcelt/rate.h b/libcelt/rate.h index f360a44c..19e8c9e5 100644 --- a/libcelt/rate.h +++ b/libcelt/rate.h @@ -155,7 +155,7 @@ static inline int pulses2bits(const celt_int16 *cache, int N, int pulses) } /** Computes a cache of the pulses->bits mapping in each band */ -celt_int16 **compute_alloc_cache(CELTMode *m, int C); +celt_int16 **compute_alloc_cache(CELTMode *m, int C, int M); /** Compute the pulse allocation, i.e. how many pulses will go in each * band. @@ -166,7 +166,7 @@ celt_int16 **compute_alloc_cache(CELTMode *m, int C); @param pulses Number of pulses per band (returned) @return Total number of bits allocated */ -void compute_allocation(const CELTMode *m, int start, int *offsets, int total, int *pulses, int *ebits, int *fine_priority, int _C); +void compute_allocation(const CELTMode *m, int start, int *offsets, int total, int *pulses, int *ebits, int *fine_priority, int _C, int M); #endif diff --git a/libcelt/vq.c b/libcelt/vq.c index 20f288df..b4255535 100644 --- a/libcelt/vq.c +++ b/libcelt/vq.c @@ -473,11 +473,11 @@ celt_word16 renormalise_vector(celt_norm *X, celt_word16 value, int N, int strid return celt_sqrt(E); } -static void fold(const CELTMode *m, int start, int N, const celt_norm * restrict Y, celt_norm * restrict P, int N0, int B) +static void fold(const CELTMode *m, int start, int N, const celt_norm * restrict Y, celt_norm * restrict P, int N0, int B, int M) { int j; int id = N0 % B; - while (id < m->eBands[start]) + while (id < M*m->eBands[start]) id += B; /* Here, we assume that id will never be greater than N0, i.e. that no band is wider than N0. In the unlikely case it happens, we set @@ -500,9 +500,9 @@ static void fold(const CELTMode *m, int start, int N, const celt_norm * restrict P[j] = Y[id++]; } -void intra_fold(const CELTMode *m, int start, int N, const celt_norm * restrict Y, celt_norm * restrict P, int N0, int B) +void intra_fold(const CELTMode *m, int start, int N, const celt_norm * restrict Y, celt_norm * restrict P, int N0, int B, int M) { - fold(m, start, N, Y, P, N0, B); + fold(m, start, N, Y, P, N0, B, M); renormalise_vector(P, Q15ONE, N, 1); } diff --git a/libcelt/vq.h b/libcelt/vq.h index 60f827ac..7e4d8622 100644 --- a/libcelt/vq.h +++ b/libcelt/vq.h @@ -75,6 +75,6 @@ celt_word16 renormalise_vector(celt_norm *X, celt_word16 value, int N, int strid * @param B Stride (number of channels multiplied by the number of MDCTs per frame) * @param N0 Number of valid offsets */ -void intra_fold(const CELTMode *m, int start, int N, const celt_norm * restrict Y, celt_norm * restrict P, int N0, int B); +void intra_fold(const CELTMode *m, int start, int N, const celt_norm * restrict Y, celt_norm * restrict P, int N0, int B, int M); #endif /* VQ_H */