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空挺団の「シンセサイザー」カテゴリーを参照してください。初回は「ドッグフードを食べる」です。

Revision:
26:e99f71165e19
Child:
27:fcb1f1da2ad7
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/eg.cpp	Fri Feb 10 21:31:17 2017 +0000
@@ -0,0 +1,69 @@
+#include "signal_processing.h"
+
+EG::EG ( int32_t block_size )
+{
+    this->block_size = 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 - attack * 0.01f;
+}
+
+void EG::set_decay( float32_t decay )
+{
+    this->decay_time_constant = 1.0f - decay * 0.01f;
+}
+
+void EG::set_release( float32_t release )
+{
+    this->release_time_constant = 1.0f - release * 0.01f;
+}
+
+