diff vorbis_enc.c @ 3861:b98ea563e9bc libavcodec

Original Commit: r61 | ods15 | 2006-09-25 13:10:56 +0300 (Mon, 25 Sep 2006) | 2 lines step 2, floor_fit, decides on the values to be encoded
author ods15
date Mon, 02 Oct 2006 06:07:49 +0000
parents be0344cea4ea
children ee9379fc77a9
line wrap: on
line diff
--- a/vorbis_enc.c	Mon Oct 02 06:07:46 2006 +0000
+++ b/vorbis_enc.c	Mon Oct 02 06:07:49 2006 +0000
@@ -643,6 +643,27 @@
     return p - *out;
 }
 
+static void floor_fit(venc_context_t * venc, floor_t * fc, float * coeffs, int * posts, int samples) {
+    int range = 255 / fc->multiplier + 1;
+    int i;
+    for (i = 0; i < fc->values; i++) {
+        int position = fc->list[fc->list[i].sort].x;
+        int begin = fc->list[fc->list[FFMAX(i-1, 0)].sort].x;
+        int end   = fc->list[fc->list[FFMIN(i+1, fc->values - 1)].sort].x;
+        int j;
+        float average = 0;
+        begin = (position + begin) / 2;
+        end   = (position + end  ) / 2;
+
+        assert(end <= samples);
+        for (j = begin; j < end; j++) average += fabs(coeffs[j]);
+        average /= end - begin;
+        average /= 64; // MAGIC!
+        for (j = 0; j < range; j++) if (floor1_inverse_db_table[j * fc->multiplier] > average) break;
+        posts[fc->list[i].sort] = j;
+    }
+}
+
 static void floor_encode(venc_context_t * venc, floor_t * fc, PutBitContext * pb, float * floor, int samples) {
     int range = 255 / fc->multiplier + 1;
     int j;
@@ -805,6 +826,7 @@
     int i;
 
     if (!window(venc, audio, samples)) return 0;
+    samples = 1 << (venc->blocksize[0] - 1);
 
     init_put_bits(&pb, packets, buf_size);
 
@@ -821,6 +843,8 @@
 
     for (i = 0; i < venc->channels; i++) {
         floor_t * fc = &venc->floors[mapping->floor[mapping->mux[i]]];
+        int posts[fc->values];
+        floor_fit(venc, fc, &venc->coeffs[i * samples], posts, samples);
         floor_encode(venc, fc, &pb, &venc->floor[i * samples], samples);
     }