process_audio.c 1.5 KB

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