Mercurial > hg > easaier-soundaccess
comparison data/model/FFTModel.cpp @ 0:fc9323a41f5a
start base : Sonic Visualiser sv1-1.0rc1
author | lbajardsilogic |
---|---|
date | Fri, 11 May 2007 09:08:14 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:fc9323a41f5a |
---|---|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ | |
2 | |
3 /* | |
4 Sonic Visualiser | |
5 An audio file viewer and annotation editor. | |
6 Centre for Digital Music, Queen Mary, University of London. | |
7 This file copyright 2006 Chris Cannam. | |
8 | |
9 This program is free software; you can redistribute it and/or | |
10 modify it under the terms of the GNU General Public License as | |
11 published by the Free Software Foundation; either version 2 of the | |
12 License, or (at your option) any later version. See the file | |
13 COPYING included with this distribution for more information. | |
14 */ | |
15 | |
16 #include "FFTModel.h" | |
17 #include "DenseTimeValueModel.h" | |
18 | |
19 #include "base/Profiler.h" | |
20 | |
21 #include <cassert> | |
22 | |
23 FFTModel::FFTModel(const DenseTimeValueModel *model, | |
24 int channel, | |
25 WindowType windowType, | |
26 size_t windowSize, | |
27 size_t windowIncrement, | |
28 size_t fftSize, | |
29 bool polar, | |
30 size_t fillFromColumn) : | |
31 //!!! ZoomConstraint! | |
32 m_server(0), | |
33 m_xshift(0), | |
34 m_yshift(0) | |
35 { | |
36 m_server = FFTDataServer::getFuzzyInstance(model, | |
37 channel, | |
38 windowType, | |
39 windowSize, | |
40 windowIncrement, | |
41 fftSize, | |
42 polar, | |
43 fillFromColumn); | |
44 | |
45 if (!m_server) return; // caller should check isOK() | |
46 | |
47 size_t xratio = windowIncrement / m_server->getWindowIncrement(); | |
48 size_t yratio = m_server->getFFTSize() / fftSize; | |
49 | |
50 while (xratio > 1) { | |
51 if (xratio & 0x1) { | |
52 std::cerr << "ERROR: FFTModel: Window increment ratio " | |
53 << windowIncrement << " / " | |
54 << m_server->getWindowIncrement() | |
55 << " must be a power of two" << std::endl; | |
56 assert(!(xratio & 0x1)); | |
57 } | |
58 ++m_xshift; | |
59 xratio >>= 1; | |
60 } | |
61 | |
62 while (yratio > 1) { | |
63 if (yratio & 0x1) { | |
64 std::cerr << "ERROR: FFTModel: FFT size ratio " | |
65 << m_server->getFFTSize() << " / " << fftSize | |
66 << " must be a power of two" << std::endl; | |
67 assert(!(yratio & 0x1)); | |
68 } | |
69 ++m_yshift; | |
70 yratio >>= 1; | |
71 } | |
72 } | |
73 | |
74 FFTModel::~FFTModel() | |
75 { | |
76 if (m_server) FFTDataServer::releaseInstance(m_server); | |
77 } | |
78 | |
79 size_t | |
80 FFTModel::getSampleRate() const | |
81 { | |
82 return isOK() ? m_server->getModel()->getSampleRate() : 0; | |
83 } | |
84 | |
85 void | |
86 FFTModel::getColumn(size_t x, Column &result) const | |
87 { | |
88 Profiler profiler("FFTModel::getColumn", false); | |
89 | |
90 result.clear(); | |
91 size_t height(getHeight()); | |
92 for (size_t y = 0; y < height; ++y) { | |
93 result.push_back(const_cast<FFTModel *>(this)->getMagnitudeAt(x, y)); | |
94 } | |
95 } | |
96 | |
97 QString | |
98 FFTModel::getBinName(size_t n) const | |
99 { | |
100 size_t sr = getSampleRate(); | |
101 if (!sr) return ""; | |
102 QString name = tr("%1 Hz").arg((n * sr) / ((getHeight()-1) * 2)); | |
103 return name; | |
104 } | |
105 | |
106 Model * | |
107 FFTModel::clone() const | |
108 { | |
109 return new FFTModel(*this); | |
110 } | |
111 | |
112 FFTModel::FFTModel(const FFTModel &model) : | |
113 DenseThreeDimensionalModel(), | |
114 m_server(model.m_server), | |
115 m_xshift(model.m_xshift), | |
116 m_yshift(model.m_yshift) | |
117 { | |
118 FFTDataServer::claimInstance(m_server); | |
119 } | |
120 |