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 CQSPECTROGRAM_H c@116: #define CQSPECTROGRAM_H c@116: c@116: #include "ConstantQ.h" c@116: c@147: /** c@147: * Calculate a dense constant-Q magnitude spectrogram from time-domain c@147: * input. The input of each \ref process call is a single frame of c@147: * time-domain samples; the output is a series of fixed-height c@147: * columns. See \ref process for details. c@147: * c@147: * If you need the full complex-valued constant-Q output, you must use c@147: * the \ref ConstantQ class instead. c@147: */ c@116: class CQSpectrogram : public CQBase c@116: { c@116: public: c@116: enum Interpolation { c@147: /// leave empty cells as zero c@147: InterpolateZeros, c@147: /// replace empty cells with a repeat of the previous column c@147: InterpolateHold, c@147: /// perform linear interpolation between consecutive time cells c@147: InterpolateLinear, c@116: }; c@116: c@147: /** c@147: * Construct a Constant-Q magnitude spectrogram object using the c@147: * given transform parameters. c@147: */ c@127: CQSpectrogram(CQParameters params, Interpolation interpolation); c@116: virtual ~CQSpectrogram(); c@116: c@147: // CQBase methods, see CQBase.h for documentation c@147: virtual bool isValid() const { return m_cq.isValid(); } c@116: virtual double getSampleRate() const { return m_cq.getSampleRate(); } c@116: virtual int getBinsPerOctave() const { return m_cq.getBinsPerOctave(); } c@116: virtual int getOctaves() const { return m_cq.getOctaves(); } c@116: virtual int getTotalBins() const { return m_cq.getTotalBins(); } c@116: virtual int getColumnHop() const { return m_cq.getColumnHop(); } c@116: virtual int getLatency() const { return m_cq.getLatency(); } c@116: virtual double getMaxFrequency() const { return m_cq.getMaxFrequency(); } c@116: virtual double getMinFrequency() const { return m_cq.getMinFrequency(); } c@145: virtual double getBinFrequency(double bin) const { return m_cq.getBinFrequency(bin); } c@116: c@136: /** c@136: * Given a series of time-domain samples, return a series of c@136: * constant-Q magnitude columns. Any samples left over (that did c@136: * not fit into a constant-Q processing block) are saved for the c@136: * next call to process or getRemainingBlocks. c@136: * c@147: * The input is assumed to be a single frame of time-domain sample c@147: * values, such that consecutive calls to \ref process receive c@147: * contiguous frames from the source signal. Each frame may be of c@147: * any length in samples. c@147: * c@147: * Each output column contains a series of constant-Q bin value c@136: * magnitudes, ordered from highest to lowest frequency. c@136: * c@136: * The columns are all of the same height, but they might not all c@136: * be populated, depending on the interpolation mode: in c@136: * InterpolateZeros mode, the lower octaves (which are spaced more c@136: * widely in the raw constant-Q than the highest octave) will c@136: * contain zeros for the undefined values, but in the other c@136: * interpolation modes every cell will be filled. c@136: * c@136: * To obtain raw, complex constant-Q bin values, use the ConstantQ c@136: * class. c@136: */ c@116: RealBlock process(const RealSequence &); c@136: c@136: /** c@136: * Return the remaining constant-Q magnitude columns following the c@136: * end of processing. Any buffered input is padded so as to ensure c@136: * that all input provided to process() will have been returned. c@136: */ c@116: RealBlock getRemainingOutput(); c@116: c@116: private: c@116: ConstantQ m_cq; c@116: Interpolation m_interpolation; c@116: c@116: RealBlock m_buffer; c@116: RealBlock postProcess(const ComplexBlock &, bool insist); c@116: RealBlock fetchHold(bool insist); c@116: RealBlock fetchLinear(bool insist); c@116: RealBlock linearInterpolated(const RealBlock &, int, int); c@116: RealColumn m_prevColumn; cannam@194: cannam@194: // Not provided (because ConstantQ isn't copyable) cannam@194: CQSpectrogram(const CQSpectrogram &); cannam@194: CQSpectrogram &operator=(const CQSpectrogram &); c@116: }; c@116: c@116: #endif