+ shared_ptr<Content> content = weak_content.lock ();
+ if (!content) {
+ return;
+ }
+
+ /* The time of this audio may indicate that some of our buffered audio is not going to
+ be added to any more, so it can be emitted.
+ */
+
+ time += content->start ();
+
+ if (time > _next_audio) {
+ /* We can emit some audio from our buffers */
+ OutputAudioFrame const N = _film->time_to_audio_frames (time - _next_audio);
+ assert (N <= _audio_buffers.frames());
+ shared_ptr<AudioBuffers> emit (new AudioBuffers (_audio_buffers.channels(), N));
+ emit->copy_from (&_audio_buffers, N, 0, 0);
+ Audio (emit, _next_audio);
+ _next_audio += _film->audio_frames_to_time (N);
+
+ /* And remove it from our buffers */
+ if (_audio_buffers.frames() > N) {
+ _audio_buffers.move (N, 0, _audio_buffers.frames() - N);
+ }
+ _audio_buffers.set_frames (_audio_buffers.frames() - N);
+ }
+
+ /* Now accumulate the new audio into our buffers */
+ _audio_buffers.ensure_size (_audio_buffers.frames() + audio->frames());
+ _audio_buffers.accumulate_frames (audio.get(), 0, 0, audio->frames ());
+ _audio_buffers.set_frames (_audio_buffers.frames() + audio->frames());