2016-04-21 04:37:45 +00:00
|
|
|
#include "voices.h"
|
|
|
|
|
|
|
|
extern uint16_t envelope_index;
|
|
|
|
extern float note_timbre;
|
|
|
|
|
|
|
|
voice_type voice = default_voice;
|
|
|
|
|
|
|
|
void set_voice(voice_type v) {
|
2016-04-21 04:40:00 +00:00
|
|
|
voice = v;
|
2016-04-21 04:37:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
float voice_envelope(float frequency) {
|
2016-04-21 04:40:00 +00:00
|
|
|
// envelope_index ranges from 0 to 0xFFFF, which is preserved at 880.0 Hz
|
2016-04-21 04:37:45 +00:00
|
|
|
uint16_t compensated_index = (uint16_t)((float)envelope_index * (880.0 / frequency));
|
|
|
|
|
|
|
|
switch (voice) {
|
2016-04-21 04:40:00 +00:00
|
|
|
case default_voice:
|
|
|
|
// nothing here on purpose
|
|
|
|
break;
|
|
|
|
case butts_fader:
|
|
|
|
switch (compensated_index) {
|
|
|
|
case 0 ... 9:
|
|
|
|
frequency = frequency / 4;
|
|
|
|
note_timbre = TIMBRE_12;
|
|
|
|
break;
|
|
|
|
case 10 ... 19:
|
|
|
|
frequency = frequency / 2;
|
|
|
|
note_timbre = TIMBRE_12;
|
|
|
|
break;
|
|
|
|
case 20 ... 200:
|
|
|
|
note_timbre = .125 - pow(((float)compensated_index - 20) / (200 - 20), 2)*.125;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
note_timbre = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case octave_crunch:
|
|
|
|
switch (compensated_index) {
|
|
|
|
case 0 ... 9:
|
|
|
|
case 20 ... 24:
|
|
|
|
case 30 ... 32:
|
|
|
|
frequency = frequency / 2;
|
|
|
|
note_timbre = TIMBRE_12;
|
|
|
|
break;
|
|
|
|
case 10 ... 19:
|
|
|
|
case 25 ... 29:
|
|
|
|
case 33 ... 35:
|
|
|
|
frequency = frequency * 2;
|
|
|
|
note_timbre = TIMBRE_12;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
note_timbre = TIMBRE_12;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2016-04-21 04:37:45 +00:00
|
|
|
|
2016-04-21 04:40:00 +00:00
|
|
|
return frequency;
|
2016-04-21 04:37:45 +00:00
|
|
|
}
|