Changeset View
Changeset View
Standalone View
Standalone View
src/context/applets/analyzer/plugin/AnalyzerWorker.cpp
Show First 20 Lines • Show All 178 Lines • ▼ Show 20 Line(s) | 178 | { | |||
---|---|---|---|---|---|
179 | m_currentScope[band.scopeIndex] += std::abs( m_out[k] ) * sqrt( k ); | 179 | m_currentScope[band.scopeIndex] += std::abs( m_out[k] ) * sqrt( k ); | ||
180 | numValues++; | 180 | numValues++; | ||
181 | } | 181 | } | ||
182 | m_currentScope[band.scopeIndex] /= numValues; | 182 | m_currentScope[band.scopeIndex] /= numValues; | ||
183 | m_currentScope[band.scopeIndex] /= m_size / 2; | 183 | m_currentScope[band.scopeIndex] /= m_size / 2; | ||
184 | } | 184 | } | ||
185 | 185 | | |||
186 | // monotone cubic interpolation | 186 | // monotone cubic interpolation | ||
187 | if( !m_interpolatedScopeBands.isEmpty() ) | ||||
188 | { | ||||
187 | QVector<QPointF> data; | 189 | QVector<QPointF> data; | ||
188 | for( uint k = 0; k < m_size / 2 + 1 && k <= m_interpolatedScopeBands.last().midK; k++ ) | 190 | for( uint k = 0; k < m_size / 2 + 1 && k <= m_interpolatedScopeBands.last().midK; k++ ) | ||
189 | { | 191 | { | ||
190 | data << QPointF( k, std::abs( m_out[k] ) * sqrt( k ) / m_size * 2 ); | 192 | data << QPointF( k, std::abs( m_out[k] ) * sqrt( k ) / m_size * 2 ); | ||
191 | } | 193 | } | ||
192 | // Get consecutive differences and slopes | 194 | // Get consecutive differences and slopes | ||
193 | QVector<double> dys, dxs, ms; | 195 | QVector<double> dys, dxs, ms; | ||
194 | for( int i = 0; i < data.size() - 1; i++ ) | 196 | for( int i = 0; i < data.size() - 1; i++ ) | ||
▲ Show 20 Lines • Show All 46 Lines • ▼ Show 20 Line(s) | 242 | else | |||
241 | scope = data[mid].y(); | 243 | scope = data[mid].y(); | ||
242 | } | 244 | } | ||
243 | int i = qMax( 0, high ); | 245 | int i = qMax( 0, high ); | ||
244 | 246 | | |||
245 | // Interpolate | 247 | // Interpolate | ||
246 | double diff = x - data[i].x(), diffSq = diff * diff; | 248 | double diff = x - data[i].x(), diffSq = diff * diff; | ||
247 | scope = qMax( 0.0, data[i].y() + c1s[i] * diff + c2s[i] * diffSq + c3s[i] * diff * diffSq ); | 249 | scope = qMax( 0.0, data[i].y() + c1s[i] * diff + c2s[i] * diffSq + c3s[i] * diff * diffSq ); | ||
248 | } | 250 | } | ||
251 | } | ||||
249 | 252 | | |||
250 | analyze(); | 253 | analyze(); | ||
251 | } | 254 | } | ||
252 | 255 | | |||
253 | void Analyzer::Worker::setSampleSize( uint size ) | 256 | void Analyzer::Worker::setSampleSize( uint size ) | ||
254 | { | 257 | { | ||
255 | if( m_size == size ) | 258 | if( m_size == size ) | ||
256 | return; | 259 | return; | ||
Show All 21 Lines | |||||
278 | { | 281 | { | ||
279 | m_currentScope.resize( size ); | 282 | m_currentScope.resize( size ); | ||
280 | } | 283 | } | ||
281 | 284 | | |||
282 | void Analyzer::Worker::calculateExpFactor( qreal minFreq, qreal maxFreq, int sampleRate ) | 285 | void Analyzer::Worker::calculateExpFactor( qreal minFreq, qreal maxFreq, int sampleRate ) | ||
283 | { | 286 | { | ||
284 | DEBUG_BLOCK | 287 | DEBUG_BLOCK | ||
285 | 288 | | |||
289 | if( minFreq <= 0.0 ) | ||||
290 | { | ||||
291 | warning() << "Minimum frequency must be greater than zero!"; | ||||
292 | minFreq = 1.0; | ||||
293 | } | ||||
294 | | ||||
286 | if( minFreq >= maxFreq ) | 295 | if( minFreq >= maxFreq ) | ||
287 | { | 296 | { | ||
288 | warning() << "Minimum frequency must be smaller than maximum frequency!"; | 297 | warning() << "Minimum frequency must be smaller than maximum frequency!"; | ||
289 | return; | 298 | maxFreq = minFreq + 1.0; | ||
299 | } | ||||
300 | | ||||
301 | if( sampleRate == 0 ) | ||||
302 | { | ||||
303 | debug() << "Reported impossible sample rate of zero. Assuming 44.1KHz."; | ||||
304 | sampleRate = 44100; | ||||
290 | } | 305 | } | ||
291 | 306 | | |||
292 | m_expFactor = pow( maxFreq / minFreq, 1.0 / m_currentScope.size() ); | 307 | m_expFactor = pow( maxFreq / minFreq, 1.0 / m_currentScope.size() ); | ||
293 | m_expectedDataTime = std::floor( (qreal)EngineController::DATAOUTPUT_DATA_SIZE * 1000.0 / sampleRate ); | 308 | m_expectedDataTime = std::floor( (qreal)EngineController::DATAOUTPUT_DATA_SIZE * 1000.0 / sampleRate ); | ||
294 | 309 | | |||
295 | m_interpolatedScopeBands.clear(); | 310 | m_interpolatedScopeBands.clear(); | ||
296 | m_notInterpolatedScopeBands.clear(); | 311 | m_notInterpolatedScopeBands.clear(); | ||
297 | const uint outputSize = m_size / 2 + 1; | 312 | const uint outputSize = m_size / 2 + 1; | ||
▲ Show 20 Lines • Show All 60 Lines • Show Last 20 Lines |