Mercurial > hg > svcore
comparison transform/RealTimeEffectModelTransformer.cpp @ 851:c9846844ac11 tonioni
Merge branch tonioni_multi_transform
author | Chris Cannam |
---|---|
date | Mon, 02 Dec 2013 15:47:06 +0000 |
parents | dba8a02b0413 |
children | 06579b8ffb7b |
comparison
equal
deleted
inserted
replaced
847:2d53205f70cd | 851:c9846844ac11 |
---|---|
28 #include "TransformFactory.h" | 28 #include "TransformFactory.h" |
29 | 29 |
30 #include <iostream> | 30 #include <iostream> |
31 | 31 |
32 RealTimeEffectModelTransformer::RealTimeEffectModelTransformer(Input in, | 32 RealTimeEffectModelTransformer::RealTimeEffectModelTransformer(Input in, |
33 const Transform &transform) : | 33 const Transform &t) : |
34 ModelTransformer(in, transform), | 34 ModelTransformer(in, t), |
35 m_plugin(0) | 35 m_plugin(0) |
36 { | 36 { |
37 Transform transform(t); | |
38 if (!transform.getBlockSize()) { | |
39 transform.setBlockSize(1024); | |
40 m_transforms[0] = transform; | |
41 } | |
42 | |
37 m_units = TransformFactory::getInstance()->getTransformUnits | 43 m_units = TransformFactory::getInstance()->getTransformUnits |
38 (transform.getIdentifier()); | 44 (transform.getIdentifier()); |
39 m_outputNo = | 45 m_outputNo = |
40 (transform.getOutput() == "A") ? -1 : transform.getOutput().toInt(); | 46 (transform.getOutput() == "A") ? -1 : transform.getOutput().toInt(); |
41 | 47 |
42 QString pluginId = transform.getPluginIdentifier(); | 48 QString pluginId = transform.getPluginIdentifier(); |
43 | 49 |
44 if (!m_transform.getBlockSize()) m_transform.setBlockSize(1024); | |
45 | |
46 // SVDEBUG << "RealTimeEffectModelTransformer::RealTimeEffectModelTransformer: plugin " << pluginId << ", output " << output << endl; | 50 // SVDEBUG << "RealTimeEffectModelTransformer::RealTimeEffectModelTransformer: plugin " << pluginId << ", output " << output << endl; |
47 | 51 |
48 RealTimePluginFactory *factory = | 52 RealTimePluginFactory *factory = |
49 RealTimePluginFactory::instanceFor(pluginId); | 53 RealTimePluginFactory::instanceFor(pluginId); |
50 | 54 |
57 DenseTimeValueModel *input = getConformingInput(); | 61 DenseTimeValueModel *input = getConformingInput(); |
58 if (!input) return; | 62 if (!input) return; |
59 | 63 |
60 m_plugin = factory->instantiatePlugin(pluginId, 0, 0, | 64 m_plugin = factory->instantiatePlugin(pluginId, 0, 0, |
61 input->getSampleRate(), | 65 input->getSampleRate(), |
62 m_transform.getBlockSize(), | 66 transform.getBlockSize(), |
63 input->getChannelCount()); | 67 input->getChannelCount()); |
64 | 68 |
65 if (!m_plugin) { | 69 if (!m_plugin) { |
66 cerr << "RealTimeEffectModelTransformer: Failed to instantiate plugin \"" | 70 cerr << "RealTimeEffectModelTransformer: Failed to instantiate plugin \"" |
67 << pluginId << "\"" << endl; | 71 << pluginId << "\"" << endl; |
68 return; | 72 return; |
69 } | 73 } |
70 | 74 |
71 TransformFactory::getInstance()->setPluginParameters(m_transform, m_plugin); | 75 TransformFactory::getInstance()->setPluginParameters(transform, m_plugin); |
72 | 76 |
73 if (m_outputNo >= 0 && | 77 if (m_outputNo >= 0 && |
74 m_outputNo >= int(m_plugin->getControlOutputCount())) { | 78 m_outputNo >= int(m_plugin->getControlOutputCount())) { |
75 cerr << "RealTimeEffectModelTransformer: Plugin has fewer than desired " << m_outputNo << " control outputs" << endl; | 79 cerr << "RealTimeEffectModelTransformer: Plugin has fewer than desired " << m_outputNo << " control outputs" << endl; |
76 return; | 80 return; |
84 } | 88 } |
85 | 89 |
86 WritableWaveFileModel *model = new WritableWaveFileModel | 90 WritableWaveFileModel *model = new WritableWaveFileModel |
87 (input->getSampleRate(), outputChannels); | 91 (input->getSampleRate(), outputChannels); |
88 | 92 |
89 m_output = model; | 93 m_outputs.push_back(model); |
90 | 94 |
91 } else { | 95 } else { |
92 | 96 |
93 SparseTimeValueModel *model = new SparseTimeValueModel | 97 SparseTimeValueModel *model = new SparseTimeValueModel |
94 (input->getSampleRate(), m_transform.getBlockSize(), 0.0, 0.0, false); | 98 (input->getSampleRate(), transform.getBlockSize(), 0.0, 0.0, false); |
95 | 99 |
96 if (m_units != "") model->setScaleUnits(m_units); | 100 if (m_units != "") model->setScaleUnits(m_units); |
97 | 101 |
98 m_output = model; | 102 m_outputs.push_back(model); |
99 } | 103 } |
100 } | 104 } |
101 | 105 |
102 RealTimeEffectModelTransformer::~RealTimeEffectModelTransformer() | 106 RealTimeEffectModelTransformer::~RealTimeEffectModelTransformer() |
103 { | 107 { |
125 SVDEBUG << "RealTimeEffectModelTransformer::run: Waiting for input model to be ready..." << endl; | 129 SVDEBUG << "RealTimeEffectModelTransformer::run: Waiting for input model to be ready..." << endl; |
126 usleep(500000); | 130 usleep(500000); |
127 } | 131 } |
128 if (m_abandoned) return; | 132 if (m_abandoned) return; |
129 | 133 |
130 SparseTimeValueModel *stvm = dynamic_cast<SparseTimeValueModel *>(m_output); | 134 SparseTimeValueModel *stvm = dynamic_cast<SparseTimeValueModel *>(m_outputs[0]); |
131 WritableWaveFileModel *wwfm = dynamic_cast<WritableWaveFileModel *>(m_output); | 135 WritableWaveFileModel *wwfm = dynamic_cast<WritableWaveFileModel *>(m_outputs[0]); |
132 if (!stvm && !wwfm) return; | 136 if (!stvm && !wwfm) return; |
133 | 137 |
134 if (stvm && (m_outputNo >= int(m_plugin->getControlOutputCount()))) return; | 138 if (stvm && (m_outputNo >= int(m_plugin->getControlOutputCount()))) return; |
135 | 139 |
136 size_t sampleRate = input->getSampleRate(); | 140 size_t sampleRate = input->getSampleRate(); |
141 | 145 |
142 float **inbufs = m_plugin->getAudioInputBuffers(); | 146 float **inbufs = m_plugin->getAudioInputBuffers(); |
143 | 147 |
144 long startFrame = m_input.getModel()->getStartFrame(); | 148 long startFrame = m_input.getModel()->getStartFrame(); |
145 long endFrame = m_input.getModel()->getEndFrame(); | 149 long endFrame = m_input.getModel()->getEndFrame(); |
150 | |
151 Transform transform = m_transforms[0]; | |
146 | 152 |
147 RealTime contextStartRT = m_transform.getStartTime(); | 153 RealTime contextStartRT = transform.getStartTime(); |
148 RealTime contextDurationRT = m_transform.getDuration(); | 154 RealTime contextDurationRT = transform.getDuration(); |
149 | 155 |
150 long contextStart = | 156 long contextStart = |
151 RealTime::realTime2Frame(contextStartRT, sampleRate); | 157 RealTime::realTime2Frame(contextStartRT, sampleRate); |
152 | 158 |
153 long contextDuration = | 159 long contextDuration = |