annotate data/model/FFTModel.h @ 158:74abef65711b

* Fixes pulled across from Rosegarden
author Chris Cannam
date Wed, 16 Aug 2006 14:57:22 +0000
parents ae9be6b6b522
children f75f8a1cd7b1
rev   line source
Chris@152 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@152 2
Chris@152 3 /*
Chris@152 4 Sonic Visualiser
Chris@152 5 An audio file viewer and annotation editor.
Chris@152 6 Centre for Digital Music, Queen Mary, University of London.
Chris@152 7 This file copyright 2006 Chris Cannam.
Chris@152 8
Chris@152 9 This program is free software; you can redistribute it and/or
Chris@152 10 modify it under the terms of the GNU General Public License as
Chris@152 11 published by the Free Software Foundation; either version 2 of the
Chris@152 12 License, or (at your option) any later version. See the file
Chris@152 13 COPYING included with this distribution for more information.
Chris@152 14 */
Chris@152 15
Chris@152 16 #ifndef _FFT_MODEL_H_
Chris@152 17 #define _FFT_MODEL_H_
Chris@152 18
Chris@152 19 #include "data/fft/FFTDataServer.h"
Chris@152 20 #include "DenseThreeDimensionalModel.h"
Chris@152 21
Chris@152 22 class FFTModel : public DenseThreeDimensionalModel
Chris@152 23 {
Chris@152 24 public:
Chris@152 25 FFTModel(const DenseTimeValueModel *model,
Chris@152 26 int channel,
Chris@152 27 WindowType windowType,
Chris@152 28 size_t windowSize,
Chris@152 29 size_t windowIncrement,
Chris@152 30 size_t fftSize,
Chris@152 31 bool polar,
Chris@152 32 size_t fillFromColumn = 0);
Chris@152 33 ~FFTModel();
Chris@152 34
Chris@152 35 size_t getWidth() const {
Chris@152 36 return m_server->getWidth() >> m_xshift;
Chris@152 37 }
Chris@152 38 size_t getHeight() const {
Chris@152 39 return m_server->getHeight() >> m_yshift;
Chris@152 40 }
Chris@152 41 float getMagnitudeAt(size_t x, size_t y) {
Chris@152 42 return m_server->getMagnitudeAt(x << m_xshift, y << m_yshift);
Chris@152 43 }
Chris@152 44 float getNormalizedMagnitudeAt(size_t x, size_t y) {
Chris@152 45 return m_server->getNormalizedMagnitudeAt(x << m_xshift, y << m_yshift);
Chris@152 46 }
Chris@152 47 float getMaximumMagnitudeAt(size_t x) {
Chris@152 48 return m_server->getMaximumMagnitudeAt(x << m_xshift);
Chris@152 49 }
Chris@152 50 float getPhaseAt(size_t x, size_t y) {
Chris@152 51 return m_server->getPhaseAt(x << m_xshift, y << m_yshift);
Chris@152 52 }
Chris@152 53 void getValuesAt(size_t x, size_t y, float &real, float &imaginary) {
Chris@152 54 m_server->getValuesAt(x << m_xshift, y << m_yshift, real, imaginary);
Chris@152 55 }
Chris@152 56 bool isColumnReady(size_t x) {
Chris@152 57 return m_server->isColumnReady(x << m_xshift);
Chris@152 58 }
Chris@152 59 bool isLocalPeak(size_t x, size_t y) {
Chris@152 60 float mag = getMagnitudeAt(x, y);
Chris@152 61 if (y > 0 && mag < getMagnitudeAt(x, y - 1)) return false;
Chris@152 62 if (y < getHeight() - 1 && mag < getMagnitudeAt(x, y + 1)) return false;
Chris@152 63 return true;
Chris@152 64 }
Chris@152 65 bool isOverThreshold(size_t x, size_t y, float threshold) {
Chris@152 66 return getMagnitudeAt(x, y) > threshold;
Chris@152 67 }
Chris@152 68
Chris@152 69 size_t getFillExtent() const { return m_server->getFillExtent(); }
Chris@152 70
Chris@152 71 // DenseThreeDimensionalModel and Model methods:
Chris@152 72 //
Chris@152 73 virtual bool isOK() const {
Chris@152 74 return m_server && m_server->getModel();
Chris@152 75 }
Chris@152 76 virtual size_t getStartFrame() const {
Chris@152 77 return 0;
Chris@152 78 }
Chris@152 79 virtual size_t getEndFrame() const {
Chris@152 80 return getWidth() * getResolution() + getResolution();
Chris@152 81 }
Chris@152 82 virtual size_t getSampleRate() const;
Chris@152 83 virtual size_t getResolution() const {
Chris@152 84 return m_server->getWindowIncrement() << m_xshift;
Chris@152 85 }
Chris@152 86 virtual size_t getYBinCount() const {
Chris@152 87 return getHeight();
Chris@152 88 }
Chris@152 89 virtual float getMinimumLevel() const {
Chris@152 90 return 0.f; // Can't provide
Chris@152 91 }
Chris@152 92 virtual float getMaximumLevel() const {
Chris@152 93 return 1.f; // Can't provide
Chris@152 94 }
Chris@152 95 virtual void getBinValues(long windowStartFrame, BinValueSet &result) const;
Chris@152 96 virtual float getBinValue(long windowStartFrame, size_t n) const;
Chris@152 97 virtual QString getBinName(size_t n) const;
Chris@152 98
Chris@152 99 virtual int getCompletion() const { return m_server->getFillCompletion(); }
Chris@152 100
Chris@152 101 virtual Model *clone() const;
Chris@152 102
Chris@154 103 virtual void suspend() { m_server->suspend(); }
Chris@155 104 virtual void suspendWrites() { m_server->suspendWrites(); }
Chris@154 105 virtual void resume() { m_server->resume(); }
Chris@154 106
Chris@152 107 private:
Chris@152 108 FFTModel(const FFTModel &);
Chris@152 109 FFTModel &operator=(const FFTModel &); // not implemented
Chris@152 110
Chris@152 111 FFTDataServer *m_server;
Chris@152 112 int m_xshift;
Chris@152 113 int m_yshift;
Chris@152 114 };
Chris@152 115
Chris@152 116 #endif