diff options
| author | Carl Hetherington <cth@carlh.net> | 2017-12-29 16:23:40 +0000 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2017-12-29 16:23:40 +0000 |
| commit | 2d99ab149d1eedb144337eb927c2ee1b92a046cc (patch) | |
| tree | 9fae7b17091f0e3db187942121aeb7288abf9afc /src | |
| parent | 3b2610481c4553ca26a778342adaf5a16aad8549 (diff) | |
Do split buffers over reel boundaries correctly.
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib/writer.cc | 31 |
1 files changed, 24 insertions, 7 deletions
diff --git a/src/lib/writer.cc b/src/lib/writer.cc index 6295058b8..10e4514fb 100644 --- a/src/lib/writer.cc +++ b/src/lib/writer.cc @@ -259,16 +259,33 @@ Writer::write (shared_ptr<const AudioBuffers> audio, DCPTime const time) _audio_reel->write (audio); t = end; } else { - /* Write the part we can */ - DCPTime const this_reel = _audio_reel->period().to - t; - Frame const this_reel_frames = this_reel.frames_ceil(afr); - if (this_reel_frames) { - shared_ptr<AudioBuffers> part (new AudioBuffers (audio->channels(), this_reel_frames)); - part->copy_from (audio.get(), this_reel_frames, DCPTime(t - time).frames_ceil(afr), 0); + /* Split the audio into two and write the first part */ + DCPTime part_lengths[2] = { + _audio_reel->period().to - t, + end - _audio_reel->period().to + }; + + Frame part_frames[2] = { + part_lengths[0].frames_ceil(afr), + part_lengths[1].frames_ceil(afr) + }; + + if (part_frames[0]) { + shared_ptr<AudioBuffers> part (new AudioBuffers (audio->channels(), part_frames[0])); + part->copy_from (audio.get(), part_frames[0], 0, 0); _audio_reel->write (part); } + + if (part_frames[1]) { + shared_ptr<AudioBuffers> part (new AudioBuffers (audio->channels(), part_frames[1])); + part->copy_from (audio.get(), part_frames[1], part_frames[0], 0); + audio = part; + } else { + audio.reset (); + } + ++_audio_reel; - t += this_reel; + t += part_lengths[0]; } } } |
