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