X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Fanalyse_audio_job.cc;h=e2c9c5b1854747d5703a7037655c24f050dac211;hb=db468a15e50c8491d4b8462ad0676be905f49065;hp=bcabb6c91e8697b96c3f162ff7364c77faaf193c;hpb=a6901cb85be6e7664375b68c8315c32d57de8107;p=dcpomatic.git diff --git a/src/lib/analyse_audio_job.cc b/src/lib/analyse_audio_job.cc index bcabb6c91..e2c9c5b18 100644 --- a/src/lib/analyse_audio_job.cc +++ b/src/lib/analyse_audio_job.cc @@ -21,12 +21,13 @@ #include "analyse_audio_job.h" #include "compose.hpp" #include "film.h" -#include "options.h" -#include "decoder_factory.h" -#include "audio_decoder.h" +#include "playlist.h" + +#include "i18n.h" using std::string; using std::max; +using std::min; using std::cout; using boost::shared_ptr; @@ -43,35 +44,24 @@ AnalyseAudioJob::AnalyseAudioJob (shared_ptr f) string AnalyseAudioJob::name () const { - return String::compose ("Analyse audio of %1", _film->name()); + return String::compose (_("Analyse audio of %1"), _film->name()); } void AnalyseAudioJob::run () { - if (!_film->audio_stream () || !_film->length()) { - set_progress (1); - set_state (FINISHED_ERROR); - return; - } - - DecodeOptions options; - options.decode_video = false; - - Decoders decoders = decoder_factory (_film, options); - assert (decoders.audio); + shared_ptr player = _film->player (); + player->disable_video (); - decoders.audio->set_audio_stream (_film->audio_stream ()); - decoders.audio->Audio.connect (bind (&AnalyseAudioJob::audio, this, _1)); + player->Audio.connect (bind (&AnalyseAudioJob::audio, this, _1)); - int64_t total_audio_frames = video_frames_to_audio_frames (_film->length().get(), _film->audio_stream()->sample_rate(), _film->frames_per_second()); - _samples_per_point = total_audio_frames / _num_points; + _samples_per_point = max (int64_t (1), _film->audio_length() / _num_points); - _current.resize (_film->audio_stream()->channels ()); - _analysis.reset (new AudioAnalysis (_film->audio_stream()->channels())); + _current.resize (_film->audio_channels ()); + _analysis.reset (new AudioAnalysis (_film->audio_channels())); - while (!decoders.audio->pass()) { - set_progress (float (_done) / total_audio_frames); + while (!player->pass()) { + set_progress (float (_done) / _film->audio_length ()); } _analysis->write (_film->audio_analysis_path ());