-
-void
-AnalyseAudioJob::analyse (shared_ptr<const AudioBuffers> b, DCPTime time)
-{
- DCPOMATIC_ASSERT (time >= _start);
-
-#ifdef DCPOMATIC_HAVE_EBUR128_PATCHED_FFMPEG
- if (Config::instance()->analyse_ebur128 ()) {
- _ebur128->process (b);
- }
-#endif
-
- int const frames = b->frames ();
- int const channels = b->channels ();
-
- for (int j = 0; j < channels; ++j) {
- float* data = b->data(j);
- for (int i = 0; i < frames; ++i) {
- float s = data[i];
- float as = fabsf (s);
- if (as < 10e-7) {
- /* We may struggle to serialise and recover inf or -inf, so prevent such
- values by replacing with this (140dB down) */
- s = as = 10e-7;
- }
- _current[j][AudioPoint::RMS] += pow (s, 2);
- _current[j][AudioPoint::PEAK] = max (_current[j][AudioPoint::PEAK], as);
-
- if (as > _sample_peak[j]) {
- _sample_peak[j] = as;
- _sample_peak_frame[j] = _done + i;
- }
-
- if (((_done + i) % _samples_per_point) == 0) {
- _current[j][AudioPoint::RMS] = sqrt (_current[j][AudioPoint::RMS] / _samples_per_point);
- _analysis->add_point (j, _current[j]);
- _current[j] = AudioPoint ();
- }
- }
- }
-
- _done += frames;
-
- DCPTime const length = _playlist->length (_film);
- set_progress ((time.seconds() - _start.seconds()) / (length.seconds() - _start.seconds()));
-}