From bbbfb3208e74a4de2f9b4540a17ec43d4e3541a3 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Thu, 1 May 2014 12:34:18 +0100 Subject: [PATCH] Fix assert failure. --- src/lib/audio_decoder.cc | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/lib/audio_decoder.cc b/src/lib/audio_decoder.cc index c0c92476a..f914ecf8a 100644 --- a/src/lib/audio_decoder.cc +++ b/src/lib/audio_decoder.cc @@ -86,21 +86,23 @@ AudioDecoder::get_audio (AudioFrame frame, AudioFrame length, bool accurate) } /* The amount of data available in _decoded_audio.audio starting from `frame'. This could be -ve - if pass() returned true before we got enough data + if pass() returned true before we got enough data. */ - AudioFrame const amount_left = _decoded_audio.audio->frames() - decoded_offset; - + AudioFrame const available = _decoded_audio.audio->frames() - decoded_offset; + /* We will return either that, or the requested amount, whichever is smaller */ - AudioFrame const to_return = max ((AudioFrame) 0, min (amount_left, length)); + AudioFrame const to_return = max ((AudioFrame) 0, min (available, length)); /* Copy our data to the output */ shared_ptr out (new AudioBuffers (_decoded_audio.audio->channels(), to_return)); out->copy_from (_decoded_audio.audio.get(), to_return, decoded_offset, 0); - + + AudioFrame const remaining = max ((AudioFrame) 0, available - to_return); + /* Clean up decoded; first, move the data after what we just returned to the start of the buffer */ - _decoded_audio.audio->move (decoded_offset + to_return, 0, amount_left - to_return); + _decoded_audio.audio->move (decoded_offset + to_return, 0, remaining); /* And set up the number of frames we have left */ - _decoded_audio.audio->set_frames (amount_left - to_return); + _decoded_audio.audio->set_frames (remaining); /* Also bump where those frames are in terms of the content */ _decoded_audio.frame += decoded_offset + to_return; -- 2.30.2