Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mumble-voip/celt-0.7.0.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJean-Marc Valin <jean-marc.valin@usherbrooke.ca>2009-10-09 07:10:45 +0400
committerJean-Marc Valin <jean-marc.valin@usherbrooke.ca>2009-10-09 07:10:45 +0400
commita9947c480c80c53366a9ac441bdd5d47c36ca14e (patch)
treef3ba648445f09f852ea83b044e0aa60dc381e42a
parentf7a1e165aa8be3b2cad7c8c304e8fe15e5d32433 (diff)
merged the code for quant_bands() and unquant_bands()
-rw-r--r--libcelt/bands.c74
-rw-r--r--libcelt/bands.h2
-rw-r--r--libcelt/celt.c4
3 files changed, 12 insertions, 68 deletions
diff --git a/libcelt/bands.c b/libcelt/bands.c
index 194e34c..6818b6f 100644
--- a/libcelt/bands.c
+++ b/libcelt/bands.c
@@ -430,7 +430,7 @@ int folding_decision(const CELTMode *m, celt_norm_t *X, celt_word16_t *average,
}
/* Quantisation of the residual */
-void quant_bands(const CELTMode *m, celt_norm_t * restrict X, const celt_ener_t *bandE, int *pulses, int shortBlocks, int fold, int total_bits, ec_enc *enc)
+void quant_bands(const CELTMode *m, celt_norm_t * restrict X, const celt_ener_t *bandE, int *pulses, int shortBlocks, int fold, int total_bits, int encode, void *enc_dec)
{
int i, j, remaining_bits, balance;
const celt_int16_t * restrict eBands = m->eBands;
@@ -457,7 +457,10 @@ void quant_bands(const CELTMode *m, celt_norm_t * restrict X, const celt_ener_t
N = eBands[i+1]-eBands[i];
BPbits = m->bits;
- tell = ec_enc_tell(enc, BITRES);
+ if (encode)
+ tell = ec_enc_tell(enc_dec, BITRES);
+ else
+ tell = ec_dec_tell(enc_dec, BITRES);
if (i != 0)
balance -= tell;
remaining_bits = (total_bits<<BITRES)-tell-1;
@@ -482,7 +485,10 @@ void quant_bands(const CELTMode *m, celt_norm_t * restrict X, const celt_ener_t
if (q > 0)
{
int spread = fold ? B : 0;
- alg_quant(X+eBands[i], eBands[i+1]-eBands[i], q, spread, enc);
+ if (encode)
+ alg_quant(X+eBands[i], eBands[i+1]-eBands[i], q, spread, enc_dec);
+ else
+ alg_unquant(X+eBands[i], eBands[i+1]-eBands[i], q, spread, enc_dec);
} else {
intra_fold(m, eBands[i+1]-eBands[i], norm, X+eBands[i], eBands[i], B);
}
@@ -722,68 +728,6 @@ void quant_bands_stereo(const CELTMode *m, celt_norm_t *_X, const celt_ener_t *b
}
#endif /* DISABLE_STEREO */
-/* Decoding of the residual */
-void unquant_bands(const CELTMode *m, celt_norm_t * restrict X, const celt_ener_t *bandE, int *pulses, int shortBlocks, int fold, int total_bits, ec_dec *dec)
-{
- int i, j, remaining_bits, balance;
- const celt_int16_t * restrict eBands = m->eBands;
- celt_norm_t * restrict norm;
- VARDECL(celt_norm_t, _norm);
- int B;
- SAVE_STACK;
-
- B = shortBlocks ? m->nbShortMdcts : 1;
- ALLOC(_norm, eBands[m->nbEBands+1], celt_norm_t);
- norm = _norm;
-
- balance = 0;
- for (i=0;i<m->nbEBands;i++)
- {
- int tell;
- int N;
- int q;
- celt_word16_t n;
- const celt_int16_t * const *BPbits;
-
- int curr_balance, curr_bits;
-
- N = eBands[i+1]-eBands[i];
- BPbits = m->bits;
-
- tell = ec_dec_tell(dec, BITRES);
- if (i != 0)
- balance -= tell;
- remaining_bits = (total_bits<<BITRES)-tell-1;
- curr_balance = (m->nbEBands-i);
- if (curr_balance > 3)
- curr_balance = 3;
- curr_balance = balance / curr_balance;
- q = bits2pulses(m, BPbits[i], N, pulses[i]+curr_balance);
- curr_bits = pulses2bits(BPbits[i], N, q);
- remaining_bits -= curr_bits;
- while (remaining_bits < 0 && q > 0)
- {
- remaining_bits += curr_bits;
- q--;
- curr_bits = pulses2bits(BPbits[i], N, q);
- remaining_bits -= curr_bits;
- }
- balance += pulses[i] + tell;
-
- n = SHL16(celt_sqrt(eBands[i+1]-eBands[i]),11);
-
- if (q > 0)
- {
- int spread = fold ? B : 0;
- alg_unquant(X+eBands[i], eBands[i+1]-eBands[i], q, spread, dec);
- } else {
- intra_fold(m, eBands[i+1]-eBands[i], norm, X+eBands[i], eBands[i], B);
- }
- for (j=eBands[i];j<eBands[i+1];j++)
- norm[j] = MULT16_16_Q15(n,X[j]);
- }
- RESTORE_STACK;
-}
#ifndef DISABLE_STEREO
diff --git a/libcelt/bands.h b/libcelt/bands.h
index ad4a5e0..11fa928 100644
--- a/libcelt/bands.h
+++ b/libcelt/bands.h
@@ -83,7 +83,7 @@ int folding_decision(const CELTMode *m, celt_norm_t *X, celt_word16_t *average,
* @param total_bits Total number of bits that can be used for the frame (including the ones already spent)
* @param enc Entropy encoder
*/
-void quant_bands(const CELTMode *m, celt_norm_t * restrict X, const celt_ener_t *bandE, int *pulses, int time_domain, int fold, int total_bits, ec_enc *enc);
+void quant_bands(const CELTMode *m, celt_norm_t * restrict X, const celt_ener_t *bandE, int *pulses, int time_domain, int fold, int total_bits, int encode, void *enc_dec);
void quant_bands_stereo(const CELTMode *m, celt_norm_t * restrict X, const celt_ener_t *bandE, int *pulses, int time_domain, int fold, int total_bits, ec_enc *enc);
diff --git a/libcelt/celt.c b/libcelt/celt.c
index a75eb37..bd3a3fd 100644
--- a/libcelt/celt.c
+++ b/libcelt/celt.c
@@ -764,7 +764,7 @@ int celt_encode_float(CELTEncoder * restrict st, const celt_sig_t * pcm, celt_si
/* Residual quantisation */
if (C==1)
- quant_bands(st->mode, X, bandE, pulses, shortBlocks, has_fold, nbCompressedBytes*8, &enc);
+ quant_bands(st->mode, X, bandE, pulses, shortBlocks, has_fold, nbCompressedBytes*8, 1, &enc);
#ifndef DISABLE_STEREO
else
quant_bands_stereo(st->mode, X, bandE, pulses, shortBlocks, has_fold, nbCompressedBytes*8, &enc);
@@ -1286,7 +1286,7 @@ int celt_decode_float(CELTDecoder * restrict st, const unsigned char *data, int
/* Decode fixed codebook and merge with pitch */
if (C==1)
- unquant_bands(st->mode, X, bandE, pulses, shortBlocks, has_fold, len*8, &dec);
+ quant_bands(st->mode, X, bandE, pulses, shortBlocks, has_fold, len*8, 0, &dec);
#ifndef DISABLE_STEREO
else
unquant_bands_stereo(st->mode, X, bandE, pulses, shortBlocks, has_fold, len*8, &dec);