From 1a2351bbd0c0901bae92777d41a8fc7e8d8e55ab Mon Sep 17 00:00:00 2001 From: Vesa Date: Thu, 17 Jul 2014 01:48:24 +0300 Subject: [PATCH] Improve performance of effect processing, fix autoquit bugs Also a slight NPH tweak --- include/Effect.h | 7 +++---- src/core/Effect.cpp | 9 +++------ src/core/FxMixer.cpp | 10 ++++------ src/core/NotePlayHandle.cpp | 17 ++++++++++++----- 4 files changed, 22 insertions(+), 21 deletions(-) diff --git a/include/Effect.h b/include/Effect.h index 10d3fcf23..e0ad3ebad 100644 --- a/include/Effect.h +++ b/include/Effect.h @@ -23,8 +23,8 @@ * */ -#ifndef _EFFECT_H -#define _EFFECT_H +#ifndef EFFECT_H +#define EFFECT_H #include "Plugin.h" #include "engine.h" @@ -118,8 +118,7 @@ public: inline float gate() const { const float level = m_gateModel.value(); - return level*level * m_processors * - engine::mixer()->framesPerPeriod(); + return level*level * m_processors; } inline f_cnt_t bufferCount() const diff --git a/src/core/Effect.cpp b/src/core/Effect.cpp index 619ed438e..fc94132cb 100644 --- a/src/core/Effect.cpp +++ b/src/core/Effect.cpp @@ -25,9 +25,6 @@ #include -#include -#include - #include "Effect.h" #include "engine.h" #include "EffectChain.h" @@ -136,7 +133,7 @@ void Effect::checkGate( double _out_sum ) { // Check whether we need to continue processing input. Restart the // counter if the threshold has been exceeded. - if( _out_sum <= gate() + FLT_MIN ) + if( _out_sum - gate() <= typeInfo::minEps() ) { incrementBufferCount(); if( bufferCount() > timeout() ) @@ -176,7 +173,7 @@ void Effect::reinitSRC() libsrcInterpolation(), DEFAULT_CHANNELS, &error ) ) == NULL ) { - fprintf( stderr, "Error: src_new() failed in effect.cpp!\n" ); + qFatal( "Error: src_new() failed in effect.cpp!\n" ); } } } @@ -202,7 +199,7 @@ void Effect::resample( int _i, const sampleFrame * _src_buf, int error; if( ( error = src_process( m_srcState[_i], &m_srcData[_i] ) ) ) { - fprintf( stderr, "Effect::resample(): error while resampling: %s\n", + qFatal( "Effect::resample(): error while resampling: %s\n", src_strerror( error ) ); } } diff --git a/src/core/FxMixer.cpp b/src/core/FxMixer.cpp index 98aea9811..c9df355b8 100644 --- a/src/core/FxMixer.cpp +++ b/src/core/FxMixer.cpp @@ -137,9 +137,8 @@ void FxChannel::doProcessing( sampleFrame * _buf ) _buf[f][1] += ch_buf[f][1] * v; } } - // if sender channel hasInput, then we hasInput too - if( sender->m_hasInput ) m_hasInput = true; + if( sender->m_hasInput ) { m_hasInput = true; } } } @@ -150,10 +149,9 @@ void FxChannel::doProcessing( sampleFrame * _buf ) // only start fxchain when we have input... m_fxChain.startRunning(); } - if( m_hasInput || m_stillRunning ) - { - m_stillRunning = m_fxChain.processAudioBuffer( _buf, fpp, m_hasInput ); - } + + m_stillRunning = m_fxChain.processAudioBuffer( _buf, fpp, m_hasInput ); + m_peakLeft = qMax( m_peakLeft, engine::mixer()->peakValueLeft( _buf, fpp ) * v ); m_peakRight = qMax( m_peakRight, engine::mixer()->peakValueRight( _buf, fpp ) * v ); } diff --git a/src/core/NotePlayHandle.cpp b/src/core/NotePlayHandle.cpp index 0a3107acd..67f2319ab 100644 --- a/src/core/NotePlayHandle.cpp +++ b/src/core/NotePlayHandle.cpp @@ -192,11 +192,18 @@ void NotePlayHandle::play( sampleFrame * _working_buffer ) { if( m_scheduledNoteOff >= 0 ) // always trigger scheduled noteoffs, because they're only scheduled if the note is released { - m_instrumentTrack->processOutEvent( - MidiEvent( MidiNoteOff, midiChannel(), midiKey(), 0 ), - MidiTime::fromFrames( m_scheduledNoteOff, engine::framesPerTick() ), - m_scheduledNoteOff ); - m_scheduledNoteOff = -1; + if( m_scheduledNoteOff < engine::mixer()->framesPerPeriod() ) + { + m_instrumentTrack->processOutEvent( + MidiEvent( MidiNoteOff, midiChannel(), midiKey(), 0 ), + MidiTime::fromFrames( m_scheduledNoteOff, engine::framesPerTick() ), + m_scheduledNoteOff ); + m_scheduledNoteOff = -1; + } + else + { + m_scheduledNoteOff -= engine::mixer()->framesPerPeriod(); + } } if( m_muted )