Mercurial > hg > svapp
comparison audio/AudioCallbackRecordTarget.cpp @ 611:37b23e50832b
Smoother model updates, some debug
author | Chris Cannam |
---|---|
date | Wed, 08 Aug 2018 15:19:06 +0100 |
parents | 96b605673585 |
children | 1822563a5da1 |
comparison
equal
deleted
inserted
replaced
610:5ddcbc55b6a2 | 611:37b23e50832b |
---|---|
140 } | 140 } |
141 | 141 |
142 void | 142 void |
143 AudioCallbackRecordTarget::updateModel() | 143 AudioCallbackRecordTarget::updateModel() |
144 { | 144 { |
145 #ifdef DEBUG_AUDIO_CALLBACK_RECORD_TARGET | |
146 cerr << "AudioCallbackRecordTarget::updateModel" << endl; | |
147 #endif | |
148 | |
145 bool secChanged = false; | 149 bool secChanged = false; |
146 sv_frame_t frameToEmit = 0; | 150 sv_frame_t frameToEmit = 0; |
147 | 151 |
148 int nframes = 0; | 152 int nframes = 0; |
149 for (int c = 0; c < m_recordChannelCount; ++c) { | 153 for (int c = 0; c < m_recordChannelCount; ++c) { |
160 QTimer::singleShot(recordUpdateTimeout, this, SLOT(updateModel())); | 164 QTimer::singleShot(recordUpdateTimeout, this, SLOT(updateModel())); |
161 } | 165 } |
162 return; | 166 return; |
163 } | 167 } |
164 | 168 |
169 #ifdef DEBUG_AUDIO_CALLBACK_RECORD_TARGET | |
170 cerr << "AudioCallbackRecordTarget::updateModel: have " << nframes << " frames" << endl; | |
171 #endif | |
172 | |
165 float **samples = new float *[m_recordChannelCount]; | 173 float **samples = new float *[m_recordChannelCount]; |
166 for (int c = 0; c < m_recordChannelCount; ++c) { | 174 for (int c = 0; c < m_recordChannelCount; ++c) { |
167 samples[c] = new float[nframes]; | 175 samples[c] = new float[nframes]; |
168 m_buffers[c]->read(samples[c], nframes); | 176 m_buffers[c]->read(samples[c], nframes); |
169 } | 177 } |
175 } | 183 } |
176 delete[] samples; | 184 delete[] samples; |
177 | 185 |
178 sv_frame_t priorFrameCount = m_frameCount; | 186 sv_frame_t priorFrameCount = m_frameCount; |
179 m_frameCount += nframes; | 187 m_frameCount += nframes; |
180 | 188 |
181 RealTime priorRT = | 189 m_model->updateModel(); |
182 RealTime::frame2RealTime(priorFrameCount, m_recordSampleRate); | 190 frameToEmit = m_frameCount; |
183 | 191 emit recordDurationChanged(frameToEmit, m_recordSampleRate); |
184 RealTime postRT = | |
185 RealTime::frame2RealTime(m_frameCount, m_recordSampleRate); | |
186 | |
187 secChanged = (postRT.sec > priorRT.sec); | |
188 if (secChanged) { | |
189 m_model->updateModel(); | |
190 frameToEmit = m_frameCount; | |
191 } | |
192 | |
193 if (secChanged) { | |
194 emit recordDurationChanged(frameToEmit, m_recordSampleRate); | |
195 } | |
196 | 192 |
197 if (m_recording) { | 193 if (m_recording) { |
198 QTimer::singleShot(1000, this, SLOT(updateModel())); | 194 QTimer::singleShot(recordUpdateTimeout, this, SLOT(updateModel())); |
199 } | 195 } |
200 } | 196 } |
201 | 197 |
202 void | 198 void |
203 AudioCallbackRecordTarget::setInputLevels(float left, float right) | 199 AudioCallbackRecordTarget::setInputLevels(float left, float right) |
299 m_model->setObjectName(label); | 295 m_model->setObjectName(label); |
300 m_recording = true; | 296 m_recording = true; |
301 | 297 |
302 emit recordStatusChanged(true); | 298 emit recordStatusChanged(true); |
303 | 299 |
304 QTimer::singleShot(1000, this, SLOT(updateModel())); | 300 QTimer::singleShot(recordUpdateTimeout, this, SLOT(updateModel())); |
305 | 301 |
306 return m_model; | 302 return m_model; |
307 } | 303 } |
308 | 304 |
309 void | 305 void |