X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=quantum%2Faudio%2Fvoices.c;h=94147ccb660e8a72f50459263065515a9676fb0c;hb=4c1164c469a103981478222b21ef5ffaa364448d;hp=06ff275ba43b985739b74e737a392865ccab9914;hpb=06c64bbff3e228df542149acde64eadaf59b9b0f;p=qmk_firmware.git diff --git a/quantum/audio/voices.c b/quantum/audio/voices.c index 06ff275ba..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" @@ -24,15 +39,18 @@ 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 = true; + glissando = false; note_timbre = TIMBRE_50; polyphony_rate = 0; break; + #ifdef AUDIO_VOICES + case something: glissando = false; polyphony_rate = 0; @@ -58,36 +76,87 @@ float voice_envelope(float frequency) { case drums: glissando = false; polyphony_rate = 0; - note_timbre = 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 ... 20: + case 0 ... 15: note_timbre = 0.5; + break; + case 16 ... 20: + note_timbre = 0.5 * (21 - envelope_index) / 5; + break; default: - frequency = (rand() % (int)(frequency * 1.2 - frequency)) + (frequency * 0.8); + note_timbre = 0; break; } - // if (frequency < 80.0) { - // switch (envelope_index % 4) { - // case 0: - // frequency = 348.0; - // case 1: - // frequency = 53.0; - // case 2: - // frequency = 128.0; - // case 3: - // frequency = 934.0; - // default: - // break; - // } - // } else if (frequency < 160.0) { - - // } else if (frequency < 320.0) { - - // } else if (frequency < 640.0) { - - // } else if (frequency < 1280.0) { - - // } + + } 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; @@ -217,11 +286,11 @@ float voice_envelope(float frequency) { // note_timbre = 0.25; // break; + #endif + default: break; } return frequency; } - -