diff options
author | Damien <Dbroqua@users.noreply.github.com> | 2017-01-07 08:45:19 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-01-07 08:45:19 -0600 |
commit | 0fb82c15a5c9a69e17cff8dcd04c652d21381958 (patch) | |
tree | dd7a441ad7d086bb7cb4b093bd8d0cbd4d39d69d /quantum/audio | |
parent | db48b28eeb5ebe5252cc04495d5eb326fa62dc26 (diff) | |
parent | e7df488a92da56cf160ac64c8cc7302ab717e145 (diff) |
Merge pull request #15 from jackhumbert/master
Merge from qmk
Diffstat (limited to 'quantum/audio')
-rw-r--r-- | quantum/audio/audio.c | 15 | ||||
-rw-r--r-- | quantum/audio/voices.c | 102 | ||||
-rw-r--r-- | quantum/audio/voices.h | 3 |
3 files changed, 111 insertions, 9 deletions
diff --git a/quantum/audio/audio.c b/quantum/audio/audio.c index ead5fbf3e9..2a315fd168 100644 --- a/quantum/audio/audio.c +++ b/quantum/audio/audio.c @@ -77,6 +77,7 @@ static bool audio_initialized = false; audio_config_t audio_config; uint16_t envelope_index = 0; +bool glissando = true; void audio_init() { @@ -205,13 +206,17 @@ ISR(TIMER3_COMPA_vect) freq = frequencies[voice_place]; #endif } else { - if (frequency != 0 && frequency < frequencies[voices - 1] && frequency < frequencies[voices - 1] * pow(2, -440/frequencies[voices - 1]/12/2)) { - frequency = frequency * pow(2, 440/frequency/12/2); - } else if (frequency != 0 && frequency > frequencies[voices - 1] && frequency > frequencies[voices - 1] * pow(2, 440/frequencies[voices - 1]/12/2)) { - frequency = frequency * pow(2, -440/frequency/12/2); + if (glissando) { + if (frequency != 0 && frequency < frequencies[voices - 1] && frequency < frequencies[voices - 1] * pow(2, -440/frequencies[voices - 1]/12/2)) { + frequency = frequency * pow(2, 440/frequency/12/2); + } else if (frequency != 0 && frequency > frequencies[voices - 1] && frequency > frequencies[voices - 1] * pow(2, 440/frequencies[voices - 1]/12/2)) { + frequency = frequency * pow(2, -440/frequency/12/2); + } else { + frequency = frequencies[voices - 1]; + } } else { frequency = frequencies[voices - 1]; - } + } #ifdef VIBRATO_ENABLE if (vibrato_strength > 0) { diff --git a/quantum/audio/voices.c b/quantum/audio/voices.c index 19f7b646ef..8326e91eaa 100644 --- a/quantum/audio/voices.c +++ b/quantum/audio/voices.c @@ -6,6 +6,7 @@ extern uint16_t envelope_index; extern float note_timbre; extern float polyphony_rate; +extern bool glissando; voice_type voice = default_voice; @@ -27,11 +28,15 @@ float voice_envelope(float frequency) { switch (voice) { case default_voice: + glissando = true; note_timbre = TIMBRE_50; polyphony_rate = 0; break; + #ifdef AUDIO_VOICES + case something: + glissando = false; polyphony_rate = 0; switch (compensated_index) { case 0 ... 9: @@ -43,16 +48,102 @@ float voice_envelope(float frequency) { break; case 20 ... 200: - note_timbre = .25 + .125 + pow(((float)compensated_index - 20) / (200 - 20), 2)*.125; + note_timbre = .125 + .125; break; default: - note_timbre = .25; + note_timbre = .125; break; } break; + case drums: + glissando = false; + polyphony_rate = 0; + // switch (compensated_index) { + // case 0 ... 10: + // note_timbre = 0.5; + // break; + // case 11 ... 20: + // note_timbre = 0.5 * (21 - compensated_index) / 10; + // break; + // default: + // note_timbre = 0; + // break; + // } + // frequency = (rand() % (int)(frequency * 1.2 - frequency)) + (frequency * 0.8); + + if (frequency < 80.0) { + + } else if (frequency < 160.0) { + + // Bass drum: 60 - 100 Hz + frequency = (rand() % (int)(40)) + 60; + switch (envelope_index) { + case 0 ... 10: + note_timbre = 0.5; + break; + case 11 ... 20: + note_timbre = 0.5 * (21 - envelope_index) / 10; + break; + default: + note_timbre = 0; + break; + } + + } else if (frequency < 320.0) { + + + // Snare drum: 1 - 2 KHz + frequency = (rand() % (int)(1000)) + 1000; + switch (envelope_index) { + case 0 ... 5: + note_timbre = 0.5; + break; + case 6 ... 20: + note_timbre = 0.5 * (21 - envelope_index) / 15; + break; + default: + note_timbre = 0; + break; + } + + } else if (frequency < 640.0) { + + // Closed Hi-hat: 3 - 5 KHz + frequency = (rand() % (int)(2000)) + 3000; + switch (envelope_index) { + case 0 ... 15: + note_timbre = 0.5; + break; + case 16 ... 20: + note_timbre = 0.5 * (21 - envelope_index) / 5; + break; + default: + note_timbre = 0; + break; + } + + } else if (frequency < 1280.0) { + + // Open Hi-hat: 3 - 5 KHz + frequency = (rand() % (int)(2000)) + 3000; + switch (envelope_index) { + case 0 ... 35: + note_timbre = 0.5; + break; + case 36 ... 50: + note_timbre = 0.5 * (51 - envelope_index) / 15; + break; + default: + note_timbre = 0; + break; + } + + } + break; case butts_fader: + glissando = true; polyphony_rate = 0; switch (compensated_index) { case 0 ... 9: @@ -100,6 +191,7 @@ float voice_envelope(float frequency) { case duty_osc: // This slows the loop down a substantial amount, so higher notes may freeze + glissando = true; polyphony_rate = 0; switch (compensated_index) { default: @@ -114,6 +206,7 @@ float voice_envelope(float frequency) { break; case duty_octave_down: + glissando = true; polyphony_rate = 0; note_timbre = (envelope_index % 2) * .125 + .375 * 2; if ((envelope_index % 4) == 0) @@ -122,6 +215,7 @@ float voice_envelope(float frequency) { note_timbre = 0; break; case delayed_vibrato: + glissando = true; polyphony_rate = 0; note_timbre = TIMBRE_50; #define VOICE_VIBRATO_DELAY 150 @@ -176,11 +270,11 @@ float voice_envelope(float frequency) { // note_timbre = 0.25; // break; + #endif + default: break; } return frequency; } - - diff --git a/quantum/audio/voices.h b/quantum/audio/voices.h index b43def3d7d..52f7e006d6 100644 --- a/quantum/audio/voices.h +++ b/quantum/audio/voices.h @@ -11,7 +11,9 @@ float voice_envelope(float frequency); typedef enum { default_voice, + #ifdef AUDIO_VOICES something, + drums, butts_fader, octave_crunch, duty_osc, @@ -22,6 +24,7 @@ typedef enum { // duty_fourth_down, // duty_third_down, // duty_fifth_third_down, + #endif number_of_voices // important that this is last } voice_type; |