@@ -687,6 +687,46 @@ static int ec_dec_depth(ec_dec *dec, opus_int32 cap, opus_int32 *last) {
687
687
return depth ;
688
688
}
689
689
690
+ #define MSWAP16 (a ,b ) do {opus_val16 tmp = a;a=b;b=tmp;} while(0)
691
+ static opus_val16 median_of_5_val16 (const opus_val16 * x )
692
+ {
693
+ opus_val16 t0 , t1 , t2 , t3 , t4 ;
694
+ t2 = x [2 ];
695
+ if (x [0 ] > x [1 ])
696
+ {
697
+ t0 = x [1 ];
698
+ t1 = x [0 ];
699
+ } else {
700
+ t0 = x [0 ];
701
+ t1 = x [1 ];
702
+ }
703
+ if (x [3 ] > x [4 ])
704
+ {
705
+ t3 = x [4 ];
706
+ t4 = x [3 ];
707
+ } else {
708
+ t3 = x [3 ];
709
+ t4 = x [4 ];
710
+ }
711
+ if (t0 > t3 )
712
+ {
713
+ MSWAP16 (t0 , t3 );
714
+ MSWAP16 (t1 , t4 );
715
+ }
716
+ if (t2 > t1 )
717
+ {
718
+ if (t1 < t3 )
719
+ return MIN16 (t2 , t3 );
720
+ else
721
+ return MIN16 (t4 , t1 );
722
+ } else {
723
+ if (t2 < t3 )
724
+ return MIN16 (t1 , t3 );
725
+ else
726
+ return MIN16 (t2 , t4 );
727
+ }
728
+ }
729
+
690
730
void clt_compute_extra_allocation (const CELTMode * m , const CELTMode * qext_mode , int start , int end , int qext_end , const celt_glog * bandLogE , const celt_glog * qext_bandLogE ,
691
731
opus_int32 total , int * extra_pulses , int * extra_equant , int C , int LM , ec_ctx * ec , int encode , opus_val16 tone_freq , opus_val32 toneishness )
692
732
{
@@ -723,6 +763,7 @@ void clt_compute_extra_allocation(const CELTMode *m, const CELTMode *qext_mode,
723
763
VARDECL (opus_val16 , flatE );
724
764
VARDECL (int , Ncoef );
725
765
VARDECL (opus_val16 , min );
766
+ VARDECL (opus_val16 , follower );
726
767
727
768
ALLOC (flatE , tot_bands , opus_val16 );
728
769
ALLOC (min , tot_bands , opus_val16 );
@@ -758,6 +799,21 @@ void clt_compute_extra_allocation(const CELTMode *m, const CELTMode *qext_mode,
758
799
flatE [end + i ] = MAXG (flatE [end + i ], PSHR32 (qext_bandLogE [NB_QEXT_BANDS + i ] - GCONST (0.0625f )* qext_mode -> logN [i ] + SHL32 (eMeans [i ],DB_SHIFT - 4 ) - GCONST (.0062f )* (end + i + 5 )* (end + i + 5 ), DB_SHIFT - 10 ));
759
800
}
760
801
}
802
+ }
803
+ ALLOC (follower , tot_bands , opus_val16 );
804
+ for (i = start + 2 ;i < tot_bands - 2 ;i ++ ) {
805
+ follower [i ] = median_of_5_val16 (& flatE [i - 2 ]);
806
+ }
807
+ follower [start ] = follower [start + 1 ] = follower [start + 2 ];
808
+ follower [tot_bands - 1 ] = follower [tot_bands - 2 ] = follower [tot_bands - 3 ];
809
+ for (i = start + 1 ;i < tot_bands ;i ++ ) {
810
+ follower [i ] = MAX16 (follower [i ], follower [i - 1 ]- QCONST16 (1.f , 10 ));
811
+ }
812
+ for (i = tot_bands - 2 ;i >=start ;i -- ) {
813
+ follower [i ] = MAX16 (follower [i ], follower [i + 1 ]- QCONST16 (1.f , 10 ));
814
+ }
815
+ for (i = start ;i < tot_bands ;i ++ ) flatE [i ] -= MULT16_16_Q15 (Q15ONE - PSHR32 (toneishness , 14 ), follower [i ]);
816
+ if (qext_mode != NULL ) {
761
817
for (i = 0 ;i < qext_end ;i ++ ) flatE [end + i ] = flatE [end + i ] + QCONST16 (3.f , 10 ) + QCONST16 (.2f , 10 )* i ;
762
818
}
763
819
/* Approximate fill level assuming all bands contribute fully. */
0 commit comments