]> git.donarmstrong.com Git - qmk_firmware.git/blob - quantum/process_keycode/process_audio.c
Adds support for Planck Rev 6 (#2666)
[qmk_firmware.git] / quantum / process_keycode / process_audio.c
1 #include "audio.h"
2 #include "process_audio.h"
3
4 #ifndef VOICE_CHANGE_SONG
5     #define VOICE_CHANGE_SONG SONG(VOICE_CHANGE_SOUND)
6 #endif
7 float voice_change_song[][2] = VOICE_CHANGE_SONG;
8
9 #ifndef PITCH_STANDARD_A
10     #define PITCH_STANDARD_A 440.0f
11 #endif
12
13 float compute_freq_for_midi_note(uint8_t note)
14 {
15     // https://en.wikipedia.org/wiki/MIDI_tuning_standard
16     return pow(2.0, (note - 69) / 12.0) * PITCH_STANDARD_A;
17 }
18
19 bool process_audio(uint16_t keycode, keyrecord_t *record) {
20
21     if (keycode == AU_ON && record->event.pressed) {
22       audio_on();
23       return false;
24     }
25
26     if (keycode == AU_OFF && record->event.pressed) {
27       audio_off();
28       return false;
29     }
30
31     if (keycode == AU_TOG && record->event.pressed) {
32         if (is_audio_on()) {
33             audio_off();
34         } else {
35             audio_on();
36         }
37         return false;
38     }
39
40     if (keycode == MUV_IN && record->event.pressed) {
41         voice_iterate();
42         PLAY_SONG(voice_change_song);
43         return false;
44     }
45
46     if (keycode == MUV_DE && record->event.pressed) {
47         voice_deiterate();
48         PLAY_SONG(voice_change_song);
49         return false;
50     }
51
52     return true;
53 }
54
55 void process_audio_noteon(uint8_t note) {
56     play_note(compute_freq_for_midi_note(note), 0xF);
57 }
58
59 void process_audio_noteoff(uint8_t note) {
60     stop_note(compute_freq_for_midi_note(note));
61 }
62
63 void process_audio_all_notes_off(void) {
64     stop_all_notes();
65 }
66
67 __attribute__ ((weak))
68 void audio_on_user() {}