X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Fanalyse_audio_job.cc;h=2848c1ed773c16dfe5b6acbf0b3c0f6b61f65aac;hb=50cb31af16240b248700dab1484d7f07656c66df;hp=50096d7c125f183d694d4534febbadb4f20f4739;hpb=c921cfe23b593d7c367ad76094308c5f08037374;p=dcpomatic.git diff --git a/src/lib/analyse_audio_job.cc b/src/lib/analyse_audio_job.cc index 50096d7c1..2848c1ed7 100644 --- a/src/lib/analyse_audio_job.cc +++ b/src/lib/analyse_audio_job.cc @@ -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,34 +45,47 @@ AnalyseAudioJob::AnalyseAudioJob (shared_ptr f) string AnalyseAudioJob::name () const { - return String::compose (_("Analyse audio of %1"), _film->name()); + shared_ptr content = _content.lock (); + if (!content) { + return ""; + } + + return String::compose (_("Analyse audio of %1"), content->file().filename()); } void AnalyseAudioJob::run () { - shared_ptr player = _film->player (); + 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 (); - player->Audio.connect (bind (&AnalyseAudioJob::audio, this, _1)); + 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); - _samples_per_point = max (int64_t (1), _film->audio_length() / _num_points); + _current.resize (_film->dcp_audio_channels ()); + _analysis.reset (new AudioAnalysis (_film->dcp_audio_channels ())); - _current.resize (MAX_AUDIO_CHANNELS); - _analysis.reset (new AudioAnalysis (MAX_AUDIO_CHANNELS)); - - while (!player->pass()) { - set_progress (float (_done) / _film->audio_length ()); + _done = 0; + while (!player->pass ()) { + set_progress (double (_film->audio_frames_to_time (_done)) / _film->length ()); } - _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) { @@ -87,7 +101,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 (); } }