Mercurial > hg > sonic-visualiser
comparison transform/RealTimePluginTransform.cpp @ 27:61259228d029
* More to do with passing around step/blocksize etc from plugin dialog to
plugins. Still some puzzling unresolved details.
author | Chris Cannam |
---|---|
date | Tue, 19 Sep 2006 14:37:06 +0000 |
parents | d88d117e0c34 |
children | 8ad306d8a568 |
comparison
equal
deleted
inserted
replaced
26:d88d117e0c34 | 27:61259228d029 |
---|---|
26 | 26 |
27 #include <iostream> | 27 #include <iostream> |
28 | 28 |
29 RealTimePluginTransform::RealTimePluginTransform(Model *inputModel, | 29 RealTimePluginTransform::RealTimePluginTransform(Model *inputModel, |
30 QString pluginId, | 30 QString pluginId, |
31 int channel, | 31 const ExecutionContext &context, |
32 QString configurationXml, | 32 QString configurationXml, |
33 QString units, | 33 QString units, |
34 int output, | 34 int output) : |
35 size_t blockSize) : | 35 PluginTransform(inputModel, context), |
36 Transform(inputModel), | |
37 m_plugin(0), | 36 m_plugin(0), |
38 m_channel(channel), | 37 m_outputNo(output) |
39 m_outputNo(output), | |
40 m_blockSize(blockSize) | |
41 { | 38 { |
42 if (!m_blockSize) m_blockSize = 1024; | 39 if (!m_context.blockSize) m_context.blockSize = 1024; |
43 | 40 |
44 std::cerr << "RealTimePluginTransform::RealTimePluginTransform: plugin " << pluginId.toStdString() << ", output " << output << std::endl; | 41 std::cerr << "RealTimePluginTransform::RealTimePluginTransform: plugin " << pluginId.toStdString() << ", output " << output << std::endl; |
45 | 42 |
46 RealTimePluginFactory *factory = | 43 RealTimePluginFactory *factory = |
47 RealTimePluginFactory::instanceFor(pluginId); | 44 RealTimePluginFactory::instanceFor(pluginId); |
54 | 51 |
55 DenseTimeValueModel *input = getInput(); | 52 DenseTimeValueModel *input = getInput(); |
56 if (!input) return; | 53 if (!input) return; |
57 | 54 |
58 m_plugin = factory->instantiatePlugin(pluginId, 0, 0, m_input->getSampleRate(), | 55 m_plugin = factory->instantiatePlugin(pluginId, 0, 0, m_input->getSampleRate(), |
59 m_blockSize, | 56 m_context.blockSize, |
60 input->getChannelCount()); | 57 input->getChannelCount()); |
61 | 58 |
62 if (!m_plugin) { | 59 if (!m_plugin) { |
63 std::cerr << "RealTimePluginTransform: Failed to instantiate plugin \"" | 60 std::cerr << "RealTimePluginTransform: Failed to instantiate plugin \"" |
64 << pluginId.toStdString() << "\"" << std::endl; | 61 << pluginId.toStdString() << "\"" << std::endl; |
73 std::cerr << "RealTimePluginTransform: Plugin has fewer than desired " << m_outputNo << " control outputs" << std::endl; | 70 std::cerr << "RealTimePluginTransform: Plugin has fewer than desired " << m_outputNo << " control outputs" << std::endl; |
74 return; | 71 return; |
75 } | 72 } |
76 | 73 |
77 SparseTimeValueModel *model = new SparseTimeValueModel | 74 SparseTimeValueModel *model = new SparseTimeValueModel |
78 (input->getSampleRate(), m_blockSize, 0.0, 0.0, false); | 75 (input->getSampleRate(), m_context.blockSize, 0.0, 0.0, false); |
79 | 76 |
80 if (units != "") model->setScaleUnits(units); | 77 if (units != "") model->setScaleUnits(units); |
81 | 78 |
82 m_output = model; | 79 m_output = model; |
83 } | 80 } |
109 | 106 |
110 if (m_outputNo >= m_plugin->getControlOutputCount()) return; | 107 if (m_outputNo >= m_plugin->getControlOutputCount()) return; |
111 | 108 |
112 size_t sampleRate = input->getSampleRate(); | 109 size_t sampleRate = input->getSampleRate(); |
113 int channelCount = input->getChannelCount(); | 110 int channelCount = input->getChannelCount(); |
114 if (m_channel != -1) channelCount = 1; | 111 if (m_context.channel != -1) channelCount = 1; |
115 | 112 |
116 size_t blockSize = m_plugin->getBufferSize(); | 113 size_t blockSize = m_plugin->getBufferSize(); |
117 | 114 |
118 float **buffers = m_plugin->getAudioInputBuffers(); | 115 float **buffers = m_plugin->getAudioInputBuffers(); |
119 | 116 |
133 | 130 |
134 size_t got = 0; | 131 size_t got = 0; |
135 | 132 |
136 if (channelCount == 1) { | 133 if (channelCount == 1) { |
137 got = input->getValues | 134 got = input->getValues |
138 (m_channel, blockFrame, blockFrame + blockSize, buffers[0]); | 135 (m_context.channel, blockFrame, blockFrame + blockSize, buffers[0]); |
139 while (got < blockSize) { | 136 while (got < blockSize) { |
140 buffers[0][got++] = 0.0; | 137 buffers[0][got++] = 0.0; |
141 } | 138 } |
142 if (m_channel == -1 && channelCount > 1) { | 139 if (m_context.channel == -1 && channelCount > 1) { |
143 // use mean instead of sum, as plugin input | 140 // use mean instead of sum, as plugin input |
144 for (size_t i = 0; i < got; ++i) { | 141 for (size_t i = 0; i < got; ++i) { |
145 buffers[0][i] /= channelCount; | 142 buffers[0][i] /= channelCount; |
146 } | 143 } |
147 } | 144 } |