]> git.sesse.net Git - mlt/commitdiff
Merge branch 'master' of dennedy.org:git/mltframework.org/mlt
authorDan Dennedy <dan@dennedy.org>
Mon, 15 Feb 2010 04:18:43 +0000 (20:18 -0800)
committerDan Dennedy <dan@dennedy.org>
Mon, 15 Feb 2010 04:18:43 +0000 (20:18 -0800)
src/framework/mlt_frame.c

index 976cecf0e7d37a1903b617a72ae1a2a9f6582a49..6ca882428dd844247da123458961f8613756aa79 100644 (file)
@@ -791,28 +791,15 @@ void mlt_frame_close( mlt_frame this )
 
 int mlt_sample_calculator( float fps, int frequency, int64_t position )
 {
-       int samples = 0;
-
-       if ( fps )
-       {
-               /* Compute the cumulative number of samples until the start of this frame and the
-               cumulative number of samples until the start of the next frame. Round each to the
-               nearest integer and take the difference to determine the number of samples in
-               this frame.
-
-               This approach should prevent rounding errors that can accumulate over a large number
-               of frames causing A/V sync problems. */
-
-               int64_t samples_at_this =
-                       (int64_t)( (double) position * (double) frequency / (double) fps +
-                       ( position < 0 ? -0.5 : 0.5 ) );
-               int64_t samples_at_next =
-                       (int64_t)( (double) (position + 1) * (double) frequency / (double) fps +
-                       ( position < 0 ? -0.5 : 0.5 ) );
-               samples = (int)( samples_at_next - samples_at_this );
-       }
-
-       return samples;
+       /* Compute the cumulative number of samples until the start of this frame and the
+       cumulative number of samples until the start of the next frame. Round each to the
+       nearest integer and take the difference to determine the number of samples in
+       this frame.
+
+       This approach should prevent rounding errors that can accumulate over a large number
+       of frames causing A/V sync problems. */
+       return mlt_sample_calculator_to_now( fps, frequency, position )
+                - mlt_sample_calculator_to_now( fps, frequency, position + 1 );
 }
 
 /** Determine the number of samples that belong before a time position.
@@ -825,7 +812,7 @@ int mlt_sample_calculator( float fps, int frequency, int64_t position )
  * \bug Will this break when mlt_position is converted to double?
  */
 
-int64_t mlt_sample_calculator_to_now( float fps, int frequency, int64_t position )
+inline int64_t mlt_sample_calculator_to_now( float fps, int frequency, int64_t position )
 {
        int64_t samples = 0;