process_audio.c 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. static float compute_freq_for_midi_note(uint8_t note)
  8. {
  9. // https://en.wikipedia.org/wiki/MIDI_tuning_standard
  10. return pow(2.0, (note - 69) / 12.0) * 440.0f;
  11. }
  12. bool process_audio(uint16_t keycode, keyrecord_t *record) {
  13. if (keycode == AU_ON && record->event.pressed) {
  14. audio_on();
  15. return false;
  16. }
  17. if (keycode == AU_OFF && record->event.pressed) {
  18. audio_off();
  19. return false;
  20. }
  21. if (keycode == AU_TOG && record->event.pressed) {
  22. if (is_audio_on()) {
  23. audio_off();
  24. } else {
  25. audio_on();
  26. }
  27. return false;
  28. }
  29. if (keycode == MUV_IN && record->event.pressed) {
  30. voice_iterate();
  31. PLAY_SONG(voice_change_song);
  32. return false;
  33. }
  34. if (keycode == MUV_DE && record->event.pressed) {
  35. voice_deiterate();
  36. PLAY_SONG(voice_change_song);
  37. return false;
  38. }
  39. return true;
  40. }
  41. void process_audio_noteon(uint8_t note) {
  42. play_note(compute_freq_for_midi_note(note), 0xF);
  43. }
  44. void process_audio_noteoff(uint8_t note) {
  45. stop_note(compute_freq_for_midi_note(note));
  46. }
  47. void process_audio_all_notes_off(void) {
  48. stop_all_notes();
  49. }
  50. __attribute__ ((weak))
  51. void audio_on_user() {}