diff options
| author | Jack Humbert <jack.humb@gmail.com> | 2016-04-21 00:37:45 -0400 |
|---|---|---|
| committer | Jack Humbert <jack.humb@gmail.com> | 2016-04-21 00:37:45 -0400 |
| commit | 73228f5e5d1d4cd31a46e5e93aa893a8f727e3b9 (patch) | |
| tree | a2c07de2c28427d8114ebcdaa2df36cea4d1800b | |
| parent | 2e60054951ce08e973c735991bd95390c6aa3842 (diff) | |
| download | qmk_firmware-73228f5e5d1d4cd31a46e5e93aa893a8f727e3b9.tar.gz qmk_firmware-73228f5e5d1d4cd31a46e5e93aa893a8f727e3b9.zip | |
restructures audio, begins voicing
| -rw-r--r-- | quantum/audio/audio.c (renamed from quantum/audio.c) | 29 | ||||
| -rw-r--r-- | quantum/audio/audio.h (renamed from quantum/audio.h) | 1 | ||||
| -rw-r--r-- | quantum/audio/musical_notes.h (renamed from quantum/musical_notes.h) | 0 | ||||
| -rw-r--r-- | quantum/audio/song_list.h (renamed from quantum/song_list.h) | 0 | ||||
| -rw-r--r-- | quantum/audio/vibrato_lut.h (renamed from quantum/vibrato_lut.h) | 0 | ||||
| -rw-r--r-- | quantum/audio/voices.c | 60 | ||||
| -rw-r--r-- | quantum/audio/voices.h | 21 | ||||
| -rw-r--r-- | quantum/audio/wave.h (renamed from quantum/wave.h) | 0 | ||||
| -rw-r--r-- | quantum/quantum.mk | 3 |
9 files changed, 91 insertions, 23 deletions
diff --git a/quantum/audio.c b/quantum/audio/audio.c index df421ef99..3225557ba 100644 --- a/quantum/audio.c +++ b/quantum/audio/audio.c | |||
| @@ -299,27 +299,6 @@ float vibrato(float average_freq) { | |||
| 299 | 299 | ||
| 300 | #endif | 300 | #endif |
| 301 | 301 | ||
| 302 | float envelope(float f) { | ||
| 303 | uint16_t compensated_index = (uint16_t)((float)envelope_index * (880.0 / f)); | ||
| 304 | switch (compensated_index) { | ||
| 305 | case 0 ... 9: | ||
| 306 | f = f / 4; | ||
| 307 | note_timbre = TIMBRE_12; | ||
| 308 | break; | ||
| 309 | case 10 ... 19: | ||
| 310 | f = f / 2; | ||
| 311 | note_timbre = TIMBRE_12; | ||
| 312 | break; | ||
| 313 | case 20 ... 200: | ||
| 314 | note_timbre = .125 - pow(((float)compensated_index - 20) / (200 - 20), 2)*.125; | ||
| 315 | break; | ||
| 316 | default: | ||
| 317 | note_timbre = 0; | ||
| 318 | break; | ||
| 319 | } | ||
| 320 | return f; | ||
| 321 | } | ||
| 322 | |||
| 323 | ISR(TIMER3_COMPA_vect) { | 302 | ISR(TIMER3_COMPA_vect) { |
| 324 | if (note) { | 303 | if (note) { |
| 325 | #ifdef PWM_AUDIO | 304 | #ifdef PWM_AUDIO |
| @@ -413,7 +392,7 @@ ISR(TIMER3_COMPA_vect) { | |||
| 413 | if (envelope_index < 65535) { | 392 | if (envelope_index < 65535) { |
| 414 | envelope_index++; | 393 | envelope_index++; |
| 415 | } | 394 | } |
| 416 | freq = envelope(freq); | 395 | freq = voice_envelope(freq); |
| 417 | 396 | ||
| 418 | if (freq < 30.517578125) | 397 | if (freq < 30.517578125) |
| 419 | freq = 30.52; | 398 | freq = 30.52; |
| @@ -456,6 +435,11 @@ ISR(TIMER3_COMPA_vect) { | |||
| 456 | freq = note_frequency; | 435 | freq = note_frequency; |
| 457 | } | 436 | } |
| 458 | 437 | ||
| 438 | if (envelope_index < 65535) { | ||
| 439 | envelope_index++; | ||
| 440 | } | ||
| 441 | freq = voice_envelope(freq); | ||
| 442 | |||
| 459 | ICR3 = (int)(((double)F_CPU) / (freq * CPU_PRESCALER)); // Set max to the period | 443 | ICR3 = (int)(((double)F_CPU) / (freq * CPU_PRESCALER)); // Set max to the period |
| 460 | OCR3A = (int)((((double)F_CPU) / (freq * CPU_PRESCALER)) * note_timbre); // Set compare to half the period | 444 | OCR3A = (int)((((double)F_CPU) / (freq * CPU_PRESCALER)) * note_timbre); // Set compare to half the period |
| 461 | } else { | 445 | } else { |
| @@ -498,6 +482,7 @@ ISR(TIMER3_COMPA_vect) { | |||
| 498 | note_frequency = (*notes_pointer)[current_note][0] / SAMPLE_RATE; | 482 | note_frequency = (*notes_pointer)[current_note][0] / SAMPLE_RATE; |
| 499 | note_length = (*notes_pointer)[current_note][1] * (note_tempo / 100); | 483 | note_length = (*notes_pointer)[current_note][1] * (note_tempo / 100); |
| 500 | #else | 484 | #else |
| 485 | envelope_index = 0; | ||
| 501 | note_frequency = (*notes_pointer)[current_note][0]; | 486 | note_frequency = (*notes_pointer)[current_note][0]; |
| 502 | note_length = ((*notes_pointer)[current_note][1] / 4) * (note_tempo / 100); | 487 | note_length = ((*notes_pointer)[current_note][1] / 4) * (note_tempo / 100); |
| 503 | #endif | 488 | #endif |
diff --git a/quantum/audio.h b/quantum/audio/audio.h index 2d4d303ce..d1ccfdb82 100644 --- a/quantum/audio.h +++ b/quantum/audio/audio.h | |||
| @@ -4,6 +4,7 @@ | |||
| 4 | #include <util/delay.h> | 4 | #include <util/delay.h> |
| 5 | #include "musical_notes.h" | 5 | #include "musical_notes.h" |
| 6 | #include "song_list.h" | 6 | #include "song_list.h" |
| 7 | #include "voices.h" | ||
| 7 | 8 | ||
| 8 | #ifndef AUDIO_H | 9 | #ifndef AUDIO_H |
| 9 | #define AUDIO_H | 10 | #define AUDIO_H |
diff --git a/quantum/musical_notes.h b/quantum/audio/musical_notes.h index b08d16a6f..b08d16a6f 100644 --- a/quantum/musical_notes.h +++ b/quantum/audio/musical_notes.h | |||
diff --git a/quantum/song_list.h b/quantum/audio/song_list.h index fc6fcdeef..fc6fcdeef 100644 --- a/quantum/song_list.h +++ b/quantum/audio/song_list.h | |||
diff --git a/quantum/vibrato_lut.h b/quantum/audio/vibrato_lut.h index a2b1f3e5c..a2b1f3e5c 100644 --- a/quantum/vibrato_lut.h +++ b/quantum/audio/vibrato_lut.h | |||
diff --git a/quantum/audio/voices.c b/quantum/audio/voices.c new file mode 100644 index 000000000..30e8be641 --- /dev/null +++ b/quantum/audio/voices.c | |||
| @@ -0,0 +1,60 @@ | |||
| 1 | #include "voices.h" | ||
| 2 | |||
| 3 | extern uint16_t envelope_index; | ||
| 4 | extern float note_timbre; | ||
| 5 | |||
| 6 | voice_type voice = default_voice; | ||
| 7 | |||
| 8 | void set_voice(voice_type v) { | ||
| 9 | voice = v; | ||
| 10 | } | ||
| 11 | |||
| 12 | float voice_envelope(float frequency) { | ||
| 13 | // envelope_index ranges from 0 to 0xFFFF, which is preserved at 880.0 Hz | ||
| 14 | uint16_t compensated_index = (uint16_t)((float)envelope_index * (880.0 / frequency)); | ||
| 15 | |||
| 16 | switch (voice) { | ||
| 17 | case default_voice: | ||
| 18 | // nothing here on purpose | ||
| 19 | break; | ||
| 20 | case butts_fader: | ||
| 21 | switch (compensated_index) { | ||
| 22 | case 0 ... 9: | ||
| 23 | frequency = frequency / 4; | ||
| 24 | note_timbre = TIMBRE_12; | ||
| 25 | break; | ||
| 26 | case 10 ... 19: | ||
| 27 | frequency = frequency / 2; | ||
| 28 | note_timbre = TIMBRE_12; | ||
| 29 | break; | ||
| 30 | case 20 ... 200: | ||
| 31 | note_timbre = .125 - pow(((float)compensated_index - 20) / (200 - 20), 2)*.125; | ||
| 32 | break; | ||
| 33 | default: | ||
| 34 | note_timbre = 0; | ||
| 35 | break; | ||
| 36 | } | ||
| 37 | break; | ||
| 38 | case octave_crunch: | ||
| 39 | switch (compensated_index) { | ||
| 40 | case 0 ... 9: | ||
| 41 | case 20 ... 24: | ||
| 42 | case 30 ... 32: | ||
| 43 | frequency = frequency / 2; | ||
| 44 | note_timbre = TIMBRE_12; | ||
| 45 | break; | ||
| 46 | case 10 ... 19: | ||
| 47 | case 25 ... 29: | ||
| 48 | case 33 ... 35: | ||
| 49 | frequency = frequency * 2; | ||
| 50 | note_timbre = TIMBRE_12; | ||
| 51 | break; | ||
| 52 | default: | ||
| 53 | note_timbre = TIMBRE_12; | ||
| 54 | break; | ||
| 55 | } | ||
| 56 | break; | ||
| 57 | } | ||
| 58 | |||
| 59 | return frequency; | ||
| 60 | } \ No newline at end of file | ||
diff --git a/quantum/audio/voices.h b/quantum/audio/voices.h new file mode 100644 index 000000000..32135dac7 --- /dev/null +++ b/quantum/audio/voices.h | |||
| @@ -0,0 +1,21 @@ | |||
| 1 | #include <stdint.h> | ||
| 2 | #include <stdbool.h> | ||
| 3 | #include <avr/io.h> | ||
| 4 | #include <util/delay.h> | ||
| 5 | #include "musical_notes.h" | ||
| 6 | #include "song_list.h" | ||
| 7 | |||
| 8 | #ifndef VOICES_H | ||
| 9 | #define VOICES_H | ||
| 10 | |||
| 11 | float voice_envelope(float frequency); | ||
| 12 | |||
| 13 | typedef enum { | ||
| 14 | default_voice, | ||
| 15 | butts_fader, | ||
| 16 | octave_crunch | ||
| 17 | } voice_type; | ||
| 18 | |||
| 19 | void set_voice(voice_type v); | ||
| 20 | |||
| 21 | #endif \ No newline at end of file | ||
diff --git a/quantum/wave.h b/quantum/audio/wave.h index 6ebc34851..6ebc34851 100644 --- a/quantum/wave.h +++ b/quantum/audio/wave.h | |||
diff --git a/quantum/quantum.mk b/quantum/quantum.mk index 1fe7390eb..83c4f1d1d 100644 --- a/quantum/quantum.mk +++ b/quantum/quantum.mk | |||
| @@ -28,7 +28,7 @@ ifeq ($(strip $(MIDI_ENABLE)), yes) | |||
| 28 | endif | 28 | endif |
| 29 | 29 | ||
| 30 | ifeq ($(strip $(AUDIO_ENABLE)), yes) | 30 | ifeq ($(strip $(AUDIO_ENABLE)), yes) |
| 31 | SRC += $(QUANTUM_DIR)/audio.c | 31 | SRC += $(QUANTUM_DIR)/audio/audio.c $(QUANTUM_DIR)/audio/voices.c |
| 32 | endif | 32 | endif |
| 33 | 33 | ||
| 34 | ifeq ($(strip $(UNICODE_ENABLE)), yes) | 34 | ifeq ($(strip $(UNICODE_ENABLE)), yes) |
| @@ -47,6 +47,7 @@ endif | |||
| 47 | # Search Path | 47 | # Search Path |
| 48 | VPATH += $(TOP_DIR)/$(QUANTUM_DIR) | 48 | VPATH += $(TOP_DIR)/$(QUANTUM_DIR) |
| 49 | VPATH += $(TOP_DIR)/$(QUANTUM_DIR)/keymap_extras | 49 | VPATH += $(TOP_DIR)/$(QUANTUM_DIR)/keymap_extras |
| 50 | VPATH += $(TOP_DIR)/$(QUANTUM_DIR)/audio | ||
| 50 | 51 | ||
| 51 | include $(TMK_DIR)/protocol/lufa.mk | 52 | include $(TMK_DIR)/protocol/lufa.mk |
| 52 | 53 | ||
