void PeakController::updateValueBuffer() { if( m_peakEffect ) { float targetSample = m_peakEffect->lastSample(); if( m_currentSample != targetSample ) { const f_cnt_t frames = engine::mixer()->framesPerPeriod(); float * values = m_valueBuffer.values(); const float ratio = ( 44100.0 / 256.0 ) / engine::mixer()->processingSampleRate(); const float v = m_currentSample >= targetSample ? m_peakEffect->decayModel()->value() : m_peakEffect->attackModel()->value(); const float diff = ( targetSample - m_currentSample ) * ratio; const float a = ( 1.0f - sqrt_neg( sqrt_neg( v ) ) ) * diff; const bool att = m_currentSample < targetSample; for( f_cnt_t f = 0; f < frames; ++f ) { if( att ) // going up... { m_currentSample = qMin( targetSample, m_currentSample + a ); // qmin prevents overshoot } else { m_currentSample = qMax( targetSample, m_currentSample + a ); // qmax prevents overshoot } values[f] = m_currentSample; } } else { m_valueBuffer.fill( m_currentSample ); } } else { m_valueBuffer.fill( 0 ); } m_bufferLastUpdated = s_periods; }
bool PeakControllerEffect::processAudioBuffer( sampleFrame * _buf, const fpp_t _frames ) { PeakControllerEffectControls & c = m_peakControls; // This appears to be used for determining whether or not to continue processing // audio with this effect if( !isEnabled() || !isRunning() ) { return false; } // RMS: double sum = 0; if( c.m_absModel.value() ) { for( int i = 0; i < _frames; ++i ) { // absolute value is achieved because the squares are > 0 sum += _buf[i][0]*_buf[i][0] + _buf[i][1]*_buf[i][1]; } } else { for( int i = 0; i < _frames; ++i ) { // the value is absolute because of squaring, // so we need to correct it sum += _buf[i][0] * _buf[i][0] * sign( _buf[i][0] ) + _buf[i][1] * _buf[i][1] * sign( _buf[i][1] ); } } // TODO: flipping this might cause clipping // this will mute the output after the values were measured if( c.m_muteModel.value() ) { for( int i = 0; i < _frames; ++i ) { _buf[i][0] = _buf[i][1] = 0.0f; } } float curRMS = sqrt_neg( sum / _frames ); const float tres = c.m_tresholdModel.value(); const float amount = c.m_amountModel.value() * c.m_amountMultModel.value(); curRMS = qAbs( curRMS ) < tres ? 0.0f : curRMS; m_lastSample = qBound( 0.0f, c.m_baseModel.value() + amount * curRMS, 1.0f ); return isRunning(); }