]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/opus_pvq.c
opus_pvq: remove unneeded assert
[ffmpeg] / libavcodec / opus_pvq.c
index 5920ab0ed1b57948fd868d2c9f9b9ba4c487f0a7..706e2394229cda561ebe658b978d21ea509e0315 100644 (file)
@@ -285,7 +285,6 @@ static inline uint32_t celt_icwrsi(uint32_t N, uint32_t K, const int *y)
         idx += CELT_PVQ_U(N - i, sum) + (y[i] < 0)*i_s;
         sum += FFABS(y[i]);
     }
-    av_assert0(sum == K);
     return idx;
 }
 
@@ -413,11 +412,14 @@ static void celt_pvq_search(float *X, int *y, int K, int N)
         y_norm += 1.0f;
 
         for (i = 0; i < N; i++) {
+            /* If the sum has been overshot and the best place has 0 pulses allocated
+             * to it, attempting to decrease it further will actually increase the
+             * sum. Prevent this by disregarding any 0 positions when decrementing. */
+            const int ca = 1 ^ ((y[i] == 0) & (phase < 0));
             float xy_new = xy_norm + 1*phase*FFABS(X[i]);
             float y_new  = y_norm  + 2*phase*FFABS(y[i]);
             xy_new = xy_new * xy_new;
-            /* FIXME: the y[i] check makes the search slightly worse at Ks below 5 */
-            if (y[i] && (max_den*xy_new) > (y_new*max_num)) {
+            if (ca && (max_den*xy_new) > (y_new*max_num)) {
                 max_den = y_new;
                 max_num = xy_new;
                 max_idx = i;