Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: amakusa mbed-dsp mbed shimabara ukifune unzen_nucleo_f746
Fork of skeleton_unzen_nucleo_f746 by
Revision 28:547f19ed6f67, committed 2017-02-11
- Comitter:
- shorie
- Date:
- Sat Feb 11 07:44:56 2017 +0000
- Parent:
- 27:fcb1f1da2ad7
- Child:
- 29:8ee84bda128c
- Commit message:
- 13 tone is ready to play
Changed in this revision
--- a/eg.cpp Sat Feb 11 07:15:21 2017 +0000
+++ b/eg.cpp Sat Feb 11 07:44:56 2017 +0000
@@ -53,17 +53,17 @@
void EG::set_attack( float32_t attack )
{
- this->attack_time_constant = 1.0f - attack * 0.001f;
+ this->attack_time_constant = 1.0f - (1.0f-attack) * 0.001f;
}
void EG::set_decay( float32_t decay )
{
- this->decay_time_constant = 1.0f - decay * 0.001f;
+ this->decay_time_constant = 1.0f - (1.0f-decay) * 0.001f;
}
void EG::set_release( float32_t release )
{
- this->release_time_constant = 1.0f - release * 0.001f;
+ this->release_time_constant = 1.0f - (1.0f-release) * 0.001f;
}
--- a/main.cpp Sat Feb 11 07:15:21 2017 +0000
+++ b/main.cpp Sat Feb 11 07:44:56 2017 +0000
@@ -39,6 +39,15 @@
/*========================= Main program. ====================================*/
+#define KEYCTRL( SWITCH, FREQ )\
+ if ( pushing & ( 1 << ukifune::SWITCH ) )\
+ {\
+ process->set_vfo_frequency(FREQ);\
+ process->eg_on();\
+ }\
+ else if ( releasing & ( 1 << ukifune::SWITCH ) )\
+ process->eg_off();
+
int main()
{
uint32_t pushing, releasing, holding;
@@ -134,10 +143,20 @@
}
- if ( pushing & ( 1 << ukifune::swk1 ) )
- process->eg_on();
- else if ( releasing & ( 1 << ukifune::swk1 ) )
- process->eg_off();
+ // Key board control
+ KEYCTRL( swk1, 261.626 )
+ KEYCTRL( swk2, 277.183 )
+ KEYCTRL( swk3, 293.665 )
+ KEYCTRL( swk4, 311.123 )
+ KEYCTRL( swk5, 329.628 )
+ KEYCTRL( swk6, 349.228 )
+ KEYCTRL( swk7, 369.994 )
+ KEYCTRL( swk8, 391.995 )
+ KEYCTRL( swk9, 415.305 )
+ KEYCTRL( swk10, 440.000 )
+ KEYCTRL( swk11, 466.164 )
+ KEYCTRL( swk12, 498.883 )
+ KEYCTRL( swk13, 523.251 )
// you have to call tick() every 20mS-50mS if you need get_volume()
--- a/monophonic.cpp Sat Feb 11 07:15:21 2017 +0000
+++ b/monophonic.cpp Sat Feb 11 07:44:56 2017 +0000
@@ -63,7 +63,7 @@
}
// Oscillation Frequency
-void Monophonic::set_vfo_frequency( int freq )
+void Monophonic::set_vfo_frequency( float freq )
{
this->vfo->set_frequency( freq );
this->sv_filter->set_fc( freq );
--- a/signal_processing.cpp Sat Feb 11 07:15:21 2017 +0000
+++ b/signal_processing.cpp Sat Feb 11 07:44:56 2017 +0000
@@ -44,7 +44,7 @@
}
// Oscillation Frequency
-void SignalProcessing::set_vfo_frequency( int freq )
+void SignalProcessing::set_vfo_frequency( float freq )
{
this->enter_critical_section(); // forbidden interrrupt.
this->note->set_vfo_frequency( freq );
--- a/signal_processing.h Sat Feb 11 07:15:21 2017 +0000
+++ b/signal_processing.h Sat Feb 11 07:44:56 2017 +0000
@@ -19,7 +19,7 @@
);
// parameter settings
- void set_frequency( int freq ); // unit is Hz.
+ void set_frequency( float freq ); // unit is Hz.
void set_Fs( int Fs ); // unit is Hz.
void set_duty_cycle( float duty ); // 0 ... 0.5
void set_wave_form( wave_form form );
@@ -27,14 +27,14 @@
int32_t block_size;
// control variables.
- int frequency; // VFO frequency [Hz]
+ float frequency; // VFO frequency [Hz]
int Fs; // sampling Frequency [Hz]
float duty_cycle; // VFO duty cycle. 0 ... 0.5
wave_form form; // form of the wave form.
// internal variable.
- int current_phase; // internal variable of VFO.
- int half_way; // change point by duty cycle. ( period * duty_cycle ).
+ float current_phase; // internal variable of VFO.
+ float half_way; // change point by duty cycle. ( period * duty_cycle ).
float rising_rate;
float falling_rate;
@@ -45,7 +45,7 @@
class DCBlocker : public amakusa::AbstractFilter {
public:
DCBlocker( uint32_t blockSize );
- virtual void run( float32_t *pSrc, float32_t *pDst );
+ virtual void run( float *pSrc, float *pDst );
private:
float x_last;
float y_last;
@@ -56,19 +56,19 @@
class SVFilter : public amakusa::AbstractFilter {
public:
SVFilter( uint32_t a_block_size );
- virtual void run( float32_t *pSrc, float32_t *pDst);
- void set_Q( float32_t Q ); // real Q factor [ 0.5 ... inf ]
+ virtual void run( float *pSrc, float *pDst);
+ void set_Q( float Q ); // real Q factor [ 0.5 ... inf ]
void set_Fs( int new_Fs ); // Hz
void set_fc( int new_fc ); // Hz
- void set_f_factor( float32_t new_f_factor );
+ void set_f_factor( float new_f_factor );
void set_mode( svf_mode new_mode );
private:
// internal variable
- float32_t d1, d2; // delay 1, delay 2;
- float32_t q, f; // q = 1/Q, f = 2 * sin( fc*f_factor*pi/Fs );
+ float d1, d2; // delay 1, delay 2;
+ float q, f; // q = 1/Q, f = 2 * sin( fc*f_factor*pi/Fs );
// parameter set by method
int Fs, fc; // sampling frequency and control frequency
- float32_t f_factor;
+ float f_factor;
svf_mode mode; // lpf, hpf, bpf
void update_parameters( void );
};
@@ -76,16 +76,16 @@
class EG {
public:
EG ( int32_t a_block_size );
- virtual void run( float32_t *pEnvelope );
+ virtual void run( float *pEnvelope );
void on(void);
void off(void);
- void set_attack( float32_t attack ); // [0,1.0]
- void set_decay( float32_t attack ); // [0,1.0]
- void set_sustain( float32_t sustain ); // [0,1.0]
- void set_release ( float32_t attack ); // [0,1.0]
+ void set_attack( float attack ); // [0,1.0]
+ void set_decay( float attack ); // [0,1.0]
+ void set_sustain( float sustain ); // [0,1.0]
+ void set_release ( float attack ); // [0,1.0]
private:
- float32_t current_level, sustain_level;
- float32_t attack_time_constant, decay_time_constant, release_time_constant;
+ float current_level, sustain_level;
+ float attack_time_constant, decay_time_constant, release_time_constant;
eg_state state;
int32_t block_size;
};
@@ -99,7 +99,7 @@
float out_buffer[] // place to write the right output samples
);
void set_Fs( int Fs ); // unit is Hz.
- void set_vfo_frequency( int freq ); // unit is Hz.
+ void set_vfo_frequency( float freq ); // unit is Hz.
void set_vfo_duty_cycle( float duty ); // 0 ... 0.5
void set_vfo_wave_form( wave_form form );
void set_filter_mode( svf_mode mode );
@@ -107,16 +107,16 @@
void set_filter_f_factor( float f_factor ); // 0.0..1.0
void eg_on(void);
void eg_off(void);
- void set_eg_attack( float32_t attack ); // [0,1.0]
- void set_eg_decay( float32_t decay ); // [0,1.0]
- void set_eg_sustain( float32_t sustain ); // [0,1.0]
- void set_eg_release ( float32_t release ); // [0,1.0]
+ void set_eg_attack( float attack ); // [0,1.0]
+ void set_eg_decay( float decay ); // [0,1.0]
+ void set_eg_sustain( float sustain ); // [0,1.0]
+ void set_eg_release ( float release ); // [0,1.0]
private:
VFO *vfo;
DCBlocker *dc_blocker;
SVFilter *sv_filter;
EG *eg;
- float32_t *work_buf_a, *work_buf_b;
+ float *work_buf_a, *work_buf_b;
int32_t block_size;
};
@@ -137,7 +137,7 @@
// project depenedent members.
void set_volume( float vol );
void set_Fs( int Fs ); // unit is Hz.
- void set_vfo_frequency( int freq ); // unit is Hz.
+ void set_vfo_frequency( float freq ); // unit is Hz.
void set_vfo_duty_cycle( float duty ); // 0 ... 1.0
void set_vfo_wave_form( wave_form form );
void set_filter_mode( svf_mode mode );
@@ -145,10 +145,10 @@
void set_filter_f_factor( float f_factor ); // 0.0..1.0
void eg_on(void);
void eg_off(void);
- void set_eg_attack( float32_t attack ); // [0,1.0]
- void set_eg_decay( float32_t decay ); // [0,1.0]
- void set_eg_sustain( float32_t sustain ); // [0,1.0]
- void set_eg_release ( float32_t release ); // [0,1.0]
+ void set_eg_attack( float attack ); // [0,1.0]
+ void set_eg_decay( float decay ); // [0,1.0]
+ void set_eg_sustain( float sustain ); // [0,1.0]
+ void set_eg_release ( float release ); // [0,1.0]
private:
// essential members. Do not touch.
void enter_critical_section(void);
--- a/vfo.cpp Sat Feb 11 07:15:21 2017 +0000
+++ b/vfo.cpp Sat Feb 11 07:44:56 2017 +0000
@@ -64,7 +64,7 @@
this->update_parameters();
}
-void VFO::set_frequency( int freq )
+void VFO::set_frequency( float freq )
{
if ( freq > this->Fs / 4 )
freq = Fs / 4;
@@ -97,7 +97,7 @@
this-> half_way = this->Fs * this-> duty_cycle;
// make it integer multiple of frequency
- this->half_way /= this->frequency;
+ this->half_way = (int)(this->half_way/this->frequency);
this->half_way *= this->frequency;
// forbid to be zero.
