process_audio.c 1.3 KB

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