shithub: opus

Download patch

ref: 411a84faeada5092e2e94d8116b8adba45808183
parent: 4499263b444645cba4b616e0d8cc85d280695933
author: Timothy B. Terriberry <[email protected]>
date: Mon Jan 31 20:55:01 EST 2011

Add a seprate qtheta offset for two-phase stereo.

9b34bd83 caused serious regressions for 240-sample frame stereo,
 because the previous qb limit was _always_ hit for two-phase
 stereo.
Two-phase stereo really does operate with a different model (for
 example, the single bit allocated to the side should really
 probably be thought of as a sign bit for qtheta, but we don't
 count it as part of qtheta's allocation).
The old code was equivalent to a separate two-phase offset of 12,
 however Greg Maxwell's testing demonstrates that 16 performs
 best.

--- a/libcelt/bands.c
+++ b/libcelt/bands.c
@@ -769,7 +769,7 @@
 
       /* Decide on the resolution to give to the split parameter theta */
       pulse_cap = m->logN[i]+(LM<<BITRES);
-      offset = (pulse_cap>>1) - (stereo ? QTHETA_OFFSET_STEREO : QTHETA_OFFSET);
+      offset = (pulse_cap>>1) - (stereo&&N==2 ? QTHETA_OFFSET_TWOPHASE : QTHETA_OFFSET);
       qn = compute_qn(N, b, offset, pulse_cap, stereo);
       if (stereo && i>=intensity)
          qn = 1;
--- a/libcelt/rate.c
+++ b/libcelt/rate.c
@@ -212,7 +212,7 @@
                if (C==2)
                {
                   max_bits <<= 1;
-                  offset = (m->logN[j]+(i<<BITRES)>>1)-QTHETA_OFFSET_STEREO;
+                  offset = (m->logN[j]+(i<<BITRES)>>1)-(N==2?QTHETA_OFFSET_TWOPHASE:QTHETA_OFFSET);
                   ndof = 2*N-1-(N==2);
                   /* The average measured cost for theta with the step PDF is
                       0.95164 times qb, approximated here as 487/512. */
--- a/libcelt/rate.h
+++ b/libcelt/rate.h
@@ -43,7 +43,7 @@
 #define BITRES 3
 #define FINE_OFFSET 21
 #define QTHETA_OFFSET 4
-#define QTHETA_OFFSET_STEREO 4
+#define QTHETA_OFFSET_TWOPHASE 16
 
 #define BITOVERFLOW 30000