1 #ifndef _CORRELATION_MEASURER_H
2 #define _CORRELATION_MEASURER_H 1
4 // Measurement of left/right stereo correlation. +1 is pure mono
5 // (okay but not ideal), 0 is no correlation (usually bad, unless
6 // it is due to silence), strongly negative values means inverted
7 // phase (bad). Typical values for e.g. music would be somewhere
8 // around +0.7, although you can expect it to vary a bit.
10 // This is, of course, based on the regular Pearson correlation,
11 // where µ_L and µ_R is taken to be 0 (ie., no DC offset). It is
12 // filtered through a simple IIR filter so that older values are
13 // weighed less than newer, depending on <falloff_seconds>.
16 // Adapted from Adriaensen's project Zita-mu1 (as of January 2016).
17 // Original copyright follows:
19 // Copyright (C) 2008-2015 Fons Adriaensen <fons@linuxaudio.org>
21 // This program is free software; you can redistribute it and/or modify
22 // it under the terms of the GNU General Public License as published by
23 // the Free Software Foundation; either version 3 of the License, or
24 // (at your option) any later version.
26 // This program is distributed in the hope that it will be useful,
27 // but WITHOUT ANY WARRANTY; without even the implied warranty of
28 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29 // GNU General Public License for more details.
31 // You should have received a copy of the GNU General Public License
32 // along with this program. If not, see <http://www.gnu.org/licenses/>.
36 class CorrelationMeasurer {
38 CorrelationMeasurer(unsigned sample_rate, float lowpass_cutoff_hz = 1000.0f,
39 float falloff_seconds = 0.150f);
40 void process_samples(const std::vector<float> &samples); // Taken to be stereo, interleaved.
42 float get_correlation() const;
47 // Filtered values of left and right channel, respectively.
48 float zl = 0.0f, zr = 0.0f;
50 // Filtered values of l², r² and lr (where l and r are the filtered
51 // versions, given by zl and zr). Together, they make up what we need
52 // to calculate the correlation.
53 float zll = 0.0f, zlr = 0.0f, zrr = 0.0f;
56 #endif // !defined(_CORRELATION_MEASURER_H)