added instrument::applyRelease(...)

git-svn-id: https://lmms.svn.sf.net/svnroot/lmms/trunk/lmms@519 0778d3d1-df1d-0410-868b-ea421aaaa00d
This commit is contained in:
Tobias Doerffel
2007-08-06 13:29:21 +00:00
parent 83f339852d
commit 02433380c6
2 changed files with 27 additions and 0 deletions

View File

@@ -49,6 +49,7 @@
#include "plugin.h"
#include "mixer.h"
// forward-declarations
@@ -131,6 +132,11 @@ protected:
return( m_instrumentTrack );
}
// instruments may use this to apply a soft fade out at the end of
// notes - method does this only if really less or equal
// desiredReleaseFrames() frames are left
void applyRelease( sampleFrame * buf, const notePlayHandle * _n );
private:
instrumentTrack * m_instrumentTrack;

View File

@@ -28,6 +28,7 @@
#include "instrument.h"
#include "instrument_track.h"
#include "dummy_instrument.h"
#include "note_play_handle.h"
instrument::instrument( instrumentTrack * _instrument_track,
@@ -105,5 +106,25 @@ bool instrument::isFromTrack( const track * _track ) const
void instrument::applyRelease( sampleFrame * buf, const notePlayHandle * _n )
{
const fpp_t frames = _n->framesLeftForCurrentPeriod();
const fpp_t fpp = engine::getMixer()->framesPerPeriod();
const f_cnt_t fl = _n->framesLeft();
if( fl <= desiredReleaseFrames()+fpp )
{
for( fpp_t f = fl > desiredReleaseFrames() ?
( tMax( fpp - desiredReleaseFrames(), 0 ) +
fl % fpp ) : 0; f < frames; ++f )
{
const float fac = (float)( fl-f-1 ) /
desiredReleaseFrames();
for( ch_cnt_t ch = 0; ch < DEFAULT_CHANNELS; ++ch )
{
buf[f][ch] *= fac;
}
}
}
}
#endif