diff options
| author | Carl Hetherington <cth@carlh.net> | 2013-06-20 17:34:23 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2013-06-20 21:20:38 +0100 |
| commit | 50cb31af16240b248700dab1484d7f07656c66df (patch) | |
| tree | 393568f3c24506ac6b004346b9ef5101f9fdcf61 /src/lib/analyse_audio_job.cc | |
| parent | edfd92e5554e3389e6456f497f44ca6e866800bf (diff) | |
Various fixes to make audio analysis sort-of work.
Diffstat (limited to 'src/lib/analyse_audio_job.cc')
| -rw-r--r-- | src/lib/analyse_audio_job.cc | 33 |
1 files changed, 23 insertions, 10 deletions
diff --git a/src/lib/analyse_audio_job.cc b/src/lib/analyse_audio_job.cc index 3a44a408f..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<Film> f) +AnalyseAudioJob::AnalyseAudioJob (shared_ptr<const Film> f, shared_ptr<AudioContent> c) : Job (f) + , _content (c) , _done (0) , _samples_per_point (1) { @@ -44,13 +45,25 @@ AnalyseAudioJob::AnalyseAudioJob (shared_ptr<Film> f) string AnalyseAudioJob::name () const { - return String::compose (_("Analyse audio of %1"), _film->name()); + shared_ptr<AudioContent> content = _content.lock (); + if (!content) { + return ""; + } + + return String::compose (_("Analyse audio of %1"), content->file().filename()); } void AnalyseAudioJob::run () { - shared_ptr<Player> player = _film->player (); + shared_ptr<AudioContent> content = _content.lock (); + if (!content) { + return; + } + + shared_ptr<Playlist> playlist (new Playlist); + playlist->add (content); + shared_ptr<Player> player (new Player (_film, playlist)); player->disable_video (); player->Audio.connect (bind (&AnalyseAudioJob::audio, this, _1, _2)); @@ -61,18 +74,18 @@ AnalyseAudioJob::run () _analysis.reset (new AudioAnalysis (_film->dcp_audio_channels ())); _done = 0; - while (player->pass ()) { - set_progress (double (_done) / _film->length ()); + 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<const AudioBuffers> b, Time t) +AnalyseAudioJob::audio (shared_ptr<const AudioBuffers> b, Time) { for (int i = 0; i < b->frames(); ++i) { for (int j = 0; j < b->channels(); ++j) { @@ -88,12 +101,12 @@ AnalyseAudioJob::audio (shared_ptr<const AudioBuffers> b, Time t) 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 (); } } - } - _done = t; + ++_done; + } } |
