From 5b7eb30756df4910d0b574fdef7d95aa980d9dcc Mon Sep 17 00:00:00 2001 From: Garrett Date: Fri, 23 May 2014 12:45:52 -0700 Subject: [PATCH] Use release time as linear fade out time This makes it sound better than before, so that pianos fade out like expected and synths abruptly stop as intended. It's not the fully implemented ADSR of the format, but it's better. --- plugins/gig_player/gig_player.cpp | 41 +++++++++++++++++++++---------- plugins/gig_player/gig_player.h | 5 ++-- 2 files changed, 31 insertions(+), 15 deletions(-) diff --git a/plugins/gig_player/gig_player.cpp b/plugins/gig_player/gig_player.cpp index 2a334c1eb..8b2e2edef 100644 --- a/plugins/gig_player/gig_player.cpp +++ b/plugins/gig_player/gig_player.cpp @@ -427,12 +427,12 @@ void gigInstrument::deleteNotePluginData( NotePlayHandle * _n ) { noteRelease = i->release; - float fadeOut = 0.25; // Seconds + float fadeOut = i->releaseTime; // Seconds int len = std::min( int( floor( fadeOut * engine::mixer()->processingSampleRate() ) ), i->size-i->position ); int endPoint = i->position+len; - if (len <= 0) + if (len < 0) break; for( int k = i->position, j = 0; k < endPoint; ++k, ++j ) @@ -548,13 +548,14 @@ Dimension gigInstrument::getDimensions( gig::Region* pRegion, int velocity, bool -gigNote gigInstrument::sampleToNote( gig::Sample* pSample, int midiNote, float attenuation, bool release ) +gigNote gigInstrument::sampleToNote( gig::Sample* pSample, int midiNote, + float attenuation, bool release, float releaseTime ) { if( !pSample || pSample->Channels == 0 ) return gigNote(); gig::buffer_t buf = pSample->LoadSampleData(); - gigNote note( pSample->SamplesTotal, release ); + gigNote note( pSample->SamplesTotal, release, releaseTime ); note.midiNote = midiNote; if( pSample->Channels > 2 ) @@ -656,7 +657,7 @@ void gigInstrument::getInstrument() gigNote gigInstrument::convertSampleRate( gigNote& old, int oldRate, int newRate ) { - gigNote note( ceil( (double)old.size*newRate/oldRate ), old.release ); + gigNote note( ceil( (double)old.size*newRate/oldRate ), old.release, old.releaseTime ); note.midiNote = old.midiNote; SRC_DATA src_data; @@ -749,7 +750,7 @@ void gigInstrument::addNotes( int midiNote, int velocity, bool release ) attenuation *= pDimRegion->SampleAttenuation; gigNote note = sampleToNote( pSample, midiNote, - attenuation, dim.release ); + attenuation, dim.release, pDimRegion->EG1Release ); m_notes.push_back(note); } @@ -969,17 +970,20 @@ gigNote::gigNote() : midiNote( -1 ), note( NULL ), size( 0 ), - release( false ) + release( false ), + releaseTime( 0 ) { } -gigNote::gigNote(int size, bool release ) : +gigNote::gigNote(int size, bool release, float releaseTime ) : position( 0 ), midiNote( -1 ), size( size ), - release( release ) + release( release ), + releaseTime( releaseTime ) { - note = new sampleFrame[size]; + if( size > 0 ) + note = new sampleFrame[size]; // Initialize to no sound for (int i = 0; i < size; ++i) @@ -994,12 +998,18 @@ gigNote::gigNote( const gigNote& g ) : midiNote( g.midiNote ), note( NULL ), size( g.size ), - release( g.release ) + release( g.release ), + releaseTime( g.releaseTime ) { if (size > 0) { note = new sampleFrame[size]; - std::copy(&g.note[0], &g.note[size], ¬e[0]); + + for (int i = 0; i < size; ++i) + { + note[i][0] = g.note[i][0]; + note[i][1] = g.note[i][1]; + } } } @@ -1009,7 +1019,8 @@ gigNote::gigNote( gigNote&& g ) : midiNote( g.midiNote ), note( NULL ), size( 0 ), - release( g.release ) + release( g.release ), + releaseTime( g.releaseTime ) { *this = std::move( g ); } @@ -1024,6 +1035,10 @@ gigNote& gigNote::operator=( gigNote&& g ) size = g.size; note = g.note; + position = g.position; + midiNote = g.midiNote; + release = g.release; + releaseTime = g.releaseTime; g.size = 0; g.note = NULL; diff --git a/plugins/gig_player/gig_player.h b/plugins/gig_player/gig_player.h index d05342bf2..ff210e3d4 100644 --- a/plugins/gig_player/gig_player.h +++ b/plugins/gig_player/gig_player.h @@ -84,7 +84,7 @@ class gigNote { public: gigNote(); - gigNote(int size, bool release ); + gigNote(int size, bool release, float releaseTime ); gigNote( const gigNote& g ); ~gigNote(); @@ -99,6 +99,7 @@ public: sampleFrame* note; int size; // Don't try changing this... bool release; // Whether to trigger a release sample on key up + float releaseTime; // After letting up, time to fade out }; @@ -186,7 +187,7 @@ private: private: void freeInstance(); void getInstrument(); - gigNote sampleToNote( gig::Sample* pSample, int midiNote, float attenuation, bool release ); + gigNote sampleToNote( gig::Sample* pSample, int midiNote, float attenuation, bool release, float releaseTime ); Dimension getDimensions( gig::Region* pRegion, int velocity, bool release ); gigNote convertSampleRate( gigNote& old, int oldRate, int newRate ); void addNotes( int midiNote, int velocity, bool release ); // Locks m_synthMutex internally