From 3781f7734971145faf74412d13590731c49cdb05 Mon Sep 17 00:00:00 2001 From: Jean-Marc Valin Date: Thu, 4 Aug 2016 16:12:26 -0400 Subject: wip --- celt/celt_encoder.c | 52 +++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 37 insertions(+), 15 deletions(-) diff --git a/celt/celt_encoder.c b/celt/celt_encoder.c index d1f9339f..a16e3c0b 100644 --- a/celt/celt_encoder.c +++ b/celt/celt_encoder.c @@ -758,14 +758,12 @@ static const float band_ref_sin_phi[25] = { 0.769366f }; -static float dist_from_bits(float bits, int N, float sin_phi) +static float dist_from_bits(float r, float sin_phi) { - float r; - r = MIN16(8, bits/(2*N - 1)); return 3*(pow(4., -r)*sin_phi + pow(4., -2*r)*(1-sin_phi)); } -static float bits_from_dist(float dist, int N, float sin_phi) +static float bits_from_dist(float dist, float sin_phi) { float R; if (fabs(sin_phi)<.99) @@ -775,16 +773,17 @@ static float bits_from_dist(float dist, int N, float sin_phi) R = dist/3; } //printf("=> %f %f %f\n", dist, sin_phi, R); - return MAX16(0, -(2*N-1)*log(R)/log(4)); + return MAX16(0, -log(R)/log(4)); } -static float delta_bits(float bits, int N, float sin_phi, float sin_phi_ref) +static float delta_bits(float r, float sin_phi, float sin_phi_ref) { - float dist = dist_from_bits(bits, N, sin_phi_ref); - return bits_from_dist(dist, N, sin_phi)-bits; + float dist = dist_from_bits(r, sin_phi_ref); + return bits_from_dist(dist, sin_phi)-r; } extern int band_bits[25]; float stereo_delta; +float stereo_avg; static int alloc_trim_analysis(const CELTMode *m, const celt_norm *X, const opus_val16 *bandLogE, int end, int LM, int C, int N0, @@ -797,31 +796,47 @@ static int alloc_trim_analysis(const CELTMode *m, const celt_norm *X, int trim_index; opus_val16 trim = QCONST16(5.f, 8); opus_val16 logXC, logXC2; - if (C==2) + if (C==2 && intensity > 0) { opus_val16 sum = 0; /* Q10 */ opus_val16 minXC; /* Q10 */ + opus_val16 stereo_tilt=0; + opus_val16 stereo_diff = 0; + float mono_ratio; /* Compute inter-channel correlation for low frequencies */ stereo_delta = 0; + stereo_avg = 0; + mono_ratio = 0; for (i=0;ieBands[i]<eBands[i]<eBands[i+1]-m->eBands[i])<eBands[i+1]-m->eBands[i])<