-void
-Player::audio_flush (shared_ptr<Piece> piece, AudioStreamPtr stream)
-{
- shared_ptr<AudioContent> content = piece->content->audio;
- DCPOMATIC_ASSERT (content);
-
- shared_ptr<Resampler> r = resampler (content, stream, false);
- if (!r) {
- return;
- }
-
- pair<shared_ptr<const AudioBuffers>, Frame> ro = r->flush ();
- if (ro.first->frames() == 0) {
- return;
- }
-
- ContentAudio content_audio;
- content_audio.audio = ro.first;
- content_audio.frame = ro.second;
-
- /* Compute time in the DCP */
- DCPTime time = resampled_audio_to_dcp (piece, content_audio.frame) + DCPTime::from_seconds (content->delay() / 1000.0);
-
- audio_transform (content, stream, content_audio, time);
-}
-
-/** Do our common processing on some audio */
-void
-Player::audio_transform (shared_ptr<AudioContent> content, AudioStreamPtr stream, ContentAudio content_audio, DCPTime time)
-{
- DCPOMATIC_ASSERT (content_audio.audio->frames() > 0);
-
- /* Gain */
-
- if (content->gain() != 0) {
- shared_ptr<AudioBuffers> gain (new AudioBuffers (content_audio.audio));
- gain->apply_gain (content->gain ());
- content_audio.audio = gain;
- }
-
- /* Remap */
-
- shared_ptr<AudioBuffers> dcp_mapped (new AudioBuffers (_film->audio_channels(), content_audio.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 (
- content_audio.audio.get(),
- i,
- static_cast<dcp::Channel> (j),
- map.get (i, static_cast<dcp::Channel> (j))
- );
- }
- }
- }
-
- content_audio.audio = dcp_mapped;
-
- /* Process */
-
- if (_audio_processor) {
- content_audio.audio = _audio_processor->run (content_audio.audio, _film->audio_channels ());
- }
-
- /* Pad any gap which may be caused by audio delay */
-
- if (_last_audio_time) {
- fill_audio (DCPTimePeriod (*_last_audio_time, time));
- }
-
- /* Push */
-
- _audio_merger.push (content_audio.audio, time);
- DCPOMATIC_ASSERT (_stream_states.find (stream) != _stream_states.end ());
- _stream_states[stream].last_push_end = time + DCPTime::from_frames (content_audio.audio->frames(), _film->audio_frame_rate());
-}
-