aboutsummaryrefslogtreecommitdiff
path: root/quantum/process_keycode/process_audio.c
diff options
context:
space:
mode:
authorDrashna Jaelre <drashna@live.com>2018-04-18 22:47:04 -0700
committerJack Humbert <jack.humb@gmail.com>2018-04-19 01:47:04 -0400
commit8b0b17a369be6d3dff4cb9bad4253960252a5e95 (patch)
tree11d453ef480983571de84147db3bc9c1bfcb5054 /quantum/process_keycode/process_audio.c
parent23b45710acc57ed147e006a8c79a1caf6fa57fd7 (diff)
downloadqmk_firmware-8b0b17a369be6d3dff4cb9bad4253960252a5e95.tar.gz
qmk_firmware-8b0b17a369be6d3dff4cb9bad4253960252a5e95.zip
Add Faux Clicking as subset of Audio feature (#2748)
* Add Faux Clicky to main Audio feature * Make clicky settings user configurable * Add additional documentation * Don't play when music mode is enabled (hopefully)
Diffstat (limited to 'quantum/process_keycode/process_audio.c')
-rw-r--r--quantum/process_keycode/process_audio.c69
1 files changed, 68 insertions, 1 deletions
diff --git a/quantum/process_keycode/process_audio.c b/quantum/process_keycode/process_audio.c
index 32057ae8d..2d92e4064 100644
--- a/quantum/process_keycode/process_audio.c
+++ b/quantum/process_keycode/process_audio.c
@@ -10,6 +10,46 @@ float voice_change_song[][2] = VOICE_CHANGE_SONG;
10 #define PITCH_STANDARD_A 440.0f 10 #define PITCH_STANDARD_A 440.0f
11#endif 11#endif
12 12
13#ifdef AUDIO_CLICKY
14#ifdef AUDIO_CLICKY_ON
15bool clicky_enable = true;
16#else
17bool clicky_enable = false;
18#endif
19#ifndef AUDIO_CLICKY_FREQ_DEFAULT
20#define AUDIO_CLICKY_FREQ_DEFAULT 440.0f
21#endif
22#ifndef AUDIO_CLICKY_FREQ_MIN
23#define AUDIO_CLICKY_FREQ_MIN 65.0f
24#endif
25#ifndef AUDIO_CLICKY_FREQ_MAX
26#define AUDIO_CLICKY_FREQ_MAX 1500.0f
27#endif
28#ifndef AUDIO_CLICKY_FREQ_FACTOR
29#define AUDIO_CLICKY_FREQ_FACTOR 1.18921f
30#endif
31#ifndef AUDIO_CLICKY_FREQ_RANDOMNESS
32#define AUDIO_CLICKY_FREQ_RANDOMNESS 0.05f
33#endif
34
35float clicky_freq = AUDIO_CLICKY_FREQ_DEFAULT;
36float clicky_song[][2] = {{AUDIO_CLICKY_FREQ_DEFAULT, 3}, {AUDIO_CLICKY_FREQ_DEFAULT, 1}}; // 3 and 1 --> durations
37
38#ifndef NO_MUSIC_MODE
39extern bool music_activated;
40extern bool midi_activated;
41#endif
42
43void clicky_play(void) {
44#ifndef NO_MUSIC_MODE
45 if (music_activated || midi_activated) return;
46#endif
47 clicky_song[0][0] = 2.0f * clicky_freq * (1.0f + AUDIO_CLICKY_FREQ_RANDOMNESS * ( ((float)rand()) / ((float)(RAND_MAX)) ) );
48 clicky_song[1][0] = clicky_freq * (1.0f + AUDIO_CLICKY_FREQ_RANDOMNESS * ( ((float)rand()) / ((float)(RAND_MAX)) ) );
49 PLAY_SONG(clicky_song);
50}
51#endif
52
13static float compute_freq_for_midi_note(uint8_t note) 53static float compute_freq_for_midi_note(uint8_t note)
14{ 54{
15 // https://en.wikipedia.org/wiki/MIDI_tuning_standard 55 // https://en.wikipedia.org/wiki/MIDI_tuning_standard
@@ -49,6 +89,33 @@ bool process_audio(uint16_t keycode, keyrecord_t *record) {
49 return false; 89 return false;
50 } 90 }
51 91
92#ifdef AUDIO_CLICKY
93 if (keycode == CLICKY_TOGGLE && record->event.pressed) { clicky_enable = !clicky_enable; }
94
95 if (keycode == CLICKY_RESET && record->event.pressed) { clicky_freq = AUDIO_CLICKY_FREQ_DEFAULT; }
96
97 if (keycode == CLICKY_UP && record->event.pressed) {
98 float new_freq = clicky_freq * AUDIO_CLICKY_FREQ_FACTOR;
99 if (new_freq < AUDIO_CLICKY_FREQ_MAX) {
100 clicky_freq = new_freq;
101 }
102 }
103 if (keycode == CLICKY_TOGGLE && record->event.pressed) {
104 float new_freq = clicky_freq / AUDIO_CLICKY_FREQ_FACTOR;
105 if (new_freq > AUDIO_CLICKY_FREQ_MIN) {
106 clicky_freq = new_freq;
107 }
108 }
109
110
111 if ( (clicky_enable && keycode != CLICKY_TOGGLE) || (!clicky_enable && keycode == CLICKY_TOGGLE) ) {
112 if (record->event.pressed) {
113 stop_all_notes();
114 clicky_play();;
115 }
116 }
117#endif // AUDIO_CLICKY
118
52 return true; 119 return true;
53} 120}
54 121
@@ -65,4 +132,4 @@ void process_audio_all_notes_off(void) {
65} 132}
66 133
67__attribute__ ((weak)) 134__attribute__ ((weak))
68void audio_on_user() {} \ No newline at end of file 135void audio_on_user() {}