-
-
Notifications
You must be signed in to change notification settings - Fork 39.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Factor basic note processing into respective processors
- Loading branch information
Gabriel Young
committed
Feb 26, 2017
1 parent
525be99
commit 1000799
Showing
9 changed files
with
184 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#include "process_audio.h" | ||
#include "audio.h" | ||
|
||
static float compute_freq_for_midi_note(uint8_t note) | ||
{ | ||
// https://en.wikipedia.org/wiki/MIDI_tuning_standard | ||
return pow(2.0, (note - 69) / 12.0) * 440.0f; | ||
} | ||
|
||
bool process_audio(uint16_t keycode, keyrecord_t *record) { | ||
|
||
if (keycode == AU_ON && record->event.pressed) { | ||
audio_on(); | ||
return false; | ||
} | ||
|
||
if (keycode == AU_OFF && record->event.pressed) { | ||
audio_off(); | ||
return false; | ||
} | ||
|
||
if (keycode == AU_TOG && record->event.pressed) { | ||
if (is_audio_on()) | ||
{ | ||
audio_off(); | ||
} | ||
else | ||
{ | ||
audio_on(); | ||
} | ||
return false; | ||
} | ||
|
||
if (keycode == MUV_IN && record->event.pressed) { | ||
voice_iterate(); | ||
music_scale_user(); | ||
return false; | ||
} | ||
|
||
if (keycode == MUV_DE && record->event.pressed) { | ||
voice_deiterate(); | ||
music_scale_user(); | ||
return false; | ||
} | ||
|
||
return true | ||
} | ||
|
||
void process_audio_noteon(uint8_t note) { | ||
play_note(compute_freq_for_midi_note(note), 0xF); | ||
} | ||
|
||
void process_audio_noteoff(uint8_t note) { | ||
stop_note(compute_freq_for_midi_note(note)); | ||
} | ||
|
||
void process_audio_stop_all_notes(void) { | ||
stop_all_notes(); | ||
} | ||
|
||
__attribute__ ((weak)) | ||
void audio_on_user() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#ifndef PROCESS_AUDIO_H | ||
#define PROCESS_AUDIO_H | ||
|
||
bool process_audio(uint16_t keycode, keyrecord_t *record); | ||
void process_audio_noteon(uint8_t note); | ||
void process_audio_noteoff(uint8_t note); | ||
void process_audio_stop_all_notes(void); | ||
|
||
void audio_on_user(void); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.