OSDN Git Service

fix audio sync when resampling 48khz to 44.1khz
authorjstebbins <jstebbins@b64f7644-9d1e-0410-96f1-a4d463321fa5>
Sat, 6 Nov 2010 21:14:14 +0000 (21:14 +0000)
committerjstebbins <jstebbins@b64f7644-9d1e-0410-96f1-a4d463321fa5>
Sat, 6 Nov 2010 21:14:14 +0000 (21:14 +0000)
Rounding errors in timestamp calculations caused a gradual slip
in both sync.c and encfaac.c.

git-svn-id: svn://localhost/HandBrake/trunk@3653 b64f7644-9d1e-0410-96f1-a4d463321fa5

libhb/encfaac.c
libhb/sync.c

index c955199..cc7e3b9 100644 (file)
@@ -18,8 +18,8 @@ struct hb_work_private_s
     uint8_t       * buf;
     uint8_t       * obuf;
     hb_list_t     * list;
-    int64_t         pts;
-    int64_t         framedur;
+    double          pts;
+    double          framedur;
        int             out_discrete_channels;
 };
 
@@ -97,8 +97,9 @@ int encfaacInit( hb_work_object_t * w, hb_job_t * job )
                             &pv->input_samples, &pv->output_bytes );
     pv->buf  = malloc( pv->input_samples * sizeof( float ) );
     pv->obuf = malloc( pv->output_bytes );
-    pv->framedur = 90000LL * pv->input_samples /
+    pv->framedur = 90000.0 * pv->input_samples /
                    ( audio->config.out.samplerate * pv->out_discrete_channels );
+printf("in %ld out %ld sr %d dur %g\n", pv->input_samples, pv->output_bytes, audio->config.out.samplerate, pv->framedur);
 
     cfg                = faacEncGetCurrentConfiguration( pv->faac );
     cfg->mpegVersion   = MPEG4;
index 57809d7..fac0c34 100644 (file)
@@ -36,7 +36,7 @@ typedef struct
 typedef struct
 {
     int          index;
-    int64_t      next_start;    /* start time of next output frame */
+    double       next_start;   /* start time of next output frame */
     int64_t      next_pts;     /* start time of next input frame */
     int64_t      first_drop;   /* PTS of first 'went backwards' frame dropped */
     int          drop_count;   /* count of 'time went backwards' drops */
@@ -1193,8 +1193,8 @@ static void InitAudio( hb_job_t * job, hb_sync_common_t * common, int i )
 static hb_buffer_t * OutputAudioFrame( hb_audio_t *audio, hb_buffer_t *buf,
                                        hb_sync_audio_t *sync )
 {
-    int64_t start = sync->next_start;
-    int64_t duration = buf->stop - buf->start;
+    int64_t start = (int64_t)sync->next_start;
+    double duration = buf->stop - buf->start;
 
     sync->next_pts += duration;
 
@@ -1244,13 +1244,13 @@ static hb_buffer_t * OutputAudioFrame( hb_audio_t *audio, hb_buffer_t *buf,
         hb_buffer_close( &buf_raw );
 
         buf->size = sync->data.output_frames_gen * channel_count;
-        duration = ( sync->data.output_frames_gen * 90000 ) /
+        duration = (double)( sync->data.output_frames_gen * 90000 ) /
                    audio->config.out.samplerate;
     }
     buf->frametype = HB_FRAME_AUDIO;
     buf->start = start;
-    buf->stop  = start + duration;
-    sync->next_start = start + duration;
+    sync->next_start += duration;
+    buf->stop  = (int64_t)sync->next_start;
     return buf;
 }