summaryrefslogtreecommitdiff
path: root/quantum
diff options
context:
space:
mode:
authorJack Humbert <jack.humb@gmail.com>2016-04-20 23:16:39 -0400
committerJack Humbert <jack.humb@gmail.com>2016-04-20 23:16:39 -0400
commit2e60054951ce08e973c735991bd95390c6aa3842 (patch)
treed70248bce2189967115da3d3b72554622f1df07b /quantum
parent2e303b40aed372ea69b79850dae41e4f8ea457f4 (diff)
downloadqmk_firmware-2e60054951ce08e973c735991bd95390c6aa3842.tar.gz
qmk_firmware-2e60054951ce08e973c735991bd95390c6aa3842.zip
fade envelope
Diffstat (limited to 'quantum')
-rw-r--r--quantum/audio.c21
1 files changed, 12 insertions, 9 deletions
diff --git a/quantum/audio.c b/quantum/audio.c
index 1327887d9a..df421ef999 100644
--- a/quantum/audio.c
+++ b/quantum/audio.c
@@ -302,18 +302,19 @@ float vibrato(float average_freq) {
float envelope(float f) {
uint16_t compensated_index = (uint16_t)((float)envelope_index * (880.0 / f));
switch (compensated_index) {
- case 0:
- note_timbre = TIMBRE_50;
- break;
- case 20:
- note_timbre = TIMBRE_25;
- break;
- case 32:
+ case 0 ... 9:
+ f = f / 4;
note_timbre = TIMBRE_12;
break;
- case 40 ... 60:
+ case 10 ... 19:
f = f / 2;
- note_timbre = TIMBRE_50;
+ note_timbre = TIMBRE_12;
+ break;
+ case 20 ... 200:
+ note_timbre = .125 - pow(((float)compensated_index - 20) / (200 - 20), 2)*.125;
+ break;
+ default:
+ note_timbre = 0;
break;
}
return f;
@@ -414,6 +415,8 @@ ISR(TIMER3_COMPA_vect) {
}
freq = envelope(freq);
+ if (freq < 30.517578125)
+ freq = 30.52;
ICR3 = (int)(((double)F_CPU) / (freq * CPU_PRESCALER)); // Set max to the period
OCR3A = (int)((((double)F_CPU) / (freq * CPU_PRESCALER)) * note_timbre); // Set compare to half the period
}