diff --git a/libs/ardour/ardour/export_graph_builder.h b/libs/ardour/ardour/export_graph_builder.h index a91858ee31..8fe3bb8a83 100644 --- a/libs/ardour/ardour/export_graph_builder.h +++ b/libs/ardour/ardour/export_graph_builder.h @@ -136,6 +136,7 @@ class LIBARDOUR_API ExportGraphBuilder void remove_children (bool remove_out_files); bool operator== (FileSpec const & other_config) const; + void set_duration (samplecnt_t); void set_peak_dbfs (float, bool force = false); void set_peak_lufs (AudioGrapher::LoudnessReader const&); diff --git a/libs/ardour/export_graph_builder.cc b/libs/ardour/export_graph_builder.cc index 0fbd997f9a..0d12cf6a5c 100644 --- a/libs/ardour/export_graph_builder.cc +++ b/libs/ardour/export_graph_builder.cc @@ -452,6 +452,7 @@ ExportGraphBuilder::SFC::SFC (ExportGraphBuilder &parent, FileSpec const & new_c samplecnt_t sb = config.format->silence_beginning_at (parent.timespan->get_start(), sample_rate); samplecnt_t se = config.format->silence_end_at (parent.timespan->get_end(), sample_rate); samplecnt_t duration = parent.timespan->get_length () + sb + se; + max_samples = std::min ((samplecnt_t) 8192 * channels, std::max ((samplecnt_t) 4096 * channels, max_samples)); chunker.reset (new Chunker (max_samples)); analyser.reset (new Analyser (config.format->sample_rate(), channels, max_samples, @@ -502,6 +503,15 @@ ExportGraphBuilder::SFC::SFC (ExportGraphBuilder &parent, FileSpec const & new_c } } +void +ExportGraphBuilder::SFC::set_duration (samplecnt_t n_samples) +{ + /* update after silence trim */ + if (analyser) { + analyser->set_duration (n_samples); + } +} + void ExportGraphBuilder::SFC::set_peak_dbfs (float peak, bool force) { @@ -704,14 +714,13 @@ ExportGraphBuilder::Intermediate::process() void ExportGraphBuilder::Intermediate::prepare_post_processing() { - if (use_loudness || use_peak) { - for (boost::ptr_list::iterator i = children.begin(); i != children.end(); ++i) { - if (use_peak) { - (*i).set_peak_dbfs (peak_reader->get_peak()); - } - if (use_loudness) { - (*i).set_peak_lufs (*loudness_reader); - } + for (boost::ptr_list::iterator i = children.begin(); i != children.end(); ++i) { + (*i).set_duration (tmp_file->get_samples_written() / config.channel_config->get_n_chans()); + if (use_peak) { + (*i).set_peak_dbfs (peak_reader->get_peak()); + } + if (use_loudness) { + (*i).set_peak_lufs (*loudness_reader); } } diff --git a/libs/audiographer/audiographer/general/analyser.h b/libs/audiographer/audiographer/general/analyser.h index 6271231432..c7b2a72b8c 100644 --- a/libs/audiographer/audiographer/general/analyser.h +++ b/libs/audiographer/audiographer/general/analyser.h @@ -34,6 +34,8 @@ class LIBAUDIOGRAPHER_API Analyser : public LoudnessReader void process (ProcessContext const & c); ARDOUR::ExportAnalysisPtr result (); + void set_duration (samplecnt_t n_samples); + void set_normalization_gain (float gain) { _result.normalized = true; _result.norm_gain_factor = gain; diff --git a/libs/audiographer/src/general/analyser.cc b/libs/audiographer/src/general/analyser.cc index 73f3422f95..60a1c934bf 100644 --- a/libs/audiographer/src/general/analyser.cc +++ b/libs/audiographer/src/general/analyser.cc @@ -33,15 +33,7 @@ Analyser::Analyser (float sample_rate, unsigned int channels, samplecnt_t bufsiz assert (bufsize > 1); assert (_bufsize > 0); - - - const size_t peaks = sizeof (_result.peaks) / sizeof (ARDOUR::PeakData::PeakDatum) / 4; - _spp = ceil ((_n_samples + 2.f) / (float) peaks); - - const size_t swh = sizeof (_result.spectrum) / sizeof (float); - const size_t height = sizeof (_result.spectrum[0]) / sizeof (float); - const size_t width = swh / height; - _fpp = ceil ((_n_samples + 2.f) / (float) width); + set_duration (n_samples); _fft_data_size = _bufsize / 2; _fft_freq_per_bin = sample_rate / _fft_data_size / 2.f; @@ -57,6 +49,7 @@ Analyser::Analyser (float sample_rate, unsigned int channels, samplecnt_t bufsiz _fft_data_out[i] = 0; } + const size_t height = sizeof (_result.spectrum[0]) / sizeof (float); const float nyquist = (sample_rate * .5); #if 0 // linear #define YPOS(FREQ) rint (height * (1.0 - FREQ / nyquist)) @@ -101,6 +94,23 @@ Analyser::~Analyser () free (_hann_window); } +void +Analyser::set_duration (samplecnt_t n_samples) +{ + if (_pos != 0) { + return; + } + _n_samples = n_samples; + + const size_t peaks = sizeof (_result.peaks) / sizeof (ARDOUR::PeakData::PeakDatum) / 4; + _spp = ceil ((_n_samples + 2.f) / (float) peaks); + + const size_t swh = sizeof (_result.spectrum) / sizeof (float); + const size_t height = sizeof (_result.spectrum[0]) / sizeof (float); + const size_t width = swh / height; + _fpp = ceil ((_n_samples + 2.f) / (float) width); +} + void Analyser::process (ProcessContext const & ctx) {