+void
+Player::audio (weak_ptr<Piece> wp, AudioStreamPtr stream, ContentAudio content_audio)
+{
+ shared_ptr<Piece> piece = wp.lock ();
+ if (!piece) {
+ return;
+ }
+
+ shared_ptr<AudioContent> content = piece->content->audio;
+ DCPOMATIC_ASSERT (content);
+
+ /* Resample */
+ if (stream->frame_rate() != content->resampled_frame_rate()) {
+ shared_ptr<Resampler> r = resampler (content, stream);
+ pair<shared_ptr<const AudioBuffers>, Frame> ro = r->run (content_audio.audio, content_audio.frame);
+ content_audio.audio = ro.first;
+ content_audio.frame = ro.second;
+ }
+
+ /* XXX: end-trimming used to be checked here */
+
+ /* Compute time in the DCP */
+ DCPTime time = resampled_audio_to_dcp (piece, content_audio.frame) + DCPTime::from_seconds (content->delay() / 1000.0);
+
+ /* Remove anything that comes before the start of the content */
+ if (time < piece->content->position()) {
+ DCPTime const discard_time = piece->content->position() - time;
+ Frame discard_frames = discard_time.frames_round(_film->audio_frame_rate());
+ Frame remaining_frames = content_audio.audio->frames() - discard_frames;
+ if (remaining_frames <= 0) {
+ /* This audio is entirely discarded */
+ return;
+ }
+ shared_ptr<AudioBuffers> cut (new AudioBuffers (content_audio.audio->channels(), remaining_frames));
+ cut->copy_from (content_audio.audio.get(), remaining_frames, discard_frames, 0);
+ content_audio.audio = cut;
+ time += discard_time;
+ }
+
+ audio_transform (content, stream, content_audio, time);
+}
+