From 240daf95f5377464d775a7a49e7981310f22204b Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Tue, 16 Feb 2016 15:09:31 +0100 Subject: re-bin analysis results to take silence striping into account. --- libs/audiographer/src/general/analyser.cc | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) (limited to 'libs') diff --git a/libs/audiographer/src/general/analyser.cc b/libs/audiographer/src/general/analyser.cc index ec47b13b32..b6a3e1bbde 100644 --- a/libs/audiographer/src/general/analyser.cc +++ b/libs/audiographer/src/general/analyser.cc @@ -242,11 +242,33 @@ ARDOUR::ExportAnalysisPtr Analyser::result () { DEBUG_TRACE (PBD::DEBUG::ExportAnalysis, string_compose ("Processed %1 / %2 samples\n", _pos, _n_samples)); - if (_pos == 0 || ::llabs (_pos -_n_samples) > 1) { - printf("NO ANAL\n"); + if (_pos == 0 || _pos > _n_samples + 1) { return ARDOUR::ExportAnalysisPtr (); } + if (_pos + 1 < _n_samples) { + // crude re-bin (silence stripped version) + const size_t peaks = sizeof (_result.peaks) / sizeof (ARDOUR::PeakData::PeakDatum) / 4; + for (framecnt_t b = peaks - 1; b > 0; --b) { + for (unsigned int c = 0; c < _result.n_channels; ++c) { + const framecnt_t sb = b * _pos / _n_samples; + _result.peaks[c][b].min = _result.peaks[c][sb].min; + _result.peaks[c][b].max = _result.peaks[c][sb].max; + } + } + + 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; + for (framecnt_t b = width - 1; b > 0; --b) { + // TODO round down to prev _fft_data_size bin + const framecnt_t sb = b * _pos / _n_samples; + for (unsigned int y = 0; y < height; ++y) { + _result.spectrum[b][y] = _result.spectrum[sb][y]; + } + } + } + if (_ebur128_plugin) { Vamp::Plugin::FeatureSet features = _ebur128_plugin->getRemainingFeatures (); if (!features.empty () && features.size () == 3) { -- cgit v1.2.3