[MPlayer-dev-eng] scaletempo speedup, listen-test-request

Reimar Döffinger Reimar.Doeffinger at stud.uni-karlsruhe.de
Sun Nov 18 17:15:42 CET 2007


Hello,
On Sun, Nov 18, 2007 at 01:16:42PM +0100, A Mennucc wrote:
> On Thu, Nov 15, 2007 at 10:15:15PM +0100, Reimar Döffinger wrote:
> > since my ears aren't the best at all, could you please test attached
> > patch if it decreases quality audibly?
> 
> I did some tests. 

Sorry, that version had a stupid bug, if corr is changed to int64_t, of
course best_corr must be as well.
Please try again with attached patch.
Benchmarks are welcome, too.

Greetings,
Reimar Döffinger
-------------- next part --------------
Index: libaf/af_scaletempo.c
===================================================================
--- libaf/af_scaletempo.c	(revision 25098)
+++ libaf/af_scaletempo.c	(working copy)
@@ -69,7 +69,6 @@
   void*   buf_pre_corr;
   void*   table_window;
   int     (*best_overlap_offset)(struct af_scaletempo_s* s);
-  short   shift_corr;
   // command line
   float   scale_nominal;
   float   ms_stride;
@@ -151,9 +150,10 @@
 
 static int best_overlap_offset_s16(af_scaletempo_t* s)
 {
-  int32_t *pw, *ppc;
+  uint16_t *pw;
+  int16_t *ppc;
   int16_t *po, *search_start;
-  int32_t best_corr = INT_MIN;
+  int64_t best_corr = INT64_MIN;
   int best_off = 0;
   int i, off;
 
@@ -162,17 +162,20 @@
   po += s->num_channels;
   ppc = s->buf_pre_corr;
   for (i=s->num_channels; i<s->samples_overlap; i++) {
-    *ppc++ = ( *pw++ * *po++ ) >> 15;
+    *ppc++ = ( *pw++ * *po++ ) >> 16;
   }
 
   search_start = (int16_t*)s->buf_queue + s->num_channels;
   for (off=0; off<s->frames_search; off++) {
-    int32_t corr = 0;
+    int64_t corr = 0;
     int16_t* ps = search_start;
     ppc = s->buf_pre_corr;
-    for (i=s->num_channels; i<s->samples_overlap; i++) {
-      corr += ( *ppc++ * *ps++ ) >> s->shift_corr;
-    }
+    ppc += s->samples_overlap - s->num_channels;
+    ps  += s->samples_overlap - s->num_channels;
+    i  = -(s->samples_overlap - s->num_channels);
+    do {
+      corr += ppc[i] * ps[i];
+    } while (++i < 0);
     if (corr > best_corr) {
       best_corr = corr;
       best_off  = off;
@@ -364,21 +367,20 @@
       if (use_int) {
         int64_t t = frames_overlap;
         int32_t n = 8589934588LL / (t * t);  // 4 * (2^31 - 1) / t^2
-        int32_t* pw;
-        s->buf_pre_corr = realloc(s->buf_pre_corr, s->bytes_overlap * 2);
-        s->table_window = realloc(s->table_window, s->bytes_overlap * 2 - nch * bps * 2);
+        uint16_t* pw;
+        s->buf_pre_corr = realloc(s->buf_pre_corr, s->bytes_overlap);
+        s->table_window = realloc(s->table_window, s->bytes_overlap - nch * bps);
         if(!s->buf_pre_corr || !s->table_window) {
           af_msg(AF_MSG_FATAL, "[scaletempo] Out of memory\n");
           return AF_ERROR;
         }
         pw = s->table_window;
         for (i=1; i<frames_overlap; i++) {
-          int32_t v = ( i * (t - i) * n ) >> 15;
+          uint16_t v = ( i * (t - i) * n ) >> 15;
           for (j=0; j<nch; j++) {
             *pw++ = v;
           }
         }
-        s->shift_corr = av_log2( 2*(s->samples_overlap - nch) - 1 );
         s->best_overlap_offset = best_overlap_offset_s16;
       } else {
         float* pw;


More information about the MPlayer-dev-eng mailing list