#include "Envelope.h" #include #include "minorGems/util/log/AppLog.h" // #include Envelope::Envelope( double inAttackTime, double inDecayTime, double inSustainLevel, double inReleaseTime, int inMinNoteLengthInGridSteps, int inMaxNoteLengthInGridSteps, int inGridStepDurationInSamples ) : mActiveNoteCount( 0 ), mGridStepDurationInSamples( inGridStepDurationInSamples ), mMinEnvNum( inMinNoteLengthInGridSteps ), mNumComputedEnvelopes( inMaxNoteLengthInGridSteps ), mEvelopeLengths( new int[ inMaxNoteLengthInGridSteps ] ), mComputedEnvelopes( new double*[ inMaxNoteLengthInGridSteps ] ) { for( int i=mMinEnvNum-1; i 0 ); mComputedEnvelopes[i][s] = t / inAttackTime; } else if( t < inAttackTime + inDecayTime ) { // assert( inDecayTime > 0 ); // decay down to sustain level mComputedEnvelopes[i][s] = ( 1.0 - inSustainLevel ) * ( inAttackTime + inDecayTime - t ) / ( inDecayTime ) + inSustainLevel; } else if( 1.0 - t > inReleaseTime ) { mComputedEnvelopes[i][s] = inSustainLevel; } else { if( inReleaseTime > 0 ) { mComputedEnvelopes[i][s] = inSustainLevel - inSustainLevel * ( inReleaseTime - ( 1.0 - t ) ) / inReleaseTime; } else { // release time 0 // hold sustain until end mComputedEnvelopes[i][s] = inSustainLevel; } } } // test code to output evelopes for plotting in gnuplot if( false && i == 0 ) { FILE *file = fopen( "env0.txt", "w" ); for( int s=0; s 0 ); thisEnv[s] = t / inAttackTime; } //else if( t < inAttackTime + inHoldTime ) { else if( s < attackHoldSamples ) { // assert( inDecayTime > 0 ); // hold at 1 thisEnv[s] = 1.0; } else { if( inReleaseTime > 0 && //t < inAttackTime + inHoldTime + inReleaseTime ) { s < attackHoldReleaseSamples ) { thisEnv[s] = 1.0 - ( t - ( inAttackTime + inHoldTime ) ) / inReleaseTime; } else { // release time 0 // end immediately after hold thisEnv[s] = 0; } } } */ // test code to output evelopes for plotting in gnuplot if( false && i == 0 ) { FILE *file = fopen( "env0.txt", "w" ); for( int s=0; s mNumComputedEnvelopes || inNoteLengthInGridSteps < mMinEnvNum ) { AppLog::error( "Error: evelope for unsupported number of" " grid steps requested" ); inNoteLengthInGridSteps = mMinEnvNum; } return mComputedEnvelopes[ inNoteLengthInGridSteps - 1 ]; }