Mercurial > hg > svcore
comparison base/FFTFileCache.cpp @ 90:c4e163f911dd
* Switch spectrogram layer over to using the new rudimentary disk-backed
FFT cache
author | Chris Cannam |
---|---|
date | Wed, 03 May 2006 14:26:26 +0000 |
parents | 024d4a71f5bf |
children | 1aebdc68ec6d |
comparison
equal
deleted
inserted
replaced
89:6a1803d578e0 | 90:c4e163f911dd |
---|---|
15 | 15 |
16 #include "FFTFileCache.h" | 16 #include "FFTFileCache.h" |
17 | 17 |
18 #include "MatrixFileCache.h" | 18 #include "MatrixFileCache.h" |
19 | 19 |
20 FFTFileCache::FFTFileCache() | 20 #include <iostream> |
21 | |
22 //!!! This class is a work in progress -- it does only as much as we | |
23 // need for the current SpectrogramLayer. Slated for substantial | |
24 // refactoring and extension. | |
25 | |
26 // The underlying matrix has height (m_height * 2 + 1). In each | |
27 // column we store magnitude at [0], [2] etc and phase at [1], [3] | |
28 // etc, and then store the normalization factor (maximum magnitude) at | |
29 // [m_height * 2]. | |
30 | |
31 FFTFileCache::FFTFileCache(QString fileBase, MatrixFileCache::Mode mode) : | |
32 m_colbuf(0), | |
33 m_mfc(new MatrixFileCache(fileBase, mode)) | |
21 { | 34 { |
22 //... | |
23 | |
24 } | 35 } |
36 | |
37 FFTFileCache::~FFTFileCache() | |
38 { | |
39 delete m_colbuf; | |
40 delete m_mfc; | |
41 } | |
42 | |
43 size_t | |
44 FFTFileCache::getWidth() const | |
45 { | |
46 return m_mfc->getWidth(); | |
47 } | |
48 | |
49 size_t | |
50 FFTFileCache::getHeight() const | |
51 { | |
52 size_t mh = m_mfc->getHeight(); | |
53 if (mh > 0) return (mh - 1) / 2; | |
54 else return 0; | |
55 } | |
56 | |
57 void | |
58 FFTFileCache::resize(size_t width, size_t height) | |
59 { | |
60 m_mfc->resize(width, height * 2 + 1); | |
61 delete m_colbuf; | |
62 m_colbuf = new float[height * 2 + 1]; | |
63 } | |
64 | |
65 void | |
66 FFTFileCache::reset() | |
67 { | |
68 m_mfc->reset(); | |
69 } | |
70 | |
71 float | |
72 FFTFileCache::getMagnitudeAt(size_t x, size_t y) const | |
73 { | |
74 return m_mfc->getValueAt(x, y * 2); | |
75 } | |
76 | |
77 float | |
78 FFTFileCache::getNormalizedMagnitudeAt(size_t x, size_t y) const | |
79 { | |
80 float factor = m_mfc->getValueAt(x, m_mfc->getHeight() - 1); | |
81 float mag = m_mfc->getValueAt(x, y * 2); | |
82 if (factor != 0) return mag / factor; | |
83 else return 0.f; | |
84 } | |
85 | |
86 float | |
87 FFTFileCache::getPhaseAt(size_t x, size_t y) const | |
88 { | |
89 return m_mfc->getValueAt(x, y * 2 + 1); | |
90 } | |
91 | |
92 void | |
93 FFTFileCache::setNormalizationFactor(size_t x, float factor) | |
94 { | |
95 m_mfc->setValueAt(x, m_mfc->getHeight() - 1, factor); | |
96 } | |
97 | |
98 void | |
99 FFTFileCache::setMagnitudeAt(size_t x, size_t y, float mag) | |
100 { | |
101 m_mfc->setValueAt(x, y * 2, mag); | |
102 } | |
103 | |
104 void | |
105 FFTFileCache::setNormalizedMagnitudeAt(size_t x, size_t y, float norm) | |
106 { | |
107 float factor = m_mfc->getValueAt(x, m_mfc->getHeight() - 1); | |
108 m_mfc->setValueAt(x, y * 2, norm * factor); | |
109 } | |
110 | |
111 void | |
112 FFTFileCache::setPhaseAt(size_t x, size_t y, float phase) | |
113 { | |
114 m_mfc->setValueAt(x, y * 2 + 1, phase); | |
115 } | |
116 | |
117 void | |
118 FFTFileCache::setColumnAt(size_t x, float *mags, float *phases, float factor) | |
119 { | |
120 size_t h = getHeight(); | |
121 for (size_t y = 0; y < h; ++y) { | |
122 m_colbuf[y * 2] = mags[y]; | |
123 m_colbuf[y * 2 + 1] = phases[y]; | |
124 } | |
125 m_colbuf[h * 2] = factor; | |
126 m_mfc->setColumnAt(x, m_colbuf); | |
127 } | |
128 |