Synthesizer based on the Unzen / Nucleo F746ZG
Dependencies: amakusa mbed-dsp mbed shimabara ukifune unzen_nucleo_f746
Fork of skeleton_unzen_nucleo_f746 by
eg.cpp
00001 #include "signal_processing.h" 00002 00003 EG::EG ( int32_t a_block_size ) 00004 { 00005 this->block_size = a_block_size; 00006 00007 this->state = release; 00008 this->set_sustain( 0.0f ); 00009 this->current_level = 0.0f; 00010 this->set_attack( 0.999 ); 00011 this->set_decay( 0.999 ); 00012 this->set_release( 0.999 ); 00013 00014 } 00015 00016 void EG::run( float32_t *pEnvelope ) 00017 { 00018 if ( this->state == release ) 00019 for ( int i= 0; i< this->block_size; i++ ) 00020 pEnvelope[i] = this->current_level = 00021 this->current_level * this->release_time_constant; 00022 else if ( this->state == decay ) 00023 for ( int i= 0; i< this->block_size; i++ ) 00024 pEnvelope[i] = this->current_level = 00025 ( this->current_level - this->sustain_level ) * this->decay_time_constant 00026 + this->sustain_level; 00027 else // attack 00028 { 00029 for ( int i= 0; i< this->block_size; i++ ) 00030 pEnvelope[i] = this->current_level = 00031 1.5f - 00032 ( 1.5f - this->current_level ) * this->attack_time_constant; 00033 if ( this->current_level >= 1.0f ) 00034 this->state = decay; 00035 } 00036 00037 } 00038 00039 void EG::on(void) 00040 { 00041 this->state = attack; 00042 } 00043 00044 void EG::off(void) 00045 { 00046 this->state = release; 00047 } 00048 00049 void EG::set_sustain( float32_t sustain ) 00050 { 00051 this->sustain_level = sustain; 00052 } 00053 00054 void EG::set_attack( float32_t attack ) 00055 { 00056 this->attack_time_constant = 1.0f - (1.0f-attack) * 0.001f; 00057 } 00058 00059 void EG::set_decay( float32_t decay ) 00060 { 00061 this->decay_time_constant = 1.0f - (1.0f-decay) * 0.001f; 00062 } 00063 00064 void EG::set_release( float32_t release ) 00065 { 00066 this->release_time_constant = 1.0f - (1.0f-release) * 0.001f; 00067 } 00068 00069
Generated on Wed Jul 13 2022 23:24:36 by 1.7.2