diff options
| author | Carl Hetherington <cth@carlh.net> | 2015-05-10 00:15:44 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2015-05-10 00:15:44 +0100 |
| commit | fc96a4b3d6985f28db6bc0e9418e98cc5bec87e3 (patch) | |
| tree | e6866c8006ccf4fb400bfb8e8481a4f1142fb2e3 /src/lib | |
| parent | 55002ca15ba288002aeedf3867fb9d07b7b653f0 (diff) | |
7fd73c0cf1f723896826c77fec3720c5c404d4e8 from master; tidy audio analysis dialogue and add overall peak.
Diffstat (limited to 'src/lib')
| -rw-r--r-- | src/lib/analyse_audio_job.cc | 14 | ||||
| -rw-r--r-- | src/lib/analyse_audio_job.h | 3 | ||||
| -rw-r--r-- | src/lib/audio_analysis.cc | 16 | ||||
| -rw-r--r-- | src/lib/audio_analysis.h | 18 |
4 files changed, 49 insertions, 2 deletions
diff --git a/src/lib/analyse_audio_job.cc b/src/lib/analyse_audio_job.cc index 079fe884e..cdf623876 100644 --- a/src/lib/analyse_audio_job.cc +++ b/src/lib/analyse_audio_job.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2012 Carl Hetherington <cth@carlh.net> + Copyright (C) 2012-2015 Carl Hetherington <cth@carlh.net> This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -39,6 +39,8 @@ AnalyseAudioJob::AnalyseAudioJob (shared_ptr<const Film> f, shared_ptr<AudioCont , _content (c) , _done (0) , _samples_per_point (1) + , _overall_peak (0) + , _overall_peak_frame (0) { } @@ -81,6 +83,7 @@ AnalyseAudioJob::run () set_progress (t.seconds() / _film->length().seconds()); } + _analysis->set_peak (_overall_peak, DCPTime::from_frames (_overall_peak_frame, _film->audio_frame_rate ())); _analysis->write (content->audio_analysis_path ()); set_progress (1); @@ -101,6 +104,15 @@ AnalyseAudioJob::analyse (shared_ptr<const AudioBuffers> b) _current[j][AudioPoint::RMS] += pow (s, 2); _current[j][AudioPoint::PEAK] = max (_current[j][AudioPoint::PEAK], fabsf (s)); + float const as = fabs (s); + + _current[j][AudioPoint::PEAK] = max (_current[j][AudioPoint::PEAK], as); + + if (as > _overall_peak) { + _overall_peak = as; + _overall_peak_frame = _done + i; + } + if ((_done % _samples_per_point) == 0) { _current[j][AudioPoint::RMS] = sqrt (_current[j][AudioPoint::RMS] / _samples_per_point); _analysis->add_point (j, _current[j]); diff --git a/src/lib/analyse_audio_job.h b/src/lib/analyse_audio_job.h index 6f64dd272..0f9605eed 100644 --- a/src/lib/analyse_audio_job.h +++ b/src/lib/analyse_audio_job.h @@ -52,6 +52,9 @@ private: int64_t _samples_per_point; std::vector<AudioPoint> _current; + float _overall_peak; + AudioFrame _overall_peak_frame; + boost::shared_ptr<AudioAnalysis> _analysis; static const int _num_points; diff --git a/src/lib/audio_analysis.cc b/src/lib/audio_analysis.cc index 19a0d876e..ee34b0d80 100644 --- a/src/lib/audio_analysis.cc +++ b/src/lib/audio_analysis.cc @@ -22,6 +22,7 @@ #include "cross.h" #include <boost/filesystem.hpp> #include <stdint.h> +#include <inttypes.h> #include <cmath> #include <cassert> #include <cstdio> @@ -115,6 +116,17 @@ AudioAnalysis::AudioAnalysis (boost::filesystem::path filename) } } + /* These may not exist in old analysis files, so be careful + about reading them. + */ + + float peak; + DCPTime::Type peak_time; + if (fscanf (f, "%f%" SCNd64, &peak, &peak_time) == 2) { + _peak = peak; + _peak_time = DCPTime (peak_time); + } + fclose (f); } @@ -164,6 +176,10 @@ AudioAnalysis::write (boost::filesystem::path filename) } } + if (_peak) { + fprintf (f, "%f%" PRId64, _peak.get (), _peak_time.get().get ()); + } + fclose (f); boost::filesystem::rename (tmp, filename); } diff --git a/src/lib/audio_analysis.h b/src/lib/audio_analysis.h index 865d64781..1872c57ad 100644 --- a/src/lib/audio_analysis.h +++ b/src/lib/audio_analysis.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2012-2014 Carl Hetherington <cth@carlh.net> + Copyright (C) 2012-2015 Carl Hetherington <cth@carlh.net> This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -24,7 +24,9 @@ #ifndef DCPOMATIC_AUDIO_ANALYSIS_H #define DCPOMATIC_AUDIO_ANALYSIS_H +#include "types.h" #include <boost/filesystem.hpp> +#include <boost/optional.hpp> #include <vector> /** @class AudioPoint @@ -69,15 +71,29 @@ public: AudioAnalysis (boost::filesystem::path); void add_point (int c, AudioPoint const & p); + void set_peak (float peak, DCPTime time) { + _peak = peak; + _peak_time = time; + } AudioPoint get_point (int c, int p) const; int points (int c) const; int channels () const; + boost::optional<float> peak () const { + return _peak; + } + + boost::optional<DCPTime> peak_time () const { + return _peak_time; + } + void write (boost::filesystem::path); private: std::vector<std::vector<AudioPoint> > _data; + boost::optional<float> _peak; + boost::optional<DCPTime> _peak_time; }; #endif |
