c@116: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ c@116: /* c@116: Constant-Q library c@116: Copyright (c) 2013-2014 Queen Mary, University of London c@116: c@116: Permission is hereby granted, free of charge, to any person c@116: obtaining a copy of this software and associated documentation c@116: files (the "Software"), to deal in the Software without c@116: restriction, including without limitation the rights to use, copy, c@116: modify, merge, publish, distribute, sublicense, and/or sell copies c@116: of the Software, and to permit persons to whom the Software is c@116: furnished to do so, subject to the following conditions: c@116: c@116: The above copyright notice and this permission notice shall be c@116: included in all copies or substantial portions of the Software. c@116: c@116: THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, c@116: EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF c@116: MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND c@116: NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY c@116: CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF c@116: CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION c@116: WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. c@116: c@116: Except as contained in this notice, the names of the Centre for c@116: Digital Music; Queen Mary, University of London; and Chris Cannam c@116: shall not be used in advertising or otherwise to promote the sale, c@116: use or other dealings in this Software without prior written c@116: authorization. c@116: */ c@116: c@116: #ifndef CONSTANTQ_H c@116: #define CONSTANTQ_H c@116: c@116: #include "CQBase.h" c@127: #include "CQParameters.h" c@116: #include "CQKernel.h" c@116: c@116: class Resampler; c@116: class FFTReal; c@116: c@116: /** c@116: * Calculate a complex sparse constant-Q representation from c@116: * time-domain input. c@116: * c@116: * For a real (magnitude-only) or interpolated representation, see c@116: * CQSpectrogram. c@116: */ c@116: class ConstantQ : public CQBase c@116: { c@116: public: c@127: ConstantQ(CQParameters params); c@116: virtual ~ConstantQ(); c@116: c@116: virtual double getSampleRate() const { return m_sampleRate; } c@116: virtual int getBinsPerOctave() const { return m_binsPerOctave; } c@116: virtual int getOctaves() const { return m_octaves; } c@116: virtual int getTotalBins() const { return m_octaves * m_binsPerOctave; } c@116: virtual int getColumnHop() const { return m_p.fftHop / m_p.atomsPerFrame; } c@116: virtual int getLatency() const { return m_outputLatency; } c@116: virtual double getMaxFrequency() const { return m_p.maxFrequency; } c@116: virtual double getMinFrequency() const; c@116: virtual double getBinFrequency(int bin) const; c@116: c@116: /** c@116: * Given a series of time-domain samples, return a series of c@116: * constant-Q columns. Any samples left over (that did not fit c@116: * into a constant-Q processing block) are saved for the next call c@116: * to process or getRemainingBlocks. c@116: * c@116: * Each column contains a series of constant-Q bin values ordered c@116: * from highest to lowest frequency. c@116: * c@116: * Columns are of variable height: each will contain at least c@116: * getBinsPerOctave() values, because the highest-frequency octave c@116: * is always present, but a second octave (if requested) will c@116: * appear only in alternate columns, a third octave only in every c@116: * fourth column, and so on. c@116: * c@116: * If you need a format in which all columns are of equal height c@116: * and every bin contains a value, use CQInterpolated instead of c@116: * ConstantQ. c@116: */ c@116: ComplexBlock process(const RealSequence &); c@116: c@116: /** c@116: * Return the remaining constant-Q columns following the end of c@116: * processing. Any buffered input is padded so as to ensure that c@116: * all input provided to process() will have been returned. c@116: */ c@116: ComplexBlock getRemainingOutput(); c@116: c@116: private: c@127: const CQParameters m_inparams; c@127: const double m_sampleRate; c@127: const double m_maxFrequency; c@127: const double m_minFrequency; c@127: const int m_binsPerOctave; c@127: c@116: int m_octaves; c@116: CQKernel *m_kernel; c@116: CQKernel::Properties m_p; c@116: int m_bigBlockSize; c@116: c@116: std::vector m_decimators; c@116: std::vector m_buffers; c@116: c@116: int m_outputLatency; c@116: c@116: FFTReal *m_fft; c@116: c@116: void initialise(); c@116: ComplexBlock processOctaveBlock(int octave); c@116: }; c@116: c@116: #endif c@116: