diff options
author | Jack Humbert <jack.humb@gmail.com> | 2016-04-22 00:14:25 +0200 |
---|---|---|
committer | Jack Humbert <jack.humb@gmail.com> | 2016-04-22 00:14:25 +0200 |
commit | 9828aba2a12f03fccbc1095bc8e4918ae58fa31b (patch) | |
tree | 9990820fa4f42650599b40527c94fe3e6c3f6a2d /quantum | |
parent | a8fd65d86f1bb43a845555ee2ac4b588798684ad (diff) | |
download | qmk_firmware-9828aba2a12f03fccbc1095bc8e4918ae58fa31b.tar.gz qmk_firmware-9828aba2a12f03fccbc1095bc8e4918ae58fa31b.tar.xz |
adds multiple voices and the ability to iterate/deiterate between them
Diffstat (limited to 'quantum')
-rw-r--r-- | quantum/audio/voices.c | 31 | ||||
-rw-r--r-- | quantum/audio/voices.h | 6 |
2 files changed, 34 insertions, 3 deletions
diff --git a/quantum/audio/voices.c b/quantum/audio/voices.c index 51652927b..92ada47f7 100644 --- a/quantum/audio/voices.c +++ b/quantum/audio/voices.c @@ -1,23 +1,35 @@ #include "voices.h" +// these are imported from audio.c extern uint16_t envelope_index; extern float note_timbre; +extern float polyphony_rate; -voice_type voice = default_voice; +voice_type voice = duty_osc; void set_voice(voice_type v) { voice = v; } +void voice_iterate() { + voice = (voice + 1) % number_of_voices; +} + +void voice_deiterate() { + voice = (voice - 1) % number_of_voices; +} + float voice_envelope(float frequency) { // envelope_index ranges from 0 to 0xFFFF, which is preserved at 880.0 Hz uint16_t compensated_index = (uint16_t)((float)envelope_index * (880.0 / frequency)); switch (voice) { case default_voice: - // nothing here on purpose + note_timbre = TIMBRE_50; + polyphony_rate = 0; break; case butts_fader: + polyphony_rate = 0; switch (compensated_index) { case 0 ... 9: frequency = frequency / 4; @@ -36,6 +48,7 @@ float voice_envelope(float frequency) { } break; case octave_crunch: + polyphony_rate = 0; switch (compensated_index) { case 0 ... 9: case 20 ... 24: @@ -54,6 +67,20 @@ float voice_envelope(float frequency) { break; } break; + case duty_osc: + // This slows the loop down a substantial amount, so higher notes may freeze + polyphony_rate = 0; + switch (compensated_index) { + default: + #define SPEED 10 + #define AMP .75 + // sine wave is slow + // note_timbre = (sin((float)compensated_index/10000*SPEED) * AMP / 2) + .5; + // triangle wave is a bit faster + note_timbre = (float)abs((compensated_index*SPEED % 3000) - 1500) * ( AMP / 1500 ) + (1 - AMP) / 2; + break; + } + break; } return frequency; diff --git a/quantum/audio/voices.h b/quantum/audio/voices.h index 317f5d98c..44c5066b5 100644 --- a/quantum/audio/voices.h +++ b/quantum/audio/voices.h @@ -13,9 +13,13 @@ float voice_envelope(float frequency); typedef enum { default_voice, butts_fader, - octave_crunch + octave_crunch, + duty_osc, + number_of_voices // important that this is last } voice_type; void set_voice(voice_type v); +void voice_iterate(); +void voice_deiterate(); #endif
\ No newline at end of file |