leaf/Src/leaf-envelopes.c
//initialize with an exponential function that decays -- i.e. a call to LEAF_generate_exp(expBuffer, 0.001f, 0.0f, 1.0f, -0.0008f, EXP_BUFFER_SIZE);
//times are in ms

initialize with an exponential function that decays -- i.e.
initialize with an exponential function that decays -- i . e .
void    tADSRT_initToPool    (tADSRT* const adsrenv, float attack, float decay, float sustain, float release, float* expBuffer, int bufferSize, tMempool* const mp)
{
    _tMempool* m = *mp;
    _tADSRT* adsr = *adsrenv = (_tADSRT*) mpool_alloc(sizeof(_tADSRT), m);
    adsr->mempool = m;
    LEAF* leaf = adsr->mempool->leaf;
    adsr->exp_buff = expBuffer;
    adsr->buff_size = bufferSize;
    adsr->buff_sizeMinusOne = bufferSize - 1;
    adsr->sampleRate = leaf->sampleRate;
    adsr->bufferSizeDividedBySampleRateInMs = adsr->buff_size / (adsr->sampleRate * 0.001f);
    if (attack < 0.0f)
        attack = 0.0f;
    if (decay < 0.0f)
        decay = 0.0f;
    if (sustain > 1.0f)
        sustain = 1.0f;
    if (sustain < 0.0f)
        sustain = 0.0f;
    if (release < 0.0f)
        release = 0.0f;
    adsr->next = 0.0f;
    adsr->whichStage = env_idle;
    adsr->sustain = sustain;
    adsr->attack = attack;
    adsr->decay = decay;
    adsr->release = release;
    adsr->attackInc = adsr->bufferSizeDividedBySampleRateInMs / attack;
    adsr->decayInc = adsr->bufferSizeDividedBySampleRateInMs / decay;
    adsr->releaseInc = adsr->bufferSizeDividedBySampleRateInMs / release;
    adsr->rampInc = adsr->bufferSizeDividedBySampleRateInMs / 8.0f;
    adsr->baseLeakFactor = 1.0f;
    adsr->leakFactor = 1.0f;
    adsr->invSampleRate = leaf->invSampleRate;
}
void tADSRT_initToPool ( tADSRT * const adsrenv , float attack , float decay , float sustain , float release , float * expBuffer , int bufferSize , tMempool * const mp ) { _tMempool * m = * mp ; _tADSRT * adsr = * adsrenv = ( _tADSRT * ) mpool_alloc ( sizeof ( _tADSRT ) , m ) ; adsr -> mempool = m ; LEAF * leaf = adsr -> mempool -> leaf ; adsr -> exp_buff = expBuffer ; adsr -> buff_size = bufferSize ; adsr -> buff_sizeMinusOne = bufferSize - 1 ; adsr -> sampleRate = leaf -> sampleRate ; adsr -> bufferSizeDividedBySampleRateInMs = adsr -> buff_size / ( adsr -> sampleRate * 0.001f ) ; if ( attack < 0.0f ) attack = 0.0f ; if ( decay < 0.0f ) decay = 0.0f ; if ( sustain > 1.0f ) sustain = 1.0f ; if ( sustain < 0.0f ) sustain = 0.0f ; if ( release < 0.0f ) release = 0.0f ; adsr -> next = 0.0f ; adsr -> whichStage = env_idle ; adsr -> sustain = sustain ; adsr -> attack = attack ; adsr -> decay = decay ; adsr -> release = release ; adsr -> attackInc = adsr -> bufferSizeDividedBySampleRateInMs / attack ; adsr -> decayInc = adsr -> bufferSizeDividedBySampleRateInMs / decay ; adsr -> releaseInc = adsr -> bufferSizeDividedBySampleRateInMs / release ; adsr -> rampInc = adsr -> bufferSizeDividedBySampleRateInMs / 8.0f ; adsr -> baseLeakFactor = 1.0f ; adsr -> leakFactor = 1.0f ; adsr -> invSampleRate = leaf -> invSampleRate ; }
initialize with an exponential function that decays -- i.e.
initialize with an exponential function that decays -- i . e .