X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Fanalyse_audio_job.cc;h=60b10e7b6e05ba69dc418894fa10b4ca8ef7781e;hb=391d85619ac19a2a93696ddc35c222eb9bb5d9d6;hp=2848c1ed773c16dfe5b6acbf0b3c0f6b61f65aac;hpb=5fd5e78c51bd5630f6777001db5aa25103218c22;p=dcpomatic.git diff --git a/src/lib/analyse_audio_job.cc b/src/lib/analyse_audio_job.cc index 2848c1ed7..60b10e7b6 100644 --- a/src/lib/analyse_audio_job.cc +++ b/src/lib/analyse_audio_job.cc @@ -18,6 +18,7 @@ */ #include "audio_analysis.h" +#include "audio_buffers.h" #include "analyse_audio_job.h" #include "compose.hpp" #include "film.h" @@ -45,12 +46,7 @@ AnalyseAudioJob::AnalyseAudioJob (shared_ptr f, shared_ptr content = _content.lock (); - if (!content) { - return ""; - } - - return String::compose (_("Analyse audio of %1"), content->file().filename()); + return _("Analyse audio"); } void @@ -64,18 +60,18 @@ AnalyseAudioJob::run () shared_ptr playlist (new Playlist); playlist->add (content); shared_ptr player (new Player (_film, playlist)); - player->disable_video (); - player->Audio.connect (bind (&AnalyseAudioJob::audio, this, _1, _2)); - - _samples_per_point = max (int64_t (1), _film->time_to_audio_frames (_film->length()) / _num_points); + int64_t const len = _film->length().frames (_film->audio_frame_rate()); + _samples_per_point = max (int64_t (1), len / _num_points); - _current.resize (_film->dcp_audio_channels ()); - _analysis.reset (new AudioAnalysis (_film->dcp_audio_channels ())); + _current.resize (_film->audio_channels ()); + _analysis.reset (new AudioAnalysis (_film->audio_channels ())); _done = 0; - while (!player->pass ()) { - set_progress (double (_film->audio_frames_to_time (_done)) / _film->length ()); + DCPTime const block = DCPTime::from_seconds (1.0 / 8); + for (DCPTime t; t < _film->length(); t += block) { + analyse (player->get_audio (t, block, false)); + set_progress (t.seconds() / _film->length().seconds()); } _analysis->write (content->audio_analysis_path ()); @@ -85,13 +81,13 @@ AnalyseAudioJob::run () } void -AnalyseAudioJob::audio (shared_ptr b, Time) +AnalyseAudioJob::analyse (shared_ptr b) { for (int i = 0; i < b->frames(); ++i) { for (int j = 0; j < b->channels(); ++j) { float s = b->data(j)[i]; if (fabsf (s) < 10e-7) { - /* stringstream can't serialise and recover inf or -inf, so prevent such + /* SafeStringStream can't serialise and recover inf or -inf, so prevent such values by replacing with this (140dB down) */ s = 10e-7; }