If we are requesting audio from before the start of a piece of content we need to...
authorCarl Hetherington <cth@carlh.net>
Sat, 31 Jan 2015 22:50:56 +0000 (22:50 +0000)
committerCarl Hetherington <cth@carlh.net>
Sat, 31 Jan 2015 22:50:56 +0000 (22:50 +0000)
ChangeLog
src/lib/player.cc

index b0aef0b297e258478fe71000e0489de80286d8ad..06955cadbc5634d11a12cd2002f087f78aa48af5 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2015-01-31  Carl Hetherington  <cth@carlh.net>
+
+       * Fix error when using audio delay.
+
 2015-01-30  Carl Hetherington  <cth@carlh.net>
 
        * Fix update of preview when video fade changes.
index 5c29efc4674ede50a6a9f759a52cb30b0ad76672..de513ea170132228b8898e1ea17a255e611ec08e 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2013-2014 Carl Hetherington <cth@carlh.net>
+    Copyright (C) 2013-2015 Carl Hetherington <cth@carlh.net>
 
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
@@ -436,19 +436,24 @@ Player::get_audio (DCPTime time, DCPTime length, bool accurate)
 
                /* The time that we should request from the content */
                DCPTime request = time - DCPTime::from_seconds (content->audio_delay() / 1000.0);
+               AudioFrame request_frames = length_frames;
                DCPTime offset;
                if (request < DCPTime ()) {
                        /* We went off the start of the content, so we will need to offset
                           the stuff we get back.
                        */
                        offset = -request;
+                       request_frames += request.frames (_film->audio_frame_rate ());
+                       if (request_frames < 0) {
+                               request_frames = 0;
+                       }
                        request = DCPTime ();
                }
 
                AudioFrame const content_frame = dcp_to_content_audio (*i, request);
 
                /* Audio from this piece's decoder (which might be more or less than what we asked for) */
-               shared_ptr<ContentAudio> all = decoder->get_audio (content_frame, length_frames, accurate);
+               shared_ptr<ContentAudio> all = decoder->get_audio (content_frame, request_frames, accurate);
 
                /* Gain */
                if (content->audio_gain() != 0) {
@@ -480,7 +485,7 @@ Player::get_audio (DCPTime time, DCPTime length, bool accurate)
                        all->audio.get(),
                        content_frame - all->frame,
                        offset.frames (_film->audio_frame_rate()),
-                       min (AudioFrame (all->audio->frames()), length_frames) - offset.frames (_film->audio_frame_rate ())
+                       min (AudioFrame (all->audio->frames()), request_frames)
                        );
        }