Mercurial > hg > vamp-plugin-sdk
comparison vamp-sdk/hostext/PluginInputDomainAdapter.cpp @ 70:fd58037b4a7b
* use m_impl for channel and input domain adapters as well
author | cannam |
---|---|
date | Wed, 06 Jun 2007 10:00:36 +0000 |
parents | 47d6e670a810 |
children | 64697dca0d48 |
comparison
equal
deleted
inserted
replaced
69:3456fe86d385 | 70:fd58037b4a7b |
---|---|
40 | 40 |
41 namespace Vamp { | 41 namespace Vamp { |
42 | 42 |
43 namespace HostExt { | 43 namespace HostExt { |
44 | 44 |
45 class PluginInputDomainAdapter::Impl | |
46 { | |
47 public: | |
48 Impl(Plugin *plugin, float inputSampleRate); | |
49 ~Impl(); | |
50 | |
51 bool initialise(size_t channels, size_t stepSize, size_t blockSize); | |
52 | |
53 size_t getPreferredStepSize() const; | |
54 size_t getPreferredBlockSize() const; | |
55 | |
56 FeatureSet process(const float *const *inputBuffers, RealTime timestamp); | |
57 | |
58 protected: | |
59 Plugin *m_plugin; | |
60 float m_inputSampleRate; | |
61 size_t m_channels; | |
62 size_t m_blockSize; | |
63 float **m_freqbuf; | |
64 double *m_ri; | |
65 double *m_ro; | |
66 double *m_io; | |
67 | |
68 void fft(unsigned int n, bool inverse, | |
69 double *ri, double *ii, double *ro, double *io); | |
70 | |
71 size_t makeBlockSizeAcceptable(size_t) const; | |
72 }; | |
73 | |
45 PluginInputDomainAdapter::PluginInputDomainAdapter(Plugin *plugin) : | 74 PluginInputDomainAdapter::PluginInputDomainAdapter(Plugin *plugin) : |
46 PluginWrapper(plugin), | 75 PluginWrapper(plugin) |
76 { | |
77 m_impl = new Impl(plugin, m_inputSampleRate); | |
78 } | |
79 | |
80 PluginInputDomainAdapter::~PluginInputDomainAdapter() | |
81 { | |
82 delete m_impl; | |
83 } | |
84 | |
85 bool | |
86 PluginInputDomainAdapter::initialise(size_t channels, size_t stepSize, size_t blockSize) | |
87 { | |
88 return m_impl->initialise(channels, stepSize, blockSize); | |
89 } | |
90 | |
91 Plugin::InputDomain | |
92 PluginInputDomainAdapter::getInputDomain() const | |
93 { | |
94 return TimeDomain; | |
95 } | |
96 | |
97 size_t | |
98 PluginInputDomainAdapter::getPreferredStepSize() const | |
99 { | |
100 return m_impl->getPreferredStepSize(); | |
101 } | |
102 | |
103 size_t | |
104 PluginInputDomainAdapter::getPreferredBlockSize() const | |
105 { | |
106 return m_impl->getPreferredBlockSize(); | |
107 } | |
108 | |
109 Plugin::FeatureSet | |
110 PluginInputDomainAdapter::process(const float *const *inputBuffers, RealTime timestamp) | |
111 { | |
112 return m_impl->process(inputBuffers, timestamp); | |
113 } | |
114 | |
115 PluginInputDomainAdapter::Impl::Impl(Plugin *plugin, float inputSampleRate) : | |
116 m_plugin(plugin), | |
117 m_inputSampleRate(inputSampleRate), | |
47 m_channels(0), | 118 m_channels(0), |
48 m_blockSize(0), | 119 m_blockSize(0), |
49 m_freqbuf(0) | 120 m_freqbuf(0) |
50 { | 121 { |
51 } | 122 } |
52 | 123 |
53 PluginInputDomainAdapter::~PluginInputDomainAdapter() | 124 PluginInputDomainAdapter::Impl::~Impl() |
54 { | 125 { |
126 // the adapter will delete the plugin | |
127 | |
128 if (m_channels > 0) { | |
129 for (size_t c = 0; c < m_channels; ++c) { | |
130 delete[] m_freqbuf[c]; | |
131 } | |
132 delete[] m_freqbuf; | |
133 delete[] m_ri; | |
134 delete[] m_ro; | |
135 delete[] m_io; | |
136 } | |
55 } | 137 } |
56 | 138 |
57 bool | 139 bool |
58 PluginInputDomainAdapter::initialise(size_t channels, size_t stepSize, size_t blockSize) | 140 PluginInputDomainAdapter::Impl::initialise(size_t channels, size_t stepSize, size_t blockSize) |
59 { | 141 { |
60 if (m_plugin->getInputDomain() == TimeDomain) { | 142 if (m_plugin->getInputDomain() == TimeDomain) { |
61 | 143 |
62 m_blockSize = blockSize; | 144 m_blockSize = blockSize; |
63 m_channels = channels; | 145 m_channels = channels; |
64 | 146 |
65 return m_plugin->initialise(channels, stepSize, blockSize); | 147 return m_plugin->initialise(channels, stepSize, blockSize); |
66 } | 148 } |
67 | 149 |
68 if (blockSize < 2) { | 150 if (blockSize < 2) { |
69 std::cerr << "ERROR: Vamp::HostExt::PluginInputDomainAdapter::initialise: blocksize < 2 not supported" << std::endl; | 151 std::cerr << "ERROR: Vamp::HostExt::PluginInputDomainAdapter::Impl::initialise: blocksize < 2 not supported" << std::endl; |
70 return false; | 152 return false; |
71 } | 153 } |
72 | 154 |
73 if (blockSize & (blockSize-1)) { | 155 if (blockSize & (blockSize-1)) { |
74 std::cerr << "ERROR: Vamp::HostExt::PluginInputDomainAdapter::initialise: non-power-of-two\nblocksize " << blockSize << " not supported" << std::endl; | 156 std::cerr << "ERROR: Vamp::HostExt::PluginInputDomainAdapter::Impl::initialise: non-power-of-two\nblocksize " << blockSize << " not supported" << std::endl; |
75 return false; | 157 return false; |
76 } | 158 } |
77 | 159 |
78 if (m_channels > 0) { | 160 if (m_channels > 0) { |
79 for (size_t c = 0; c < m_channels; ++c) { | 161 for (size_t c = 0; c < m_channels; ++c) { |
97 m_io = new double[m_blockSize]; | 179 m_io = new double[m_blockSize]; |
98 | 180 |
99 return m_plugin->initialise(channels, stepSize, blockSize); | 181 return m_plugin->initialise(channels, stepSize, blockSize); |
100 } | 182 } |
101 | 183 |
102 Plugin::InputDomain | |
103 PluginInputDomainAdapter::getInputDomain() const | |
104 { | |
105 return TimeDomain; | |
106 } | |
107 | |
108 size_t | 184 size_t |
109 PluginInputDomainAdapter::getPreferredStepSize() const | 185 PluginInputDomainAdapter::Impl::getPreferredStepSize() const |
110 { | 186 { |
111 size_t step = m_plugin->getPreferredStepSize(); | 187 size_t step = m_plugin->getPreferredStepSize(); |
112 | 188 |
113 if (step == 0 && (m_plugin->getInputDomain() == FrequencyDomain)) { | 189 if (step == 0 && (m_plugin->getInputDomain() == FrequencyDomain)) { |
114 step = getPreferredBlockSize() / 2; | 190 step = getPreferredBlockSize() / 2; |
116 | 192 |
117 return step; | 193 return step; |
118 } | 194 } |
119 | 195 |
120 size_t | 196 size_t |
121 PluginInputDomainAdapter::getPreferredBlockSize() const | 197 PluginInputDomainAdapter::Impl::getPreferredBlockSize() const |
122 { | 198 { |
123 size_t block = m_plugin->getPreferredBlockSize(); | 199 size_t block = m_plugin->getPreferredBlockSize(); |
124 | 200 |
125 if (m_plugin->getInputDomain() == FrequencyDomain) { | 201 if (m_plugin->getInputDomain() == FrequencyDomain) { |
126 if (block == 0) { | 202 if (block == 0) { |
132 | 208 |
133 return block; | 209 return block; |
134 } | 210 } |
135 | 211 |
136 size_t | 212 size_t |
137 PluginInputDomainAdapter::makeBlockSizeAcceptable(size_t blockSize) const | 213 PluginInputDomainAdapter::Impl::makeBlockSizeAcceptable(size_t blockSize) const |
138 { | 214 { |
139 if (blockSize < 2) { | 215 if (blockSize < 2) { |
140 | 216 |
141 std::cerr << "WARNING: Vamp::HostExt::PluginInputDomainAdapter::initialise: blocksize < 2 not" << std::endl | 217 std::cerr << "WARNING: Vamp::HostExt::PluginInputDomainAdapter::Impl::initialise: blocksize < 2 not" << std::endl |
142 << "supported, increasing from " << blockSize << " to 2" << std::endl; | 218 << "supported, increasing from " << blockSize << " to 2" << std::endl; |
143 blockSize = 2; | 219 blockSize = 2; |
144 | 220 |
145 } else if (blockSize & (blockSize-1)) { | 221 } else if (blockSize & (blockSize-1)) { |
146 | 222 |
161 | 237 |
162 if (blockSize - nearest > (nearest*2) - blockSize) { | 238 if (blockSize - nearest > (nearest*2) - blockSize) { |
163 nearest = nearest*2; | 239 nearest = nearest*2; |
164 } | 240 } |
165 | 241 |
166 std::cerr << "WARNING: Vamp::HostExt::PluginInputDomainAdapter::initialise: non-power-of-two\nblocksize " << blockSize << " not supported, using blocksize " << nearest << " instead" << std::endl; | 242 std::cerr << "WARNING: Vamp::HostExt::PluginInputDomainAdapter::Impl::initialise: non-power-of-two\nblocksize " << blockSize << " not supported, using blocksize " << nearest << " instead" << std::endl; |
167 blockSize = nearest; | 243 blockSize = nearest; |
168 } | 244 } |
169 | 245 |
170 return blockSize; | 246 return blockSize; |
171 } | 247 } |
174 #ifndef M_PI | 250 #ifndef M_PI |
175 #define M_PI 3.14159265358979232846 | 251 #define M_PI 3.14159265358979232846 |
176 #endif | 252 #endif |
177 | 253 |
178 Plugin::FeatureSet | 254 Plugin::FeatureSet |
179 PluginInputDomainAdapter::process(const float *const *inputBuffers, RealTime timestamp) | 255 PluginInputDomainAdapter::Impl::process(const float *const *inputBuffers, |
256 RealTime timestamp) | |
180 { | 257 { |
181 if (m_plugin->getInputDomain() == TimeDomain) { | 258 if (m_plugin->getInputDomain() == TimeDomain) { |
182 return m_plugin->process(inputBuffers, timestamp); | 259 return m_plugin->process(inputBuffers, timestamp); |
183 } | 260 } |
184 | 261 |
257 | 334 |
258 return m_plugin->process(m_freqbuf, timestamp); | 335 return m_plugin->process(m_freqbuf, timestamp); |
259 } | 336 } |
260 | 337 |
261 void | 338 void |
262 PluginInputDomainAdapter::fft(unsigned int n, bool inverse, | 339 PluginInputDomainAdapter::Impl::fft(unsigned int n, bool inverse, |
263 double *ri, double *ii, double *ro, double *io) | 340 double *ri, double *ii, double *ro, double *io) |
264 { | 341 { |
265 if (!ri || !ro || !io) return; | 342 if (!ri || !ro || !io) return; |
266 | 343 |
267 unsigned int bits; | 344 unsigned int bits; |
268 unsigned int i, j, k, m; | 345 unsigned int i, j, k, m; |