c@170: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ c@170: /* c@170: Constant-Q library c@170: Copyright (c) 2013-2015 Queen Mary, University of London c@170: c@170: Permission is hereby granted, free of charge, to any person c@170: obtaining a copy of this software and associated documentation c@170: files (the "Software"), to deal in the Software without c@170: restriction, including without limitation the rights to use, copy, c@170: modify, merge, publish, distribute, sublicense, and/or sell copies c@170: of the Software, and to permit persons to whom the Software is c@170: furnished to do so, subject to the following conditions: c@170: c@170: The above copyright notice and this permission notice shall be c@170: included in all copies or substantial portions of the Software. c@170: c@170: THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, c@170: EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF c@170: MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND c@170: NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY c@170: CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF c@170: CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION c@170: WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. c@170: c@170: Except as contained in this notice, the names of the Centre for c@170: Digital Music; Queen Mary, University of London; and Chris Cannam c@170: shall not be used in advertising or otherwise to promote the sale, c@170: use or other dealings in this Software without prior written c@170: authorization. c@170: */ c@170: c@170: #ifndef CQCHROMAGRAM_H c@170: #define CQCHROMAGRAM_H c@170: c@170: #include "CQBase.h" c@171: #include "CQParameters.h" c@170: c@170: class CQSpectrogram; c@170: c@170: class Chromagram c@170: { c@170: public: c@170: struct Parameters { c@170: Parameters(double sr) : c@170: sampleRate(sr), c@170: lowestOctave(0), c@171: octaveCount(7), c@171: binsPerOctave(36), c@171: tuningFrequency(440.), c@171: q(1.0), // Q scaling factor c@171: atomHopFactor(0.25), // hop size of shortest temporal atom c@171: threshold(0.0005), // sparsity threshold for resulting kernel c@171: window(CQParameters::SqrtBlackmanHarris) // window shape c@171: { } c@173: c@173: /** c@173: * Sampling rate of input signal. c@173: */ c@170: double sampleRate; c@173: c@173: /** c@173: * Octave number of lowest octave to include in the c@173: * chromagram. Numbering is per ASA standard with -1 as the c@173: * first octave in the MIDI range and middle-C being C4. The c@173: * octave starts at C. c@173: */ c@170: int lowestOctave; c@173: c@173: /** c@173: * Number of source constant-Q octaves to wrap around into the c@173: * single-octave chroma output. c@173: */ c@171: int octaveCount; c@173: c@173: /** c@173: * Number of constant-Q transform bins per octave and the c@173: * number of bins in the chroma output. c@173: */ c@171: int binsPerOctave; c@171: c@173: /** c@173: * Frequency of concert A, used when mapping the note-based c@173: * octave extents into frequency extents for the constant-Q c@173: * transform. c@173: */ c@170: double tuningFrequency; c@173: c@173: /** c@173: * Spectral atom bandwidth scaling factor. c@173: */ c@171: double q; c@173: c@173: /** c@173: * Hop size between temporal atoms, where 1 == no overlap and c@173: * smaller values indicate overlapping atoms. c@173: */ c@171: double atomHopFactor; c@173: c@173: /** c@173: * Sparsity threshold for Constant-Q kernel: values with c@173: * magnitude smaller than this are truncated to zero. c@173: */ c@171: double threshold; c@173: c@173: /** c@173: * Window shape to use for the Constant-Q kernel atoms. c@173: */ c@171: CQParameters::WindowType window; c@170: }; c@170: c@170: Chromagram(Parameters params); c@170: virtual ~Chromagram(); c@170: c@170: CQBase::RealBlock process(const CQBase::RealSequence &); c@170: CQBase::RealBlock getRemainingOutput(); c@170: c@170: double getMinFrequency() const { return m_minFrequency; } c@170: double getMaxFrequency() const { return m_maxFrequency; } c@170: c@170: std::string getBinName(int bin) const; c@170: c@170: bool isValid() const; c@170: int getColumnHop() const; c@170: int getLatency() const; c@170: c@170: private: c@170: Parameters m_params; c@170: CQSpectrogram *m_cq; c@170: double m_minFrequency; c@170: double m_maxFrequency; c@170: CQBase::RealBlock convert(const CQBase::RealBlock &); c@170: }; c@170: c@170: #endif c@170: c@170: c@170: