diff options
Diffstat (limited to 'quantum/audio/voices.c')
| -rw-r--r-- | quantum/audio/voices.c | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/quantum/audio/voices.c b/quantum/audio/voices.c new file mode 100644 index 000000000..51652927b --- /dev/null +++ b/quantum/audio/voices.c | |||
| @@ -0,0 +1,60 @@ | |||
| 1 | #include "voices.h" | ||
| 2 | |||
| 3 | extern uint16_t envelope_index; | ||
| 4 | extern float note_timbre; | ||
| 5 | |||
| 6 | voice_type voice = default_voice; | ||
| 7 | |||
| 8 | void set_voice(voice_type v) { | ||
| 9 | voice = v; | ||
| 10 | } | ||
| 11 | |||
| 12 | float voice_envelope(float frequency) { | ||
| 13 | // envelope_index ranges from 0 to 0xFFFF, which is preserved at 880.0 Hz | ||
| 14 | uint16_t compensated_index = (uint16_t)((float)envelope_index * (880.0 / frequency)); | ||
| 15 | |||
| 16 | switch (voice) { | ||
| 17 | case default_voice: | ||
| 18 | // nothing here on purpose | ||
| 19 | break; | ||
| 20 | case butts_fader: | ||
| 21 | switch (compensated_index) { | ||
| 22 | case 0 ... 9: | ||
| 23 | frequency = frequency / 4; | ||
| 24 | note_timbre = TIMBRE_12; | ||
| 25 | break; | ||
| 26 | case 10 ... 19: | ||
| 27 | frequency = frequency / 2; | ||
| 28 | note_timbre = TIMBRE_12; | ||
| 29 | break; | ||
| 30 | case 20 ... 200: | ||
| 31 | note_timbre = .125 - pow(((float)compensated_index - 20) / (200 - 20), 2)*.125; | ||
| 32 | break; | ||
| 33 | default: | ||
| 34 | note_timbre = 0; | ||
| 35 | break; | ||
| 36 | } | ||
| 37 | break; | ||
| 38 | case octave_crunch: | ||
| 39 | switch (compensated_index) { | ||
| 40 | case 0 ... 9: | ||
| 41 | case 20 ... 24: | ||
| 42 | case 30 ... 32: | ||
| 43 | frequency = frequency / 2; | ||
| 44 | note_timbre = TIMBRE_12; | ||
| 45 | break; | ||
| 46 | case 10 ... 19: | ||
| 47 | case 25 ... 29: | ||
| 48 | case 33 ... 35: | ||
| 49 | frequency = frequency * 2; | ||
| 50 | note_timbre = TIMBRE_12; | ||
| 51 | break; | ||
| 52 | default: | ||
| 53 | note_timbre = TIMBRE_12; | ||
| 54 | break; | ||
| 55 | } | ||
| 56 | break; | ||
| 57 | } | ||
| 58 | |||
| 59 | return frequency; | ||
| 60 | } \ No newline at end of file | ||
