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