summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--keyboard/planck/keymaps/default/keymap.c41
-rw-r--r--keyboard/preonic/Makefile2
-rw-r--r--keyboard/preonic/keymaps/default/keymap.c4
-rw-r--r--quantum/audio/audio.c (renamed from quantum/audio.c)17
-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)16
-rw-r--r--quantum/audio/vibrato_lut.h (renamed from quantum/vibrato_lut.h)0
-rw-r--r--quantum/audio/voices.c60
-rw-r--r--quantum/audio/voices.h21
-rw-r--r--quantum/audio/wave.h (renamed from quantum/wave.h)0
-rw-r--r--quantum/quantum.mk3
-rw-r--r--tmk_core/common/avr/suspend.c3
13 files changed, 134 insertions, 34 deletions
diff --git a/keyboard/planck/keymaps/default/keymap.c b/keyboard/planck/keymaps/default/keymap.c
index 29a3ccf6ad..3239dda71d 100644
--- a/keyboard/planck/keymaps/default/keymap.c
+++ b/keyboard/planck/keymaps/default/keymap.c
@@ -153,7 +153,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
* |------+------+------+------+------+------|------+------+------+------+------+------|
* | | S | K | W | R | * | * | R | B | G | S | Z |
* |------+------+------+------+------+------+------+------+------+------+------+------|
- * | Exit | | | C | V | | N | M | | | |
+ * | Exit | | | A | O | | E | U | | | |
* `-----------------------------------------------------------------------------------'
*/
@@ -198,33 +198,11 @@ float tone_startup[][2] = {
{440.0*pow(2.0,(28)/12.0), 20}
};
-float tone_qwerty[][2] = {
- {440.0*pow(2.0,(23)/12.0), 8},
- {440.0*pow(2.0,(24)/12.0), 8},
- {0, 4},
- {440.0*pow(2.0,(31)/12.0), 16}
-};
-
-float tone_colemak[][2] = {
- {440.0*pow(2.0,(23)/12.0), 8},
- {440.0*pow(2.0,(24)/12.0), 8},
- {0, 4},
- {440.0*pow(2.0,(31)/12.0), 12},
- {0, 4},
- {440.0*pow(2.0,(35)/12.0), 12}
-};
-
-float tone_dvorak[][2] = {
- {440.0*pow(2.0,(23)/12.0), 8},
- {440.0*pow(2.0,(24)/12.0), 8},
- {0, 4},
- {440.0*pow(2.0,(31)/12.0), 8},
- {0, 4},
- {440.0*pow(2.0,(33)/12.0), 8},
- {0, 4},
- {440.0*pow(2.0,(31)/12.0), 8}
-};
-
+float tone_qwerty[][2] = SONG(QWERTY_SOUND);
+float tone_dvorak[][2] = SONG(DVORAK_SOUND);
+float tone_colemak[][2] = SONG(COLEMAK_SOUND);
+float tone_plover[][2] = SONG(PLOVER_SOUND);
+float tone_plover_gb[][2] = SONG(PLOVER_GOODBYE_SOUND);
float music_scale[][2] = SONG(MUSIC_SCALE_SOUND);
float goodbye[][2] = SONG(GOODBYE_SOUND);
@@ -325,6 +303,9 @@ const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
break;
case 10:
if (record->event.pressed) {
+ #ifdef AUDIO_ENABLE
+ PLAY_NOTE_ARRAY(tone_plover, false, 0);
+ #endif
layer_off(_RAISE);
layer_off(_LOWER);
layer_off(_ADJUST);
@@ -339,6 +320,9 @@ const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
break;
case 11:
if (record->event.pressed) {
+ #ifdef AUDIO_ENABLE
+ PLAY_NOTE_ARRAY(tone_plover_gb, false, 0);
+ #endif
layer_off(_PLOVER);
}
break;
@@ -364,6 +348,7 @@ void process_action_user(keyrecord_t *record) {
void matrix_init_user(void) {
#ifdef AUDIO_ENABLE
+ _delay_ms(10); // stops the tick
PLAY_NOTE_ARRAY(tone_startup, false, 0);
#endif
}
diff --git a/keyboard/preonic/Makefile b/keyboard/preonic/Makefile
index c2648d2294..3504e27201 100644
--- a/keyboard/preonic/Makefile
+++ b/keyboard/preonic/Makefile
@@ -133,7 +133,7 @@ OPT_DEFS += -DBOOTLOADER_SIZE=4096
BOOTMAGIC_ENABLE = no # Virtual DIP switch configuration(+1000)
MOUSEKEY_ENABLE = yes # Mouse keys(+4700)
EXTRAKEY_ENABLE = yes # Audio control and System control(+450)
-CONSOLE_ENABLE = on # Console for debug(+400)
+CONSOLE_ENABLE = no # Console for debug(+400)
COMMAND_ENABLE = yes # Commands for debug and configuration
NKRO_ENABLE = no # Nkey Rollover - if this doesn't work, see here: https://github.com/tmk/tmk_keyboard/wiki/FAQ#nkro-doesnt-work
BACKLIGHT_ENABLE = yes # Enable keyboard backlight functionality
diff --git a/keyboard/preonic/keymaps/default/keymap.c b/keyboard/preonic/keymaps/default/keymap.c
index 9ee803b063..267bfab3d7 100644
--- a/keyboard/preonic/keymaps/default/keymap.c
+++ b/keyboard/preonic/keymaps/default/keymap.c
@@ -309,13 +309,13 @@ void process_action_user(keyrecord_t *record) {
}
void matrix_init_user(void) {
- // audio_init();
+ _delay_ms(10); // gets rid of tick
play_startup_tone();
}
void play_startup_tone()
{
- PLAY_NOTE_ARRAY(music_scale, false, 0);
+ PLAY_NOTE_ARRAY(start_up, false, 0);
}
void play_goodbye_tone()
diff --git a/quantum/audio.c b/quantum/audio/audio.c
index ab3444bc97..3225557bae 100644
--- a/quantum/audio.c
+++ b/quantum/audio/audio.c
@@ -81,6 +81,7 @@ bool inited = false;
audio_config_t audio_config;
+uint16_t envelope_index = 0;
void audio_toggle(void) {
audio_config.enable ^= 1;
@@ -213,7 +214,6 @@ void audio_init() {
#endif
inited = true;
- _delay_ms(500);
}
void stop_all_notes() {
@@ -388,6 +388,14 @@ ISR(TIMER3_COMPA_vect) {
freq = frequency;
}
}
+
+ if (envelope_index < 65535) {
+ envelope_index++;
+ }
+ freq = voice_envelope(freq);
+
+ if (freq < 30.517578125)
+ freq = 30.52;
ICR3 = (int)(((double)F_CPU) / (freq * CPU_PRESCALER)); // Set max to the period
OCR3A = (int)((((double)F_CPU) / (freq * CPU_PRESCALER)) * note_timbre); // Set compare to half the period
}
@@ -427,6 +435,11 @@ ISR(TIMER3_COMPA_vect) {
freq = note_frequency;
}
+ if (envelope_index < 65535) {
+ envelope_index++;
+ }
+ freq = voice_envelope(freq);
+
ICR3 = (int)(((double)F_CPU) / (freq * CPU_PRESCALER)); // Set max to the period
OCR3A = (int)((((double)F_CPU) / (freq * CPU_PRESCALER)) * note_timbre); // Set compare to half the period
} else {
@@ -469,6 +482,7 @@ ISR(TIMER3_COMPA_vect) {
note_frequency = (*notes_pointer)[current_note][0] / SAMPLE_RATE;
note_length = (*notes_pointer)[current_note][1] * (note_tempo / 100);
#else
+ envelope_index = 0;
note_frequency = (*notes_pointer)[current_note][0];
note_length = ((*notes_pointer)[current_note][1] / 4) * (note_tempo / 100);
#endif
@@ -496,6 +510,7 @@ if (audio_config.enable && voices < 8) {
if (notes)
stop_all_notes();
note = true;
+ envelope_index = 0;
#ifdef PWM_AUDIO
freq = freq / SAMPLE_RATE;
#endif
diff --git a/quantum/audio.h b/quantum/audio/audio.h
index 2d4d303ced..d1ccfdb824 100644
--- a/quantum/audio.h
+++ b/quantum/audio/audio.h
@@ -4,6 +4,7 @@
#include <util/delay.h>
#include "musical_notes.h"
#include "song_list.h"
+#include "voices.h"
#ifndef AUDIO_H
#define AUDIO_H
diff --git a/quantum/musical_notes.h b/quantum/audio/musical_notes.h
index b08d16a6fa..b08d16a6fa 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 e992bd18a2..fc6fcdeef1 100644
--- a/quantum/song_list.h
+++ b/quantum/audio/song_list.h
@@ -64,6 +64,22 @@
S__NOTE(_REST), \
E__NOTE(_E7 ),
+#define PLOVER_SOUND \
+ E__NOTE(_GS6 ), \
+ E__NOTE(_A6 ), \
+ S__NOTE(_REST), \
+ ED_NOTE(_E7 ), \
+ S__NOTE(_REST), \
+ ED_NOTE(_A7 ),
+
+#define PLOVER_GOODBYE_SOUND \
+ E__NOTE(_GS6 ), \
+ E__NOTE(_A6 ), \
+ S__NOTE(_REST), \
+ ED_NOTE(_A7 ), \
+ S__NOTE(_REST), \
+ ED_NOTE(_E7 ),
+
#define MUSIC_SCALE_SOUND \
E__NOTE(_A5 ), \
E__NOTE(_B5 ), \
diff --git a/quantum/vibrato_lut.h b/quantum/audio/vibrato_lut.h
index a2b1f3e5ce..a2b1f3e5ce 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 0000000000..51652927bd
--- /dev/null
+++ b/quantum/audio/voices.c
@@ -0,0 +1,60 @@
+#include "voices.h"
+
+extern uint16_t envelope_index;
+extern float note_timbre;
+
+voice_type voice = default_voice;
+
+void set_voice(voice_type v) {
+ voice = v;
+}
+
+float voice_envelope(float frequency) {
+ // envelope_index ranges from 0 to 0xFFFF, which is preserved at 880.0 Hz
+ uint16_t compensated_index = (uint16_t)((float)envelope_index * (880.0 / frequency));
+
+ switch (voice) {
+ case default_voice:
+ // nothing here on purpose
+ break;
+ case butts_fader:
+ switch (compensated_index) {
+ case 0 ... 9:
+ frequency = frequency / 4;
+ note_timbre = TIMBRE_12;
+ break;
+ case 10 ... 19:
+ frequency = frequency / 2;
+ note_timbre = TIMBRE_12;
+ break;
+ case 20 ... 200:
+ note_timbre = .125 - pow(((float)compensated_index - 20) / (200 - 20), 2)*.125;
+ break;
+ default:
+ note_timbre = 0;
+ break;
+ }
+ break;
+ case octave_crunch:
+ switch (compensated_index) {
+ case 0 ... 9:
+ case 20 ... 24:
+ case 30 ... 32:
+ frequency = frequency / 2;
+ note_timbre = TIMBRE_12;
+ break;
+ case 10 ... 19:
+ case 25 ... 29:
+ case 33 ... 35:
+ frequency = frequency * 2;
+ note_timbre = TIMBRE_12;
+ break;
+ default:
+ note_timbre = TIMBRE_12;
+ break;
+ }
+ break;
+ }
+
+ return frequency;
+} \ No newline at end of file
diff --git a/quantum/audio/voices.h b/quantum/audio/voices.h
new file mode 100644
index 0000000000..317f5d98c5
--- /dev/null
+++ b/quantum/audio/voices.h
@@ -0,0 +1,21 @@
+#include <stdint.h>
+#include <stdbool.h>
+#include <avr/io.h>
+#include <util/delay.h>
+#include "musical_notes.h"
+#include "song_list.h"
+
+#ifndef VOICES_H
+#define VOICES_H
+
+float voice_envelope(float frequency);
+
+typedef enum {
+ default_voice,
+ butts_fader,
+ octave_crunch
+} voice_type;
+
+void set_voice(voice_type v);
+
+#endif \ No newline at end of file
diff --git a/quantum/wave.h b/quantum/audio/wave.h
index 6ebc348519..6ebc348519 100644
--- a/quantum/wave.h
+++ b/quantum/audio/wave.h
diff --git a/quantum/quantum.mk b/quantum/quantum.mk
index 1fe7390eba..83c4f1d1db 100644
--- a/quantum/quantum.mk
+++ b/quantum/quantum.mk
@@ -28,7 +28,7 @@ ifeq ($(strip $(MIDI_ENABLE)), yes)
endif
ifeq ($(strip $(AUDIO_ENABLE)), yes)
- SRC += $(QUANTUM_DIR)/audio.c
+ SRC += $(QUANTUM_DIR)/audio/audio.c $(QUANTUM_DIR)/audio/voices.c
endif
ifeq ($(strip $(UNICODE_ENABLE)), yes)
@@ -47,6 +47,7 @@ endif
# Search Path
VPATH += $(TOP_DIR)/$(QUANTUM_DIR)
VPATH += $(TOP_DIR)/$(QUANTUM_DIR)/keymap_extras
+VPATH += $(TOP_DIR)/$(QUANTUM_DIR)/audio
include $(TMK_DIR)/protocol/lufa.mk
diff --git a/tmk_core/common/avr/suspend.c b/tmk_core/common/avr/suspend.c
index e295dbe18b..4980680198 100644
--- a/tmk_core/common/avr/suspend.c
+++ b/tmk_core/common/avr/suspend.c
@@ -79,7 +79,8 @@ static void power_down(uint8_t wdto)
led_set(0);
#ifdef AUDIO_ENABLE
- stop_all_notes();
+ // This sometimes disables the start-up noise, so it's been disabled
+ // stop_all_notes();
#endif /* AUDIO_ENABLE */
// TODO: more power saving