13
0

Update analysis duration when post-processing

This prevents the need to re-bin data in case silence is
trimmed at start or end of the export.
This commit is contained in:
Robin Gareus 2021-04-09 03:50:12 +02:00
parent df47da4e55
commit 89a65f76b0
Signed by: rgareus
GPG Key ID: A090BCE02CF57F04
4 changed files with 39 additions and 17 deletions

View File

@ -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&);

View File

@ -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<Sample> (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<SFC>::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<SFC>::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);
}
}

View File

@ -34,6 +34,8 @@ class LIBAUDIOGRAPHER_API Analyser : public LoudnessReader
void process (ProcessContext<float> 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;

View File

@ -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<float> const & ctx)
{