Commit b6a3b0c4 authored by Gregory Maxwell's avatar Gregory Maxwell Committed by Jean-Marc Valin
Browse files

Fix stereo support; correctly deallocate bits_stereo.

parent 60d0837e
......@@ -355,9 +355,15 @@ void quant_bands(const CELTMode *m, celt_norm_t * restrict X, celt_norm_t *P, ce
int tell;
int q;
celt_word16_t n;
celt_int16_t * const *BPbits;
int curr_balance, curr_bits;
if (C>1 && stereo_mode[i]==0)
BPbits = m->bits_stereo;
else
BPbits = m->bits;
tell = ec_enc_tell(enc, 4);
if (i != 0)
balance -= tell;
......@@ -366,14 +372,14 @@ void quant_bands(const CELTMode *m, celt_norm_t * restrict X, celt_norm_t *P, ce
if (curr_balance > 3)
curr_balance = 3;
curr_balance = balance / curr_balance;
q = bits2pulses(m, m->bits[i], pulses[i]+curr_balance);
curr_bits = m->bits[i][q];
q = bits2pulses(m, BPbits[i], pulses[i]+curr_balance);
curr_bits = BPbits[i][q];
remaining_bits -= curr_bits;
if (remaining_bits < 0)
{
q--;
remaining_bits += curr_bits;
curr_bits = m->bits[i][q];
curr_bits = BPbits[i][q];
remaining_bits -= curr_bits;
}
balance += pulses[i] + tell;
......@@ -434,9 +440,15 @@ void unquant_bands(const CELTMode *m, celt_norm_t * restrict X, celt_norm_t *P,
int tell;
int q;
celt_word16_t n;
celt_int16_t * const *BPbits;
int curr_balance, curr_bits;
if (C>1 && stereo_mode[i]==0)
BPbits = m->bits_stereo;
else
BPbits = m->bits;
tell = ec_dec_tell(dec, 4);
if (i != 0)
balance -= tell;
......@@ -445,14 +457,14 @@ void unquant_bands(const CELTMode *m, celt_norm_t * restrict X, celt_norm_t *P,
if (curr_balance > 3)
curr_balance = 3;
curr_balance = balance / curr_balance;
q = bits2pulses(m, m->bits[i], pulses[i]+curr_balance);
curr_bits = m->bits[i][q];
q = bits2pulses(m, BPbits[i], pulses[i]+curr_balance);
curr_bits = BPbits[i][q];
remaining_bits -= curr_bits;
if (remaining_bits < 0)
{
q--;
remaining_bits += curr_bits;
curr_bits = m->bits[i][q];
curr_bits = BPbits[i][q];
remaining_bits -= curr_bits;
}
balance += pulses[i] + tell;
......
......@@ -394,7 +394,6 @@ CELTMode *celt_mode_create(celt_int32_t Fs, int channels, int frame_size, int *e
if (mode->nbChannels>=2)
mode->bits_stereo = (const celt_int16_t **)compute_alloc_cache(mode, mode->nbChannels);
mode->bits_stereo = NULL;
#ifndef SHORTCUTS
psydecay_init(&mode->psy, MAX_PERIOD/2, mode->Fs);
#endif
......@@ -430,6 +429,18 @@ void celt_mode_destroy(CELTMode *mode)
}
}
celt_free((int**)mode->bits);
if (mode->bits_stereo != NULL)
{
for (i=0;i<mode->nbEBands;i++)
{
if (mode->bits_stereo[i] != prevPtr)
{
prevPtr = mode->bits_stereo[i];
celt_free((int*)mode->bits_stereo[i]);
}
}
celt_free((int**)mode->bits_stereo);
}
if (check_mode(mode) != CELT_OK)
return;
celt_free((int*)mode->eBands);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment