-
- DecodeOptions options;
- options.decode_video = false;
-
- Decoders decoders = decoder_factory (_film, options);
- assert (decoders.audio);
-
- decoders.audio->set_audio_stream (_film->audio_stream ());
- decoders.audio->Audio.connect (bind (&AnalyseAudioJob::audio, this, _1));
-
- int64_t total_audio_frames = video_frames_to_audio_frames (_film->length().get(), _film->audio_stream()->sample_rate(), _film->frames_per_second());
- _samples_per_point = total_audio_frames / _num_points;
-
- _current.resize (_film->audio_stream()->channels ());
- _analysis.reset (new AudioAnalysis (_film->audio_stream()->channels()));
-
- while (!decoders.audio->pass()) {
- set_progress (float (_done) / total_audio_frames);
+
+ if (has_any_audio) {
+ _done = 0;
+ DCPTime const block = DCPTime::from_seconds (1.0 / 8);
+ for (DCPTime t = start; t < length; t += block) {
+ shared_ptr<const AudioBuffers> audio = player->get_audio (t, block, false);
+#ifdef DCPOMATIC_HAVE_EBUR128_PATCHED_FFMPEG
+ if (Config::instance()->analyse_ebur128 ()) {
+ _ebur128->process (audio);
+ }
+#endif
+ analyse (audio);
+ set_progress ((t.seconds() - start.seconds()) / (length.seconds() - start.seconds()));
+ }
+ }
+
+ vector<AudioAnalysis::PeakTime> sample_peak;
+ for (int i = 0; i < _film->audio_channels(); ++i) {
+ sample_peak.push_back (
+ AudioAnalysis::PeakTime (_sample_peak[i], DCPTime::from_frames (_sample_peak_frame[i], _film->audio_frame_rate ()))
+ );
+ }
+ _analysis->set_sample_peak (sample_peak);
+
+#ifdef DCPOMATIC_HAVE_EBUR128_PATCHED_FFMPEG
+ if (Config::instance()->analyse_ebur128 ()) {
+ void* eb = _ebur128->get("Parsed_ebur128_0")->priv;
+ vector<float> true_peak;
+ for (int i = 0; i < _film->audio_channels(); ++i) {
+ true_peak.push_back (av_ebur128_get_true_peaks(eb)[i]);
+ }
+ _analysis->set_true_peak (true_peak);
+ _analysis->set_integrated_loudness (av_ebur128_get_integrated_loudness(eb));
+ _analysis->set_loudness_range (av_ebur128_get_loudness_range(eb));