diff options
| author | Carl Hetherington <cth@carlh.net> | 2017-02-23 11:42:48 +0000 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2017-04-19 23:04:32 +0100 |
| commit | a93d6e9872f0de79f5d612320837a1fc9d557f63 (patch) | |
| tree | dab20eff026d17a20c0b75bb8849d0950ea118b3 /src | |
| parent | 2d9deb25659ef6007fb800ae024917dfca04f9ca (diff) | |
Fix audio when it spans reel boundaries.
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib/writer.cc | 32 |
1 files changed, 25 insertions, 7 deletions
diff --git a/src/lib/writer.cc b/src/lib/writer.cc index 74e5e3ec0..c507c5527 100644 --- a/src/lib/writer.cc +++ b/src/lib/writer.cc @@ -236,15 +236,33 @@ Writer::fake_write (Frame frame, Eyes eyes) void Writer::write (shared_ptr<const AudioBuffers> audio) { - if (_audio_reel == _reels.end ()) { - /* This audio is off the end of the last reel; ignore it */ - return; - } + /* The audio we get might span a reel boundary, and if so we have to write it in bits */ - _audio_reel->write (audio); + int32_t offset = 0; + while (offset < audio->frames ()) { + + if (_audio_reel == _reels.end ()) { + /* This audio is off the end of the last reel; ignore it */ + return; + } + + int32_t const this_time = min ( + audio->frames() - offset, + (int32_t) (_audio_reel->period().duration().frames_floor(_film->audio_frame_rate()) - _audio_reel->total_written_audio_frames()) + ); + + if (this_time == audio->frames()) { + /* Easy case: we can write all the audio to this reel */ + _audio_reel->write (audio); + } else { + /* Write the part we can */ + shared_ptr<AudioBuffers> part (new AudioBuffers (audio->channels(), this_time)); + part->copy_from (audio.get(), this_time, offset, 0); + _audio_reel->write (part); + ++_audio_reel; + } - if (_audio_reel->total_written_audio_frames() >= _audio_reel->period().duration().frames_floor (_film->audio_frame_rate())) { - ++_audio_reel; + offset += this_time; } } |
