projects
/
dcpomatic.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Auto-save metadata before starting a DCP encode.
[dcpomatic.git]
/
src
/
lib
/
analyse_audio_job.cc
diff --git
a/src/lib/analyse_audio_job.cc
b/src/lib/analyse_audio_job.cc
index bcabb6c91e8697b96c3f162ff7364c77faaf193c..bfe0ed61f281816a71e20b66f17c18e429d46ac9 100644
(file)
--- a/
src/lib/analyse_audio_job.cc
+++ b/
src/lib/analyse_audio_job.cc
@@
-21,19
+21,21
@@
#include "analyse_audio_job.h"
#include "compose.hpp"
#include "film.h"
#include "analyse_audio_job.h"
#include "compose.hpp"
#include "film.h"
-#include "
options
.h"
-#include "decoder_factory.h"
-#include "
audio_decoder
.h"
+#include "
player
.h"
+
+#include "
i18n
.h"
using std::string;
using std::max;
using std::string;
using std::max;
+using std::min;
using std::cout;
using boost::shared_ptr;
int const AnalyseAudioJob::_num_points = 1024;
using std::cout;
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)
: Job (f)
+ , _content (c)
, _done (0)
, _samples_per_point (1)
{
, _done (0)
, _samples_per_point (1)
{
@@
-43,45
+45,49
@@
AnalyseAudioJob::AnalyseAudioJob (shared_ptr<Film> f)
string
AnalyseAudioJob::name () const
{
string
AnalyseAudioJob::name () const
{
- return String::compose ("Analyse audio of %1", _film->name());
+ return _("Analyse audio");
+}
+
+string
+AnalyseAudioJob::json_name () const
+{
+ return N_("analyse_audio");
}
void
AnalyseAudioJob::run ()
{
}
void
AnalyseAudioJob::run ()
{
- if (!_film->audio_stream () || !_film->length()) {
- set_progress (1);
- set_state (FINISHED_ERROR);
+ shared_ptr<AudioContent> content = _content.lock ();
+ if (!content) {
return;
}
return;
}
-
- DecodeOptions options;
- options.decode_video = false;
- Decoders decoders = decoder_factory (_film, options);
- assert (decoders.audio);
+ shared_ptr<Playlist> playlist (new Playlist);
+ playlist->add (content);
+ shared_ptr<Player> player (new Player (_film, playlist));
+ 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, _2));
+
+ _samples_per_point = max (int64_t (1), _film->time_to_audio_frames (_film->length()) / _num_points);
-
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
;
+
_current.resize (_film->audio_channels
());
+ _
analysis.reset (new AudioAnalysis (_film->audio_channels ()))
;
- _current.resize (_film->audio_stream()->channels ());
- _analysis.reset (new AudioAnalysis (_film->audio_stream()->channels()));
-
- while (!decoders.audio->pass()) {
- set_progress (float (_done) / total_audio_frames);
+ _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
set_progress (1);
set_state (FINISHED_OK);
}
void
-AnalyseAudioJob::audio (shared_ptr<
AudioBuffers> b
)
+AnalyseAudioJob::audio (shared_ptr<
const AudioBuffers> b, Time
)
{
for (int i = 0; i < b->frames(); ++i) {
for (int j = 0; j < b->channels(); ++j) {
{
for (int i = 0; i < b->frames(); ++i) {
for (int j = 0; j < b->channels(); ++j) {
@@
-97,7
+103,7
@@
AnalyseAudioJob::audio (shared_ptr<AudioBuffers> 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]);
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 ();
}
}
_current[j] = AudioPoint ();
}
}