aboutsummaryrefslogtreecommitdiff
path: root/quantum/audio
diff options
context:
space:
mode:
authorJack Humbert <jack.humb@gmail.com>2017-06-26 23:13:27 -0400
committerJack Humbert <jack.humb@gmail.com>2017-06-27 14:20:44 -0400
commitbfc73e90cfc6532331d1532e2ff9020d25c96a69 (patch)
tree91d1a8fb076c6b08c18d92c4bf3ff602de6fae26 /quantum/audio
parenteabf530a0eaffb5fb7d6ebe375225e2d8b0b559a (diff)
downloadqmk_firmware-bfc73e90cfc6532331d1532e2ff9020d25c96a69.tar.gz
qmk_firmware-bfc73e90cfc6532331d1532e2ff9020d25c96a69.zip
working duopholy
Diffstat (limited to 'quantum/audio')
-rw-r--r--quantum/audio/audio.c62
1 files changed, 58 insertions, 4 deletions
diff --git a/quantum/audio/audio.c b/quantum/audio/audio.c
index f2948f18a..04f346003 100644
--- a/quantum/audio/audio.c
+++ b/quantum/audio/audio.c
@@ -75,6 +75,7 @@
75int voices = 0; 75int voices = 0;
76int voice_place = 0; 76int voice_place = 0;
77float frequency = 0; 77float frequency = 0;
78float frequency_alt = 0;
78int volume = 0; 79int volume = 0;
79long position = 0; 80long position = 0;
80 81
@@ -193,6 +194,7 @@ void stop_all_notes()
193 playing_notes = false; 194 playing_notes = false;
194 playing_note = false; 195 playing_note = false;
195 frequency = 0; 196 frequency = 0;
197 frequency_alt = 0;
196 volume = 0; 198 volume = 0;
197 199
198 for (uint8_t i = 0; i < 8; i++) 200 for (uint8_t i = 0; i < 8; i++)
@@ -239,6 +241,7 @@ void stop_note(float freq)
239 DISABLE_AUDIO_COUNTER_1_OUTPUT; 241 DISABLE_AUDIO_COUNTER_1_OUTPUT;
240 #endif 242 #endif
241 frequency = 0; 243 frequency = 0;
244 frequency_alt = 0;
242 volume = 0; 245 volume = 0;
243 playing_note = false; 246 playing_note = false;
244 } 247 }
@@ -268,10 +271,52 @@ float vibrato(float average_freq) {
268#ifdef C6_AUDIO 271#ifdef C6_AUDIO
269ISR(TIMER3_COMPA_vect) 272ISR(TIMER3_COMPA_vect)
270{ 273{
271 float freq; 274 float freq, freq_alt = 0;
272 275
273 if (playing_note) { 276 if (playing_note) {
274 if (voices > 0) { 277 if (voices > 0) {
278
279 #ifdef B5_AUDIO
280 if (voices > 1) {
281 if (polyphony_rate == 0) {
282 if (glissando) {
283 if (frequency_alt != 0 && frequency_alt < frequencies[voices - 2] && frequency_alt < frequencies[voices - 2] * pow(2, -440/frequencies[voices - 2]/12/2)) {
284 frequency_alt = frequency_alt * pow(2, 440/frequency_alt/12/2);
285 } else if (frequency_alt != 0 && frequency_alt > frequencies[voices - 2] && frequency_alt > frequencies[voices - 2] * pow(2, 440/frequencies[voices - 2]/12/2)) {
286 frequency_alt = frequency_alt * pow(2, -440/frequency_alt/12/2);
287 } else {
288 frequency_alt = frequencies[voices - 2];
289 }
290 } else {
291 frequency_alt = frequencies[voices - 2];
292 }
293
294 #ifdef VIBRATO_ENABLE
295 if (vibrato_strength > 0) {
296 freq_alt = vibrato(frequency_alt);
297 } else {
298 freq_alt = frequency_alt;
299 }
300 #else
301 freq_alt = frequency_alt;
302 #endif
303 }
304
305 if (envelope_index < 65535) {
306 envelope_index++;
307 }
308
309 freq_alt = voice_envelope(freq_alt);
310
311 if (freq_alt < 30.517578125) {
312 freq_alt = 30.52;
313 }
314
315 TIMER_1_PERIOD = (uint16_t)(((float)F_CPU) / (freq_alt * CPU_PRESCALER));
316 TIMER_1_DUTY_CYCLE = (uint16_t)((((float)F_CPU) / (freq_alt * CPU_PRESCALER)) * note_timbre);
317 }
318 #endif
319
275 if (polyphony_rate > 0) { 320 if (polyphony_rate > 0) {
276 if (voices > 1) { 321 if (voices > 1) {
277 voice_place %= voices; 322 voice_place %= voices;
@@ -396,10 +441,10 @@ ISR(TIMER3_COMPA_vect)
396} 441}
397#endif 442#endif
398 443
399#ifdef B5_AUDIO
400ISR(TIMER1_COMPA_vect) 444ISR(TIMER1_COMPA_vect)
401{ 445{
402 float freq; 446 #if defined(B5_AUDIO) && !defined(C6_AUDIO)
447 float freq = 0;
403 448
404 if (playing_note) { 449 if (playing_note) {
405 if (voices > 0) { 450 if (voices > 0) {
@@ -524,8 +569,8 @@ ISR(TIMER1_COMPA_vect)
524 playing_notes = false; 569 playing_notes = false;
525 playing_note = false; 570 playing_note = false;
526 } 571 }
527}
528#endif 572#endif
573}
529 574
530void play_note(float freq, int vol) { 575void play_note(float freq, int vol) {
531 576
@@ -562,8 +607,15 @@ void play_note(float freq, int vol) {
562 ENABLE_AUDIO_COUNTER_3_OUTPUT; 607 ENABLE_AUDIO_COUNTER_3_OUTPUT;
563 #endif 608 #endif
564 #ifdef B5_AUDIO 609 #ifdef B5_AUDIO
610 #ifdef C6_AUDIO
611 if (voices > 1) {
612 ENABLE_AUDIO_COUNTER_1_ISR;
613 ENABLE_AUDIO_COUNTER_1_OUTPUT;
614 }
615 #else
565 ENABLE_AUDIO_COUNTER_1_ISR; 616 ENABLE_AUDIO_COUNTER_1_ISR;
566 ENABLE_AUDIO_COUNTER_1_OUTPUT; 617 ENABLE_AUDIO_COUNTER_1_OUTPUT;
618 #endif
567 #endif 619 #endif
568 } 620 }
569 621
@@ -609,8 +661,10 @@ void play_notes(float (*np)[][2], uint16_t n_count, bool n_repeat, float n_rest)
609 ENABLE_AUDIO_COUNTER_3_OUTPUT; 661 ENABLE_AUDIO_COUNTER_3_OUTPUT;
610 #endif 662 #endif
611 #ifdef B5_AUDIO 663 #ifdef B5_AUDIO
664 #ifndef C6_AUDIO
612 ENABLE_AUDIO_COUNTER_1_ISR; 665 ENABLE_AUDIO_COUNTER_1_ISR;
613 ENABLE_AUDIO_COUNTER_1_OUTPUT; 666 ENABLE_AUDIO_COUNTER_1_OUTPUT;
667 #endif
614 #endif 668 #endif
615 } 669 }
616 670