]> git.donarmstrong.com Git - qmk_firmware.git/blob - quantum/process_keycode/process_audio.c
e9b20512e7440b196136580b6b54a4a6794dc11d
[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
14
15 static float compute_freq_for_midi_note(uint8_t note)
16 {
17     // https://en.wikipedia.org/wiki/MIDI_tuning_standard
18     return pow(2.0, (note - 69) / 12.0) * PITCH_STANDARD_A;
19 }
20
21 bool process_audio(uint16_t keycode, keyrecord_t *record) {
22
23     if (keycode == AU_ON && record->event.pressed) {
24       audio_on();
25       return false;
26     }
27
28     if (keycode == AU_OFF && record->event.pressed) {
29       audio_off();
30       return false;
31     }
32
33     if (keycode == AU_TOG && record->event.pressed) {
34         if (is_audio_on()) {
35             audio_off();
36         } else {
37             audio_on();
38         }
39         return false;
40     }
41
42     if (keycode == MUV_IN && record->event.pressed) {
43         voice_iterate();
44         PLAY_SONG(voice_change_song);
45         return false;
46     }
47
48     if (keycode == MUV_DE && record->event.pressed) {
49         voice_deiterate();
50         PLAY_SONG(voice_change_song);
51         return false;
52     }
53
54     return true;
55 }
56
57 void process_audio_noteon(uint8_t note) {
58     play_note(compute_freq_for_midi_note(note), 0xF);
59 }
60
61 void process_audio_noteoff(uint8_t note) {
62     stop_note(compute_freq_for_midi_note(note));
63 }
64
65 void process_audio_all_notes_off(void) {
66     stop_all_notes();
67 }
68
69 __attribute__ ((weak))
70 void audio_on_user() {}