diff options
| author | Carl Hetherington <cth@carlh.net> | 2014-05-01 12:34:18 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2014-05-01 12:34:18 +0100 |
| commit | bbbfb3208e74a4de2f9b4540a17ec43d4e3541a3 (patch) | |
| tree | 0f78cdc1f0a939f4b19ea3493afcecdb36498f9c /src | |
| parent | b33c48eb1982ea8c994353b86732110fa5d0e7ae (diff) | |
Fix assert failure.
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib/audio_decoder.cc | 16 |
1 files 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<AudioBuffers> 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; |
