]> granicus.if.org Git - handbrake/commitdiff
Softer resampling when audio dates are messed up (fix for LPCM issues).
authortiter <eric@lapsus.org>
Thu, 23 Feb 2006 14:37:47 +0000 (14:37 +0000)
committertiter <eric@lapsus.org>
Thu, 23 Feb 2006 14:37:47 +0000 (14:37 +0000)
Disabled verbose in the OS X UI

git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk/libhb@30 b64f7644-9d1e-0410-96f1-a4d463321fa5

declpcm.c
sync.c

index 59163c366a08bd9f5b469bd1d56d62744f22fb97..5b9d5a3b6dc59645e58dab73b5d0448455a34a02 100644 (file)
--- a/declpcm.c
+++ b/declpcm.c
@@ -12,8 +12,6 @@ struct hb_work_object_s
 
     hb_job_t    * job;
     hb_audio_t  * audio;
-
-    int64_t       pts_last;
 };
 
 static int Work( hb_work_object_t * w, hb_buffer_t ** buf_in,
@@ -51,22 +49,11 @@ static int Work( hb_work_object_t * w, hb_buffer_t ** buf_in,
             break;
     }
 
-    count      = ( in->size - 6 ) / 2;
-    out        = hb_buffer_init( count * sizeof( float ) );
-    duration   = count * 90000 / samplerate / 2;
-    if( w->pts_last > 0 &&
-        in->start < w->pts_last + duration / 6 &&
-        in->start > w->pts_last - duration / 6 )
-    {
-        /* Workaround for DVDs where dates aren't exact */
-        out->start = w->pts_last;
-    }
-    else
-    {
-        out->start = in->start;
-    }
+    count       = ( in->size - 6 ) / 2;
+    out         = hb_buffer_init( count * sizeof( float ) );
+    duration    = count * 90000 / samplerate / 2;
+    out->start  = in->start;
     out->stop   = out->start + duration;
-    w->pts_last = out->stop;
 
     samples_u8   = in->data + 6;
     samples_fl32 = (float *) out->data;
@@ -106,8 +93,6 @@ hb_work_object_t * hb_work_declpcm_init( hb_job_t * job, hb_audio_t * audio )
     w->job   = job;
     w->audio = audio;
 
-    w->pts_last = -1;
-
     return w;
 }
 
diff --git a/sync.c b/sync.c
index 32ddb52b744ff4b81d30237250a184e4a8232ab0..61e567bbc80546283937591ed1a1de0f0d5a13e7 100644 (file)
--- a/sync.c
+++ b/sync.c
@@ -465,17 +465,18 @@ static void SyncAudio( hb_work_object_t * w, int i )
             start = pts_expected - w->pts_offset;
         }
 
-        if( ( buf->start + buf->stop ) / 2 < pts_expected )
+        /* Tolerance: 100 ms */
+        if( buf->start < pts_expected - 9000 )
         {
             /* Late audio, trash it */
+            hb_log( "sync: trashing late audio" );
             buf = hb_fifo_get( audio->fifo_raw );
             hb_buffer_close( &buf );
             continue;
         }
-
-        if( buf->start > pts_expected + ( buf->stop - buf->start ) / 2 )
+        else if( buf->start > pts_expected + 9000 )
         {
-            /* Audio push, send a frame of silence */
+            /* Missing audio, send a frame of silence */
             InsertSilence( w, i );
             continue;
         }
@@ -495,24 +496,16 @@ static void SyncAudio( hb_work_object_t * w, int i )
             int count_in, count_out;
 
             count_in  = buf_raw->size / 2 / sizeof( float );
-            count_out = ( buf->stop - pts_expected ) * job->arate / 90000;
+            count_out = ( buf_raw->stop - buf_raw->start ) * job->arate / 90000;
+            if( buf->start < pts_expected - 1500 )
+                count_out--;
+            else if( buf->start > pts_expected + 1500 )
+                count_out++;
 
             sync->data.data_in      = (float *) buf_raw->data;
             sync->data.input_frames = count_in;
-
-            if( buf->start < pts_expected - ( buf->stop - buf->start ) / 5 )
-            {
-                /* Avoid too heavy downsampling, trash the beginning of
-                   the buffer instead */
-                int drop;
-                drop = count_in * ( pts_expected - buf->start ) /
-                           ( buf->stop - buf->start );
-                sync->data.data_in      += 2 * drop;
-                sync->data.input_frames -= drop;
-                hb_log( "dropping %d of %d samples", drop, count_in );
-            }
-
             sync->data.output_frames = count_out;
+
             sync->data.src_ratio = (double) sync->data.output_frames /
                                    (double) sync->data.input_frames;