Mercurial > hg > svcore
comparison transform/RealTimeEffectModelTransformer.cpp @ 1740:fe3f7f8df3a3 by-id
More work on transformers
author | Chris Cannam |
---|---|
date | Wed, 26 Jun 2019 17:25:20 +0100 |
parents | 7a56bb85030f |
children | 6d09d68165a4 |
comparison
equal
deleted
inserted
replaced
1739:565575463752 | 1740:fe3f7f8df3a3 |
---|---|
56 SVCERR << "RealTimeEffectModelTransformer: No factory available for plugin id \"" | 56 SVCERR << "RealTimeEffectModelTransformer: No factory available for plugin id \"" |
57 << pluginId << "\"" << endl; | 57 << pluginId << "\"" << endl; |
58 return; | 58 return; |
59 } | 59 } |
60 | 60 |
61 DenseTimeValueModel *input = getConformingInput(); | 61 auto input = ModelById::getAs<DenseTimeValueModel>(getInputModel()); |
62 if (!input) return; | 62 if (!input) { |
63 SVCERR << "RealTimeEffectModelTransformer: Input is absent or of wrong type" << endl; | |
64 return; | |
65 } | |
63 | 66 |
64 m_plugin = factory->instantiatePlugin(pluginId, 0, 0, | 67 m_plugin = factory->instantiatePlugin(pluginId, 0, 0, |
65 input->getSampleRate(), | 68 input->getSampleRate(), |
66 transform.getBlockSize(), | 69 transform.getBlockSize(), |
67 input->getChannelCount()); | 70 input->getChannelCount()); |
85 int outputChannels = (int)m_plugin->getAudioOutputCount(); | 88 int outputChannels = (int)m_plugin->getAudioOutputCount(); |
86 if (outputChannels > input->getChannelCount()) { | 89 if (outputChannels > input->getChannelCount()) { |
87 outputChannels = input->getChannelCount(); | 90 outputChannels = input->getChannelCount(); |
88 } | 91 } |
89 | 92 |
90 WritableWaveFileModel *model = new WritableWaveFileModel | 93 auto model = std::make_shared<WritableWaveFileModel> |
91 (input->getSampleRate(), outputChannels); | 94 (input->getSampleRate(), outputChannels); |
92 | 95 |
93 m_outputs.push_back(model); | 96 ModelById::add(model); |
97 m_outputs.push_back(model->getId()); | |
94 | 98 |
95 } else { | 99 } else { |
96 | 100 |
97 SparseTimeValueModel *model = new SparseTimeValueModel | 101 auto model = std::make_shared<SparseTimeValueModel> |
98 (input->getSampleRate(), transform.getBlockSize(), 0.0, 0.0, false); | 102 (input->getSampleRate(), transform.getBlockSize(), |
99 | 103 0.0, 0.0, false); |
100 if (m_units != "") model->setScaleUnits(m_units); | 104 if (m_units != "") model->setScaleUnits(m_units); |
101 | 105 |
102 m_outputs.push_back(model); | 106 ModelById::add(model); |
107 m_outputs.push_back(model->getId()); | |
103 } | 108 } |
104 } | 109 } |
105 | 110 |
106 RealTimeEffectModelTransformer::~RealTimeEffectModelTransformer() | 111 RealTimeEffectModelTransformer::~RealTimeEffectModelTransformer() |
107 { | 112 { |
108 delete m_plugin; | 113 delete m_plugin; |
109 } | 114 } |
110 | 115 |
111 DenseTimeValueModel * | |
112 RealTimeEffectModelTransformer::getConformingInput() | |
113 { | |
114 DenseTimeValueModel *dtvm = | |
115 dynamic_cast<DenseTimeValueModel *>(getInputModel()); | |
116 if (!dtvm) { | |
117 SVDEBUG << "RealTimeEffectModelTransformer::getConformingInput: WARNING: Input model is not conformable to DenseTimeValueModel" << endl; | |
118 } | |
119 return dtvm; | |
120 } | |
121 | |
122 void | 116 void |
123 RealTimeEffectModelTransformer::run() | 117 RealTimeEffectModelTransformer::run() |
124 { | 118 { |
125 DenseTimeValueModel *input = getConformingInput(); | |
126 if (!input) return; | |
127 | |
128 while (!input->isReady() && !m_abandoned) { | |
129 SVDEBUG << "RealTimeEffectModelTransformer::run: Waiting for input model to be ready..." << endl; | |
130 usleep(500000); | |
131 } | |
132 if (m_abandoned) { | |
133 return; | |
134 } | |
135 if (m_outputs.empty()) { | 119 if (m_outputs.empty()) { |
136 return; | 120 abandon(); |
137 } | 121 return; |
138 | 122 } |
139 SparseTimeValueModel *stvm = | 123 |
140 dynamic_cast<SparseTimeValueModel *>(m_outputs[0]); | 124 bool ready = false; |
141 WritableWaveFileModel *wwfm = | 125 while (!ready && !m_abandoned) { |
142 dynamic_cast<WritableWaveFileModel *>(m_outputs[0]); | 126 { // scope so as to release input shared_ptr before sleeping |
127 auto input = ModelById::getAs<DenseTimeValueModel>(getInputModel()); | |
128 if (!input) { | |
129 abandon(); | |
130 return; | |
131 } | |
132 ready = input->isReady(); | |
133 } | |
134 if (!ready) { | |
135 SVDEBUG << "RealTimeEffectModelTransformer::run: Waiting for input model to be ready..." << endl; | |
136 usleep(500000); | |
137 } | |
138 } | |
139 if (m_abandoned) return; | |
140 | |
141 auto input = ModelById::getAs<DenseTimeValueModel>(getInputModel()); | |
142 if (!input) { | |
143 abandon(); | |
144 return; | |
145 } | |
146 | |
147 auto stvm = ModelById::getAs<SparseTimeValueModel>(m_outputs[0]); | |
148 auto wwfm = ModelById::getAs<WritableWaveFileModel>(m_outputs[0]); | |
143 | 149 |
144 if (!stvm && !wwfm) { | 150 if (!stvm && !wwfm) { |
145 return; | 151 return; |
146 } | 152 } |
147 | 153 |
155 | 161 |
156 sv_frame_t blockSize = m_plugin->getBufferSize(); | 162 sv_frame_t blockSize = m_plugin->getBufferSize(); |
157 | 163 |
158 float **inbufs = m_plugin->getAudioInputBuffers(); | 164 float **inbufs = m_plugin->getAudioInputBuffers(); |
159 | 165 |
160 sv_frame_t startFrame = m_input.getModel()->getStartFrame(); | 166 sv_frame_t startFrame = input->getStartFrame(); |
161 sv_frame_t endFrame = m_input.getModel()->getEndFrame(); | 167 sv_frame_t endFrame = input->getEndFrame(); |
162 | 168 |
163 Transform transform = m_transforms[0]; | 169 Transform transform = m_transforms[0]; |
164 | 170 |
165 RealTime contextStartRT = transform.getStartTime(); | 171 RealTime contextStartRT = transform.getStartTime(); |
166 RealTime contextDurationRT = transform.getDuration(); | 172 RealTime contextDurationRT = transform.getDuration(); |
239 inbufs[ch][i] = inbufs[ch % channelCount][i]; | 245 inbufs[ch][i] = inbufs[ch % channelCount][i]; |
240 } | 246 } |
241 } | 247 } |
242 } | 248 } |
243 } | 249 } |
244 | |
245 /* | |
246 cerr << "Input for plugin: " << m_plugin->getAudioInputCount() << " channels "<< endl; | |
247 | |
248 for (int ch = 0; ch < m_plugin->getAudioInputCount(); ++ch) { | |
249 cerr << "Input channel " << ch << endl; | |
250 for (int i = 0; i < 100; ++i) { | |
251 cerr << inbufs[ch][i] << " "; | |
252 if (isnan(inbufs[ch][i])) { | |
253 cerr << "\n\nWARNING: NaN in audio input" << endl; | |
254 } | |
255 } | |
256 } | |
257 */ | |
258 | 250 |
259 m_plugin->run(RealTime::frame2RealTime(blockFrame, sampleRate)); | 251 m_plugin->run(RealTime::frame2RealTime(blockFrame, sampleRate)); |
260 | 252 |
261 if (stvm) { | 253 if (stvm) { |
262 | 254 |