Browse code

opus_pvq: minor cleanups

Removes unneeded variables, renames confusing and innacurate variables
and rewrites and slightly optimizes hadamard interleave/deinterleave
functions.

Signed-off-by: Rostislav Pehlivanov <atomnuker@gmail.com>

Rostislav Pehlivanov authored on 2017/04/21 04:00:25
Showing 3 changed files
... ...
@@ -33,7 +33,7 @@ static inline int16_t celt_cos(int16_t x)
33 33
 {
34 34
     x = (MUL16(x, x) + 4096) >> 13;
35 35
     x = (32767-x) + ROUND_MUL16(x, (-7651 + ROUND_MUL16(x, (8277 + ROUND_MUL16(-626, x)))));
36
-    return 1+x;
36
+    return x + 1;
37 37
 }
38 38
 
39 39
 static inline int celt_log2tan(int isin, int icos)
... ...
@@ -163,7 +163,7 @@ static inline uint32_t celt_extract_collapse_mask(const int *iy, uint32_t N, uin
163 163
     collapse_mask = 0;
164 164
     for (i = 0; i < B; i++)
165 165
         for (j = 0; j < N0; j++)
166
-            collapse_mask |= (iy[i*N0+j]!=0)<<i;
166
+            collapse_mask |= (!!iy[i*N0+j]) << i;
167 167
     return collapse_mask;
168 168
 }
169 169
 
... ...
@@ -173,7 +173,7 @@ static inline void celt_stereo_merge(float *X, float *Y, float mid, int N)
173 173
     float xp = 0, side = 0;
174 174
     float E[2];
175 175
     float mid2;
176
-    float t, gain[2];
176
+    float gain[2];
177 177
 
178 178
     /* Compute the norm of X+Y and X-Y as |X|^2 + |Y|^2 +/- sum(xy) */
179 179
     for (i = 0; i < N; i++) {
... ...
@@ -192,10 +192,8 @@ static inline void celt_stereo_merge(float *X, float *Y, float mid, int N)
192 192
         return;
193 193
     }
194 194
 
195
-    t = E[0];
196
-    gain[0] = 1.0f / sqrtf(t);
197
-    t = E[1];
198
-    gain[1] = 1.0f / sqrtf(t);
195
+    gain[0] = 1.0f / sqrtf(E[0]);
196
+    gain[1] = 1.0f / sqrtf(E[1]);
199 197
 
200 198
     for (i = 0; i < N; i++) {
201 199
         float value[2];
... ...
@@ -210,43 +208,27 @@ static inline void celt_stereo_merge(float *X, float *Y, float mid, int N)
210 210
 static void celt_interleave_hadamard(float *tmp, float *X, int N0,
211 211
                                      int stride, int hadamard)
212 212
 {
213
-    int i, j;
214
-    int N = N0*stride;
213
+    int i, j, N = N0*stride;
214
+    const uint8_t *order = &ff_celt_hadamard_order[hadamard ? stride - 2 : 30];
215 215
 
216
-    if (hadamard) {
217
-        const uint8_t *ordery = ff_celt_hadamard_ordery + stride - 2;
218
-        for (i = 0; i < stride; i++)
219
-            for (j = 0; j < N0; j++)
220
-                tmp[j*stride+i] = X[ordery[i]*N0+j];
221
-    } else {
222
-        for (i = 0; i < stride; i++)
223
-            for (j = 0; j < N0; j++)
224
-                tmp[j*stride+i] = X[i*N0+j];
225
-    }
216
+    for (i = 0; i < stride; i++)
217
+        for (j = 0; j < N0; j++)
218
+            tmp[j*stride+i] = X[order[i]*N0+j];
226 219
 
227
-    for (i = 0; i < N; i++)
228
-        X[i] = tmp[i];
220
+    memcpy(X, tmp, N*sizeof(float));
229 221
 }
230 222
 
231 223
 static void celt_deinterleave_hadamard(float *tmp, float *X, int N0,
232 224
                                        int stride, int hadamard)
233 225
 {
234
-    int i, j;
235
-    int N = N0*stride;
226
+    int i, j, N = N0*stride;
227
+    const uint8_t *order = &ff_celt_hadamard_order[hadamard ? stride - 2 : 30];
236 228
 
237
-    if (hadamard) {
238
-        const uint8_t *ordery = ff_celt_hadamard_ordery + stride - 2;
239
-        for (i = 0; i < stride; i++)
240
-            for (j = 0; j < N0; j++)
241
-                tmp[ordery[i]*N0+j] = X[j*stride+i];
242
-    } else {
243
-        for (i = 0; i < stride; i++)
244
-            for (j = 0; j < N0; j++)
245
-                tmp[i*N0+j] = X[j*stride+i];
246
-    }
229
+    for (i = 0; i < stride; i++)
230
+        for (j = 0; j < N0; j++)
231
+            tmp[order[i]*N0+j] = X[j*stride+i];
247 232
 
248
-    for (i = 0; i < N; i++)
249
-        X[i] = tmp[i];
233
+    memcpy(X, tmp, N*sizeof(float));
250 234
 }
251 235
 
252 236
 static void celt_haar1(float *X, int N0, int stride)
... ...
@@ -264,11 +246,11 @@ static void celt_haar1(float *X, int N0, int stride)
264 264
 }
