@@ -1325,9 +1325,44 @@ int celt_encode_with_ec(CELTEncoder * restrict st, const opus_val16 * pcm, int f
13251325 compute_band_energies (st -> mode , freq , bandE , effEnd , C , M );
13261326
13271327 amp2Log2 (st -> mode , effEnd , st -> end , bandE , bandLogE , C );
1328- /*for (i=0;i<17 ;i++)
1328+ /*for (i=0;i<21 ;i++)
13291329 printf("%f ", bandLogE[i]);
13301330 printf("\n");*/
1331+
1332+ ALLOC (bandLogE2 , C * st -> mode -> nbEBands , opus_val16 );
1333+ if (shortBlocks )
1334+ {
1335+ ALLOC (freq2 , C * N , celt_sig );
1336+ compute_mdcts (st -> mode , 0 , in , freq2 , CC , LM );
1337+ if (CC == 2 && C == 1 )
1338+ {
1339+ for (i = 0 ;i < N ;i ++ )
1340+ freq2 [i ] = ADD32 (HALF32 (freq2 [i ]), HALF32 (freq2 [N + i ]));
1341+ }
1342+ if (st -> upsample != 1 )
1343+ {
1344+ c = 0 ; do
1345+ {
1346+ int bound = N /st -> upsample ;
1347+ for (i = 0 ;i < bound ;i ++ )
1348+ freq2 [c * N + i ] *= st -> upsample ;
1349+ for (;i < N ;i ++ )
1350+ freq2 [c * N + i ] = 0 ;
1351+ } while (++ c < C );
1352+ }
1353+ ALLOC (bandE2 , C * st -> mode -> nbEBands , opus_val32 );
1354+ compute_band_energies (st -> mode , freq2 , bandE2 , effEnd , C , M );
1355+ amp2Log2 (st -> mode , effEnd , st -> end , bandE2 , bandLogE2 , C );
1356+ for (i = 0 ;i < C * st -> mode -> nbEBands ;i ++ )
1357+ bandLogE2 [i ] += LM /2. ;
1358+ } else {
1359+ for (i = 0 ;i < C * st -> mode -> nbEBands ;i ++ )
1360+ bandLogE2 [i ] = bandLogE [i ];
1361+ }
1362+ /*for (i=0;i<C*st->mode->nbEBands;i++)
1363+ printf("%f ", MAX16(0,bandLogE[i]-bandLogE2[i]-LM/2.));
1364+ printf("\n");*/
1365+
13311366 {
13321367 opus_val16 follower [42 ]= {0 };
13331368 c = 0 ;do
@@ -1403,11 +1438,11 @@ int celt_encode_with_ec(CELTEncoder * restrict st, const opus_val16 * pcm, int f
14031438 opus_val16 follower [42 ]= {0 };
14041439 c = 0 ;do
14051440 {
1406- follower [c * st -> mode -> nbEBands ] = bandLogE [c * st -> mode -> nbEBands ];
1441+ follower [c * st -> mode -> nbEBands ] = bandLogE2 [c * st -> mode -> nbEBands ];
14071442 for (i = 1 ;i < st -> mode -> nbEBands ;i ++ )
1408- follower [c * st -> mode -> nbEBands + i ] = MIN16 (follower [c * st -> mode -> nbEBands + i - 1 ]+ 2 , bandLogE [c * st -> mode -> nbEBands + i ]);
1443+ follower [c * st -> mode -> nbEBands + i ] = MIN16 (follower [c * st -> mode -> nbEBands + i - 1 ]+ 2 , bandLogE2 [c * st -> mode -> nbEBands + i ]);
14091444 for (i = st -> mode -> nbEBands - 2 ;i >=0 ;i -- )
1410- follower [c * st -> mode -> nbEBands + i ] = MIN16 (follower [c * st -> mode -> nbEBands + i ], MIN16 (follower [c * st -> mode -> nbEBands + i + 1 ]+ 2 , bandLogE [c * st -> mode -> nbEBands + i ]));
1445+ follower [c * st -> mode -> nbEBands + i ] = MIN16 (follower [c * st -> mode -> nbEBands + i ], MIN16 (follower [c * st -> mode -> nbEBands + i + 1 ]+ 2 , bandLogE2 [c * st -> mode -> nbEBands + i ]));
14111446 } while (++ c < 2 );
14121447 if (C == 2 )
14131448 {
@@ -1423,13 +1458,13 @@ int celt_encode_with_ec(CELTEncoder * restrict st, const opus_val16 * pcm, int f
14231458 follower [i ] = MAX16 (0 , bandLogE [i ]- follower [i ]);
14241459 }
14251460 }
1426- opus_val32 tot_boost = effectiveBytes * 8 / 6 ;
1461+ opus_val32 tot_boost = ( effectiveBytes * 8 - 20 - 40 * C )/ 5 ;
14271462 for (i = st -> start ;i < st -> end - 1 ;i ++ )
14281463 {
14291464 int width ;
14301465 int boost ;
14311466
1432- follower [i ] = MIN16 (follower [i ], QCONST16 (2 , DB_SHIFT ));
1467+ follower [i ] = MIN16 (2 * follower [i ], i < 10 ? QCONST16 ( 4 , DB_SHIFT ) : QCONST16 (2 , DB_SHIFT ));
14331468 width = C * (st -> mode -> eBands [i + 1 ]- st -> mode -> eBands [i ])<<LM ;
14341469 if (width < 6 )
14351470 {
@@ -1446,43 +1481,10 @@ int celt_encode_with_ec(CELTEncoder * restrict st, const opus_val16 * pcm, int f
14461481 offsets [i ] = boost ;
14471482 }
14481483 /*for (i=st->start;i<st->end-1;i++)
1449- printf("%f ", follower[i]);*/
1450- //printf("%f\n", tot_boost);
1451- #if 0
1452- if (LM <= 1 )
1453- {
1454- t1 = 3 ;
1455- t2 = 5 ;
1456- } else {
1457- t1 = 2 ;
1458- t2 = 4 ;
1459- }
1460- for (i = st -> start + 1 ;i < st -> end - 1 ;i ++ )
1461- {
1462- opus_val32 d2 ;
1463- d2 = 2 * bandLogE [i ]- bandLogE [i - 1 ]- bandLogE [i + 1 ];
1464- if (C == 2 )
1465- d2 = HALF32 (d2 + 2 * bandLogE [i + st -> mode -> nbEBands ]-
1466- bandLogE [i - 1 + st -> mode -> nbEBands ]- bandLogE [i + 1 + st -> mode -> nbEBands ]);
1467- #ifdef FUZZING
1468- if ((rand ()& 0xF )== 0 )
1469- {
1470- offsets [i ] += 1 ;
1471- if ((rand ()& 0x3 )== 0 )
1472- offsets [i ] += 1 + (rand ()& 0x3 );
1473- }
1474- #else
1475- if (d2 > SHL16 (t1 ,DB_SHIFT ))
1476- offsets [i ] += 1 ;
1477- if (d2 > SHL16 (t2 ,DB_SHIFT ))
1478- offsets [i ] += 1 ;
1479- #endif
1480- }
1481- #endif
1484+ printf("%f ", follower[i]);
1485+ printf("%f\n", tot_boost);*/
14821486 }
14831487#ifndef FIXED_POINT
1484- //offsets[4] += 12;
1485- //offsets[10] += 12;
14861488 if (0 && st -> analysis .valid )
14871489 {
14881490 if (st -> analysis .boost_amount [0 ]> .2 )
0 commit comments