changeset 3890:de883494646e libavcodec

Original Commit: r91 | ods15 | 2006-09-30 10:05:16 +0300 (Sat, 30 Sep 2006) | 4 lines even better psy. My encoder officially kicks ass :) same bitrate to libvorbis, and (IMO) same quality! :)
author ods15
date Mon, 02 Oct 2006 06:08:57 +0000
parents a0462572fefa
children 50e912426a32
files vorbis_enc.c
diffstat 1 files changed, 17 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/vorbis_enc.c	Mon Oct 02 06:08:55 2006 +0000
+++ b/vorbis_enc.c	Mon Oct 02 06:08:57 2006 +0000
@@ -771,20 +771,30 @@
     return p - *out;
 }
 
+static float get_floor_average(floor_t * fc, float * coeffs, int i) {
+    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;
+
+    for (j = begin; j < end; j++) average += fabs(coeffs[j]);
+    return average / (end - begin);
+}
+
 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;
+    float tot_average = 0.;
+    for (i = 0; i < fc->values; i++) tot_average += get_floor_average(fc, coeffs, i);
+    tot_average /= fc->values;
+    tot_average /= 0.5;
+
     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;
+        float average = get_floor_average(fc, coeffs, i);
         int j;
-        float average = 0;
 
-        assert(end <= samples);
-        for (j = begin; j < end; j++) average += fabs(coeffs[j]);
-        average /= end - begin;
-        average /= pow(4, 1 - position/400.); // MAGIC!
+        average /= pow(average, 0.7) / tot_average * pow(0.9, position/200.); // MAGIC!
         for (j = 0; j < range - 1; j++) if (floor1_inverse_db_table[j * fc->multiplier] > average) break;
         posts[fc->list[i].sort] = j;
     }