From 9828aba2a12f03fccbc1095bc8e4918ae58fa31b Mon Sep 17 00:00:00 2001 From: Jack Humbert Date: Thu, 21 Apr 2016 18:14:25 -0400 Subject: adds multiple voices and the ability to iterate/deiterate between them --- quantum/audio/voices.c | 31 +++++++++++++++++++++++++++++-- quantum/audio/voices.h | 6 +++++- 2 files changed, 34 insertions(+), 3 deletions(-) (limited to 'quantum/audio') 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 -- cgit v1.2.3-24-g4f1b