annotate data/model/FFTModel.h @ 254:d2ffb480ff33

* Experiment with sizing the property stacks and using a frame on the overview widget with an eye to making the default empty window look a bit nicer
author Chris Cannam
date Mon, 16 Apr 2007 12:20:27 +0000
parents 21b9b25bff48
children f1f47660483d
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@254 22 /**
Chris@254 23 * An implementation of DenseThreeDimensionalModel that makes FFT data
Chris@254 24 * derived from a DenseTimeValueModel available as a generic data grid.
Chris@254 25 * The FFT data is acquired using FFTDataServer.
Chris@254 26 */
Chris@254 27
Chris@152 28 class FFTModel : public DenseThreeDimensionalModel
Chris@152 29 {
Chris@247 30 Q_OBJECT
Chris@247 31
Chris@152 32 public:
Chris@254 33 /**
Chris@254 34 * Construct an FFT model derived from the given
Chris@254 35 * DenseTimeValueModel, with the given window parameters and FFT
Chris@254 36 * size (which may exceed the window size, for zero-padded FFTs).
Chris@254 37 *
Chris@254 38 * If the model has multiple channels use only the given channel,
Chris@254 39 * unless the channel is -1 in which case merge all available
Chris@254 40 * channels.
Chris@254 41 *
Chris@254 42 * If polar is true, the data will normally be retrieved from the
Chris@254 43 * FFT model in magnitude/phase form; otherwise it will normally
Chris@254 44 * be retrieved in "cartesian" real/imaginary form. The results
Chris@254 45 * should be the same either way, but a "polar" model addressed in
Chris@254 46 * "cartesian" form or vice versa may suffer a performance
Chris@254 47 * penalty.
Chris@254 48 *
Chris@254 49 * The fillFromColumn argument gives a hint that the FFT data
Chris@254 50 * server should aim to start calculating FFT data at that column
Chris@254 51 * number if possible, as that is likely to be requested first.
Chris@254 52 */
Chris@152 53 FFTModel(const DenseTimeValueModel *model,
Chris@152 54 int channel,
Chris@152 55 WindowType windowType,
Chris@152 56 size_t windowSize,
Chris@152 57 size_t windowIncrement,
Chris@152 58 size_t fftSize,
Chris@152 59 bool polar,
Chris@152 60 size_t fillFromColumn = 0);
Chris@152 61 ~FFTModel();
Chris@152 62
Chris@152 63 float getMagnitudeAt(size_t x, size_t y) {
Chris@152 64 return m_server->getMagnitudeAt(x << m_xshift, y << m_yshift);
Chris@152 65 }
Chris@152 66 float getNormalizedMagnitudeAt(size_t x, size_t y) {
Chris@152 67 return m_server->getNormalizedMagnitudeAt(x << m_xshift, y << m_yshift);
Chris@152 68 }
Chris@152 69 float getMaximumMagnitudeAt(size_t x) {
Chris@152 70 return m_server->getMaximumMagnitudeAt(x << m_xshift);
Chris@152 71 }
Chris@152 72 float getPhaseAt(size_t x, size_t y) {
Chris@152 73 return m_server->getPhaseAt(x << m_xshift, y << m_yshift);
Chris@152 74 }
Chris@152 75 void getValuesAt(size_t x, size_t y, float &real, float &imaginary) {
Chris@152 76 m_server->getValuesAt(x << m_xshift, y << m_yshift, real, imaginary);
Chris@152 77 }
Chris@182 78 bool isColumnAvailable(size_t x) const {
Chris@152 79 return m_server->isColumnReady(x << m_xshift);
Chris@152 80 }
Chris@152 81
Chris@152 82 size_t getFillExtent() const { return m_server->getFillExtent(); }
Chris@152 83
Chris@152 84 // DenseThreeDimensionalModel and Model methods:
Chris@152 85 //
Chris@182 86 virtual size_t getWidth() const {
Chris@182 87 return m_server->getWidth() >> m_xshift;
Chris@182 88 }
Chris@182 89 virtual size_t getHeight() const {
Chris@212 90 // If there is no y-shift, the server's height (based on its
Chris@212 91 // fftsize/2 + 1) is correct. If there is a shift, then the
Chris@212 92 // server is using a larger fft size than we want, so we shift
Chris@212 93 // it right as many times as necessary, but then we need to
Chris@212 94 // re-add the "+1" part (because ((fftsize*2)/2 + 1) / 2 !=
Chris@212 95 // fftsize/2 + 1).
Chris@212 96 return (m_server->getHeight() >> m_yshift) + (m_yshift > 0 ? 1 : 0);
Chris@182 97 }
Chris@182 98 virtual float getValueAt(size_t x, size_t y) const {
Chris@182 99 return const_cast<FFTModel *>(this)->getMagnitudeAt(x, y);
Chris@182 100 }
Chris@152 101 virtual bool isOK() const {
Chris@152 102 return m_server && m_server->getModel();
Chris@152 103 }
Chris@152 104 virtual size_t getStartFrame() const {
Chris@152 105 return 0;
Chris@152 106 }
Chris@152 107 virtual size_t getEndFrame() const {
Chris@152 108 return getWidth() * getResolution() + getResolution();
Chris@152 109 }
Chris@152 110 virtual size_t getSampleRate() const;
Chris@152 111 virtual size_t getResolution() const {
Chris@152 112 return m_server->getWindowIncrement() << m_xshift;
Chris@152 113 }
Chris@152 114 virtual size_t getYBinCount() const {
Chris@152 115 return getHeight();
Chris@152 116 }
Chris@152 117 virtual float getMinimumLevel() const {
Chris@152 118 return 0.f; // Can't provide
Chris@152 119 }
Chris@152 120 virtual float getMaximumLevel() const {
Chris@152 121 return 1.f; // Can't provide
Chris@152 122 }
Chris@182 123 virtual void getColumn(size_t x, Column &result) const;
Chris@152 124 virtual QString getBinName(size_t n) const;
Chris@152 125
Chris@152 126 virtual int getCompletion() const { return m_server->getFillCompletion(); }
Chris@152 127
Chris@152 128 virtual Model *clone() const;
Chris@152 129
Chris@154 130 virtual void suspend() { m_server->suspend(); }
Chris@155 131 virtual void suspendWrites() { m_server->suspendWrites(); }
Chris@154 132 virtual void resume() { m_server->resume(); }
Chris@154 133
Chris@152 134 private:
Chris@152 135 FFTModel(const FFTModel &);
Chris@152 136 FFTModel &operator=(const FFTModel &); // not implemented
Chris@152 137
Chris@152 138 FFTDataServer *m_server;
Chris@152 139 int m_xshift;
Chris@152 140 int m_yshift;
Chris@152 141 };
Chris@152 142
Chris@152 143 #endif