X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Fanalyse_audio_job.cc;h=ab985bdf75468ee557a81f0307d09a919df390e0;hb=7edf8e601ed2ede5b6758840fb9d8940393cf7e2;hp=6e6dda88634891449b2897be29aa18633583d693;hpb=a054c067ab2cbf6c5abc5df4caa08ffaac206f0b;p=dcpomatic.git diff --git a/src/lib/analyse_audio_job.cc b/src/lib/analyse_audio_job.cc index 6e6dda886..ab985bdf7 100644 --- a/src/lib/analyse_audio_job.cc +++ b/src/lib/analyse_audio_job.cc @@ -21,7 +21,7 @@ #include "analyse_audio_job.h" #include "compose.hpp" #include "film.h" -#include "playlist.h" +#include "player.h" #include "i18n.h" @@ -33,8 +33,9 @@ using boost::shared_ptr; int const AnalyseAudioJob::_num_points = 1024; -AnalyseAudioJob::AnalyseAudioJob (shared_ptr f) +AnalyseAudioJob::AnalyseAudioJob (shared_ptr f, shared_ptr c) : Job (f) + , _content (c) , _done (0) , _samples_per_point (1) { @@ -44,40 +45,49 @@ AnalyseAudioJob::AnalyseAudioJob (shared_ptr f) string AnalyseAudioJob::name () const { - return String::compose (_("Analyse audio of %1"), _film->name()); + return _("Analyse audio"); } void AnalyseAudioJob::run () { - shared_ptr playlist = _film->playlist (); - playlist->disable_video (); + shared_ptr content = _content.lock (); + if (!content) { + return; + } + + shared_ptr playlist (new Playlist); + playlist->add (content); + shared_ptr player (new Player (_film, playlist)); + player->disable_video (); - playlist->Audio.connect (bind (&AnalyseAudioJob::audio, this, _1)); + player->Audio.connect (bind (&AnalyseAudioJob::audio, this, _1, _2)); - _samples_per_point = max (int64_t (1), playlist->audio_length() / _num_points); + _samples_per_point = max (int64_t (1), _film->time_to_audio_frames (_film->length()) / _num_points); - _current.resize (playlist->audio_channels ()); - _analysis.reset (new AudioAnalysis (playlist->audio_channels())); - - while (!playlist->pass()) { - set_progress (float (_done) / playlist->audio_length ()); + _current.resize (_film->audio_channels ()); + _analysis.reset (new AudioAnalysis (_film->audio_channels ())); + + _done = 0; + OutputAudioFrame const len = _film->time_to_audio_frames (_film->length ()); + while (!player->pass ()) { + set_progress (double (_done) / len); } - _analysis->write (_film->audio_analysis_path ()); + _analysis->write (content->audio_analysis_path ()); set_progress (1); set_state (FINISHED_OK); } void -AnalyseAudioJob::audio (shared_ptr b) +AnalyseAudioJob::audio (shared_ptr b, Time) { 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; } @@ -87,7 +97,7 @@ AnalyseAudioJob::audio (shared_ptr b) if ((_done % _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 (); } }