diff options
Diffstat (limited to 'quantum/process_keycode/process_audio.c')
-rw-r--r-- | quantum/process_keycode/process_audio.c | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/quantum/process_keycode/process_audio.c b/quantum/process_keycode/process_audio.c new file mode 100644 index 000000000..0b6380ed3 --- /dev/null +++ b/quantum/process_keycode/process_audio.c | |||
@@ -0,0 +1,62 @@ | |||
1 | #include "audio.h" | ||
2 | #include "process_audio.h" | ||
3 | |||
4 | static float compute_freq_for_midi_note(uint8_t note) | ||
5 | { | ||
6 | // https://en.wikipedia.org/wiki/MIDI_tuning_standard | ||
7 | return pow(2.0, (note - 69) / 12.0) * 440.0f; | ||
8 | } | ||
9 | |||
10 | bool process_audio(uint16_t keycode, keyrecord_t *record) { | ||
11 | |||
12 | if (keycode == AU_ON && record->event.pressed) { | ||
13 | audio_on(); | ||
14 | return false; | ||
15 | } | ||
16 | |||
17 | if (keycode == AU_OFF && record->event.pressed) { | ||
18 | audio_off(); | ||
19 | return false; | ||
20 | } | ||
21 | |||
22 | if (keycode == AU_TOG && record->event.pressed) { | ||
23 | if (is_audio_on()) | ||
24 | { | ||
25 | audio_off(); | ||
26 | } | ||
27 | else | ||
28 | { | ||
29 | audio_on(); | ||
30 | } | ||
31 | return false; | ||
32 | } | ||
33 | |||
34 | if (keycode == MUV_IN && record->event.pressed) { | ||
35 | voice_iterate(); | ||
36 | music_scale_user(); | ||
37 | return false; | ||
38 | } | ||
39 | |||
40 | if (keycode == MUV_DE && record->event.pressed) { | ||
41 | voice_deiterate(); | ||
42 | music_scale_user(); | ||
43 | return false; | ||
44 | } | ||
45 | |||
46 | return true; | ||
47 | } | ||
48 | |||
49 | void process_audio_noteon(uint8_t note) { | ||
50 | play_note(compute_freq_for_midi_note(note), 0xF); | ||
51 | } | ||
52 | |||
53 | void process_audio_noteoff(uint8_t note) { | ||
54 | stop_note(compute_freq_for_midi_note(note)); | ||
55 | } | ||
56 | |||
57 | void process_audio_all_notes_off(void) { | ||
58 | stop_all_notes(); | ||
59 | } | ||
60 | |||
61 | __attribute__ ((weak)) | ||
62 | void audio_on_user() {} \ No newline at end of file | ||