Synthesizer based on the Unzen / Nucleo F746ZG

Dependencies:   amakusa mbed-dsp mbed shimabara ukifune unzen_nucleo_f746

Fork of skeleton_unzen_nucleo_f746 by seiichi horie

雲仙フレームワークのテストとして作っているプロジェクトです。中身はどんどん変っていきます。 説明はDSP空挺団の「シンセサイザー」カテゴリーを参照してください。初回は「ドッグフードを食べる」です。

eg.cpp

Committer:
shorie
Date:
2017-02-18
Revision:
29:8ee84bda128c
Parent:
28:547f19ed6f67

File content as of revision 29:8ee84bda128c:

#include "signal_processing.h"

EG::EG ( int32_t a_block_size )
{
    this->block_size = a_block_size;
    
    this->state = release;
    this->set_sustain( 0.0f );
    this->current_level = 0.0f;
    this->set_attack( 0.999 );
    this->set_decay( 0.999 );
    this->set_release( 0.999 );

}

void EG::run( float32_t *pEnvelope )
{
    if ( this->state == release )
        for ( int i= 0; i< this->block_size; i++ )
            pEnvelope[i] = this->current_level = 
                this->current_level * this->release_time_constant;
    else if ( this->state == decay )
        for ( int i= 0; i< this->block_size; i++ )
            pEnvelope[i] = this->current_level = 
                ( this->current_level - this->sustain_level ) * this->decay_time_constant
                + this->sustain_level;
    else // attack
    {
        for ( int i= 0; i< this->block_size; i++ )
            pEnvelope[i] = this->current_level = 
                1.5f - 
                ( 1.5f - this->current_level ) * this->attack_time_constant;
        if ( this->current_level >= 1.0f )
            this->state = decay;
     }               
    
}

void EG::on(void)
{
    this->state = attack;
}

void EG::off(void)
{
    this->state = release;
}

void EG::set_sustain( float32_t sustain )
{
    this->sustain_level = sustain;
}

void EG::set_attack( float32_t attack )
{
    this->attack_time_constant = 1.0f - (1.0f-attack) * 0.001f;
}

void EG::set_decay( float32_t decay )
{
    this->decay_time_constant = 1.0f - (1.0f-decay) * 0.001f;
}

void EG::set_release( float32_t release )
{
    this->release_time_constant = 1.0f - (1.0f-release) * 0.001f;
}