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@28:547f19ed6f67, 2017-02-11 (annotated)
- Committer:
- shorie
- Date:
- Sat Feb 11 07:44:56 2017 +0000
- Revision:
- 28:547f19ed6f67
- Parent:
- 27:fcb1f1da2ad7
- Child:
- 29:8ee84bda128c
13 tone is ready to play
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 | 20:53021b2c424d | 14 | |
shorie | 20:53021b2c424d | 15 | work_buf_a = new float32_t[block_size]; |
shorie | 20:53021b2c424d | 16 | work_buf_b = new float32_t[block_size]; |
shorie | 26:e99f71165e19 | 17 | |
shorie | 18:b9b1116f8768 | 18 | } // End of constructor() |
shorie | 18:b9b1116f8768 | 19 | |
shorie | 18:b9b1116f8768 | 20 | Monophonic::~Monophonic( void ) |
shorie | 18:b9b1116f8768 | 21 | { |
shorie | 18:b9b1116f8768 | 22 | // initializing the subm-odules. |
shorie | 18:b9b1116f8768 | 23 | delete this->vfo; |
shorie | 20:53021b2c424d | 24 | delete this->dc_blocker; |
shorie | 20:53021b2c424d | 25 | delete this->sv_filter; |
shorie | 27:fcb1f1da2ad7 | 26 | delete this->eg; |
shorie | 20:53021b2c424d | 27 | |
shorie | 20:53021b2c424d | 28 | delete[] work_buf_a; |
shorie | 20:53021b2c424d | 29 | delete[] work_buf_b; |
shorie | 18:b9b1116f8768 | 30 | } // End of constructor() |
shorie | 18:b9b1116f8768 | 31 | |
shorie | 18:b9b1116f8768 | 32 | |
shorie | 18:b9b1116f8768 | 33 | |
shorie | 18:b9b1116f8768 | 34 | // Run all signal processing. |
shorie | 18:b9b1116f8768 | 35 | void Monophonic::run( |
shorie | 26:e99f71165e19 | 36 | float out_buffer[] // place to write the right output samples |
shorie | 18:b9b1116f8768 | 37 | ) |
shorie | 18:b9b1116f8768 | 38 | { |
shorie | 18:b9b1116f8768 | 39 | // place the signal processing coce here |
shorie | 26:e99f71165e19 | 40 | this->vfo->run( work_buf_a ); |
shorie | 22:dc2cbe8db9d9 | 41 | |
shorie | 22:dc2cbe8db9d9 | 42 | // blocking DC. |
shorie | 22:dc2cbe8db9d9 | 43 | this->dc_blocker->run( work_buf_a, work_buf_b ); |
shorie | 18:b9b1116f8768 | 44 | |
shorie | 22:dc2cbe8db9d9 | 45 | // applying filter. |
shorie | 22:dc2cbe8db9d9 | 46 | this->sv_filter->run( work_buf_b, out_buffer ); |
shorie | 18:b9b1116f8768 | 47 | |
shorie | 26:e99f71165e19 | 48 | // generate envelope |
shorie | 27:fcb1f1da2ad7 | 49 | this->eg->run( work_buf_a ); |
shorie | 26:e99f71165e19 | 50 | |
shorie | 26:e99f71165e19 | 51 | // apply envelope |
shorie | 27:fcb1f1da2ad7 | 52 | for ( int i= 0; i< this->block_size; i++ ) |
shorie | 27:fcb1f1da2ad7 | 53 | out_buffer[ i ] *= work_buf_a[ i ]; |
shorie | 26:e99f71165e19 | 54 | |
shorie | 18:b9b1116f8768 | 55 | } // End of run() |
shorie | 18:b9b1116f8768 | 56 | |
shorie | 18:b9b1116f8768 | 57 | |
shorie | 18:b9b1116f8768 | 58 | // Sampling Frequency |
shorie | 18:b9b1116f8768 | 59 | void Monophonic::set_Fs( int Fs ) |
shorie | 18:b9b1116f8768 | 60 | { |
shorie | 18:b9b1116f8768 | 61 | this->vfo->set_Fs( Fs ); |
shorie | 22:dc2cbe8db9d9 | 62 | this->sv_filter->set_Fs( Fs ); |
shorie | 18:b9b1116f8768 | 63 | } |
shorie | 18:b9b1116f8768 | 64 | |
shorie | 18:b9b1116f8768 | 65 | // Oscillation Frequency |
shorie | 28:547f19ed6f67 | 66 | void Monophonic::set_vfo_frequency( float freq ) |
shorie | 18:b9b1116f8768 | 67 | { |
shorie | 18:b9b1116f8768 | 68 | this->vfo->set_frequency( freq ); |
shorie | 22:dc2cbe8db9d9 | 69 | this->sv_filter->set_fc( freq ); |
shorie | 18:b9b1116f8768 | 70 | } |
shorie | 18:b9b1116f8768 | 71 | |
shorie | 18:b9b1116f8768 | 72 | // Duty Cycle of VFO |
shorie | 18:b9b1116f8768 | 73 | void Monophonic::set_vfo_duty_cycle( float duty ) |
shorie | 18:b9b1116f8768 | 74 | { |
shorie | 18:b9b1116f8768 | 75 | this->vfo->set_duty_cycle( duty ); |
shorie | 18:b9b1116f8768 | 76 | } |
shorie | 18:b9b1116f8768 | 77 | |
shorie | 18:b9b1116f8768 | 78 | // VFO wave form |
shorie | 18:b9b1116f8768 | 79 | void Monophonic::set_vfo_wave_form( wave_form form ) |
shorie | 18:b9b1116f8768 | 80 | { |
shorie | 18:b9b1116f8768 | 81 | this->vfo->set_wave_form( form ); |
shorie | 18:b9b1116f8768 | 82 | } |
shorie | 22:dc2cbe8db9d9 | 83 | |
shorie | 22:dc2cbe8db9d9 | 84 | // SVF filter mode. |
shorie | 22:dc2cbe8db9d9 | 85 | void Monophonic::set_filter_mode( svf_mode mode ) |
shorie | 22:dc2cbe8db9d9 | 86 | { |
shorie | 22:dc2cbe8db9d9 | 87 | this->sv_filter->set_mode( mode ); |
shorie | 22:dc2cbe8db9d9 | 88 | } |
shorie | 22:dc2cbe8db9d9 | 89 | |
shorie | 22:dc2cbe8db9d9 | 90 | // SVF Q factor |
shorie | 22:dc2cbe8db9d9 | 91 | void Monophonic::set_filter_Q( float Q ) |
shorie | 22:dc2cbe8db9d9 | 92 | { |
shorie | 22:dc2cbe8db9d9 | 93 | this->sv_filter->set_Q( Q ); |
shorie | 22:dc2cbe8db9d9 | 94 | } |
shorie | 22:dc2cbe8db9d9 | 95 | |
shorie | 26:e99f71165e19 | 96 | // Set the f_factor value. |
shorie | 22:dc2cbe8db9d9 | 97 | void Monophonic::set_filter_f_factor( float f_factor ) |
shorie | 22:dc2cbe8db9d9 | 98 | { |
shorie | 22:dc2cbe8db9d9 | 99 | this->sv_filter->set_f_factor( f_factor ); |
shorie | 22:dc2cbe8db9d9 | 100 | } |
shorie | 26:e99f71165e19 | 101 | |
shorie | 26:e99f71165e19 | 102 | // Turn note on |
shorie | 26:e99f71165e19 | 103 | void Monophonic::eg_on(void) |
shorie | 26:e99f71165e19 | 104 | { |
shorie | 27:fcb1f1da2ad7 | 105 | this->eg->on(); |
shorie | 26:e99f71165e19 | 106 | } |
shorie | 26:e99f71165e19 | 107 | |
shorie | 26:e99f71165e19 | 108 | // Turn note off |
shorie | 26:e99f71165e19 | 109 | void Monophonic::eg_off(void) |
shorie | 26:e99f71165e19 | 110 | { |
shorie | 27:fcb1f1da2ad7 | 111 | this->eg->off(); |
shorie | 26:e99f71165e19 | 112 | } |
shorie | 26:e99f71165e19 | 113 | |
shorie | 26:e99f71165e19 | 114 | void Monophonic::set_eg_attack( float32_t attack ) |
shorie | 26:e99f71165e19 | 115 | { |
shorie | 27:fcb1f1da2ad7 | 116 | this->eg->set_attack( attack ); |
shorie | 26:e99f71165e19 | 117 | } |
shorie | 26:e99f71165e19 | 118 | void Monophonic::set_eg_decay( float32_t decay ) |
shorie | 26:e99f71165e19 | 119 | { |
shorie | 27:fcb1f1da2ad7 | 120 | this->eg->set_decay( decay ); |
shorie | 26:e99f71165e19 | 121 | } |
shorie | 26:e99f71165e19 | 122 | |
shorie | 26:e99f71165e19 | 123 | void Monophonic::set_eg_sustain( float32_t sustain ) |
shorie | 26:e99f71165e19 | 124 | { |
shorie | 27:fcb1f1da2ad7 | 125 | this->eg->set_sustain( sustain ); |
shorie | 26:e99f71165e19 | 126 | } |
shorie | 26:e99f71165e19 | 127 | |
shorie | 26:e99f71165e19 | 128 | void Monophonic::set_eg_release ( float32_t release ) |
shorie | 26:e99f71165e19 | 129 | { |
shorie | 27:fcb1f1da2ad7 | 130 | this->eg->set_release( release ); |
shorie | 26:e99f71165e19 | 131 | } |
shorie | 26:e99f71165e19 | 132 |