265 265
 
266 266
 static inline int celt_compute_qn(int N, int b, int offset, int pulse_cap,
267
-                                  int dualstereo)
267
+                                  int stereo)
268 268
 {
269 269
     int qn, qb;
270 270
     int N2 = 2 * N - 1;
271
-    if (dualstereo && N == 2)
271
+    if (stereo && N == 2)
272 272
         N2--;
273 273
 
274 274
     /* The upper limit ensures that in a stereo split with itheta==16384, we'll
... ...
@@ -471,12 +453,13 @@ uint32_t ff_celt_decode_band(CeltFrame *f, OpusRangeCoder *rc, const int band,
471 471
                              float *lowband, int duration, float *lowband_out, int level,
472 472
                              float gain, float *lowband_scratch, int fill)
473 473
 {
474
+    int i;
474 475
     const uint8_t *cache;
475
-    int dualstereo, split;
476
+    int stereo = !!Y, split = !!Y;
476 477
     int imid = 0, iside = 0;
477 478
     uint32_t N0 = N;
478
-    int N_B;
479
-    int N_B0;
479
+    int N_B = N / blocks;
480
+    int N_B0 = N_B;
480 481
     int B0 = blocks;
481 482
     int time_divide = 0;
482 483
     int recombine = 0;
... ...
@@ -485,14 +468,10 @@ uint32_t ff_celt_decode_band(CeltFrame *f, OpusRangeCoder *rc, const int band,
485 485
     int longblocks = (B0 == 1);
486 486
     uint32_t cm = 0;
487 487
 
488
-    N_B0 = N_B = N / blocks;
489
-    split = dualstereo = (Y != NULL);
490
-
491 488
     if (N == 1) {
492 489
         /* special case for one sample */
493
-        int i;
494 490
         float *x = X;
495
-        for (i = 0; i <= dualstereo; i++) {
491
+        for (i = 0; i <= stereo; i++) {
496 492
             int sign = 0;
497 493
             if (f->remaining2 >= 1<<3) {
498 494
                 sign           = ff_opus_rc_get_raw(rc, 1);
... ...
@@ -507,7 +486,7 @@ uint32_t ff_celt_decode_band(CeltFrame *f, OpusRangeCoder *rc, const int band,
507 507
         return 1;
508 508
     }
509 509
 
510
-    if (!dualstereo && level == 0) {
510
+    if (!stereo && level == 0) {
511 511
         int tf_change = f->tf_change[band];
512 512
         int k;
513 513
         if (tf_change > 0)
... ...
@@ -516,9 +495,8 @@ uint32_t ff_celt_decode_band(CeltFrame *f, OpusRangeCoder *rc, const int band,
516 516
 
517 517
         if (lowband &&
518 518
             (recombine || ((N_B & 1) == 0 && tf_change < 0) || B0 > 1)) {
519
-            int j;
520
-            for (j = 0; j < N; j++)
521
-                lowband_scratch[j] = lowband[j];
519
+            for (i = 0; i < N; i++)
520
+                lowband_scratch[i] = lowband[i];
522 521
             lowband = lowband_scratch;
523 522
         }
524 523
 
... ...
@@ -552,7 +530,7 @@ uint32_t ff_celt_decode_band(CeltFrame *f, OpusRangeCoder *rc, const int band,
552 552
     /* If we need 1.5 more bit than we can produce, split the band in two. */
553 553
     cache = ff_celt_cache_bits +
554 554
             ff_celt_cache_index[(duration + 1) * CELT_MAX_BANDS + band];
555
-    if (!dualstereo && duration >= 0 && b > cache[cache[0]] + 12 && N > 2) {
555
+    if (!stereo && duration >= 0 && b > cache[cache[0]] + 12 && N > 2) {
556 556
         N >>= 1;
557 557
         Y = X + N;
558 558
         split = 1;
... ...
@@ -574,24 +552,24 @@ uint32_t ff_celt_decode_band(CeltFrame *f, OpusRangeCoder *rc, const int band,
574 574
 
575 575
         /* Decide on the resolution to give to the split parameter theta */
576 576
         pulse_cap = ff_celt_log_freq_range[band] + duration * 8;
577
-        offset = (pulse_cap >> 1) - (dualstereo && N == 2 ? CELT_QTHETA_OFFSET_TWOPHASE :
577
+        offset = (pulse_cap >> 1) - (stereo && N == 2 ? CELT_QTHETA_OFFSET_TWOPHASE :
578 578
                                                           CELT_QTHETA_OFFSET);
579
-        qn = (dualstereo && band >= f->intensity_stereo) ? 1 :
580
-             celt_compute_qn(N, b, offset, pulse_cap, dualstereo);
579
+        qn = (stereo && band >= f->intensity_stereo) ? 1 :
580
+             celt_compute_qn(N, b, offset, pulse_cap, stereo);
581 581
         tell = opus_rc_tell_frac(rc);
582 582
         if (qn != 1) {
583 583
             /* Entropy coding of the angle. We use a uniform pdf for the
584 584
             time split, a step for stereo, and a triangular one for the rest. */
585
-            if (dualstereo && N > 2)
585
+            if (stereo && N > 2)
586 586
                 itheta = ff_opus_rc_dec_uint_step(rc, qn/2);
587
-            else if (dualstereo || B0 > 1)
587
+            else if (stereo || B0 > 1)
588 588
                 itheta = ff_opus_rc_dec_uint(rc, qn+1);
589 589
             else
590 590
                 itheta = ff_opus_rc_dec_uint_tri(rc, qn);
591 591
             itheta = itheta * 16384 / qn;
592 592
             /* NOTE: Renormalising X and Y *may* help fixed-point a bit at very high rate.
593 593
             Let's do that at higher complexity */
594
-        } else if (dualstereo) {
594
+        } else if (stereo) {
595 595
             inv = (b > 2 << 3 && f->remaining2 > 2 << 3) ? ff_opus_rc_dec_log(rc, 2) : 0;
596 596
             itheta = 0;
597 597
         }
... ...
@@ -623,7 +601,7 @@ uint32_t ff_celt_decode_band(CeltFrame *f, OpusRangeCoder *rc, const int band,
623 623
         /* This is a special case for N=2 that only works for stereo and takes
624 624
         advantage of the fact that mid and side are orthogonal to encode
625 625
         the side with just one bit. */
626
-        if (N == 2 && dualstereo) {
626
+        if (N == 2 && stereo) {
627 627
             int c;
628 628
             int sign = 0;
629 629
             float tmp;
... ...
@@ -668,7 +646,7 @@ uint32_t ff_celt_decode_band(CeltFrame *f, OpusRangeCoder *rc, const int band,
668 668
 
669 669
             /* Give more bits to low-energy MDCTs than they would
670 670
              * otherwise deserve */
671
-            if (B0 > 1 && !dualstereo && (itheta & 0x3fff)) {
671
+            if (B0 > 1 && !stereo && (itheta & 0x3fff)) {
672 672
                 if (itheta > 8192)
673 673
                     /* Rough approximation for pre-echo masking */
674 674
                     delta -= delta >> (4 - duration);
... ...
@@ -681,12 +659,12 @@ uint32_t ff_celt_decode_band(CeltFrame *f, OpusRangeCoder *rc, const int band,
681 681
             sbits = b - mbits;
682 682
             f->remaining2 -= qalloc;
683 683
 
684
-            if (lowband && !dualstereo)
684
+            if (lowband && !stereo)
685 685
                 next_lowband2 = lowband + N; /* >32-bit split case */
686 686
 
687 687
             /* Only stereo needs to pass on lowband_out.
688 688
              * Otherwise, it's handled at the end */
689
-            if (dualstereo)
689
+            if (stereo)
690 690
                 next_lowband_out1 = lowband_out;
691 691
             else
692 692
                 next_level = level + 1;
... ...
@@ -697,7 +675,7 @@ uint32_t ff_celt_decode_band(CeltFrame *f, OpusRangeCoder *rc, const int band,
697 697
                  * because we need the normalized mid for folding later */
698 698
                 cm = ff_celt_decode_band(f, rc, band, X, NULL, N, mbits, blocks,
699 699
                                          lowband, duration, next_lowband_out1,
700
-                                         next_level, dualstereo ? 1.0f : (gain * mid),
700
+                                         next_level, stereo ? 1.0f : (gain * mid),
701 701
                                          lowband_scratch, fill);
702 702
 
703 703
                 rebalance = mbits - (rebalance - f->remaining2);
... ...
@@ -709,14 +687,14 @@ uint32_t ff_celt_decode_band(CeltFrame *f, OpusRangeCoder *rc, const int band,
709 709
                 cm |= ff_celt_decode_band(f, rc, band, Y, NULL, N, sbits, blocks,
710 710
                                           next_lowband2, duration, NULL,
711 711
                                           next_level, gain * side, NULL,
712
-                                          fill >> blocks) << ((B0 >> 1) & (dualstereo - 1));
712
+                                          fill >> blocks) << ((B0 >> 1) & (stereo - 1));
713 713
             } else {
714 714
                 /* For a stereo split, the high bits of fill are always zero,
715 715
                  * so no folding will be done to the side. */
716 716
                 cm = ff_celt_decode_band(f, rc, band, Y, NULL, N, sbits, blocks,
717 717
                                          next_lowband2, duration, NULL,
718 718
                                          next_level, gain * side, NULL,
719
-                                         fill >> blocks) << ((B0 >> 1) & (dualstereo - 1));
719
+                                         fill >> blocks) << ((B0 >> 1) & (stereo - 1));
720 720
 
721 721
                 rebalance = sbits - (rebalance - f->remaining2);
722 722
                 if (rebalance > 3 << 3 && itheta != 16384)
... ...
@@ -726,7 +704,7 @@ uint32_t ff_celt_decode_band(CeltFrame *f, OpusRangeCoder *rc, const int band,
726 726
                  * we need the normalized mid for folding later */
727 727
                 cm |= ff_celt_decode_band(f, rc, band, X, NULL, N, mbits, blocks,
728 728
                                           lowband, duration, next_lowband_out1,
729
-                                          next_level, dualstereo ? 1.0f : (gain * mid),
729
+                                          next_level, stereo ? 1.0f : (gain * mid),
730 730
                                           lowband_scratch, fill);
731 731
             }
732 732
         }
... ...
@@ -749,47 +727,44 @@ uint32_t ff_celt_decode_band(CeltFrame *f, OpusRangeCoder *rc, const int band,
749 749
                                   f->spread, blocks, gain);
750 750
         } else {
751 751
             /* If there's no pulse, fill the band anyway */
752
-            int j;
753 752
             uint32_t cm_mask = (1 << blocks) - 1;
754 753
             fill &= cm_mask;
755
-            if (!fill) {
756
-                for (j = 0; j < N; j++)
757
-                    X[j] = 0.0f;
758
-            } else {
754
+            if (fill) {
759 755
                 if (!lowband) {
760 756
                     /* Noise */
761
-                    for (j = 0; j < N; j++)
762
-                        X[j] = (((int32_t)celt_rng(f)) >> 20);
757
+                    for (i = 0; i < N; i++)
758
+                        X[i] = (((int32_t)celt_rng(f)) >> 20);
763 759
                     cm = cm_mask;
764 760
                 } else {
765 761
                     /* Folded spectrum */
766
-                    for (j = 0; j < N; j++) {
762
+                    for (i = 0; i < N; i++) {
767 763
                         /* About 48 dB below the "normal" folding level */
768
-                        X[j] = lowband[j] + (((celt_rng(f)) & 0x8000) ? 1.0f / 256 : -1.0f / 256);
764
+                        X[i] = lowband[i] + (((celt_rng(f)) & 0x8000) ? 1.0f / 256 : -1.0f / 256);
769 765
                     }
770 766
                     cm = fill;
771 767
                 }
772 768
                 celt_renormalize_vector(X, N, gain);
769
+            } else {
770
+                memset(X, 0, N*sizeof(float));
773 771
             }
774 772
         }
775 773
     }
776 774
 
777 775
     /* This code is used by the decoder and by the resynthesis-enabled encoder */
778
-    if (dualstereo) {
779
-        int j;
780
-        if (N != 2)
776
+    if (stereo) {
777
+        if (N > 2)
781 778
             celt_stereo_merge(X, Y, mid, N);
782 779
         if (inv) {
783
-            for (j = 0; j < N; j++)
784
-                Y[j] *= -1;
780
+            for (i = 0; i < N; i++)
781
+                Y[i] *= -1;
785 782
         }
786 783
     } else if (level == 0) {
787 784
         int k;
788 785
 
789 786
         /* Undo the sample reorganization going from time order to frequency order */
790 787
         if (B0 > 1)
791
-            celt_interleave_hadamard(f->scratch, X, N_B>>recombine,
792
-                                     B0<<recombine, longblocks);
788
+            celt_interleave_hadamard(f->scratch, X, N_B >> recombine,
789
+                                     B0 << recombine, longblocks);
793 790
 
794 791
         /* Undo time-freq changes that we did earlier */
795 792
         N_B = N_B0;
... ...
@@ -809,10 +784,9 @@ uint32_t ff_celt_decode_band(CeltFrame *f, OpusRangeCoder *rc, const int band,
809 809
 
810 810
         /* Scale output for later folding */
811 811
         if (lowband_out) {
812
-            int j;
813 812
             float n = sqrtf(N0);
814
-            for (j = 0; j < N0; j++)
815
-                lowband_out[j] = n * X[j];
813
+            for (i = 0; i < N0; i++)
814
+                lowband_out[i] = n * X[i];
816 815
         }
817 816
         cm = av_mod_uintp2(cm, blocks);
818 817
     }
... ...
@@ -824,15 +798,17 @@ uint32_t ff_celt_decode_band(CeltFrame *f, OpusRangeCoder *rc, const int band,
824 824
  * big impact on the entire quantization and especially huge on transients */
825 825
 static int celt_calc_theta(const float *X, const float *Y, int coupling, int N)
826 826
 {
827
-    int j;
827
+    int i;
828 828
     float e[2] = { 0.0f, 0.0f };
829
-    for (j = 0; j < N; j++) {
830
-        if (coupling) { /* Coupling case */
831
-            e[0] += (X[j] + Y[j])*(X[j] + Y[j]);
832
-            e[1] += (X[j] - Y[j])*(X[j] - Y[j]);
833
-        } else {
834
-            e[0] += X[j]*X[j];
835
-            e[1] += Y[j]*Y[j];
829
+    if (coupling) { /* Coupling case */
830
+        for (i = 0; i < N; i++) {
831
+            e[0] += (X[i] + Y[i])*(X[i] + Y[i]);
832
+            e[1] += (X[i] - Y[i])*(X[i] - Y[i]);
833
+        }
834
+    } else {
835
+        for (i = 0; i < N; i++) {
836
+            e[0] += X[i]*X[i];
837
+            e[1] += Y[i]*Y[i];
836 838
         }
837 839
     }
838 840
     return lrintf(32768.0f*atan2f(sqrtf(e[1]), sqrtf(e[0]))/M_PI);
... ...
@@ -851,11 +827,10 @@ static void celt_stereo_is_decouple(float *X, float *Y, float e_l, float e_r, in
851 851
 static void celt_stereo_ms_decouple(float *X, float *Y, int N)
852 852
 {
853 853
     int i;
854
-    const float decouple_norm = 1.0f/sqrtf(1.0f + 1.0f);
855 854
     for (i = 0; i < N; i++) {
856 855
         const float Xret = X[i];
857
-        X[i] = (X[i] + Y[i])*decouple_norm;
858
-        Y[i] = (Y[i] - Xret)*decouple_norm;
856
+        X[i] = (X[i] + Y[i])*M_SQRT1_2;
857
+        Y[i] = (Y[i] - Xret)*M_SQRT1_2;
859 858
     }
860 859
 }
861 860
 
... ...
@@ -864,8 +839,9 @@ uint32_t ff_celt_encode_band(CeltFrame *f, OpusRangeCoder *rc, const int band,
864 864
                              float *lowband, int duration, float *lowband_out, int level,
865 865
                              float gain, float *lowband_scratch, int fill)
866 866
 {
867
+    int i;
867 868
     const uint8_t *cache;
868
-    int dualstereo, split;
869
+    int stereo = !!Y, split = !!Y;
869 870
     int imid = 0, iside = 0;
870 871
     uint32_t N0 = N;
871 872
     int N_B = N / blocks;
... ...
@@ -878,13 +854,10 @@ uint32_t ff_celt_encode_band(CeltFrame *f, OpusRangeCoder *rc, const int band,
878 878
     int longblocks = (B0 == 1);
879 879
     uint32_t cm = 0;
880 880
 
881
-    split = dualstereo = (Y != NULL);
882
-
883 881
     if (N == 1) {
884 882
         /* special case for one sample - the decoder's output will be +- 1.0f!!! */
885
-        int i;
886 883
         float *x = X;
887
-        for (i = 0; i <= dualstereo; i++) {
884
+        for (i = 0; i <= stereo; i++) {
888 885
             if (f->remaining2 >= 1<<3) {
889 886
                 ff_opus_rc_put_raw(rc, x[0] < 0, 1);
890 887
                 f->remaining2 -= 1 << 3;
... ...
@@ -898,7 +871,7 @@ uint32_t ff_celt_encode_band(CeltFrame *f, OpusRangeCoder *rc, const int band,
898 898
         return 1;
899 899
     }
900 900
 
901
-    if (!dualstereo && level == 0) {
901
+    if (!stereo && level == 0) {
902 902
         int tf_change = f->tf_change[band];
903 903
         int k;
904 904
         if (tf_change > 0)
... ...
@@ -907,9 +880,8 @@ uint32_t ff_celt_encode_band(CeltFrame *f, OpusRangeCoder *rc, const int band,
907 907
 
908 908
         if (lowband &&
909 909
             (recombine || ((N_B & 1) == 0 && tf_change < 0) || B0 > 1)) {
910
-            int j;
911
-            for (j = 0; j < N; j++)
912
-                lowband_scratch[j] = lowband[j];
910
+            for (i = 0; i < N; i++)
911
+                lowband_scratch[i] = lowband[i];
913 912
             lowband = lowband_scratch;
914 913
         }
915 914
 
... ...
@@ -941,7 +913,7 @@ uint32_t ff_celt_encode_band(CeltFrame *f, OpusRangeCoder *rc, const int band,
941 941
     /* If we need 1.5 more bit than we can produce, split the band in two. */
942 942
     cache = ff_celt_cache_bits +
943 943
             ff_celt_cache_index[(duration + 1) * CELT_MAX_BANDS + band];
944
-    if (!dualstereo && duration >= 0 && b > cache[cache[0]] + 12 && N > 2) {
944
+    if (!stereo && duration >= 0 && b > cache[cache[0]] + 12 && N > 2) {
945 945
         N >>= 1;
946 946
         Y = X + N;
947 947
         split = 1;
... ...
@@ -953,7 +925,7 @@ uint32_t ff_celt_encode_band(CeltFrame *f, OpusRangeCoder *rc, const int band,
953 953
 
954 954
     if (split) {
955 955
         int qn;
956
-        int itheta = celt_calc_theta(X, Y, dualstereo, N);
956
+        int itheta = celt_calc_theta(X, Y, stereo, N);
957 957
         int mbits, sbits, delta;
958 958
         int qalloc;
959 959
         int pulse_cap;
... ...
@@ -963,10 +935,10 @@ uint32_t ff_celt_encode_band(CeltFrame *f, OpusRangeCoder *rc, const int band,
963 963
 
964 964
         /* Decide on the resolution to give to the split parameter theta */
965 965
         pulse_cap = ff_celt_log_freq_range[band] + duration * 8;
966
-        offset = (pulse_cap >> 1) - (dualstereo && N == 2 ? CELT_QTHETA_OFFSET_TWOPHASE :
966
+        offset = (pulse_cap >> 1) - (stereo && N == 2 ? CELT_QTHETA_OFFSET_TWOPHASE :
967 967
                                                           CELT_QTHETA_OFFSET);
968
-        qn = (dualstereo && band >= f->intensity_stereo) ? 1 :
969
-             celt_compute_qn(N, b, offset, pulse_cap, dualstereo);
968
+        qn = (stereo && band >= f->intensity_stereo) ? 1 :
969
+             celt_compute_qn(N, b, offset, pulse_cap, stereo);
970 970
         tell = opus_rc_tell_frac(rc);
971 971
 
972 972
         if (qn != 1) {
... ...
@@ -975,27 +947,26 @@ uint32_t ff_celt_encode_band(CeltFrame *f, OpusRangeCoder *rc, const int band,
975 975
 
976 976
             /* Entropy coding of the angle. We use a uniform pdf for the
977 977
              * time split, a step for stereo, and a triangular one for the rest. */
978
-            if (dualstereo && N > 2)
978
+            if (stereo && N > 2)
979 979
                 ff_opus_rc_enc_uint_step(rc, itheta, qn / 2);
980
-            else if (dualstereo || B0 > 1)
980
+            else if (stereo || B0 > 1)
981 981
                 ff_opus_rc_enc_uint(rc, itheta, qn + 1);
982 982
             else
983 983
                 ff_opus_rc_enc_uint_tri(rc, itheta, qn);
984 984
             itheta = itheta * 16384 / qn;
985 985
 
986
-            if (dualstereo) {
986
+            if (stereo) {
987 987
                 if (itheta == 0)
988 988
                     celt_stereo_is_decouple(X, Y, f->block[0].lin_energy[band],
989 989
                                             f->block[1].lin_energy[band], N);
990 990
                 else
991 991
                     celt_stereo_ms_decouple(X, Y, N);
992 992
             }
993
-        } else if (dualstereo) {
993
+        } else if (stereo) {
994 994
              inv = itheta > 8192;
995 995
              if (inv) {
996
-                int j;
997
-                for (j = 0; j < N; j++)
998
-                   Y[j] = -Y[j];
996
+                for (i = 0; i < N; i++)
997
+                   Y[i] *= -1;
999 998
              }
1000 999
              celt_stereo_is_decouple(X, Y, f->block[0].lin_energy[band],
1001 1000
                                      f->block[1].lin_energy[band], N);
... ...
@@ -1036,7 +1007,7 @@ uint32_t ff_celt_encode_band(CeltFrame *f, OpusRangeCoder *rc, const int band,
1036 1036
         /* This is a special case for N=2 that only works for stereo and takes
1037 1037
         advantage of the fact that mid and side are orthogonal to encode
1038 1038
         the side with just one bit. */
1039
-        if (N == 2 && dualstereo) {
1039
+        if (N == 2 && stereo) {
1040 1040
             int c;
1041 1041
             int sign = 0;
1042 1042
             float tmp;
... ...
@@ -1083,7 +1054,7 @@ uint32_t ff_celt_encode_band(CeltFrame *f, OpusRangeCoder *rc, const int band,
1083 1083
 
1084 1084
             /* Give more bits to low-energy MDCTs than they would
1085 1085
              * otherwise deserve */
1086
-            if (B0 > 1 && !dualstereo && (itheta & 0x3fff)) {
1086
+            if (B0 > 1 && !stereo && (itheta & 0x3fff)) {
1087 1087
                 if (itheta > 8192)
1088 1088
                     /* Rough approximation for pre-echo masking */
1089 1089
                     delta -= delta >> (4 - duration);
... ...
@@ -1096,12 +1067,12 @@ uint32_t ff_celt_encode_band(CeltFrame *f, OpusRangeCoder *rc, const int band,
1096 1096
             sbits = b - mbits;
1097 1097
             f->remaining2 -= qalloc;
1098 1098
 
1099
-            if (lowband && !dualstereo)
1099
+            if (lowband && !stereo)
1100 1100
                 next_lowband2 = lowband + N; /* >32-bit split case */
1101 1101
 
1102 1102
             /* Only stereo needs to pass on lowband_out.
1103 1103
              * Otherwise, it's handled at the end */
1104
-            if (dualstereo)
1104
+            if (stereo)
1105 1105
                 next_lowband_out1 = lowband_out;
1106 1106
             else
1107 1107
                 next_level = level + 1;
... ...
@@ -1112,7 +1083,7 @@ uint32_t ff_celt_encode_band(CeltFrame *f, OpusRangeCoder *rc, const int band,
1112 1112
                  * because we need the normalized mid for folding later */
1113 1113
                 cm = ff_celt_encode_band(f, rc, band, X, NULL, N, mbits, blocks,
1114 1114
                                          lowband, duration, next_lowband_out1,
1115
-                                         next_level, dualstereo ? 1.0f : (gain * mid),
1115
+                                         next_level, stereo ? 1.0f : (gain * mid),
1116 1116
                                          lowband_scratch, fill);
1117 1117
 
1118 1118
                 rebalance = mbits - (rebalance - f->remaining2);
... ...
@@ -1124,14 +1095,14 @@ uint32_t ff_celt_encode_band(CeltFrame *f, OpusRangeCoder *rc, const int band,
1124 1124
                 cm |= ff_celt_encode_band(f, rc, band, Y, NULL, N, sbits, blocks,
1125 1125
                                           next_lowband2, duration, NULL,
1126 1126
                                           next_level, gain * side, NULL,
1127
-                                          fill >> blocks) << ((B0 >> 1) & (dualstereo - 1));
1127
+                                          fill >> blocks) << ((B0 >> 1) & (stereo - 1));
1128 1128
             } else {
1129 1129
                 /* For a stereo split, the high bits of fill are always zero,
1130 1130
                  * so no folding will be done to the side. */
1131 1131
                 cm = ff_celt_encode_band(f, rc, band, Y, NULL, N, sbits, blocks,
1132 1132
                                          next_lowband2, duration, NULL,
1133 1133
                                          next_level, gain * side, NULL,
1134
-                                         fill >> blocks) << ((B0 >> 1) & (dualstereo - 1));
1134
+                                         fill >> blocks) << ((B0 >> 1) & (stereo - 1));
1135 1135
 
1136 1136
                 rebalance = sbits - (rebalance - f->remaining2);
1137 1137
                 if (rebalance > 3 << 3 && itheta != 16384)
... ...
@@ -1141,7 +1112,7 @@ uint32_t ff_celt_encode_band(CeltFrame *f, OpusRangeCoder *rc, const int band,
1141 1141
                  * we need the normalized mid for folding later */
1142 1142
                 cm |= ff_celt_encode_band(f, rc, band, X, NULL, N, mbits, blocks,
1143 1143
                                           lowband, duration, next_lowband_out1,
1144
-                                          next_level, dualstereo ? 1.0f : (gain * mid),
1144
+                                          next_level, stereo ? 1.0f : (gain * mid),
1145 1145
                                           lowband_scratch, fill);
1146 1146
             }
1147 1147
         }
... ...
@@ -1164,39 +1135,36 @@ uint32_t ff_celt_encode_band(CeltFrame *f, OpusRangeCoder *rc, const int band,
1164 1164
                                 f->spread, blocks, gain);
1165 1165
         } else {
1166 1166
             /* If there's no pulse, fill the band anyway */
1167
-            int j;
1168 1167
             uint32_t cm_mask = (1 << blocks) - 1;
1169 1168
             fill &= cm_mask;
1170
-            if (!fill) {
1171
-                for (j = 0; j < N; j++)
1172
-                    X[j] = 0.0f;
1173
-            } else {
1169
+            if (fill) {
1174 1170
                 if (!lowband) {
1175 1171
                     /* Noise */
1176
-                    for (j = 0; j < N; j++)
1177
-                        X[j] = (((int32_t)celt_rng(f)) >> 20);
1172
+                    for (i = 0; i < N; i++)
1173
+                        X[i] = (((int32_t)celt_rng(f)) >> 20);
1178 1174
                     cm = cm_mask;
1179 1175
                 } else {
1180 1176
                     /* Folded spectrum */
1181
-                    for (j = 0; j < N; j++) {
1177
+                    for (i = 0; i < N; i++) {
1182 1178
                         /* About 48 dB below the "normal" folding level */
1183
-                        X[j] = lowband[j] + (((celt_rng(f)) & 0x8000) ? 1.0f / 256 : -1.0f / 256);
1179
+                        X[i] = lowband[i] + (((celt_rng(f)) & 0x8000) ? 1.0f / 256 : -1.0f / 256);
1184 1180
                     }
1185 1181
                     cm = fill;
1186 1182
                 }
1187 1183
                 celt_renormalize_vector(X, N, gain);
1184
+            } else {
1185
+                memset(X, 0, N*sizeof(float));
1188 1186
             }
1189 1187
         }
1190 1188
     }
1191 1189
 
1192 1190
     /* This code is used by the decoder and by the resynthesis-enabled encoder */
1193
-    if (dualstereo) {
1194
-        int j;
1195
-        if (N != 2)
1191
+    if (stereo) {
1192
+        if (N > 2)
1196 1193
             celt_stereo_merge(X, Y, mid, N);
1197 1194
         if (inv) {
1198
-            for (j = 0; j < N; j++)
1199
-                Y[j] *= -1;
1195
+            for (i = 0; i < N; i++)
1196
+                Y[i] *= -1;
1200 1197
         }
1201 1198
     } else if (level == 0) {
1202 1199
         int k;
... ...
@@ -1204,7 +1172,7 @@ uint32_t ff_celt_encode_band(CeltFrame *f, OpusRangeCoder *rc, const int band,
1204 1204
         /* Undo the sample reorganization going from time order to frequency order */
1205 1205
         if (B0 > 1)
1206 1206
             celt_interleave_hadamard(f->scratch, X, N_B >> recombine,
1207
-                                     B0<<recombine, longblocks);
1207
+                                     B0 << recombine, longblocks);
1208 1208
 
1209 1209
         /* Undo time-freq changes that we did earlier */
1210 1210
         N_B = N_B0;
... ...
@@ -1224,10 +1192,9 @@ uint32_t ff_celt_encode_band(CeltFrame *f, OpusRangeCoder *rc, const int band,
1224 1224
 
1225 1225
         /* Scale output for later folding */
1226 1226
         if (lowband_out) {
1227
-            int j;
1228 1227
             float n = sqrtf(N0);
1229
-            for (j = 0; j < N0; j++)
1230
-                lowband_out[j] = n * X[j];
1228
+            for (i = 0; i < N0; i++)
1229
+                lowband_out[i] = n * X[i];
1231 1230
         }
1232 1231
         cm = av_mod_uintp2(cm, blocks);
1233 1232
     }
... ...
@@ -930,11 +930,12 @@ const uint8_t ff_celt_bit_deinterleave[] = {
930 930
     0xC0, 0xC3, 0xCC, 0xCF, 0xF0, 0xF3, 0xFC, 0xFF
931 931
 };
932 932
 
933
-const uint8_t ff_celt_hadamard_ordery[] = {
933
+const uint8_t ff_celt_hadamard_order[] = {
934 934
     1,   0,
935 935
     3,   0,  2,  1,
936 936
     7,   0,  4,  3,  6,  1,  5,  2,
937
-    15,  0,  8,  7, 12,  3, 11,  4, 14,  1,  9,  6, 13,  2, 10,  5
937
+    15,  0,  8,  7, 12,  3, 11,  4, 14,  1,  9,  6, 13,  2, 10,  5,
938
+    0,   1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15
938 939
 };
939 940
 
940 941
 const uint16_t ff_celt_qn_exp2[] = {
... ...
@@ -146,7 +146,7 @@ extern const uint8_t  ff_celt_log2_frac[];
146 146
 extern const uint8_t  ff_celt_bit_interleave[];
147 147
 extern const uint8_t  ff_celt_bit_deinterleave[];
148 148
 
149
-extern const uint8_t  ff_celt_hadamard_ordery[];
149
+extern const uint8_t  ff_celt_hadamard_order[];
150 150
 
151 151
 extern const uint16_t ff_celt_qn_exp2[];
152 152
 extern const uint32_t ff_celt_pvq_u[1272];