+ shared_ptr<Piece> piece = wp.lock ();
+ if (!piece) {
+ return;
+ }
+
+ shared_ptr<AudioContent> content = piece->content->audio;
+ DCPOMATIC_ASSERT (content);
+
+ shared_ptr<AudioBuffers> audio = content_audio.audio;
+
+ /* Gain */
+ if (content->gain() != 0) {
+ shared_ptr<AudioBuffers> gain (new AudioBuffers (audio));
+ gain->apply_gain (content->gain ());
+ audio = gain;
+ }
+
+ /* XXX: end-trimming used to be checked here */
+
+ /* Compute time in the DCP */
+ DCPTime const time = resampled_audio_to_dcp (piece, content_audio.frame) + DCPTime::from_seconds (content->delay() / 1000);
+
+ /* Remap channels */
+ shared_ptr<AudioBuffers> dcp_mapped (new AudioBuffers (_film->audio_channels(), audio->frames()));
+ dcp_mapped->make_silent ();
+
+ AudioMapping map = stream->mapping ();
+ for (int i = 0; i < map.input_channels(); ++i) {
+ for (int j = 0; j < dcp_mapped->channels(); ++j) {
+ if (map.get (i, static_cast<dcp::Channel> (j)) > 0) {
+ dcp_mapped->accumulate_channel (
+ audio.get(),
+ i,
+ static_cast<dcp::Channel> (j),
+ map.get (i, static_cast<dcp::Channel> (j))
+ );
+ }
+ }
+ }
+
+ audio = dcp_mapped;
+
+ if (_audio_processor) {
+ audio = _audio_processor->run (audio, _film->audio_channels ());
+ }
+
+ _audio_merger.push (audio, time);