Synthesizer based on the Unzen / Nucleo F746ZG
Dependencies: amakusa mbed-dsp mbed shimabara ukifune unzen_nucleo_f746
Fork of skeleton_unzen_nucleo_f746 by
雲仙フレームワークのテストとして作っているプロジェクトです。中身はどんどん変っていきます。 説明はDSP空挺団の「シンセサイザー」カテゴリーを参照してください。初回は「ドッグフードを食べる」です。
monophonic.cpp@29:8ee84bda128c, 2017-02-18 (annotated)
- Committer:
- shorie
- Date:
- Sat Feb 18 04:37:19 2017 +0000
- Revision:
- 29:8ee84bda128c
- Parent:
- 28:547f19ed6f67
Limiter function is confirmed. SV filter ignored bug was fixed.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
shorie | 18:b9b1116f8768 | 1 | #include "signal_processing.h" |
shorie | 18:b9b1116f8768 | 2 | |
shorie | 18:b9b1116f8768 | 3 | |
shorie | 18:b9b1116f8768 | 4 | // constructor. |
shorie | 27:fcb1f1da2ad7 | 5 | Monophonic::Monophonic( unsigned int a_block_size ) |
shorie | 18:b9b1116f8768 | 6 | { |
shorie | 27:fcb1f1da2ad7 | 7 | this->block_size = a_block_size; |
shorie | 27:fcb1f1da2ad7 | 8 | |
shorie | 18:b9b1116f8768 | 9 | // initializing the subm-odules. |
shorie | 26:e99f71165e19 | 10 | this->vfo = new VFO(block_size); // allocate VFO |
shorie | 27:fcb1f1da2ad7 | 11 | this->dc_blocker = new DCBlocker( this->block_size ); |
shorie | 27:fcb1f1da2ad7 | 12 | this->sv_filter = new SVFilter( this->block_size ); |
shorie | 27:fcb1f1da2ad7 | 13 | this->eg = new EG( this->block_size ); |
shorie | 29:8ee84bda128c | 14 | this->limitter = new amakusa::LimitterLinAtan( this->block_size ); |
shorie | 20:53021b2c424d | 15 | |
shorie | 20:53021b2c424d | 16 | work_buf_a = new float32_t[block_size]; |
shorie | 20:53021b2c424d | 17 | work_buf_b = new float32_t[block_size]; |
shorie | 26:e99f71165e19 | 18 | |
shorie | 18:b9b1116f8768 | 19 | } // End of constructor() |
shorie | 18:b9b1116f8768 | 20 | |
shorie | 18:b9b1116f8768 | 21 | Monophonic::~Monophonic( void ) |
shorie | 18:b9b1116f8768 | 22 | { |
shorie | 18:b9b1116f8768 | 23 | // initializing the subm-odules. |
shorie | 18:b9b1116f8768 | 24 | delete this->vfo; |
shorie | 20:53021b2c424d | 25 | delete this->dc_blocker; |
shorie | 20:53021b2c424d | 26 | delete this->sv_filter; |
shorie | 27:fcb1f1da2ad7 | 27 | delete this->eg; |
shorie | 29:8ee84bda128c | 28 | delete this->limitter; |
shorie | 20:53021b2c424d | 29 | |
shorie | 20:53021b2c424d | 30 | delete[] work_buf_a; |
shorie | 20:53021b2c424d | 31 | delete[] work_buf_b; |
shorie | 18:b9b1116f8768 | 32 | } // End of constructor() |
shorie | 18:b9b1116f8768 | 33 | |
shorie | 18:b9b1116f8768 | 34 | |
shorie | 18:b9b1116f8768 | 35 | |
shorie | 18:b9b1116f8768 | 36 | // Run all signal processing. |
shorie | 18:b9b1116f8768 | 37 | void Monophonic::run( |
shorie | 26:e99f71165e19 | 38 | float out_buffer[] // place to write the right output samples |
shorie | 18:b9b1116f8768 | 39 | ) |
shorie | 18:b9b1116f8768 | 40 | { |
shorie | 18:b9b1116f8768 | 41 | // place the signal processing coce here |
shorie | 26:e99f71165e19 | 42 | this->vfo->run( work_buf_a ); |
shorie | 22:dc2cbe8db9d9 | 43 | |
shorie | 22:dc2cbe8db9d9 | 44 | // blocking DC. |
shorie | 22:dc2cbe8db9d9 | 45 | this->dc_blocker->run( work_buf_a, work_buf_b ); |
shorie | 18:b9b1116f8768 | 46 | |
shorie | 22:dc2cbe8db9d9 | 47 | // applying filter. |
shorie | 29:8ee84bda128c | 48 | this->sv_filter->run( work_buf_b, work_buf_a ); |
shorie | 18:b9b1116f8768 | 49 | |
shorie | 26:e99f71165e19 | 50 | // generate envelope |
shorie | 29:8ee84bda128c | 51 | this->eg->run( work_buf_b ); |
shorie | 26:e99f71165e19 | 52 | |
shorie | 26:e99f71165e19 | 53 | // apply envelope |
shorie | 27:fcb1f1da2ad7 | 54 | for ( int i= 0; i< this->block_size; i++ ) |
shorie | 29:8ee84bda128c | 55 | work_buf_b[ i ] *= work_buf_a[ i ]; |
shorie | 29:8ee84bda128c | 56 | |
shorie | 29:8ee84bda128c | 57 | // apply amplitude limitter |
shorie | 29:8ee84bda128c | 58 | this->limitter->run( work_buf_b, out_buffer ); |
shorie | 26:e99f71165e19 | 59 | |
shorie | 18:b9b1116f8768 | 60 | } // End of run() |
shorie | 18:b9b1116f8768 | 61 | |
shorie | 18:b9b1116f8768 | 62 | |
shorie | 18:b9b1116f8768 | 63 | // Sampling Frequency |
shorie | 18:b9b1116f8768 | 64 | void Monophonic::set_Fs( int Fs ) |
shorie | 18:b9b1116f8768 | 65 | { |
shorie | 18:b9b1116f8768 | 66 | this->vfo->set_Fs( Fs ); |
shorie | 22:dc2cbe8db9d9 | 67 | this->sv_filter->set_Fs( Fs ); |
shorie | 18:b9b1116f8768 | 68 | } |
shorie | 18:b9b1116f8768 | 69 | |
shorie | 18:b9b1116f8768 | 70 | // Oscillation Frequency |
shorie | 28:547f19ed6f67 | 71 | void Monophonic::set_vfo_frequency( float freq ) |
shorie | 18:b9b1116f8768 | 72 | { |
shorie | 18:b9b1116f8768 | 73 | this->vfo->set_frequency( freq ); |
shorie | 22:dc2cbe8db9d9 | 74 | this->sv_filter->set_fc( freq ); |
shorie | 18:b9b1116f8768 | 75 | } |
shorie | 18:b9b1116f8768 | 76 | |
shorie | 18:b9b1116f8768 | 77 | // Duty Cycle of VFO |
shorie | 18:b9b1116f8768 | 78 | void Monophonic::set_vfo_duty_cycle( float duty ) |
shorie | 18:b9b1116f8768 | 79 | { |
shorie | 18:b9b1116f8768 | 80 | this->vfo->set_duty_cycle( duty ); |
shorie | 18:b9b1116f8768 | 81 | } |
shorie | 18:b9b1116f8768 | 82 | |
shorie | 18:b9b1116f8768 | 83 | // VFO wave form |
shorie | 18:b9b1116f8768 | 84 | void Monophonic::set_vfo_wave_form( wave_form form ) |
shorie | 18:b9b1116f8768 | 85 | { |
shorie | 18:b9b1116f8768 | 86 | this->vfo->set_wave_form( form ); |
shorie | 18:b9b1116f8768 | 87 | } |
shorie | 22:dc2cbe8db9d9 | 88 | |
shorie | 22:dc2cbe8db9d9 | 89 | // SVF filter mode. |
shorie | 22:dc2cbe8db9d9 | 90 | void Monophonic::set_filter_mode( svf_mode mode ) |
shorie | 22:dc2cbe8db9d9 | 91 | { |
shorie | 22:dc2cbe8db9d9 | 92 | this->sv_filter->set_mode( mode ); |
shorie | 22:dc2cbe8db9d9 | 93 | } |
shorie | 22:dc2cbe8db9d9 | 94 | |
shorie | 22:dc2cbe8db9d9 | 95 | // SVF Q factor |
shorie | 22:dc2cbe8db9d9 | 96 | void Monophonic::set_filter_Q( float Q ) |
shorie | 22:dc2cbe8db9d9 | 97 | { |
shorie | 22:dc2cbe8db9d9 | 98 | this->sv_filter->set_Q( Q ); |
shorie | 22:dc2cbe8db9d9 | 99 | } |
shorie | 22:dc2cbe8db9d9 | 100 | |
shorie | 26:e99f71165e19 | 101 | // Set the f_factor value. |
shorie | 22:dc2cbe8db9d9 | 102 | void Monophonic::set_filter_f_factor( float f_factor ) |
shorie | 22:dc2cbe8db9d9 | 103 | { |
shorie | 22:dc2cbe8db9d9 | 104 | this->sv_filter->set_f_factor( f_factor ); |
shorie | 22:dc2cbe8db9d9 | 105 | } |
shorie | 26:e99f71165e19 | 106 | |
shorie | 26:e99f71165e19 | 107 | // Turn note on |
shorie | 26:e99f71165e19 | 108 | void Monophonic::eg_on(void) |
shorie | 26:e99f71165e19 | 109 | { |
shorie | 27:fcb1f1da2ad7 | 110 | this->eg->on(); |
shorie | 26:e99f71165e19 | 111 | } |
shorie | 26:e99f71165e19 | 112 | |
shorie | 26:e99f71165e19 | 113 | // Turn note off |
shorie | 26:e99f71165e19 | 114 | void Monophonic::eg_off(void) |
shorie | 26:e99f71165e19 | 115 | { |
shorie | 27:fcb1f1da2ad7 | 116 | this->eg->off(); |
shorie | 26:e99f71165e19 | 117 | } |
shorie | 26:e99f71165e19 | 118 | |
shorie | 26:e99f71165e19 | 119 | void Monophonic::set_eg_attack( float32_t attack ) |
shorie | 26:e99f71165e19 | 120 | { |
shorie | 27:fcb1f1da2ad7 | 121 | this->eg->set_attack( attack ); |
shorie | 26:e99f71165e19 | 122 | } |
shorie | 26:e99f71165e19 | 123 | void Monophonic::set_eg_decay( float32_t decay ) |
shorie | 26:e99f71165e19 | 124 | { |
shorie | 27:fcb1f1da2ad7 | 125 | this->eg->set_decay( decay ); |
shorie | 26:e99f71165e19 | 126 | } |
shorie | 26:e99f71165e19 | 127 | |
shorie | 26:e99f71165e19 | 128 | void Monophonic::set_eg_sustain( float32_t sustain ) |
shorie | 26:e99f71165e19 | 129 | { |
shorie | 27:fcb1f1da2ad7 | 130 | this->eg->set_sustain( sustain ); |
shorie | 26:e99f71165e19 | 131 | } |
shorie | 26:e99f71165e19 | 132 | |
shorie | 26:e99f71165e19 | 133 | void Monophonic::set_eg_release ( float32_t release ) |
shorie | 26:e99f71165e19 | 134 | { |
shorie | 27:fcb1f1da2ad7 | 135 | this->eg->set_release( release ); |
shorie | 26:e99f71165e19 | 136 | } |
shorie | 26:e99f71165e19 | 137 |