aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--quantum/audio.c21
1 files changed, 12 insertions, 9 deletions
diff --git a/quantum/audio.c b/quantum/audio.c
index 1327887d9..df421ef99 100644
--- a/quantum/audio.c
+++ b/quantum/audio.c
@@ -302,18 +302,19 @@ float vibrato(float average_freq) {
302float envelope(float f) { 302float envelope(float f) {
303 uint16_t compensated_index = (uint16_t)((float)envelope_index * (880.0 / f)); 303 uint16_t compensated_index = (uint16_t)((float)envelope_index * (880.0 / f));
304 switch (compensated_index) { 304 switch (compensated_index) {
305 case 0: 305 case 0 ... 9:
306 note_timbre = TIMBRE_50; 306 f = f / 4;
307 break;
308 case 20:
309 note_timbre = TIMBRE_25;
310 break;
311 case 32:
312 note_timbre = TIMBRE_12; 307 note_timbre = TIMBRE_12;
313 break; 308 break;
314 case 40 ... 60: 309 case 10 ... 19:
315 f = f / 2; 310 f = f / 2;
316 note_timbre = TIMBRE_50; 311 note_timbre = TIMBRE_12;
312 break;
313 case 20 ... 200:
314 note_timbre = .125 - pow(((float)compensated_index - 20) / (200 - 20), 2)*.125;
315 break;
316 default:
317 note_timbre = 0;
317 break; 318 break;
318 } 319 }
319 return f; 320 return f;
@@ -414,6 +415,8 @@ ISR(TIMER3_COMPA_vect) {
414 } 415 }
415 freq = envelope(freq); 416 freq = envelope(freq);
416 417
418 if (freq < 30.517578125)
419 freq = 30.52;
417 ICR3 = (int)(((double)F_CPU) / (freq * CPU_PRESCALER)); // Set max to the period 420 ICR3 = (int)(((double)F_CPU) / (freq * CPU_PRESCALER)); // Set max to the period
418 OCR3A = (int)((((double)F_CPU) / (freq * CPU_PRESCALER)) * note_timbre); // Set compare to half the period 421 OCR3A = (int)((((double)F_CPU) / (freq * CPU_PRESCALER)) * note_timbre); // Set compare to half the period
419 } 422 }