Experimental implementation of the adaptive filter of "Interface" magazine in 2016-2017

Dependencies:   amakusa mbed-dsp mbed shimabara ukifune unzen_nucleo_f746

Fork of skeleton_unzen_nucleo_f746 by seiichi horie

ハードウェアおよびソフトウェアはskelton_unzen_nucleo_f746を基本にしています。

Committer:
shorie
Date:
Mon Jan 30 15:01:29 2017 +0000
Revision:
15:de22b9d147e0
Parent:
14:cec63d8da48c
Child:
16:d4ea3e6a0bce
Update VFO.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
shorie 14:cec63d8da48c 1 #include "signal_processing.h"
shorie 14:cec63d8da48c 2
shorie 14:cec63d8da48c 3 // Modify this constructor to initialize your audio algorithm.
shorie 14:cec63d8da48c 4 VFO::VFO( void )
shorie 14:cec63d8da48c 5 {
shorie 14:cec63d8da48c 6 // initial parameter setting.
shorie 14:cec63d8da48c 7 this->style = triangle;
shorie 14:cec63d8da48c 8 this->Fs = 48000;
shorie 14:cec63d8da48c 9 this->frequency = 440;
shorie 14:cec63d8da48c 10 this->duty_cycle = 0.5;
shorie 14:cec63d8da48c 11 } // End of constructor()
shorie 14:cec63d8da48c 12
shorie 14:cec63d8da48c 13
shorie 14:cec63d8da48c 14 // Modify this method to implement your audio algorithm.
shorie 14:cec63d8da48c 15 void VFO::run(
shorie 14:cec63d8da48c 16 float out_buffer[], // vfo output buffer
shorie 14:cec63d8da48c 17 unsigned int block_size // block size [sample]
shorie 14:cec63d8da48c 18 )
shorie 14:cec63d8da48c 19 {
shorie 14:cec63d8da48c 20 // place the signal processing coce here
shorie 14:cec63d8da48c 21 for ( int i= 0; i< block_size; i++ )
shorie 14:cec63d8da48c 22 {
shorie 15:de22b9d147e0 23 // 1 : if phase < half_way; 0 : others.
shorie 15:de22b9d147e0 24 if ( this->style == square )
shorie 15:de22b9d147e0 25 {
shorie 15:de22b9d147e0 26 if ( this->current_phase < this->half_way )
shorie 15:de22b9d147e0 27 out_buffer[i] = 0.5;
shorie 15:de22b9d147e0 28 else
shorie 15:de22b9d147e0 29 out_buffer[i] = 0.0;
shorie 15:de22b9d147e0 30 }
shorie 15:de22b9d147e0 31
shorie 15:de22b9d147e0 32 // to do, triangle.
shorie 15:de22b9d147e0 33
shorie 15:de22b9d147e0 34 // update phase
shorie 15:de22b9d147e0 35 this->current_phase += this->frequency;
shorie 15:de22b9d147e0 36 // limit the range of the phase.
shorie 15:de22b9d147e0 37 if ( this->current_phase >= this->Fs )
shorie 15:de22b9d147e0 38 this->current_phase -= this->Fs;
shorie 14:cec63d8da48c 39 }
shorie 14:cec63d8da48c 40 } // End of run()
shorie 14:cec63d8da48c 41
shorie 14:cec63d8da48c 42
shorie 14:cec63d8da48c 43 void VFO::set_Fs( int Fs )
shorie 14:cec63d8da48c 44 {
shorie 14:cec63d8da48c 45 // regulate the Fs.
shorie 14:cec63d8da48c 46 if ( Fs != 32000 && Fs != 44100 && Fs != 96000 && Fs != 48000 )
shorie 14:cec63d8da48c 47 Fs = 48000;
shorie 14:cec63d8da48c 48 this->Fs = Fs;
shorie 14:cec63d8da48c 49 }
shorie 14:cec63d8da48c 50
shorie 14:cec63d8da48c 51 void VFO::set_frequency( int freq )
shorie 14:cec63d8da48c 52 {
shorie 14:cec63d8da48c 53 if ( freq > this->Fs / 4 )
shorie 14:cec63d8da48c 54 freq = Fs/4;
shorie 14:cec63d8da48c 55 this->frequency = freq;
shorie 14:cec63d8da48c 56 }
shorie 14:cec63d8da48c 57
shorie 14:cec63d8da48c 58 void VFO::set_duty_cycle( float duty )
shorie 14:cec63d8da48c 59 {
shorie 14:cec63d8da48c 60 if ( duty > 0.5f ) // high limit
shorie 14:cec63d8da48c 61 duty = 0.5f;
shorie 14:cec63d8da48c 62 if ( duty < 0.01f ) // low limit
shorie 14:cec63d8da48c 63 duty = 0.01f;
shorie 14:cec63d8da48c 64 this->duty_cycle = duty;
shorie 14:cec63d8da48c 65 }
shorie 14:cec63d8da48c 66
shorie 14:cec63d8da48c 67 void VFO::set_wave_style( wave_style style )
shorie 14:cec63d8da48c 68 {
shorie 14:cec63d8da48c 69 this->style = style;
shorie 14:cec63d8da48c 70 }
shorie 14:cec63d8da48c 71
shorie 14:cec63d8da48c 72
shorie 14:cec63d8da48c 73