mirror of
https://github.com/xiph/opus.git
synced 2025-06-07 16:00:56 +00:00
Stereo decoding working again (fixed a few issues in the encoder at the same
time)
This commit is contained in:
parent
021478e252
commit
a4833ffada
4 changed files with 100 additions and 60 deletions
|
@ -107,7 +107,7 @@ CELTEncoder *celt_encoder_new(const CELTMode *mode)
|
||||||
= sin(.5*M_PI* sin(.5*M_PI*(i+.5)/st->overlap) * sin(.5*M_PI*(i+.5)/st->overlap));
|
= sin(.5*M_PI* sin(.5*M_PI*(i+.5)/st->overlap) * sin(.5*M_PI*(i+.5)/st->overlap));
|
||||||
for (i=0;i<2*N4;i++)
|
for (i=0;i<2*N4;i++)
|
||||||
st->window[N-N4+i] = 1;
|
st->window[N-N4+i] = 1;
|
||||||
st->oldBandE = celt_alloc(mode->nbEBands*sizeof(float));
|
st->oldBandE = celt_alloc(C*mode->nbEBands*sizeof(float));
|
||||||
|
|
||||||
st->preemph = 0.8;
|
st->preemph = 0.8;
|
||||||
st->preemph_memE = celt_alloc(C*sizeof(float));;
|
st->preemph_memE = celt_alloc(C*sizeof(float));;
|
||||||
|
@ -318,7 +318,6 @@ int celt_encode(CELTEncoder *st, short *pcm)
|
||||||
time_dct(X, N, B, C);
|
time_dct(X, N, B, C);
|
||||||
time_dct(P, N, B, C);
|
time_dct(P, N, B, C);
|
||||||
|
|
||||||
|
|
||||||
quant_energy(st->mode, bandE, st->oldBandE, &st->enc);
|
quant_energy(st->mode, bandE, st->oldBandE, &st->enc);
|
||||||
|
|
||||||
/* Pitch prediction */
|
/* Pitch prediction */
|
||||||
|
@ -447,7 +446,7 @@ CELTDecoder *celt_decoder_new(const CELTMode *mode)
|
||||||
for (i=0;i<2*N4;i++)
|
for (i=0;i<2*N4;i++)
|
||||||
st->window[N-N4+i] = 1;
|
st->window[N-N4+i] = 1;
|
||||||
|
|
||||||
st->oldBandE = celt_alloc(mode->nbEBands*sizeof(float));
|
st->oldBandE = celt_alloc(C*mode->nbEBands*sizeof(float));
|
||||||
|
|
||||||
st->preemph = 0.8;
|
st->preemph = 0.8;
|
||||||
st->preemph_memD = celt_alloc(C*sizeof(float));;
|
st->preemph_memD = celt_alloc(C*sizeof(float));;
|
||||||
|
@ -518,7 +517,7 @@ int celt_decode(CELTDecoder *st, char *data, int len, short *pcm)
|
||||||
|
|
||||||
float X[C*B*N]; /**< Interleaved signal MDCTs */
|
float X[C*B*N]; /**< Interleaved signal MDCTs */
|
||||||
float P[C*B*N]; /**< Interleaved pitch MDCTs*/
|
float P[C*B*N]; /**< Interleaved pitch MDCTs*/
|
||||||
float bandE[st->mode->nbEBands];
|
float bandE[st->mode->nbEBands*C];
|
||||||
float gains[st->mode->nbPBands];
|
float gains[st->mode->nbPBands];
|
||||||
int pitch_index;
|
int pitch_index;
|
||||||
ec_dec dec;
|
ec_dec dec;
|
||||||
|
@ -543,16 +542,16 @@ int celt_decode(CELTDecoder *st, char *data, int len, short *pcm)
|
||||||
/* Pitch MDCT */
|
/* Pitch MDCT */
|
||||||
compute_mdcts(&st->mdct_lookup, st->window, st->out_mem+pitch_index*C, P, N, B, C);
|
compute_mdcts(&st->mdct_lookup, st->window, st->out_mem+pitch_index*C, P, N, B, C);
|
||||||
|
|
||||||
if (C==2)
|
|
||||||
haar1(P, B*N*C, 1);
|
|
||||||
time_dct(P, N, B, C);
|
|
||||||
|
|
||||||
{
|
{
|
||||||
float bandEp[st->mode->nbEBands];
|
float bandEp[st->mode->nbEBands];
|
||||||
compute_band_energies(st->mode, P, bandEp);
|
compute_band_energies(st->mode, P, bandEp);
|
||||||
normalise_bands(st->mode, P, bandEp);
|
normalise_bands(st->mode, P, bandEp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (C==2)
|
||||||
|
haar1(P, B*N*C, 1);
|
||||||
|
time_dct(P, N, B, C);
|
||||||
|
|
||||||
/* Get the pitch gains */
|
/* Get the pitch gains */
|
||||||
unquant_pitch(gains, st->mode->nbPBands, &dec);
|
unquant_pitch(gains, st->mode->nbPBands, &dec);
|
||||||
|
|
||||||
|
@ -562,13 +561,16 @@ int celt_decode(CELTDecoder *st, char *data, int len, short *pcm)
|
||||||
/* Decode fixed codebook and merge with pitch */
|
/* Decode fixed codebook and merge with pitch */
|
||||||
unquant_bands(st->mode, X, P, &dec);
|
unquant_bands(st->mode, X, P, &dec);
|
||||||
|
|
||||||
/* Synthesis */
|
|
||||||
denormalise_bands(st->mode, X, bandE);
|
|
||||||
|
|
||||||
time_idct(X, N, B, C);
|
time_idct(X, N, B, C);
|
||||||
if (C==2)
|
if (C==2)
|
||||||
haar1(X, B*N*C, 1);
|
haar1(X, B*N*C, 1);
|
||||||
|
|
||||||
|
renormalise_bands(st->mode, X);
|
||||||
|
|
||||||
|
/* Synthesis */
|
||||||
|
denormalise_bands(st->mode, X, bandE);
|
||||||
|
|
||||||
|
|
||||||
CELT_MOVE(st->out_mem, st->out_mem+C*B*N, C*(MAX_PERIOD-B*N));
|
CELT_MOVE(st->out_mem, st->out_mem+C*B*N, C*(MAX_PERIOD-B*N));
|
||||||
/* Compute inverse MDCTs */
|
/* Compute inverse MDCTs */
|
||||||
compute_inv_mdcts(&st->mdct_lookup, st->window, X, st->out_mem, st->mdct_overlap, N, st->overlap, B, C);
|
compute_inv_mdcts(&st->mdct_lookup, st->window, X, st->out_mem, st->mdct_overlap, N, st->overlap, B, C);
|
||||||
|
|
|
@ -77,9 +77,9 @@ const int pbank1[PBANDS128+2] = {0, 2, 4, 6, 8, 12, 20, 28, PITCH_END128, 128};
|
||||||
#define NBANDS256 15
|
#define NBANDS256 15
|
||||||
#define PBANDS256 8
|
#define PBANDS256 8
|
||||||
#define PITCH_END256 88
|
#define PITCH_END256 88
|
||||||
const int qbank3[NBANDS256+2] = {0, 4, 8, 12, 16, 24, 32, 40, 48, 56, 72, 88, 104, 126, 168, 232, 256};
|
const int qbank3[NBANDS256+2] = {0, 4, 8, 12, 16, 24, 32, 40, 48, 56, 72, 88, 104, 136, 168, 232, 256};
|
||||||
//const int pbank3[PBANDS256+2] = {0, 8, 16, 24, 40, PITCH_END256, 256};
|
//const int pbank3[PBANDS256+2] = {0, 8, 16, 24, 40, PITCH_END256, 256};
|
||||||
const int pbank3[PBANDS256+2] = {0, 4, 8, 12, 16, 24, 40, 56, PITCH_END128, 128};
|
const int pbank3[PBANDS256+2] = {0, 4, 8, 12, 16, 24, 40, 56, PITCH_END256, 256};
|
||||||
|
|
||||||
const CELTMode mode0 = {
|
const CELTMode mode0 = {
|
||||||
128, /**< overlap */
|
128, /**< overlap */
|
||||||
|
|
|
@ -35,49 +35,7 @@
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include "os_support.h"
|
#include "os_support.h"
|
||||||
|
|
||||||
void quant_energy(const CELTMode *m, float *eBands, float *oldEBands, ec_enc *enc)
|
static void quant_energy_mono(const CELTMode *m, float *eBands, float *oldEBands, ec_enc *enc)
|
||||||
{
|
|
||||||
int C;
|
|
||||||
|
|
||||||
C = m->nbChannels;
|
|
||||||
|
|
||||||
if (C==1)
|
|
||||||
quant_energy_mono(m, eBands, oldEBands, enc);
|
|
||||||
else if (C==2)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
int NB = m->nbEBands;
|
|
||||||
float mid[NB];
|
|
||||||
float side[NB];
|
|
||||||
float left;
|
|
||||||
float right;
|
|
||||||
for (i=0;i<NB;i++)
|
|
||||||
{
|
|
||||||
//left = eBands[C*i];
|
|
||||||
//right = eBands[C*i+1];
|
|
||||||
mid[i] = sqrt(eBands[C*i]*eBands[C*i] + eBands[C*i+1]*eBands[C*i+1]);
|
|
||||||
side[i] = 20*log10((eBands[2*i]+.3)/(eBands[2*i+1]+.3));
|
|
||||||
//printf ("%f %f ", mid[i], side[i]);
|
|
||||||
}
|
|
||||||
//printf ("\n");
|
|
||||||
quant_energy_mono(m, mid, oldEBands, enc);
|
|
||||||
for (i=0;i<NB;i++)
|
|
||||||
side[i] = pow(10.f,floor(.5f+side[i])/10.f);
|
|
||||||
|
|
||||||
//quant_energy_side(m, side, oldEBands+NB, enc);
|
|
||||||
for (i=0;i<NB;i++)
|
|
||||||
{
|
|
||||||
eBands[C*i] = mid[i]*sqrt(side[i]/(1.f+side[i]));
|
|
||||||
eBands[C*i+1] = mid[i]*sqrt(1.f/(1.f+side[i]));
|
|
||||||
//printf ("%f %f ", mid[i], side[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
|
||||||
celt_fatal("more than 2 channels not supported");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void quant_energy_mono(const CELTMode *m, float *eBands, float *oldEBands, ec_enc *enc)
|
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
float prev = 0;
|
float prev = 0;
|
||||||
|
@ -109,7 +67,67 @@ void quant_energy_mono(const CELTMode *m, float *eBands, float *oldEBands, ec_en
|
||||||
//printf ("\n");
|
//printf ("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
void unquant_energy(const CELTMode *m, float *eBands, float *oldEBands, ec_dec *dec)
|
void quant_energy(const CELTMode *m, float *eBands, float *oldEBands, ec_enc *enc)
|
||||||
|
{
|
||||||
|
int C;
|
||||||
|
|
||||||
|
C = m->nbChannels;
|
||||||
|
|
||||||
|
if (C==1)
|
||||||
|
quant_energy_mono(m, eBands, oldEBands, enc);
|
||||||
|
else
|
||||||
|
#if 1
|
||||||
|
{
|
||||||
|
int c;
|
||||||
|
for (c=0;c<C;c++)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
float E[m->nbEBands];
|
||||||
|
for (i=0;i<m->nbEBands;i++)
|
||||||
|
E[i] = eBands[C*i+c];
|
||||||
|
quant_energy_mono(m, E, oldEBands+c*m->nbEBands, enc);
|
||||||
|
for (i=0;i<m->nbEBands;i++)
|
||||||
|
eBands[C*i+c] = E[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
if (C==2)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
int NB = m->nbEBands;
|
||||||
|
float mid[NB];
|
||||||
|
float side[NB];
|
||||||
|
float left;
|
||||||
|
float right;
|
||||||
|
for (i=0;i<NB;i++)
|
||||||
|
{
|
||||||
|
//left = eBands[C*i];
|
||||||
|
//right = eBands[C*i+1];
|
||||||
|
mid[i] = sqrt(eBands[C*i]*eBands[C*i] + eBands[C*i+1]*eBands[C*i+1]);
|
||||||
|
side[i] = 20*log10((eBands[2*i]+.3)/(eBands[2*i+1]+.3));
|
||||||
|
//printf ("%f %f ", mid[i], side[i]);
|
||||||
|
}
|
||||||
|
//printf ("\n");
|
||||||
|
quant_energy_mono(m, mid, oldEBands, enc);
|
||||||
|
for (i=0;i<NB;i++)
|
||||||
|
side[i] = pow(10.f,floor(.5f+side[i])/10.f);
|
||||||
|
|
||||||
|
//quant_energy_side(m, side, oldEBands+NB, enc);
|
||||||
|
for (i=0;i<NB;i++)
|
||||||
|
{
|
||||||
|
eBands[C*i] = mid[i]*sqrt(side[i]/(1.f+side[i]));
|
||||||
|
eBands[C*i+1] = mid[i]*sqrt(1.f/(1.f+side[i]));
|
||||||
|
//printf ("%f %f ", mid[i], side[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
celt_fatal("more than 2 channels not supported");
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void unquant_energy_mono(const CELTMode *m, float *eBands, float *oldEBands, ec_dec *dec)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
float prev = 0;
|
float prev = 0;
|
||||||
|
@ -135,3 +153,23 @@ void unquant_energy(const CELTMode *m, float *eBands, float *oldEBands, ec_dec *
|
||||||
}
|
}
|
||||||
//printf ("\n");
|
//printf ("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void unquant_energy(const CELTMode *m, float *eBands, float *oldEBands, ec_dec *dec)
|
||||||
|
{
|
||||||
|
int C;
|
||||||
|
C = m->nbChannels;
|
||||||
|
|
||||||
|
if (C==1)
|
||||||
|
unquant_energy_mono(m, eBands, oldEBands, dec);
|
||||||
|
else {
|
||||||
|
int c;
|
||||||
|
for (c=0;c<C;c++)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
float E[m->nbEBands];
|
||||||
|
unquant_energy_mono(m, E, oldEBands+c*m->nbEBands, dec);
|
||||||
|
for (i=0;i<m->nbEBands;i++)
|
||||||
|
eBands[C*i+c] = E[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -188,8 +188,9 @@ void alg_quant(float *x, float *W, int N, int K, float *p, float alpha, ec_enc *
|
||||||
pulse2comb(N, K, comb, signs, iy[0]);
|
pulse2comb(N, K, comb, signs, iy[0]);
|
||||||
ec_enc_uint64(enc,icwrs64(N, K, comb, signs),ncwrs64(N, K));
|
ec_enc_uint64(enc,icwrs64(N, K, comb, signs),ncwrs64(N, K));
|
||||||
|
|
||||||
/* Recompute the gain in one pass (to reduce errors) */
|
/* Recompute the gain in one pass to reduce the encoder-decoder mismatch
|
||||||
if (0) {
|
due to the recursive computation used in quantisation */
|
||||||
|
if (1) {
|
||||||
float Ryp=0;
|
float Ryp=0;
|
||||||
float Rpp=0;
|
float Rpp=0;
|
||||||
float Ryy=0;
|
float Ryy=0;
|
||||||
|
@ -203,7 +204,6 @@ void alg_quant(float *x, float *W, int N, int K, float *p, float alpha, ec_enc *
|
||||||
for (i=0;i<N;i++)
|
for (i=0;i<N;i++)
|
||||||
y[0][i] = iy[0][i] - alpha*Ryp*p[i];
|
y[0][i] = iy[0][i] - alpha*Ryp*p[i];
|
||||||
|
|
||||||
/* Recompute after the projection (I think it's right) */
|
|
||||||
Ryp = 0;
|
Ryp = 0;
|
||||||
for (i=0;i<N;i++)
|
for (i=0;i<N;i++)
|
||||||
Ryp += y[0][i]*p[i];
|
Ryp += y[0][i]*p[i];
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue