Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement fade in to prevent Triple Osc from clicking #5199

Merged
merged 12 commits into from
May 19, 2020
2 changes: 1 addition & 1 deletion include/Instrument.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ class LMMS_EXPORT Instrument : public Plugin

protected:
// fade in to prevent clicks
void applyFadeIn( sampleFrame * buf, const NotePlayHandle * _n );
void applyFadeIn(sampleFrame * buf, const NotePlayHandle * _n);
necrashter marked this conversation as resolved.
Show resolved Hide resolved

// instruments may use this to apply a soft fade out at the end of
// notes - method does this only if really less or equal
Expand Down
2 changes: 1 addition & 1 deletion plugins/triple_oscillator/TripleOscillator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ void TripleOscillator::playNote( NotePlayHandle * _n,
osc_l->update( _working_buffer + offset, frames, 0 );
osc_r->update( _working_buffer + offset, frames, 1 );

applyFadeIn( _working_buffer, _n );
applyFadeIn(_working_buffer, _n);
applyRelease( _working_buffer, _n );

instrumentTrack()->processAudioBuffer( _working_buffer, frames + offset, _n );
Expand Down
20 changes: 10 additions & 10 deletions src/core/Instrument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ bool Instrument::isFromTrack( const Track * _track ) const
}


void Instrument::applyFadeIn( sampleFrame * buf, const NotePlayHandle * n )
void Instrument::applyFadeIn(sampleFrame * buf, const NotePlayHandle * n)
{
// apply only if it's the start of the note
if (n->totalFramesPlayed() == 0)
Expand All @@ -96,15 +96,15 @@ void Instrument::applyFadeIn( sampleFrame * buf, const NotePlayHandle * n )
int max_zc = 0;

// determine the zero point crossing counts
for ( fpp_t f = 0; f < frames; ++f )
for (fpp_t f = 0; f < frames; ++f)
{
for ( ch_cnt_t ch=0; ch < DEFAULT_CHANNELS; ++ch )
for (ch_cnt_t ch=0; ch < DEFAULT_CHANNELS; ++ch)
{
if ( ( buf[f-1][ch] < 0.0 && buf[f][ch] > 0.0 ) ||
( buf[f-1][ch] > 0.0 && buf[f][ch] < 0.0 ) )
if ((buf[f-1][ch] < 0.0 && buf[f][ch] > 0.0) ||
(buf[f-1][ch] > 0.0 && buf[f][ch] < 0.0))
{
++zero_crossings[ch];
if ( zero_crossings[ch] > max_zc )
if (zero_crossings[ch] > max_zc)
{
max_zc = zero_crossings[ch];
}
Expand All @@ -114,13 +114,13 @@ void Instrument::applyFadeIn( sampleFrame * buf, const NotePlayHandle * n )

// calculate the length of the fade in
fpp_t length = (fpp_t) (
( (float)frames - 1 ) /
( (float)max_zc / 2.0f + 1.0f ) / 3.0f );
((float)frames - 1) /
((float)max_zc / 2.0f + 1.0f) / 3.0f);

// apply fade in
for ( fpp_t f = 0; f < length; ++f )
for (fpp_t f = 0; f < length; ++f)
{
for ( ch_cnt_t ch = 0; ch < DEFAULT_CHANNELS; ++ch )
for (ch_cnt_t ch = 0; ch < DEFAULT_CHANNELS; ++ch)
{
buf[f][ch] *= 0.5 - 0.5 * cosf(F_PI * (float) f / (float) length);
}
Expand Down