aboutsummaryrefslogtreecommitdiff
path: root/quantum/audio
diff options
context:
space:
mode:
authorJack Humbert <jack.humb@gmail.com>2016-04-22 01:04:13 -0400
committerJack Humbert <jack.humb@gmail.com>2016-04-22 01:04:13 -0400
commita8086126fecbdce1c192036cf1011329d406949d (patch)
treeb00149e3808780b8a64fdd7240c207cd95028261 /quantum/audio
parentb1900c8dde2a68e87aaabd84280a99bf6658ea9f (diff)
parent082a0f313d8c842a5de7bae30ec8a3597e35880b (diff)
downloadqmk_firmware-a8086126fecbdce1c192036cf1011329d406949d.tar.gz
qmk_firmware-a8086126fecbdce1c192036cf1011329d406949d.zip
Merge remote-tracking branch 'origin/master'
# Conflicts: # quantum/audio/voices.c
Diffstat (limited to 'quantum/audio')
-rw-r--r--quantum/audio/audio.h6
-rw-r--r--quantum/audio/voices.c41
-rw-r--r--quantum/audio/voices.h4
3 files changed, 32 insertions, 19 deletions
diff --git a/quantum/audio/audio.h b/quantum/audio/audio.h
index d1ccfdb82..89769507e 100644
--- a/quantum/audio/audio.h
+++ b/quantum/audio/audio.h
@@ -50,8 +50,8 @@ void decrease_vibrato_strength(float change);
50// Polyphony functions 50// Polyphony functions
51 51
52void set_polyphony_rate(float rate); 52void set_polyphony_rate(float rate);
53void enable_polyphony(); 53void enable_polyphony(void);
54void disable_polyphony(); 54void disable_polyphony(void);
55void increase_polyphony_rate(float change); 55void increase_polyphony_rate(float change);
56void decrease_polyphony_rate(float change); 56void decrease_polyphony_rate(float change);
57 57
@@ -61,7 +61,7 @@ void set_tempo(float tempo);
61void increase_tempo(uint8_t tempo_change); 61void increase_tempo(uint8_t tempo_change);
62void decrease_tempo(uint8_t tempo_change); 62void decrease_tempo(uint8_t tempo_change);
63 63
64void audio_init(); 64void audio_init(void);
65 65
66#ifdef PWM_AUDIO 66#ifdef PWM_AUDIO
67void play_sample(uint8_t * s, uint16_t l, bool r); 67void play_sample(uint8_t * s, uint16_t l, bool r);
diff --git a/quantum/audio/voices.c b/quantum/audio/voices.c
index 8b3978f3d..886101187 100644
--- a/quantum/audio/voices.c
+++ b/quantum/audio/voices.c
@@ -1,4 +1,5 @@
1#include "voices.h" 1#include "voices.h"
2#include "stdlib.h"
2 3
3// these are imported from audio.c 4// these are imported from audio.c
4extern uint16_t envelope_index; 5extern uint16_t envelope_index;
@@ -27,26 +28,31 @@ float voice_envelope(float frequency) {
27 case default_voice: 28 case default_voice:
28 note_timbre = TIMBRE_50; 29 note_timbre = TIMBRE_50;
29 polyphony_rate = 0; 30 polyphony_rate = 0;
30 break; 31 break;
32
31 case butts_fader: 33 case butts_fader:
32 polyphony_rate = 0; 34 polyphony_rate = 0;
33 switch (compensated_index) { 35 switch (compensated_index) {
34 case 0 ... 9: 36 case 0 ... 9:
35 frequency = frequency / 4; 37 frequency = frequency / 4;
36 note_timbre = TIMBRE_12; 38 note_timbre = TIMBRE_12;
37 break; 39 break;
40
38 case 10 ... 19: 41 case 10 ... 19:
39 frequency = frequency / 2; 42 frequency = frequency / 2;
40 note_timbre = TIMBRE_12; 43 note_timbre = TIMBRE_12;
41 break; 44 break;
45
42 case 20 ... 200: 46 case 20 ... 200:
43 note_timbre = .125 - pow(((float)compensated_index - 20) / (200 - 20), 2)*.125; 47 note_timbre = .125 - pow(((float)compensated_index - 20) / (200 - 20), 2)*.125;
44 break; 48 break;
49
45 default: 50 default:
46 note_timbre = 0; 51 note_timbre = 0;
47 break; 52 break;
48 } 53 }
49 break; 54 break;
55
50 case octave_crunch: 56 case octave_crunch:
51 polyphony_rate = 0; 57 polyphony_rate = 0;
52 switch (compensated_index) { 58 switch (compensated_index) {
@@ -56,17 +62,20 @@ float voice_envelope(float frequency) {
56 frequency = frequency / 2; 62 frequency = frequency / 2;
57 note_timbre = TIMBRE_12; 63 note_timbre = TIMBRE_12;
58 break; 64 break;
65
59 case 10 ... 19: 66 case 10 ... 19:
60 case 25 ... 29: 67 case 25 ... 29:
61 case 33 ... 35: 68 case 33 ... 35:
62 frequency = frequency * 2; 69 frequency = frequency * 2;
63 note_timbre = TIMBRE_12; 70 note_timbre = TIMBRE_12;
64 break; 71 break;
72
65 default: 73 default:
66 note_timbre = TIMBRE_12; 74 note_timbre = TIMBRE_12;
67 break; 75 break;
68 } 76 }
69 break; 77 break;
78
70 case duty_osc: 79 case duty_osc:
71 // This slows the loop down a substantial amount, so higher notes may freeze 80 // This slows the loop down a substantial amount, so higher notes may freeze
72 polyphony_rate = 0; 81 polyphony_rate = 0;
@@ -78,9 +87,10 @@ float voice_envelope(float frequency) {
78 // note_timbre = (sin((float)compensated_index/10000*OCS_SPEED) * OCS_AMP / 2) + .5; 87 // note_timbre = (sin((float)compensated_index/10000*OCS_SPEED) * OCS_AMP / 2) + .5;
79 // triangle wave is a bit faster 88 // triangle wave is a bit faster
80 note_timbre = (float)abs((compensated_index*OCS_SPEED % 3000) - 1500) * ( OCS_AMP / 1500 ) + (1 - OCS_AMP) / 2; 89 note_timbre = (float)abs((compensated_index*OCS_SPEED % 3000) - 1500) * ( OCS_AMP / 1500 ) + (1 - OCS_AMP) / 2;
81 break; 90 break;
82 } 91 }
83 break; 92 break;
93
84 case duty_octave_down: 94 case duty_octave_down:
85 polyphony_rate = 0; 95 polyphony_rate = 0;
86 note_timbre = (envelope_index % 2) * .125 + .375 * 2; 96 note_timbre = (envelope_index % 2) * .125 + .375 * 2;
@@ -88,18 +98,21 @@ float voice_envelope(float frequency) {
88 note_timbre = 0.5; 98 note_timbre = 0.5;
89 if ((envelope_index % 8) == 0) 99 if ((envelope_index % 8) == 0)
90 note_timbre = 0; 100 note_timbre = 0;
91 break; 101 break;
92 case duty_fifth_down: 102 case duty_fifth_down:
93 note_timbre = 0.5; 103 note_timbre = 0.5;
94 if ((envelope_index % 5) == 0) 104 if ((envelope_index % 5) == 0)
95 note_timbre = 0.75; 105 note_timbre = 0.75;
96 break; 106 break;
97 case duty_fourth_down: 107 case duty_fourth_down:
98 if ((envelope_index % 12) == 0) 108 if ((envelope_index % 12) == 0)
99 note_timbre = 0.25; 109 note_timbre = 0.25;
100 else 110 else
101 note_timbre = 0.5; 111 note_timbre = 0.5;
102 break; 112 break;
113
114 default:
115 break;
103 } 116 }
104 117
105 return frequency; 118 return frequency;
diff --git a/quantum/audio/voices.h b/quantum/audio/voices.h
index 718671f77..cdd14798b 100644
--- a/quantum/audio/voices.h
+++ b/quantum/audio/voices.h
@@ -22,7 +22,7 @@ typedef enum {
22} voice_type; 22} voice_type;
23 23
24void set_voice(voice_type v); 24void set_voice(voice_type v);
25void voice_iterate(); 25void voice_iterate(void);
26void voice_deiterate(); 26void voice_deiterate(void);
27 27
28#endif \ No newline at end of file 28#endif \ No newline at end of file