From: Carl Hetherington Date: Sat, 31 Jan 2015 22:50:56 +0000 (+0000) Subject: If we are requesting audio from before the start of a piece of content we need to... X-Git-Tag: v2.0.48~242 X-Git-Url: https://main.carlh.net/gitweb/?p=dcpomatic.git;a=commitdiff_plain;h=78dd04db5ee5d1aa5fc915f04dc71cb53d33d059 If we are requesting audio from before the start of a piece of content we need to adjust both the request position AND the amount, not just the position. --- diff --git a/ChangeLog b/ChangeLog index b0aef0b29..06955cadb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2015-01-31 Carl Hetherington + + * Fix error when using audio delay. + 2015-01-30 Carl Hetherington * Fix update of preview when video fade changes. diff --git a/src/lib/player.cc b/src/lib/player.cc index 5c29efc46..de513ea17 100644 --- a/src/lib/player.cc +++ b/src/lib/player.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2013-2014 Carl Hetherington + Copyright (C) 2013-2015 Carl Hetherington 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 all = decoder->get_audio (content_frame, length_frames, accurate); + shared_ptr 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) ); }