X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=quantum%2Faudio%2Fvoices.c;h=94147ccb660e8a72f50459263065515a9676fb0c;hb=05990c9bda0ddbc0e622f12e88bec271958c864e;hp=19f7b646ef8eb2a71304e4bb9a5b612283da27c5;hpb=20892bf706219f19a5f9cd34abd4f772ab4ee570;p=qmk_firmware.git diff --git a/quantum/audio/voices.c b/quantum/audio/voices.c index 19f7b646e..94147ccb6 100644 --- a/quantum/audio/voices.c +++ b/quantum/audio/voices.c @@ -1,3 +1,18 @@ +/* Copyright 2016 Jack Humbert + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ #include "voices.h" #include "audio.h" #include "stdlib.h" @@ -6,6 +21,7 @@ extern uint16_t envelope_index; extern float note_timbre; extern float polyphony_rate; +extern bool glissando; voice_type voice = default_voice; @@ -23,15 +39,20 @@ void voice_deiterate() { float voice_envelope(float frequency) { // envelope_index ranges from 0 to 0xFFFF, which is preserved at 880.0 Hz + __attribute__ ((unused)) uint16_t compensated_index = (uint16_t)((float)envelope_index * (880.0 / frequency)); switch (voice) { case default_voice: + glissando = false; 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 +64,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 +207,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 +222,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 +231,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 +286,11 @@ float voice_envelope(float frequency) { // note_timbre = 0.25; // break; + #endif + default: break; } return frequency; } - -