You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

59 lines
1.5 KiB

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