Compare commits

...

13 Commits

Author SHA1 Message Date
Jack Humbert
ad982e39d6 implement new features for arm 2018-01-15 23:21:28 -05:00
Jack Humbert
0ad93d7443 Merge branch 'arm_audio_fixes' of github.com:qmk/qmk_firmware into audio_out 2018-01-15 16:18:39 -05:00
Jack Humbert
690a08cbbb fix up arm audio implementation 2018-01-15 16:06:49 -05:00
skullydazed
5836d1a06a Fix up the ARM audio support (#2136)
* Get audio working on clueboard/60

* add keys for music mode

* Change doubles to floats

* add keys for all the songs

* revert to the default startup sound

* Remove music mode until we can figure out why it crashes
2018-01-13 23:38:25 -05:00
manofinterests
fd359e23e8 Update info.json 2018-01-12 20:24:48 -08:00
Jack Humbert
4aef0318aa Update info.json 2018-01-12 20:47:39 -05:00
Marco Scannadinari
8209304904 Reset color after submodule warning message
Fixes leaking bold text
2018-01-12 13:25:05 -05:00
noisebomb44
6bbe2366ec Update ergodone.c 2018-01-12 13:24:30 -05:00
Kaleb Elwert
3be81a2daf Fix call to memset for various keyboards 2018-01-12 13:23:38 -05:00
Jack Humbert
7923376de1 update music functionality 2018-01-06 23:52:20 -05:00
Jack Humbert
8582faab6f add planck audio out config 2018-01-03 14:32:10 -05:00
Jack Humbert
60a0b08da3 add b6/b7 audio 2018-01-03 13:13:50 -05:00
Jack Humbert
5cc7df8750 try out b6 and b7 audio 2017-07-28 11:29:26 -04:00
27 changed files with 1059 additions and 387 deletions

View File

@@ -34,7 +34,11 @@ ifeq ($(strip $(AUDIO_ENABLE)), yes)
OPT_DEFS += -DAUDIO_ENABLE
MUSIC_ENABLE := 1
SRC += $(QUANTUM_DIR)/process_keycode/process_audio.c
ifeq ($(PLATFORM),AVR)
SRC += $(QUANTUM_DIR)/audio/audio.c
else
SRC += $(QUANTUM_DIR)/audio/audio_arm.c
endif
SRC += $(QUANTUM_DIR)/audio/voices.c
SRC += $(QUANTUM_DIR)/audio/luts.c
endif

View File

@@ -8,6 +8,30 @@ enum keyboard_layers {
_CL
};
enum custom_keycodes {
S_BSKTC = SAFE_RANGE,
S_ODEJY,
S_RCKBY,
S_DOEDR,
S_SCALE,
S_ONEUP,
S_COIN,
S_SONIC,
S_ZELDA
};
#ifdef AUDIO_ENABLE
float song_basketcase[][2] = SONG(BASKET_CASE);
float song_ode_to_joy[][2] = SONG(ODE_TO_JOY);
float song_rock_a_bye_baby[][2] = SONG(ROCK_A_BYE_BABY);
float song_doe_a_deer[][2] = SONG(DOE_A_DEER);
float song_scale[][2] = SONG(MUSIC_SCALE_SOUND);
float song_coin[][2] = SONG(COIN_SOUND);
float song_one_up[][2] = SONG(ONE_UP_SOUND);
float song_sonic_ring[][2] = SONG(SONIC_RING);
float song_zelda_puzzle[][2] = SONG(ZELDA_PUZZLE);
#endif
const uint16_t keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
/* Layer 0: Default Layer
* ,-----------------------------------------------------------.
@@ -35,9 +59,69 @@ const uint16_t keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
_______, _______,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______, _______, _______, \
_______,_______,_______, _______, _______, _______, MO(_FL), _______),
[_CL] = KEYMAP(
BL_STEP,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______,\
BL_STEP,S_BSKTC,S_ODEJY,S_RCKBY,S_DOEDR,S_SCALE,S_ONEUP,S_COIN, S_SONIC,S_ZELDA,_______,_______,_______,_______,_______,\
_______, _______,_______,_______,RESET, _______,_______,_______,_______,_______,_______,_______,_______,_______, \
_______, _______,MO(_CL),_______,_______,_______,_______,_______,_______,_______,_______,_______,_______, _______, \
_______, _______,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______, _______, \
_______, _______, _______, _______, _______, _______, MO(_FL), _______)
};
bool process_record_user(uint16_t keycode, keyrecord_t *record) {
switch (keycode) {
case S_BSKTC:
if (record->event.pressed) {
stop_all_notes();
PLAY_SONG(song_basketcase);
}
return false;
case S_ODEJY:
if (record->event.pressed) {
stop_all_notes();
PLAY_SONG(song_ode_to_joy);
}
return false;
case S_RCKBY:
if (record->event.pressed) {
stop_all_notes();
PLAY_SONG(song_rock_a_bye_baby);
}
return false;
case S_DOEDR:
if (record->event.pressed) {
stop_all_notes();
PLAY_SONG(song_doe_a_deer);
}
return false;
case S_SCALE:
if (record->event.pressed) {
stop_all_notes();
PLAY_SONG(song_scale);
}
return false;
case S_ONEUP:
if (record->event.pressed) {
stop_all_notes();
PLAY_SONG(song_one_up);
}
return false;
case S_COIN:
if (record->event.pressed) {
stop_all_notes();
PLAY_SONG(song_coin);
}
return false;
case S_SONIC:
if (record->event.pressed) {
stop_all_notes();
PLAY_SONG(song_sonic_ring);
}
return false;
case S_ZELDA:
if (record->event.pressed) {
stop_all_notes();
PLAY_SONG(song_zelda_puzzle);
}
return false;
}
return true;
}

View File

@@ -41,13 +41,8 @@ void backlight_set(uint8_t level) {
#endif
}
void led_init_ports() {
printf("led_init_ports()\n");
palSetPadMode(GPIOB, 7, PAL_MODE_OUTPUT_PUSHPULL);
}
void led_set_kb(uint8_t usb_led) {
printf("led_init_ports()\n");
printf("led_set_kb(%d)\n", usb_led);
if (usb_led & (1<<USB_LED_CAPS_LOCK)) {
// Turn capslock on
palSetPad(GPIOB, 7);

View File

@@ -68,13 +68,10 @@ void matrix_init(void) {
palSetPadMode(GPIOA, 15, PAL_MODE_INPUT_PULLDOWN);
palSetPadMode(GPIOA, 10, PAL_MODE_INPUT_PULLDOWN);
memset(matrix, 0, MATRIX_ROWS);
memset(matrix_debouncing, 0, MATRIX_COLS);
/* Setup capslock */
// palSetPadMode(GPIOB, 7, PAL_MODE_OUTPUT_PUSHPULL);
// palClearPad(GPIOB, 7);
memset(matrix, 0, MATRIX_ROWS * sizeof(matrix_row_t));
memset(matrix_debouncing, 0, MATRIX_COLS * sizeof(matrix_row_t));
palClearPad(GPIOB, 7); // Turn off capslock
matrix_init_quantum();
}
@@ -138,6 +135,7 @@ uint8_t matrix_scan(void) {
debouncing_time = timer_read();
}
}
if (debouncing && timer_elapsed(debouncing_time) > DEBOUNCE) {
for (int row = 0; row < MATRIX_ROWS; row++) {
matrix[row] = 0;

View File

@@ -50,5 +50,5 @@ COMMAND_ENABLE = yes # Commands for debug and configuration
#SLEEP_LED_ENABLE = yes # Breathing sleep LED during USB suspend
NKRO_ENABLE = yes # USB Nkey Rollover
CUSTOM_MATRIX = yes # Custom matrix file
#AUDIO_ENABLE = yes
AUDIO_ENABLE = yes
# SERIAL_LINK_ENABLE = yes

View File

@@ -7,7 +7,7 @@
"height": 5,
"layouts": {
"KEYMAP": {
"layout": [{"x":0, "y":0}, {"x":1, "y":0}, {"x":2, "y":0}, {"x":3, "y":0}, {"x":4, "y":0}, {"x":5, "y":0}, {"x":6, "y":0}, {"x":7, "y":0}, {"x":8, "y":0}, {"x":9, "y":0}, {"x":10, "y":0}, {"x":11, "y":0}, {"x":12, "y":0}, {"x":13, "y":0}, {"x":14, "y":0}, {"x":0.5, "y":1, "w":1.5}, {"x":1.5, "y":1}, {"x":2.5, "y":1}, {"x":3.5, "y":1}, {"x":4.5, "y":1}, {"x":5.5, "y":1}, {"x":6.5, "y":1}, {"x":7.5, "y":1}, {"x":8.5, "y":1}, {"x":9.5, "y":1}, {"x":10.5, "y":1}, {"x":11.5, "y":1}, {"x":12.5, "y":1}, {"x":14, "y":1, "w":1.5}, {"x":0.75, "y":2, "w":1.75}, {"x":1.75, "y":2}, {"x":2.75, "y":2}, {"x":3.75, "y":2}, {"x":4.75, "y":2}, {"x":5.75, "y":2}, {"x":6.75, "y":2}, {"x":7.75, "y":2}, {"x":8.75, "y":2}, {"x":9.75, "y":2}, {"x":10.75, "y":2}, {"x":11.75, "y":2}, {"x":14, "y":2, "w":2.25}, {"x":1.25, "y":3, "w":2.25}, {"x":2.25, "y":3}, {"x":3.25, "y":3}, {"x":4.25, "y":3}, {"x":5.25, "y":3}, {"x":6.25, "y":3}, {"x":7.25, "y":3}, {"x":8.25, "y":3}, {"x":9.25, "y":3}, {"x":10.25, "y":3}, {"x":11.25, "y":3}, {"x":13, "y":3, "w":1.75}, {"x":14, "y":3}, {"x":0.25, "y":4, "w":1.25}, {"x":1.5, "y":4, "w":1.25}, {"x":2.75, "y":4, "w":1.25}, {"x":9, "y":4, "w":6.25}, {"x":10.25, "y":4, "w":1.25}, {"x":11.5, "y":4, "w":1.25}, {"x":12.75, "y":4, "w":1.25}, {"x":14, "y":4, "w":1.25}]
"layout": [{"label":"Esc", "x":0, "y":0}, {"label":"!", "x":1, "y":0}, {"label":"@", "x":2, "y":0}, {"label":"#", "x":3, "y":0}, {"label":"$", "x":4, "y":0}, {"label":"%", "x":5, "y":0}, {"label":"^", "x":6, "y":0}, {"label":"&", "x":7, "y":0}, {"label":"*", "x":8, "y":0}, {"label":"(", "x":9, "y":0}, {"label":")", "x":10, "y":0}, {"label":"_", "x":11, "y":0}, {"label":"+", "x":12, "y":0}, {"label":"~", "x":13, "y":0}, {"label":"Tab", "x":0, "y":1, "w":1.5}, {"label":"Q", "x":1.5, "y":1}, {"label":"W", "x":2.5, "y":1}, {"label":"E", "x":3.5, "y":1}, {"label":"R", "x":4.5, "y":1}, {"label":"T", "x":5.5, "y":1}, {"label":"Y", "x":6.5, "y":1}, {"label":"U", "x":7.5, "y":1}, {"label":"I", "x":8.5, "y":1}, {"label":"O", "x":9.5, "y":1}, {"label":"P", "x":10.5, "y":1}, {"label":"{", "x":11.5, "y":1}, {"label":"}", "x":12.5, "y":1}, {"label":"|", "x":13.5, "y":1, "w":1.5}, {"label":"Caps Lock", "x":0, "y":2, "w":1.75}, {"label":"A", "x":1.75, "y":2}, {"label":"S", "x":2.75, "y":2}, {"label":"D", "x":3.75, "y":2}, {"label":"F", "x":4.75, "y":2}, {"label":"G", "x":5.75, "y":2}, {"label":"H", "x":6.75, "y":2}, {"label":"J", "x":7.75, "y":2}, {"label":"K", "x":8.75, "y":2}, {"label":"L", "x":9.75, "y":2}, {"label":":", "x":10.75, "y":2}, {"label":"\"", "x":11.75, "y":2}, {"label":"Enter", "x":12.75, "y":2}, {"label":"Enter", "x":13.75, "y":2, "w":1.25}, {"label":"Shift", "x":0, "y":3, "w":1.25}, {"label":"iso", "x":1.25, "y":3}, {"label":"Z", "x":2.25, "y":3}, {"label":"X", "x":3.25, "y":3}, {"label":"C", "x":4.25, "y":3}, {"label":"V", "x":5.25, "y":3}, {"label":"B", "x":6.25, "y":3}, {"label":"N", "x":7.25, "y":3}, {"label":"M", "x":8.25, "y":3}, {"label":"<", "x":9.25, "y":3}, {"label":">", "x":10.25, "y":3}, {"label":"?", "x":11.25, "y":3}, {"label":"Shift", "x":12.25, "y":3, "w":1.75}, {"label":"fn", "x":14, "y":3}, {"label":"Ctrl", "x":0, "y":4, "w":1.5}, {"label":"Win", "x":1.5, "y":4}, {"label":"Alt", "x":2.5, "y":4, "w":1.5}, {"x":4, "y":4, "w":5}, {"x":9, "y":4}, {"x":10, "y":4}, {"label":"Win", "x":11, "y":4, "w":1.5}, {"label":"Menu", "x":12.5, "y":4}, {"label":"Ctrl", "x":13.5, "y":4, "w":1.5}, {"label":"|", "x":13.75, "y":5}]
}
}
}

View File

@@ -12,6 +12,8 @@ extern inline void ergodox_right_led_2_off(void);
extern inline void ergodox_right_led_3_off(void);
extern inline void ergodox_right_led_off(uint8_t led);
extern inline void ergodox_led_all_off(void);
void ergodox_led_init(void);
void ergodox_blink_all_leds(void);

View File

@@ -62,8 +62,8 @@ void matrix_init(void)
palSetPadMode(GPIOC, 11, PAL_MODE_OUTPUT_PUSHPULL);
palSetPadMode(GPIOD, 0, PAL_MODE_OUTPUT_PUSHPULL);
memset(matrix, 0, MATRIX_ROWS);
memset(matrix_debouncing, 0, LOCAL_MATRIX_ROWS);
memset(matrix, 0, MATRIX_ROWS * sizeof(matrix_row_t));
memset(matrix_debouncing, 0, LOCAL_MATRIX_ROWS * sizeof(matrix_row_t));
matrix_init_quantum();
}

View File

@@ -60,8 +60,8 @@ void matrix_init(void)
palSetPadMode(GPIOC, 5, PAL_MODE_OUTPUT_PUSHPULL);
palSetPadMode(GPIOD, 0, PAL_MODE_OUTPUT_PUSHPULL);
#endif
memset(matrix, 0, MATRIX_ROWS);
memset(matrix_debouncing, 0, MATRIX_ROWS);
memset(matrix, 0, MATRIX_ROWS * sizeof(matrix_row_t));
memset(matrix_debouncing, 0, MATRIX_ROWS * sizeof(matrix_row_t));
matrix_init_quantum();
}

View File

@@ -49,8 +49,8 @@ void matrix_init(void)
palSetPadMode(GPIOB, 1, PAL_MODE_OUTPUT_PUSHPULL);
palSetPadMode(GPIOB, 0, PAL_MODE_OUTPUT_PUSHPULL);
memset(matrix, 0, MATRIX_ROWS);
memset(matrix_debouncing, 0, MATRIX_ROWS);
memset(matrix, 0, MATRIX_ROWS * sizeof(matrix_row_t));
memset(matrix_debouncing, 0, MATRIX_ROWS * sizeof(matrix_row_t));
}
uint8_t matrix_scan(void)

View File

@@ -42,8 +42,8 @@ void matrix_init(void)
palSetPadMode(GPIOD, 1, PAL_MODE_OUTPUT_PUSHPULL);
palSetPadMode(GPIOD, 4, PAL_MODE_OUTPUT_PUSHPULL);
memset(matrix, 0, MATRIX_ROWS);
memset(matrix_debouncing, 0, MATRIX_ROWS);
memset(matrix, 0, MATRIX_ROWS * sizeof(matrix_row_t));
memset(matrix_debouncing, 0, MATRIX_ROWS * sizeof(matrix_row_t));
matrix_init_quantum();
}

View File

@@ -0,0 +1,47 @@
#ifndef CONFIG_USER_H
#define CONFIG_USER_H
#include "config_common.h"
#ifdef AUDIO_ENABLE
#define STARTUP_SONG SONG(PLANCK_SOUND)
// #define STARTUP_SONG SONG(NO_SOUND)
#define DEFAULT_LAYER_SONGS { SONG(QWERTY_SOUND), \
SONG(COLEMAK_SOUND), \
SONG(DVORAK_SOUND) \
}
#endif
#define MUSIC_MASK (keycode != KC_NO)
/*
* MIDI options
*/
/* Prevent use of disabled MIDI features in the keymap */
//#define MIDI_ENABLE_STRICT 1
/* enable basic MIDI features:
- MIDI notes can be sent when in Music mode is on
*/
#define MIDI_BASIC
/* enable advanced MIDI features:
- MIDI notes can be added to the keymap
- Octave shift and transpose
- Virtual sustain, portamento, and modulation wheel
- etc.
*/
//#define MIDI_ADVANCED
/* override number of MIDI tone keycodes (each octave adds 12 keycodes and allocates 12 bytes) */
//#define MIDI_TONE_KEYCODE_OCTAVES 2
#define C6_AUDIO
#define B7_AUDIO
#undef BACKLIGHT_PIN
#endif

View File

@@ -0,0 +1,264 @@
/* Copyright 2015-2017 Jack Humbert
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "planck.h"
#include "action_layer.h"
extern keymap_config_t keymap_config;
enum planck_layers {
_QWERTY,
_COLEMAK,
_DVORAK,
_LOWER,
_RAISE,
_PLOVER,
_ADJUST
};
enum planck_keycodes {
QWERTY = SAFE_RANGE,
COLEMAK,
DVORAK,
PLOVER,
LOWER,
RAISE,
BACKLIT,
EXT_PLV
};
const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
/* Qwerty
* ,-----------------------------------------------------------------------------------.
* | Tab | Q | W | E | R | T | Y | U | I | O | P | Bksp |
* |------+------+------+------+------+-------------+------+------+------+------+------|
* | Esc | A | S | D | F | G | H | J | K | L | ; | " |
* |------+------+------+------+------+------|------+------+------+------+------+------|
* | Shift| Z | X | C | V | B | N | M | , | . | / |Enter |
* |------+------+------+------+------+------+------+------+------+------+------+------|
* | Brite| Ctrl | Alt | GUI |Lower | Space |Raise | Left | Down | Up |Right |
* `-----------------------------------------------------------------------------------'
*/
[_QWERTY] = {
{KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_BSPC},
{KC_ESC, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT},
{KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_ENT },
{BACKLIT, KC_LCTL, KC_LALT, KC_LGUI, LOWER, KC_SPC, KC_SPC, RAISE, KC_LEFT, KC_DOWN, KC_UP, KC_RGHT}
},
/* Colemak
* ,-----------------------------------------------------------------------------------.
* | Tab | Q | W | F | P | G | J | L | U | Y | ; | Bksp |
* |------+------+------+------+------+-------------+------+------+------+------+------|
* | Esc | A | R | S | T | D | H | N | E | I | O | " |
* |------+------+------+------+------+------|------+------+------+------+------+------|
* | Shift| Z | X | C | V | B | K | M | , | . | / |Enter |
* |------+------+------+------+------+------+------+------+------+------+------+------|
* | Brite| Ctrl | Alt | GUI |Lower | Space |Raise | Left | Down | Up |Right |
* `-----------------------------------------------------------------------------------'
*/
[_COLEMAK] = {
{KC_TAB, KC_Q, KC_W, KC_F, KC_P, KC_G, KC_J, KC_L, KC_U, KC_Y, KC_SCLN, KC_BSPC},
{KC_ESC, KC_A, KC_R, KC_S, KC_T, KC_D, KC_H, KC_N, KC_E, KC_I, KC_O, KC_QUOT},
{KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_K, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_ENT },
{BACKLIT, KC_LCTL, KC_LALT, KC_LGUI, LOWER, KC_SPC, KC_SPC, RAISE, KC_LEFT, KC_DOWN, KC_UP, KC_RGHT}
},
/* Dvorak
* ,-----------------------------------------------------------------------------------.
* | Tab | " | , | . | P | Y | F | G | C | R | L | Bksp |
* |------+------+------+------+------+-------------+------+------+------+------+------|
* | Esc | A | O | E | U | I | D | H | T | N | S | / |
* |------+------+------+------+------+------|------+------+------+------+------+------|
* | Shift| ; | Q | J | K | X | B | M | W | V | Z |Enter |
* |------+------+------+------+------+------+------+------+------+------+------+------|
* | Brite| Ctrl | Alt | GUI |Lower | Space |Raise | Left | Down | Up |Right |
* `-----------------------------------------------------------------------------------'
*/
[_DVORAK] = {
{KC_TAB, KC_QUOT, KC_COMM, KC_DOT, KC_P, KC_Y, KC_F, KC_G, KC_C, KC_R, KC_L, KC_BSPC},
{KC_ESC, KC_A, KC_O, KC_E, KC_U, KC_I, KC_D, KC_H, KC_T, KC_N, KC_S, KC_SLSH},
{KC_LSFT, KC_SCLN, KC_Q, KC_J, KC_K, KC_X, KC_B, KC_M, KC_W, KC_V, KC_Z, KC_ENT },
{BACKLIT, KC_LCTL, KC_LALT, KC_LGUI, LOWER, KC_SPC, KC_SPC, RAISE, KC_LEFT, KC_DOWN, KC_UP, KC_RGHT}
},
/* Lower
* ,-----------------------------------------------------------------------------------.
* | ~ | ! | @ | # | $ | % | ^ | & | * | ( | ) | Bksp |
* |------+------+------+------+------+-------------+------+------+------+------+------|
* | Del | F1 | F2 | F3 | F4 | F5 | F6 | _ | + | { | } | | |
* |------+------+------+------+------+------|------+------+------+------+------+------|
* | | F7 | F8 | F9 | F10 | F11 | F12 |ISO ~ |ISO | | Home | End | |
* |------+------+------+------+------+------+------+------+------+------+------+------|
* | | | | | | | | Next | Vol- | Vol+ | Play |
* `-----------------------------------------------------------------------------------'
*/
[_LOWER] = {
{KC_TILD, KC_EXLM, KC_AT, KC_HASH, KC_DLR, KC_PERC, KC_CIRC, KC_AMPR, KC_ASTR, KC_LPRN, KC_RPRN, KC_BSPC},
{KC_DEL, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_UNDS, KC_PLUS, KC_LCBR, KC_RCBR, KC_PIPE},
{_______, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, S(KC_NUHS), S(KC_NUBS), KC_HOME, KC_END, _______},
{_______, _______, _______, _______, _______, _______, _______, _______, KC_MNXT, KC_VOLD, KC_VOLU, KC_MPLY}
},
/* Raise
* ,-----------------------------------------------------------------------------------.
* | ` | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 0 | Bksp |
* |------+------+------+------+------+-------------+------+------+------+------+------|
* | Del | F1 | F2 | F3 | F4 | F5 | F6 | - | = | [ | ] | \ |
* |------+------+------+------+------+------|------+------+------+------+------+------|
* | | F7 | F8 | F9 | F10 | F11 | F12 |ISO # |ISO / |Pg Up |Pg Dn | |
* |------+------+------+------+------+------+------+------+------+------+------+------|
* | | | | | | | | Next | Vol- | Vol+ | Play |
* `-----------------------------------------------------------------------------------'
*/
[_RAISE] = {
{KC_GRV, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_BSPC},
{KC_DEL, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_MINS, KC_EQL, KC_LBRC, KC_RBRC, KC_BSLS},
{_______, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, KC_NUHS, KC_NUBS, KC_PGUP, KC_PGDN, _______},
{_______, _______, _______, _______, _______, _______, _______, _______, KC_MNXT, KC_VOLD, KC_VOLU, KC_MPLY}
},
/* Plover layer (http://opensteno.org)
* ,-----------------------------------------------------------------------------------.
* | # | # | # | # | # | # | # | # | # | # | # | # |
* |------+------+------+------+------+-------------+------+------+------+------+------|
* | | S | T | P | H | * | * | F | P | L | T | D |
* |------+------+------+------+------+------|------+------+------+------+------+------|
* | | S | K | W | R | * | * | R | B | G | S | Z |
* |------+------+------+------+------+------+------+------+------+------+------+------|
* | Exit | | | A | O | | E | U | | | |
* `-----------------------------------------------------------------------------------'
*/
[_PLOVER] = {
{KC_1, KC_1, KC_1, KC_1, KC_1, KC_1, KC_1, KC_1, KC_1, KC_1, KC_1, KC_1 },
{XXXXXXX, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_LBRC},
{XXXXXXX, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT},
{EXT_PLV, XXXXXXX, XXXXXXX, KC_C, KC_V, XXXXXXX, XXXXXXX, KC_N, KC_M, XXXXXXX, XXXXXXX, XXXXXXX}
},
/* Adjust (Lower + Raise)
* ,-----------------------------------------------------------------------------------.
* | | Reset| | | | | | | | | | Del |
* |------+------+------+------+------+-------------+------+------+------+------+------|
* | | | |Aud on|Audoff|AGnorm|AGswap|Qwerty|Colemk|Dvorak|Plover| |
* |------+------+------+------+------+------|------+------+------+------+------+------|
* | |Voice-|Voice+|Mus on|Musoff|MIDIon|MIDIof| | | | | |
* |------+------+------+------+------+------+------+------+------+------+------+------|
* | | | | | | | | | | | |
* `-----------------------------------------------------------------------------------'
*/
[_ADJUST] = {
{_______, RESET, DEBUG, RGB_TOG, RGB_MOD, RGB_HUI, RGB_HUD, RGB_SAI, RGB_SAD, RGB_VAI, RGB_VAD, KC_DEL },
{_______, _______, MU_MOD, AU_ON, AU_OFF, AG_NORM, AG_SWAP, QWERTY, COLEMAK, DVORAK, PLOVER, _______},
{_______, MUV_DE, MUV_IN, MU_ON, MU_OFF, MI_ON, MI_OFF, TERM_ON, TERM_OFF, _______, _______, _______},
{_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______}
}
};
#ifdef AUDIO_ENABLE
float plover_song[][2] = SONG(PLOVER_SOUND);
float plover_gb_song[][2] = SONG(PLOVER_GOODBYE_SOUND);
#endif
bool process_record_user(uint16_t keycode, keyrecord_t *record) {
switch (keycode) {
case QWERTY:
if (record->event.pressed) {
print("mode just switched to qwerty and this is a huge string\n");
set_single_persistent_default_layer(_QWERTY);
}
return false;
break;
case COLEMAK:
if (record->event.pressed) {
set_single_persistent_default_layer(_COLEMAK);
}
return false;
break;
case DVORAK:
if (record->event.pressed) {
set_single_persistent_default_layer(_DVORAK);
}
return false;
break;
case LOWER:
if (record->event.pressed) {
layer_on(_LOWER);
update_tri_layer(_LOWER, _RAISE, _ADJUST);
} else {
layer_off(_LOWER);
update_tri_layer(_LOWER, _RAISE, _ADJUST);
}
return false;
break;
case RAISE:
if (record->event.pressed) {
layer_on(_RAISE);
update_tri_layer(_LOWER, _RAISE, _ADJUST);
} else {
layer_off(_RAISE);
update_tri_layer(_LOWER, _RAISE, _ADJUST);
}
return false;
break;
case BACKLIT:
if (record->event.pressed) {
register_code(KC_RSFT);
#ifdef BACKLIGHT_ENABLE
backlight_step();
#endif
PORTE &= ~(1<<6);
} else {
unregister_code(KC_RSFT);
PORTE |= (1<<6);
}
return false;
break;
case PLOVER:
if (record->event.pressed) {
#ifdef AUDIO_ENABLE
stop_all_notes();
PLAY_SONG(plover_song);
#endif
layer_off(_RAISE);
layer_off(_LOWER);
layer_off(_ADJUST);
layer_on(_PLOVER);
if (!eeconfig_is_enabled()) {
eeconfig_init();
}
keymap_config.raw = eeconfig_read_keymap();
keymap_config.nkro = 1;
eeconfig_update_keymap(keymap_config.raw);
}
return false;
break;
case EXT_PLV:
if (record->event.pressed) {
#ifdef AUDIO_ENABLE
PLAY_SONG(plover_gb_song);
#endif
layer_off(_PLOVER);
}
return false;
break;
}
return true;
}

View File

@@ -0,0 +1,3 @@
AUDIO_ENABLE = yes
BACKLIGHT_ENABLE = no
MIDI_ENABLE = no

View File

@@ -65,7 +65,7 @@ CONSOLE_ENABLE = yes # Console for debug(+400)
COMMAND_ENABLE = no # Commands for debug and configuration
NKRO_ENABLE = yes # Nkey Rollover - if this doesn't work, see here: https://github.com/tmk/tmk_keyboard/wiki/FAQ#nkro-doesnt-work
BACKLIGHT_ENABLE = no # Enable keyboard backlight functionality
MIDI_ENABLE = yes # MIDI controls
MIDI_ENABLE = no # MIDI controls
AUDIO_ENABLE = yes # Audio output on port C6
UNICODE_ENABLE = no # Unicode
BLUETOOTH_ENABLE = no # Enable Bluetooth with the Adafruit EZ-Key HID

View File

@@ -10,7 +10,7 @@
"width": 12,
"height": 5,
"layouts": {
"LAYOUT_preonic_mit": {
"KEYMAP": {
"key_count": 59,
"layout": [
{ "w": 1, "x": 0, "y": 0 },

View File

@@ -47,8 +47,9 @@ void matrix_init(void)
palSetPadMode(GPIOC, 10, PAL_MODE_OUTPUT_PUSHPULL);
palSetPadMode(GPIOC, 11, PAL_MODE_OUTPUT_PUSHPULL);
memset(matrix, 0, MATRIX_ROWS);
memset(matrix_debouncing, 0, MATRIX_ROWS);
memset(matrix, 0, MATRIX_ROWS * sizeof(matrix_row_t));
memset(matrix_debouncing, 0, MATRIX_ROWS * sizeof(matrix_row_t));
matrix_init_quantum();
}

View File

@@ -58,7 +58,7 @@ MSG_SUBMODULE_DIRTY = $(WARN_COLOR)WARNING:$(NO_COLOR)\n \
Some git sub-modules are out of date or modified, please consider runnning:$(BOLD)\n\
make git-submodule\n\
You can ignore this warning if you are not compiling any ChibiOS keyboards,\n\
or if you have modified the ChibiOS libraries yourself. \n\n
or if you have modified the ChibiOS libraries yourself. \n\n$(NO_COLOR)
MSG_NO_CMP = $(ERROR_COLOR)Error:$(NO_COLOR)$(BOLD) cmp command not found, please install diffutils\n$(NO_COLOR)
define GENERATE_MSG_MAKE_KB

View File

@@ -47,6 +47,16 @@
#define DISABLE_AUDIO_COUNTER_1_ISR TIMSK1 &= ~_BV(OCIE1A)
#endif
#ifdef B6_AUDIO
#define ENABLE_AUDIO_COUNTER_1_ISR TIMSK1 |= _BV(OCIE1B)
#define DISABLE_AUDIO_COUNTER_1_ISR TIMSK1 &= ~_BV(OCIE1B)
#endif
#ifdef B7_AUDIO
#define ENABLE_AUDIO_COUNTER_1_ISR TIMSK1 |= _BV(OCIE1C)
#define DISABLE_AUDIO_COUNTER_1_ISR TIMSK1 &= ~_BV(OCIE1C)
#endif
// TCCR3A: Timer/Counter #3 Control Register
// Compare Output Mode (COM3An) = 0b00 = Normal port operation, OC3A disconnected from PC6
@@ -60,6 +70,16 @@
#define DISABLE_AUDIO_COUNTER_1_OUTPUT TCCR1A &= ~(_BV(COM1A1) | _BV(COM1A0));
#endif
#ifdef B6_AUDIO
#define ENABLE_AUDIO_COUNTER_1_OUTPUT TCCR1A |= _BV(COM1B1);
#define DISABLE_AUDIO_COUNTER_1_OUTPUT TCCR1A &= ~(_BV(COM1B1) | _BV(COM1B0));
#endif
#ifdef B7_AUDIO
#define ENABLE_AUDIO_COUNTER_1_OUTPUT TCCR1A |= _BV(COM1C1);
#define DISABLE_AUDIO_COUNTER_1_OUTPUT TCCR1A &= ~(_BV(COM1C1) | _BV(COM1C0));
#endif
// Fast PWM Mode Controls
#ifdef C6_AUDIO
@@ -72,6 +92,16 @@
#define TIMER_1_DUTY_CYCLE OCR1A
#endif
#ifdef B6_AUDIO
#define TIMER_1_PERIOD ICR1
#define TIMER_1_DUTY_CYCLE OCR1B
#endif
#ifdef B7_AUDIO
#define TIMER_1_PERIOD ICR1
#define TIMER_1_DUTY_CYCLE OCR1C
#endif
// -----------------------------------------------------------------------------
@@ -97,7 +127,7 @@ bool playing_note = false;
float note_frequency = 0;
float note_length = 0;
uint8_t note_tempo = TEMPO_DEFAULT;
float note_timbre = TIMBRE_DEFAULT;
float note_timbre[NUMBER_OF_TIMERS] = {TIMBRE_DEFAULT};
uint16_t note_position = 0;
float (* notes_pointer)[][2];
uint16_t notes_count;
@@ -119,8 +149,8 @@ static bool audio_initialized = false;
audio_config_t audio_config;
uint16_t envelope_index = 0;
bool glissando = true;
uint16_t envelope_index[NUMBER_OF_TIMERS] = {0};
bool glissando[NUMBER_OF_TIMERS] = {true};
#ifndef STARTUP_SONG
#define STARTUP_SONG SONG(STARTUP_SOUND)
@@ -163,11 +193,25 @@ void audio_init()
// PORTB &= ~_BV(PORTB5);
#endif
#ifdef B6_AUDIO
DDRB |= _BV(PORTB6);
// #else
// DDRB |= _BV(PORTB6);
// PORTB &= ~_BV(PORTB6);
#endif
#ifdef B7_AUDIO
DDRB |= _BV(PORTB7);
// #else
// DDRB |= _BV(PORTB7);
// PORTB &= ~_BV(PORTB7);
#endif
#ifdef C6_AUDIO
DISABLE_AUDIO_COUNTER_3_ISR;
#endif
#ifdef B5_AUDIO
#ifdef B_AUDIO
DISABLE_AUDIO_COUNTER_1_ISR;
#endif
@@ -179,14 +223,17 @@ void audio_init()
#ifdef C6_AUDIO
TCCR3A = (0 << COM3A1) | (0 << COM3A0) | (1 << WGM31) | (0 << WGM30);
TCCR3B = (1 << WGM33) | (1 << WGM32) | (0 << CS32) | (1 << CS31) | (0 << CS30);
TIMER_3_PERIOD = (uint16_t)(((float)F_CPU) / (440 * CPU_PRESCALER));
TIMER_3_DUTY_CYCLE = (uint16_t)((((float)F_CPU) / (440 * CPU_PRESCALER)) * note_timbre[TIMER_3_INDEX]);
#endif
#ifdef B5_AUDIO
#ifdef B_AUDIO
TCCR1A = (0 << COM1A1) | (0 << COM1A0) | (1 << WGM11) | (0 << WGM10);
TCCR1B = (1 << WGM13) | (1 << WGM12) | (0 << CS12) | (1 << CS11) | (0 << CS10);
TIMER_1_PERIOD = (uint16_t)(((float)F_CPU) / (440 * CPU_PRESCALER));
TIMER_1_DUTY_CYCLE = (uint16_t)((((float)F_CPU) / (440 * CPU_PRESCALER)) * note_timbre);
TIMER_1_DUTY_CYCLE = (uint16_t)((((float)F_CPU) / (440 * CPU_PRESCALER)) * note_timbre[TIMER_1_INDEX]);
#endif
audio_initialized = true;
@@ -213,7 +260,7 @@ void stop_all_notes()
DISABLE_AUDIO_COUNTER_3_OUTPUT;
#endif
#ifdef B5_AUDIO
#ifdef B_AUDIO
DISABLE_AUDIO_COUNTER_1_ISR;
DISABLE_AUDIO_COUNTER_1_OUTPUT;
#endif
@@ -258,12 +305,18 @@ void stop_note(float freq)
if (voice_place >= voices) {
voice_place = 0;
}
if (voices == 1) {
#if defined(C6_AUDIO) && defined(B_AUDIO)
DISABLE_AUDIO_COUNTER_1_ISR;
DISABLE_AUDIO_COUNTER_1_OUTPUT;
#endif
}
if (voices == 0) {
#ifdef C6_AUDIO
DISABLE_AUDIO_COUNTER_3_ISR;
DISABLE_AUDIO_COUNTER_3_OUTPUT;
#endif
#ifdef B5_AUDIO
#ifdef B_AUDIO
DISABLE_AUDIO_COUNTER_1_ISR;
DISABLE_AUDIO_COUNTER_1_OUTPUT;
#endif
@@ -303,11 +356,11 @@ ISR(TIMER3_COMPA_vect)
if (playing_note) {
if (voices > 0) {
#ifdef B5_AUDIO
#ifdef B_AUDIO
float freq_alt = 0;
if (voices > 1) {
if (polyphony_rate == 0) {
if (glissando) {
if (glissando[TIMER_1_INDEX] && NUMBER_OF_TIMERS == 1) {
if (frequency_alt != 0 && frequency_alt < frequencies[voices - 2] && frequency_alt < frequencies[voices - 2] * pow(2, -440/frequencies[voices - 2]/12/2)) {
frequency_alt = frequency_alt * pow(2, 440/frequency_alt/12/2);
} else if (frequency_alt != 0 && frequency_alt > frequencies[voices - 2] && frequency_alt > frequencies[voices - 2] * pow(2, 440/frequencies[voices - 2]/12/2)) {
@@ -330,18 +383,18 @@ ISR(TIMER3_COMPA_vect)
#endif
}
if (envelope_index < 65535) {
envelope_index++;
if (envelope_index[TIMER_1_INDEX] < 65535) {
envelope_index[TIMER_1_INDEX]++;
}
freq_alt = voice_envelope(freq_alt);
freq_alt = voice_envelope(freq_alt,TIMER_1_INDEX);
if (freq_alt < 30.517578125) {
freq_alt = 30.52;
}
TIMER_1_PERIOD = (uint16_t)(((float)F_CPU) / (freq_alt * CPU_PRESCALER));
TIMER_1_DUTY_CYCLE = (uint16_t)((((float)F_CPU) / (freq_alt * CPU_PRESCALER)) * note_timbre);
TIMER_1_DUTY_CYCLE = (uint16_t)((((float)F_CPU) / (freq_alt * CPU_PRESCALER)) * note_timbre[TIMER_1_INDEX]);
}
#endif
@@ -364,7 +417,7 @@ ISR(TIMER3_COMPA_vect)
freq = frequencies[voice_place];
#endif
} else {
if (glissando) {
if (glissando[TIMER_3_INDEX] && NUMBER_OF_TIMERS == 1) {
if (frequency != 0 && frequency < frequencies[voices - 1] && frequency < frequencies[voices - 1] * pow(2, -440/frequencies[voices - 1]/12/2)) {
frequency = frequency * pow(2, 440/frequency/12/2);
} else if (frequency != 0 && frequency > frequencies[voices - 1] && frequency > frequencies[voices - 1] * pow(2, 440/frequencies[voices - 1]/12/2)) {
@@ -387,18 +440,18 @@ ISR(TIMER3_COMPA_vect)
#endif
}
if (envelope_index < 65535) {
envelope_index++;
if (envelope_index[TIMER_3_INDEX] < 65535) {
envelope_index[TIMER_3_INDEX]++;
}
freq = voice_envelope(freq);
freq = voice_envelope(freq, TIMER_3_INDEX);
if (freq < 30.517578125) {
freq = 30.52;
}
TIMER_3_PERIOD = (uint16_t)(((float)F_CPU) / (freq * CPU_PRESCALER));
TIMER_3_DUTY_CYCLE = (uint16_t)((((float)F_CPU) / (freq * CPU_PRESCALER)) * note_timbre);
TIMER_3_DUTY_CYCLE = (uint16_t)((((float)F_CPU) / (freq * CPU_PRESCALER)) * note_timbre[TIMER_3_INDEX]);
}
}
@@ -414,13 +467,13 @@ ISR(TIMER3_COMPA_vect)
freq = note_frequency;
#endif
if (envelope_index < 65535) {
envelope_index++;
if (envelope_index[TIMER_3_INDEX] < 65535) {
envelope_index[TIMER_3_INDEX]++;
}
freq = voice_envelope(freq);
freq = voice_envelope(freq, TIMER_3_INDEX);
TIMER_3_PERIOD = (uint16_t)(((float)F_CPU) / (freq * CPU_PRESCALER));
TIMER_3_DUTY_CYCLE = (uint16_t)((((float)F_CPU) / (freq * CPU_PRESCALER)) * note_timbre);
TIMER_3_DUTY_CYCLE = (uint16_t)((((float)F_CPU) / (freq * CPU_PRESCALER)) * note_timbre[TIMER_3_INDEX]);
} else {
TIMER_3_PERIOD = 0;
TIMER_3_DUTY_CYCLE = 0;
@@ -461,7 +514,7 @@ ISR(TIMER3_COMPA_vect)
}
} else {
note_resting = false;
envelope_index = 0;
envelope_index[TIMER_3_INDEX] = 0;
note_frequency = (*notes_pointer)[current_note][0];
note_length = ((*notes_pointer)[current_note][1] / 4) * (((float)note_tempo) / 100);
}
@@ -477,10 +530,16 @@ ISR(TIMER3_COMPA_vect)
}
#endif
#ifdef B_AUDIO
#ifdef B5_AUDIO
ISR(TIMER1_COMPA_vect)
#elif defined(B6_AUDIO)
ISR(TIMER1_COMPB_vect)
#elif defined(B7_AUDIO)
ISR(TIMER1_COMPC_vect)
#endif
{
#if defined(B5_AUDIO) && !defined(C6_AUDIO)
#if defined(B_AUDIO) && !defined(C6_AUDIO)
float freq = 0;
if (playing_note) {
@@ -504,7 +563,7 @@ ISR(TIMER1_COMPA_vect)
freq = frequencies[voice_place];
#endif
} else {
if (glissando) {
if (glissando[TIMER_1_INDEX] && NUMBER_OF_TIMERS == 1) {
if (frequency != 0 && frequency < frequencies[voices - 1] && frequency < frequencies[voices - 1] * pow(2, -440/frequencies[voices - 1]/12/2)) {
frequency = frequency * pow(2, 440/frequency/12/2);
} else if (frequency != 0 && frequency > frequencies[voices - 1] && frequency > frequencies[voices - 1] * pow(2, 440/frequencies[voices - 1]/12/2)) {
@@ -527,18 +586,18 @@ ISR(TIMER1_COMPA_vect)
#endif
}
if (envelope_index < 65535) {
envelope_index++;
if (envelope_index[TIMER_1_INDEX] < 65535) {
envelope_index[TIMER_1_INDEX]++;
}
freq = voice_envelope(freq);
freq = voice_envelope(freq, TIMER_1_INDEX);
if (freq < 30.517578125) {
freq = 30.52;
}
TIMER_1_PERIOD = (uint16_t)(((float)F_CPU) / (freq * CPU_PRESCALER));
TIMER_1_DUTY_CYCLE = (uint16_t)((((float)F_CPU) / (freq * CPU_PRESCALER)) * note_timbre);
TIMER_1_DUTY_CYCLE = (uint16_t)((((float)F_CPU) / (freq * CPU_PRESCALER)) * note_timbre[TIMER_1_INDEX]);
}
}
@@ -554,13 +613,13 @@ ISR(TIMER1_COMPA_vect)
freq = note_frequency;
#endif
if (envelope_index < 65535) {
envelope_index++;
if (envelope_index[TIMER_1_INDEX] < 65535) {
envelope_index[TIMER_1_INDEX]++;
}
freq = voice_envelope(freq);
freq = voice_envelope(freq, TIMER_1_INDEX);
TIMER_1_PERIOD = (uint16_t)(((float)F_CPU) / (freq * CPU_PRESCALER));
TIMER_1_DUTY_CYCLE = (uint16_t)((((float)F_CPU) / (freq * CPU_PRESCALER)) * note_timbre);
TIMER_1_DUTY_CYCLE = (uint16_t)((((float)F_CPU) / (freq * CPU_PRESCALER)) * note_timbre[TIMER_1_INDEX]);
} else {
TIMER_1_PERIOD = 0;
TIMER_1_DUTY_CYCLE = 0;
@@ -601,7 +660,7 @@ ISR(TIMER1_COMPA_vect)
}
} else {
note_resting = false;
envelope_index = 0;
envelope_index[TIMER_1_INDEX] = 0;
note_frequency = (*notes_pointer)[current_note][0];
note_length = ((*notes_pointer)[current_note][1] / 4) * (((float)note_tempo) / 100);
}
@@ -630,7 +689,7 @@ void play_note(float freq, int vol) {
#ifdef C6_AUDIO
DISABLE_AUDIO_COUNTER_3_ISR;
#endif
#ifdef B5_AUDIO
#ifdef B_AUDIO
DISABLE_AUDIO_COUNTER_1_ISR;
#endif
@@ -640,7 +699,6 @@ void play_note(float freq, int vol) {
playing_note = true;
envelope_index = 0;
if (freq > 0) {
frequencies[voices] = freq;
@@ -652,16 +710,23 @@ void play_note(float freq, int vol) {
ENABLE_AUDIO_COUNTER_3_ISR;
ENABLE_AUDIO_COUNTER_3_OUTPUT;
#endif
#ifdef B5_AUDIO
#ifdef B_AUDIO
#ifdef C6_AUDIO
if (voices > 1) {
envelope_index[TIMER_3_INDEX] = 0;
ENABLE_AUDIO_COUNTER_1_ISR;
ENABLE_AUDIO_COUNTER_1_OUTPUT;
} else {
envelope_index[TIMER_3_INDEX] = 0;
}
#else
envelope_index[TIMER_1_INDEX] = 0;
ENABLE_AUDIO_COUNTER_1_ISR;
ENABLE_AUDIO_COUNTER_1_OUTPUT;
#endif
#else
envelope_index[TIMER_3_INDEX] = 0;
#endif
}
@@ -679,7 +744,7 @@ void play_notes(float (*np)[][2], uint16_t n_count, bool n_repeat)
#ifdef C6_AUDIO
DISABLE_AUDIO_COUNTER_3_ISR;
#endif
#ifdef B5_AUDIO
#ifdef B_AUDIO
DISABLE_AUDIO_COUNTER_1_ISR;
#endif
@@ -705,7 +770,7 @@ void play_notes(float (*np)[][2], uint16_t n_count, bool n_repeat)
ENABLE_AUDIO_COUNTER_3_ISR;
ENABLE_AUDIO_COUNTER_3_OUTPUT;
#endif
#ifdef B5_AUDIO
#ifdef B_AUDIO
#ifndef C6_AUDIO
ENABLE_AUDIO_COUNTER_1_ISR;
ENABLE_AUDIO_COUNTER_1_OUTPUT;
@@ -803,8 +868,8 @@ void decrease_polyphony_rate(float change) {
// Timbre function
void set_timbre(float timbre) {
note_timbre = timbre;
void set_timbre(float timbre, uint8_t timer_index) {
note_timbre[timer_index] = timbre;
}
// Tempo functions

View File

@@ -36,6 +36,42 @@
// Enable vibrato strength/amplitude - slows down ISR too much
// #define VIBRATO_STRENGTH_ENABLE
#if defined(__AVR__)
// avr
#ifdef B_AUDIO
#error Please define B5_AUDIO, B6_AUDIO, or B7_AUDIO instead
#endif
#if defined(B5_AUDIO) || defined(B6_AUDIO) || defined(B7_AUDIO)
#define B_AUDIO
#endif
#if defined(C6_AUDIO) && defined (B_AUDIO)
#define NUMBER_OF_TIMERS 2
#elif defined(C6_AUDIO)
#define NUMBER_OF_TIMERS 1
#elif defined(B_AUDIO)
#define NUMBER_OF_TIMERS 1
#else
#define NUMBER_OF_TIMERS 0
#endif
#define TIMER_1_INDEX 0
#define TIMER_3_INDEX 1
#else
// chibios
#define NUMBER_OF_TIMERS 2
#define TIMER_6_INDEX 0
#define TIMER_7_INDEX 1
#endif
typedef union {
uint8_t raw;
struct {
@@ -75,7 +111,7 @@ void disable_polyphony(void);
void increase_polyphony_rate(float change);
void decrease_polyphony_rate(float change);
void set_timbre(float timbre);
void set_timbre(float timbre, uint8_t timer_index);
void set_tempo(uint8_t tempo);
void increase_tempo(uint8_t tempo_change);

View File

@@ -18,7 +18,6 @@
#include "ch.h"
#include "hal.h"
#include <stdio.h>
#include <string.h>
#include "print.h"
#include "keymap.h"
@@ -48,7 +47,7 @@ bool playing_note = false;
float note_frequency = 0;
float note_length = 0;
uint8_t note_tempo = TEMPO_DEFAULT;
float note_timbre = TIMBRE_DEFAULT;
float note_timbre[NUMBER_OF_TIMERS] = {TIMBRE_DEFAULT};
uint16_t note_position = 0;
float (* notes_pointer)[][2];
uint16_t notes_count;
@@ -70,31 +69,56 @@ static bool audio_initialized = false;
audio_config_t audio_config;
uint16_t envelope_index = 0;
bool glissando = true;
uint16_t envelope_index[NUMBER_OF_TIMERS] = {0};
bool glissando[NUMBER_OF_TIMERS] = {true};
#ifndef STARTUP_SONG
#define STARTUP_SONG SONG(STARTUP_SOUND)
#endif
float startup_song[][2] = STARTUP_SONG;
static void gpt_cb6(GPTDriver *gptp);
static void gpt_cb7(GPTDriver *gptp);
static void gpt_cb8(GPTDriver *gptp);
#define DAC_BUFFER_SIZE 360
#define START_CHANNEL_1() gptStart(&GPTD6, &gpt6cfg1); \
gptStartContinuous(&GPTD6, 2U)
#define START_CHANNEL_2() gptStart(&GPTD7, &gpt7cfg1); \
gptStartContinuous(&GPTD7, 2U)
#define STOP_CHANNEL_1() gptStopTimer(&GPTD6)
#define STOP_CHANNEL_2() gptStopTimer(&GPTD7)
#define RESTART_CHANNEL_1() STOP_CHANNEL_1(); \
START_CHANNEL_1()
#define RESTART_CHANNEL_2() STOP_CHANNEL_1(); \
START_CHANNEL_1()
#define UPDATE_CHANNEL_1_FREQ(freq) gpt6cfg1.frequency = freq * DAC_BUFFER_SIZE; \
RESTART_CHANNEL_1()
#define UPDATE_CHANNEL_2_FREQ(freq) gpt7cfg1.frequency = freq * DAC_BUFFER_SIZE; \
RESTART_CHANNEL_2()
#define GET_CHANNEL_1_FREQ gpt6cfg1.frequency
#define GET_CHANNEL_2_FREQ gpt7cfg1.frequency
/*
* GPT6 configuration.
*/
// static const GPTConfig gpt6cfg1 = {
// .frequency = 1000000U,
// .callback = NULL,
// .cr2 = TIM_CR2_MMS_1, /* MMS = 010 = TRGO on Update Event. */
// .dier = 0U
// };
GPTConfig gpt6cfg1 = {
.frequency = 440,
.callback = gpt_cb6,
.frequency = 440U*DAC_BUFFER_SIZE,
.callback = NULL,
.cr2 = TIM_CR2_MMS_1, /* MMS = 010 = TRGO on Update Event. */
.dier = 0U
};
GPTConfig gpt7cfg1 = {
.frequency = 440,
.callback = gpt_cb7,
.frequency = 440U*DAC_BUFFER_SIZE,
.callback = NULL,
.cr2 = TIM_CR2_MMS_1, /* MMS = 010 = TRGO on Update Event. */
.dier = 0U
};
@@ -106,14 +130,121 @@ GPTConfig gpt8cfg1 = {
.dier = 0U
};
static void gpt_cb6(GPTDriver *gptp) {
palTogglePad(GPIOA, 4);
/*
* DAC test buffer (sine wave).
*/
// static const dacsample_t dac_buffer[DAC_BUFFER_SIZE] = {
// 2047, 2082, 2118, 2154, 2189, 2225, 2260, 2296, 2331, 2367, 2402, 2437,
// 2472, 2507, 2542, 2576, 2611, 2645, 2679, 2713, 2747, 2780, 2813, 2846,
// 2879, 2912, 2944, 2976, 3008, 3039, 3070, 3101, 3131, 3161, 3191, 3221,
// 3250, 3278, 3307, 3335, 3362, 3389, 3416, 3443, 3468, 3494, 3519, 3544,
// 3568, 3591, 3615, 3637, 3660, 3681, 3703, 3723, 3744, 3763, 3782, 3801,
// 3819, 3837, 3854, 3870, 3886, 3902, 3917, 3931, 3944, 3958, 3970, 3982,
// 3993, 4004, 4014, 4024, 4033, 4041, 4049, 4056, 4062, 4068, 4074, 4078,
// 4082, 4086, 4089, 4091, 4092, 4093, 4094, 4093, 4092, 4091, 4089, 4086,
// 4082, 4078, 4074, 4068, 4062, 4056, 4049, 4041, 4033, 4024, 4014, 4004,
// 3993, 3982, 3970, 3958, 3944, 3931, 3917, 3902, 3886, 3870, 3854, 3837,
// 3819, 3801, 3782, 3763, 3744, 3723, 3703, 3681, 3660, 3637, 3615, 3591,
// 3568, 3544, 3519, 3494, 3468, 3443, 3416, 3389, 3362, 3335, 3307, 3278,
// 3250, 3221, 3191, 3161, 3131, 3101, 3070, 3039, 3008, 2976, 2944, 2912,
// 2879, 2846, 2813, 2780, 2747, 2713, 2679, 2645, 2611, 2576, 2542, 2507,
// 2472, 2437, 2402, 2367, 2331, 2296, 2260, 2225, 2189, 2154, 2118, 2082,
// 2047, 2012, 1976, 1940, 1905, 1869, 1834, 1798, 1763, 1727, 1692, 1657,
// 1622, 1587, 1552, 1518, 1483, 1449, 1415, 1381, 1347, 1314, 1281, 1248,
// 1215, 1182, 1150, 1118, 1086, 1055, 1024, 993, 963, 933, 903, 873,
// 844, 816, 787, 759, 732, 705, 678, 651, 626, 600, 575, 550,
// 526, 503, 479, 457, 434, 413, 391, 371, 350, 331, 312, 293,
// 275, 257, 240, 224, 208, 192, 177, 163, 150, 136, 124, 112,
// 101, 90, 80, 70, 61, 53, 45, 38, 32, 26, 20, 16,
// 12, 8, 5, 3, 2, 1, 0, 1, 2, 3, 5, 8,
// 12, 16, 20, 26, 32, 38, 45, 53, 61, 70, 80, 90,
// 101, 112, 124, 136, 150, 163, 177, 192, 208, 224, 240, 257,
// 275, 293, 312, 331, 350, 371, 391, 413, 434, 457, 479, 503,
// 526, 550, 575, 600, 626, 651, 678, 705, 732, 759, 787, 816,
// 844, 873, 903, 933, 963, 993, 1024, 1055, 1086, 1118, 1150, 1182,
// 1215, 1248, 1281, 1314, 1347, 1381, 1415, 1449, 1483, 1518, 1552, 1587,
// 1622, 1657, 1692, 1727, 1763, 1798, 1834, 1869, 1905, 1940, 1976, 2012
// };
// squarewave
static const dacsample_t dac_buffer[DAC_BUFFER_SIZE] = {
2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047,
2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047,
2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047,
2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047,
2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047,
2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047,
2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047,
2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047,
2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047,
2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047,
2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047,
2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047,
2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047,
2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047,
2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
};
/*
* DAC streaming callback.
*/
size_t nx = 0, ny = 0, nz = 0;
static void end_cb1(DACDriver *dacp, const dacsample_t *buffer, size_t n) {
(void)dacp;
nz++;
if (dac_buffer == buffer) {
nx += n;
}
else {
ny += n;
}
static void gpt_cb7(GPTDriver *gptp) {
palTogglePad(GPIOA, 5);
if ((nz % 1000) == 0) {
// palTogglePad(GPIOD, GPIOD_LED3);
}
}
/*
* DAC error callback.
*/
static void error_cb1(DACDriver *dacp, dacerror_t err) {
(void)dacp;
(void)err;
chSysHalt("DAC failure");
}
static const DACConfig dac1cfg1 = {
.init = 2047U,
.datamode = DAC_DHRM_12BIT_RIGHT
};
static const DACConversionGroup dacgrpcfg1 = {
.num_channels = 1U,
.end_cb = end_cb1,
.error_cb = error_cb1,
.trigger = DAC_TRG(0)
};
void audio_init()
{
@@ -129,8 +260,27 @@ void audio_init()
// audio_config.raw = eeconfig_read_audio();
audio_config.enable = true;
palSetPadMode(GPIOA, 4, PAL_MODE_OUTPUT_PUSHPULL);
palSetPadMode(GPIOA, 5, PAL_MODE_OUTPUT_PUSHPULL);
/*
* Starting DAC1 driver, setting up the output pin as analog as suggested
* by the Reference Manual.
*/
palSetPadMode(GPIOA, 4, PAL_MODE_INPUT_ANALOG);
palSetPadMode(GPIOA, 5, PAL_MODE_INPUT_ANALOG);
dacStart(&DACD1, &dac1cfg1);
/*
* Starting GPT6 driver, it is used for triggering the DAC.
*/
START_CHANNEL_1();
START_CHANNEL_2();
/*
* Starting a continuous conversion.
*/
dacStartConversion(&DACD1, &dacgrpcfg1,
(dacsample_t *)dac_buffer, DAC_BUFFER_SIZE);
// gptStartContinuous(&GPTD6, 2U);
audio_initialized = true;
@@ -194,8 +344,8 @@ void stop_note(float freq)
voice_place = 0;
}
if (voices == 0) {
gptStopTimer(&GPTD6);
gptStopTimer(&GPTD7);
STOP_CHANNEL_1();
STOP_CHANNEL_2();
gptStopTimer(&GPTD8);
frequency = 0;
frequency_alt = 0;
@@ -225,20 +375,6 @@ float vibrato(float average_freq) {
#endif
static void restart_gpt6(void) {
// gptStopTimer(&GPTD6);
gptStart(&GPTD6, &gpt6cfg1);
gptStartContinuous(&GPTD6, 2U);
}
static void restart_gpt7(void) {
// gptStopTimer(&GPTD7);
gptStart(&GPTD7, &gpt7cfg1);
gptStartContinuous(&GPTD7, 2U);
}
static void gpt_cb8(GPTDriver *gptp) {
float freq;
@@ -248,7 +384,7 @@ static void gpt_cb8(GPTDriver *gptp) {
float freq_alt = 0;
if (voices > 1) {
if (polyphony_rate == 0) {
if (glissando) {
if (glissando[TIMER_6_INDEX]) {
if (frequency_alt != 0 && frequency_alt < frequencies[voices - 2] && frequency_alt < frequencies[voices - 2] * pow(2, -440/frequencies[voices - 2]/12/2)) {
frequency_alt = frequency_alt * pow(2, 440/frequency_alt/12/2);
} else if (frequency_alt != 0 && frequency_alt > frequencies[voices - 2] && frequency_alt > frequencies[voices - 2] * pow(2, 440/frequencies[voices - 2]/12/2)) {
@@ -271,23 +407,22 @@ static void gpt_cb8(GPTDriver *gptp) {
#endif
}
if (envelope_index < 65535) {
envelope_index++;
if (envelope_index[TIMER_6_INDEX] < 65535) {
envelope_index[TIMER_6_INDEX]++;
}
freq_alt = voice_envelope(freq_alt);
freq_alt = voice_envelope(freq_alt, TIMER_6_INDEX);
if (freq_alt < 30.517578125) {
freq_alt = 30.52;
}
if (gpt6cfg1.frequency != (uint16_t)freq_alt) {
gpt6cfg1.frequency = freq_alt;
restart_gpt6();
if (GET_CHANNEL_1_FREQ != (uint16_t)freq_alt) {
UPDATE_CHANNEL_1_FREQ(freq_alt);
}
//note_timbre;
} else {
// gptStopTimer(&GPTD6);
STOP_CHANNEL_1();
}
if (polyphony_rate > 0) {
@@ -309,7 +444,7 @@ static void gpt_cb8(GPTDriver *gptp) {
freq = frequencies[voice_place];
#endif
} else {
if (glissando) {
if (glissando[TIMER_7_INDEX]) {
if (frequency != 0 && frequency < frequencies[voices - 1] && frequency < frequencies[voices - 1] * pow(2, -440/frequencies[voices - 1]/12/2)) {
frequency = frequency * pow(2, 440/frequency/12/2);
} else if (frequency != 0 && frequency > frequencies[voices - 1] && frequency > frequencies[voices - 1] * pow(2, 440/frequencies[voices - 1]/12/2)) {
@@ -332,20 +467,19 @@ static void gpt_cb8(GPTDriver *gptp) {
#endif
}
if (envelope_index < 65535) {
envelope_index++;
if (envelope_index[TIMER_7_INDEX] < 65535) {
envelope_index[TIMER_7_INDEX]++;
}
freq = voice_envelope(freq);
freq = voice_envelope(freq, TIMER_7_INDEX);
if (freq < 30.517578125) {
freq = 30.52;
}
if (gpt7cfg1.frequency != (uint16_t)freq) {
gpt7cfg1.frequency = freq;
restart_gpt7();
if (GET_CHANNEL_2_FREQ != (uint16_t)freq) {
UPDATE_CHANNEL_2_FREQ(freq);
}
//note_timbre;
} else {
@@ -365,17 +499,15 @@ static void gpt_cb8(GPTDriver *gptp) {
freq = note_frequency;
#endif
if (envelope_index < 65535) {
envelope_index++;
if (envelope_index[TIMER_6_INDEX] < 65535) {
envelope_index[TIMER_6_INDEX]++;
}
freq = voice_envelope(freq);
freq = voice_envelope(freq, TIMER_6_INDEX);
if (gpt6cfg1.frequency != (uint16_t)freq) {
gpt6cfg1.frequency = freq;
restart_gpt6();
gpt7cfg1.frequency = freq;
restart_gpt7();
if (GET_CHANNEL_1_FREQ != (uint16_t)freq) {
UPDATE_CHANNEL_1_FREQ(freq);
UPDATE_CHANNEL_2_FREQ(freq);
}
//note_timbre;
} else {
@@ -385,7 +517,7 @@ static void gpt_cb8(GPTDriver *gptp) {
note_position++;
bool end_of_note = false;
if (gpt6cfg1.frequency > 0) {
if (GET_CHANNEL_1_FREQ > 0) {
if (!note_resting)
end_of_note = (note_position >= (note_length*16 - 1));
else
@@ -400,8 +532,8 @@ static void gpt_cb8(GPTDriver *gptp) {
if (notes_repeat) {
current_note = 0;
} else {
gptStopTimer(&GPTD6);
gptStopTimer(&GPTD7);
STOP_CHANNEL_1();
STOP_CHANNEL_2();
// gptStopTimer(&GPTD8);
playing_notes = false;
return;
@@ -419,7 +551,7 @@ static void gpt_cb8(GPTDriver *gptp) {
}
} else {
note_resting = false;
envelope_index = 0;
envelope_index[TIMER_6_INDEX] = 0;
note_frequency = (*notes_pointer)[current_note][0];
note_length = ((*notes_pointer)[current_note][1] / 4) * (((float)note_tempo) / 100);
}
@@ -450,7 +582,8 @@ void play_note(float freq, int vol) {
playing_note = true;
envelope_index = 0;
envelope_index[TIMER_6_INDEX] = 0;
envelope_index[TIMER_7_INDEX] = 0;
if (freq > 0) {
frequencies[voices] = freq;
@@ -493,8 +626,8 @@ void play_notes(float (*np)[][2], uint16_t n_count, bool n_repeat)
gptStart(&GPTD8, &gpt8cfg1);
gptStartContinuous(&GPTD8, 2U);
restart_gpt6();
restart_gpt7();
RESTART_CHANNEL_1();
RESTART_CHANNEL_2();
}
}
@@ -583,8 +716,8 @@ void decrease_polyphony_rate(float change) {
// Timbre function
void set_timbre(float timbre) {
note_timbre = timbre;
void set_timbre(float timbre, uint8_t timer_index) {
note_timbre[timer_index] = timbre;
}
// Tempo functions

View File

@@ -53,127 +53,127 @@
// Note Timbre
// Changes how the notes sound
#define TIMBRE_12 0.125
#define TIMBRE_25 0.250
#define TIMBRE_50 0.500
#define TIMBRE_75 0.750
#define TIMBRE_12 0.125f
#define TIMBRE_25 0.250f
#define TIMBRE_50 0.500f
#define TIMBRE_75 0.750f
#define TIMBRE_DEFAULT TIMBRE_50
// Notes - # = Octave
#define NOTE_REST 0.00
#define NOTE_REST 0.00f
/* These notes are currently bugged
#define NOTE_C0 16.35
#define NOTE_CS0 17.32
#define NOTE_D0 18.35
#define NOTE_DS0 19.45
#define NOTE_E0 20.60
#define NOTE_F0 21.83
#define NOTE_FS0 23.12
#define NOTE_G0 24.50
#define NOTE_GS0 25.96
#define NOTE_A0 27.50
#define NOTE_AS0 29.14
#define NOTE_B0 30.87
#define NOTE_C1 32.70
#define NOTE_CS1 34.65
#define NOTE_D1 36.71
#define NOTE_DS1 38.89
#define NOTE_E1 41.20
#define NOTE_F1 43.65
#define NOTE_FS1 46.25
#define NOTE_G1 49.00
#define NOTE_GS1 51.91
#define NOTE_A1 55.00
#define NOTE_AS1 58.27
#define NOTE_C0 16.35f
#define NOTE_CS0 17.32f
#define NOTE_D0 18.35f
#define NOTE_DS0 19.45f
#define NOTE_E0 20.60f
#define NOTE_F0 21.83f
#define NOTE_FS0 23.12f
#define NOTE_G0 24.50f
#define NOTE_GS0 25.96f
#define NOTE_A0 27.50f
#define NOTE_AS0 29.14f
#define NOTE_B0 30.87f
#define NOTE_C1 32.70f
#define NOTE_CS1 34.65f
#define NOTE_D1 36.71f
#define NOTE_DS1 38.89f
#define NOTE_E1 41.20f
#define NOTE_F1 43.65f
#define NOTE_FS1 46.25f
#define NOTE_G1 49.00f
#define NOTE_GS1 51.91f
#define NOTE_A1 55.00f
#define NOTE_AS1 58.27f
*/
#define NOTE_B1 61.74
#define NOTE_C2 65.41
#define NOTE_CS2 69.30
#define NOTE_D2 73.42
#define NOTE_DS2 77.78
#define NOTE_E2 82.41
#define NOTE_F2 87.31
#define NOTE_FS2 92.50
#define NOTE_G2 98.00
#define NOTE_GS2 103.83
#define NOTE_A2 110.00
#define NOTE_AS2 116.54
#define NOTE_B2 123.47
#define NOTE_C3 130.81
#define NOTE_CS3 138.59
#define NOTE_D3 146.83
#define NOTE_DS3 155.56
#define NOTE_E3 164.81
#define NOTE_F3 174.61
#define NOTE_FS3 185.00
#define NOTE_G3 196.00
#define NOTE_GS3 207.65
#define NOTE_A3 220.00
#define NOTE_AS3 233.08
#define NOTE_B3 246.94
#define NOTE_C4 261.63
#define NOTE_CS4 277.18
#define NOTE_D4 293.66
#define NOTE_DS4 311.13
#define NOTE_E4 329.63
#define NOTE_F4 349.23
#define NOTE_FS4 369.99
#define NOTE_G4 392.00
#define NOTE_GS4 415.30
#define NOTE_A4 440.00
#define NOTE_AS4 466.16
#define NOTE_B4 493.88
#define NOTE_C5 523.25
#define NOTE_CS5 554.37
#define NOTE_D5 587.33
#define NOTE_DS5 622.25
#define NOTE_E5 659.26
#define NOTE_F5 698.46
#define NOTE_FS5 739.99
#define NOTE_G5 783.99
#define NOTE_GS5 830.61
#define NOTE_A5 880.00
#define NOTE_AS5 932.33
#define NOTE_B5 987.77
#define NOTE_C6 1046.50
#define NOTE_CS6 1108.73
#define NOTE_D6 1174.66
#define NOTE_DS6 1244.51
#define NOTE_E6 1318.51
#define NOTE_F6 1396.91
#define NOTE_FS6 1479.98
#define NOTE_G6 1567.98
#define NOTE_GS6 1661.22
#define NOTE_A6 1760.00
#define NOTE_AS6 1864.66
#define NOTE_B6 1975.53
#define NOTE_C7 2093.00
#define NOTE_CS7 2217.46
#define NOTE_D7 2349.32
#define NOTE_DS7 2489.02
#define NOTE_E7 2637.02
#define NOTE_F7 2793.83
#define NOTE_FS7 2959.96
#define NOTE_G7 3135.96
#define NOTE_GS7 3322.44
#define NOTE_A7 3520.00
#define NOTE_AS7 3729.31
#define NOTE_B7 3951.07
#define NOTE_C8 4186.01
#define NOTE_CS8 4434.92
#define NOTE_D8 4698.64
#define NOTE_DS8 4978.03
#define NOTE_E8 5274.04
#define NOTE_F8 5587.65
#define NOTE_FS8 5919.91
#define NOTE_G8 6271.93
#define NOTE_GS8 6644.88
#define NOTE_A8 7040.00
#define NOTE_AS8 7458.62
#define NOTE_B8 7902.13
#define NOTE_B1 61.74f
#define NOTE_C2 65.41f
#define NOTE_CS2 69.30f
#define NOTE_D2 73.42f
#define NOTE_DS2 77.78f
#define NOTE_E2 82.41f
#define NOTE_F2 87.31f
#define NOTE_FS2 92.50f
#define NOTE_G2 98.00f
#define NOTE_GS2 103.83f
#define NOTE_A2 110.00f
#define NOTE_AS2 116.54f
#define NOTE_B2 123.47f
#define NOTE_C3 130.81f
#define NOTE_CS3 138.59f
#define NOTE_D3 146.83f
#define NOTE_DS3 155.56f
#define NOTE_E3 164.81f
#define NOTE_F3 174.61f
#define NOTE_FS3 185.00f
#define NOTE_G3 196.00f
#define NOTE_GS3 207.65f
#define NOTE_A3 220.00f
#define NOTE_AS3 233.08f
#define NOTE_B3 246.94f
#define NOTE_C4 261.63f
#define NOTE_CS4 277.18f
#define NOTE_D4 293.66f
#define NOTE_DS4 311.13f
#define NOTE_E4 329.63f
#define NOTE_F4 349.23f
#define NOTE_FS4 369.99f
#define NOTE_G4 392.00f
#define NOTE_GS4 415.30f
#define NOTE_A4 440.00f
#define NOTE_AS4 466.16f
#define NOTE_B4 493.88f
#define NOTE_C5 523.25f
#define NOTE_CS5 554.37f
#define NOTE_D5 587.33f
#define NOTE_DS5 622.25f
#define NOTE_E5 659.26f
#define NOTE_F5 698.46f
#define NOTE_FS5 739.99f
#define NOTE_G5 783.99f
#define NOTE_GS5 830.61f
#define NOTE_A5 880.00f
#define NOTE_AS5 932.33f
#define NOTE_B5 987.77f
#define NOTE_C6 1046.50f
#define NOTE_CS6 1108.73f
#define NOTE_D6 1174.66f
#define NOTE_DS6 1244.51f
#define NOTE_E6 1318.51f
#define NOTE_F6 1396.91f
#define NOTE_FS6 1479.98f
#define NOTE_G6 1567.98f
#define NOTE_GS6 1661.22f
#define NOTE_A6 1760.00f
#define NOTE_AS6 1864.66f
#define NOTE_B6 1975.53f
#define NOTE_C7 2093.00f
#define NOTE_CS7 2217.46f
#define NOTE_D7 2349.32f
#define NOTE_DS7 2489.02f
#define NOTE_E7 2637.02f
#define NOTE_F7 2793.83f
#define NOTE_FS7 2959.96f
#define NOTE_G7 3135.96f
#define NOTE_GS7 3322.44f
#define NOTE_A7 3520.00f
#define NOTE_AS7 3729.31f
#define NOTE_B7 3951.07f
#define NOTE_C8 4186.01f
#define NOTE_CS8 4434.92f
#define NOTE_D8 4698.64f
#define NOTE_DS8 4978.03f
#define NOTE_E8 5274.04f
#define NOTE_F8 5587.65f
#define NOTE_FS8 5919.91f
#define NOTE_G8 6271.93f
#define NOTE_GS8 6644.88f
#define NOTE_A8 7040.00f
#define NOTE_AS8 7458.62f
#define NOTE_B8 7902.13f
// Flat Aliases
#define NOTE_DF0 NOTE_CS0

View File

@@ -53,6 +53,24 @@
E__NOTE(_CS4), E__NOTE(_B4), QD_NOTE(_AS4), \
E__NOTE(_AS4), E__NOTE(_AS4), QD_NOTE(_B4),
#define CLUEBOARD_SOUND \
HD_NOTE(_C3), HD_NOTE(_D3), HD_NOTE(_E3), HD_NOTE(_F3), HD_NOTE(_G3), HD_NOTE(_A4), HD_NOTE(_B4), HD_NOTE(_C4)
/*
HD_NOTE(_G3), HD_NOTE(_E3), HD_NOTE(_C3), \
Q__NOTE(_E3), Q__NOTE(_C3), Q__NOTE(_G3), \
Q__NOTE(_E3)
*/
/*
HD_NOTE(_C3), HD_NOTE(_G3), HD_NOTE(_E3), \
Q__NOTE(_G3), Q__NOTE(_E3), Q__NOTE(_G3), \
Q__NOTE(_F3)
*/
#define BASKET_CASE \
QD_NOTE(_G3), E__NOTE(_F3), E__NOTE(_E3), Q__NOTE(_F3), M__NOTE(_G3, 8+32), Q__NOTE(_REST), \
Q__NOTE(_B4), Q__NOTE(_C4), Q__NOTE(_B4), E__NOTE(_A4), Q__NOTE(_G3), M__NOTE(_G3, 8+32), Q__NOTE(_REST), \
Q__NOTE(_B4), Q__NOTE(_C4), Q__NOTE(_B4), E__NOTE(_A4), Q__NOTE(_G3), Q__NOTE(_G3), Q__NOTE(_G3), Q__NOTE(_G3), E__NOTE(_A4), E__NOTE(_C4), QD_NOTE(_B4), HD_NOTE(_B4)
#define STARTUP_SOUND \
E__NOTE(_E6), \
E__NOTE(_A6), \

View File

@@ -18,73 +18,91 @@
#include "stdlib.h"
// these are imported from audio.c
extern uint16_t envelope_index;
extern float note_timbre;
extern uint16_t envelope_index[NUMBER_OF_TIMERS];
extern float note_timbre[NUMBER_OF_TIMERS];
extern float polyphony_rate;
extern bool glissando;
extern bool glissando[NUMBER_OF_TIMERS];
voice_type voice = default_voice;
voice_type voice[NUMBER_OF_TIMERS] = {default_voice};
void set_voice(voice_type v) {
voice = v;
void set_all_voices(voice_type v) {
for (uint8_t i = 0; i < NUMBER_OF_TIMERS; i++) {
voice[i] = v;
}
}
void voice_iterate() {
voice = (voice + 1) % number_of_voices;
void all_voices_iterate(void) {
for (uint8_t i = 0; i < NUMBER_OF_TIMERS; i++) {
voice[i] = (voice[i] + 1) % number_of_voices;
}
}
void voice_deiterate() {
voice = (voice - 1 + number_of_voices) % number_of_voices;
void all_voices_deiterate(void) {
for (uint8_t i = 0; i < NUMBER_OF_TIMERS; i++) {
voice[i] = (voice[i] - 1 + number_of_voices) % number_of_voices;
}
}
float voice_envelope(float frequency) {
// envelope_index ranges from 0 to 0xFFFF, which is preserved at 880.0 Hz
void set_voice(voice_type v, uint8_t timer_index) {
voice[timer_index] = v;
}
void voice_iterate(uint8_t timer_index) {
voice[timer_index] = (voice[timer_index] + 1) % number_of_voices;
}
void voice_deiterate(uint8_t timer_index) {
voice[timer_index] = (voice[timer_index] - 1 + number_of_voices) % number_of_voices;
}
float voice_envelope(float frequency, uint8_t timer_index) {
// envelope_index[timer_index] ranges from 0 to 0xFFFF, which is preserved at 880.0 Hz
__attribute__ ((unused))
uint16_t compensated_index = (uint16_t)((float)envelope_index * (880.0 / frequency));
uint16_t compensated_index = (uint16_t)((float)envelope_index[timer_index] * (880.0 / frequency));
switch (voice) {
switch (voice[timer_index]) {
case default_voice:
glissando = false;
note_timbre = TIMBRE_50;
glissando[timer_index] = false;
note_timbre[timer_index] = TIMBRE_50;
polyphony_rate = 0;
break;
#ifdef AUDIO_VOICES
case something:
glissando = false;
glissando[timer_index] = false;
polyphony_rate = 0;
switch (compensated_index) {
case 0 ... 9:
note_timbre = TIMBRE_12;
note_timbre[timer_index] = TIMBRE_12;
break;
case 10 ... 19:
note_timbre = TIMBRE_25;
note_timbre[timer_index] = TIMBRE_25;
break;
case 20 ... 200:
note_timbre = .125 + .125;
note_timbre[timer_index] = .125 + .125;
break;
default:
note_timbre = .125;
note_timbre[timer_index] = .125;
break;
}
break;
case drums:
glissando = false;
glissando[timer_index] = false;
polyphony_rate = 0;
// switch (compensated_index) {
// case 0 ... 10:
// note_timbre = 0.5;
// note_timbre[timer_index] = 0.5;
// break;
// case 11 ... 20:
// note_timbre = 0.5 * (21 - compensated_index) / 10;
// note_timbre[timer_index] = 0.5 * (21 - compensated_index) / 10;
// break;
// default:
// note_timbre = 0;
// note_timbre[timer_index] = 0;
// break;
// }
// frequency = (rand() % (int)(frequency * 1.2 - frequency)) + (frequency * 0.8);
@@ -95,15 +113,15 @@ float voice_envelope(float frequency) {
// Bass drum: 60 - 100 Hz
frequency = (rand() % (int)(40)) + 60;
switch (envelope_index) {
switch (envelope_index[timer_index]) {
case 0 ... 10:
note_timbre = 0.5;
note_timbre[timer_index] = 0.5;
break;
case 11 ... 20:
note_timbre = 0.5 * (21 - envelope_index) / 10;
note_timbre[timer_index] = 0.5 * (21 - envelope_index[timer_index]) / 10;
break;
default:
note_timbre = 0;
note_timbre[timer_index] = 0;
break;
}
@@ -112,15 +130,15 @@ float voice_envelope(float frequency) {
// Snare drum: 1 - 2 KHz
frequency = (rand() % (int)(1000)) + 1000;
switch (envelope_index) {
switch (envelope_index[timer_index]) {
case 0 ... 5:
note_timbre = 0.5;
note_timbre[timer_index] = 0.5;
break;
case 6 ... 20:
note_timbre = 0.5 * (21 - envelope_index) / 15;
note_timbre[timer_index] = 0.5 * (21 - envelope_index[timer_index]) / 15;
break;
default:
note_timbre = 0;
note_timbre[timer_index] = 0;
break;
}
@@ -128,15 +146,15 @@ float voice_envelope(float frequency) {
// Closed Hi-hat: 3 - 5 KHz
frequency = (rand() % (int)(2000)) + 3000;
switch (envelope_index) {
switch (envelope_index[timer_index]) {
case 0 ... 15:
note_timbre = 0.5;
note_timbre[timer_index] = 0.5;
break;
case 16 ... 20:
note_timbre = 0.5 * (21 - envelope_index) / 5;
note_timbre[timer_index] = 0.5 * (21 - envelope_index[timer_index]) / 5;
break;
default:
note_timbre = 0;
note_timbre[timer_index] = 0;
break;
}
@@ -144,96 +162,96 @@ float voice_envelope(float frequency) {
// Open Hi-hat: 3 - 5 KHz
frequency = (rand() % (int)(2000)) + 3000;
switch (envelope_index) {
switch (envelope_index[timer_index]) {
case 0 ... 35:
note_timbre = 0.5;
note_timbre[timer_index] = 0.5;
break;
case 36 ... 50:
note_timbre = 0.5 * (51 - envelope_index) / 15;
note_timbre[timer_index] = 0.5 * (51 - envelope_index[timer_index]) / 15;
break;
default:
note_timbre = 0;
note_timbre[timer_index] = 0;
break;
}
}
break;
case butts_fader:
glissando = true;
glissando[timer_index] = true;
polyphony_rate = 0;
switch (compensated_index) {
case 0 ... 9:
frequency = frequency / 4;
note_timbre = TIMBRE_12;
note_timbre[timer_index] = TIMBRE_12;
break;
case 10 ... 19:
frequency = frequency / 2;
note_timbre = TIMBRE_12;
note_timbre[timer_index] = TIMBRE_12;
break;
case 20 ... 200:
note_timbre = .125 - pow(((float)compensated_index - 20) / (200 - 20), 2)*.125;
note_timbre[timer_index] = .125 - pow(((float)compensated_index - 20) / (200 - 20), 2)*.125;
break;
default:
note_timbre = 0;
note_timbre[timer_index] = 0;
break;
}
break;
// case octave_crunch:
// polyphony_rate = 0;
// switch (compensated_index) {
// case 0 ... 9:
// case 20 ... 24:
// case 30 ... 32:
// frequency = frequency / 2;
// note_timbre = TIMBRE_12;
// break;
case octave_crunch:
polyphony_rate = 0;
switch (compensated_index) {
case 0 ... 9:
case 20 ... 24:
case 30 ... 32:
frequency = frequency / 2;
note_timbre[timer_index] = TIMBRE_12;
break;
// case 10 ... 19:
// case 25 ... 29:
// case 33 ... 35:
// frequency = frequency * 2;
// note_timbre = TIMBRE_12;
// break;
case 10 ... 19:
case 25 ... 29:
case 33 ... 35:
frequency = frequency * 2;
note_timbre[timer_index] = TIMBRE_12;
break;
// default:
// note_timbre = TIMBRE_12;
// break;
// }
// break;
default:
note_timbre[timer_index] = TIMBRE_12;
break;
}
break;
case duty_osc:
// This slows the loop down a substantial amount, so higher notes may freeze
glissando = true;
glissando[timer_index] = true;
polyphony_rate = 0;
switch (compensated_index) {
default:
#define OCS_SPEED 10
#define OCS_AMP .25
// sine wave is slow
// note_timbre = (sin((float)compensated_index/10000*OCS_SPEED) * OCS_AMP / 2) + .5;
// note_timbre[timer_index] = (sin((float)compensated_index/10000*OCS_SPEED) * OCS_AMP / 2) + .5;
// triangle wave is a bit faster
note_timbre = (float)abs((compensated_index*OCS_SPEED % 3000) - 1500) * ( OCS_AMP / 1500 ) + (1 - OCS_AMP) / 2;
note_timbre[timer_index] = (float)abs((compensated_index*OCS_SPEED % 3000) - 1500) * ( OCS_AMP / 1500 ) + (1 - OCS_AMP) / 2;
break;
}
break;
case duty_octave_down:
glissando = true;
glissando[timer_index] = true;
polyphony_rate = 0;
note_timbre = (envelope_index % 2) * .125 + .375 * 2;
if ((envelope_index % 4) == 0)
note_timbre = 0.5;
if ((envelope_index % 8) == 0)
note_timbre = 0;
note_timbre[timer_index] = (envelope_index[timer_index] % 2) * .125 + .375 * 2;
if ((envelope_index[timer_index] % 4) == 0)
note_timbre[timer_index] = 0.5;
if ((envelope_index[timer_index] % 8) == 0)
note_timbre[timer_index] = 0;
break;
case delayed_vibrato:
glissando = true;
glissando[timer_index] = true;
polyphony_rate = 0;
note_timbre = TIMBRE_50;
note_timbre[timer_index] = TIMBRE_50;
#define VOICE_VIBRATO_DELAY 150
#define VOICE_VIBRATO_SPEED 50
switch (compensated_index) {
@@ -246,10 +264,10 @@ float voice_envelope(float frequency) {
break;
// case delayed_vibrato_octave:
// polyphony_rate = 0;
// if ((envelope_index % 2) == 1) {
// note_timbre = 0.55;
// if ((envelope_index[timer_index] % 2) == 1) {
// note_timbre[timer_index] = 0.55;
// } else {
// note_timbre = 0.45;
// note_timbre[timer_index] = 0.45;
// }
// #define VOICE_VIBRATO_DELAY 150
// #define VOICE_VIBRATO_SPEED 50
@@ -262,28 +280,28 @@ float voice_envelope(float frequency) {
// }
// break;
// case duty_fifth_down:
// note_timbre = 0.5;
// if ((envelope_index % 3) == 0)
// note_timbre = 0.75;
// note_timbre[timer_index] = 0.5;
// if ((envelope_index[timer_index] % 3) == 0)
// note_timbre[timer_index] = 0.75;
// break;
// case duty_fourth_down:
// note_timbre = 0.0;
// if ((envelope_index % 12) == 0)
// note_timbre = 0.75;
// if (((envelope_index % 12) % 4) != 1)
// note_timbre = 0.75;
// note_timbre[timer_index] = 0.0;
// if ((envelope_index[timer_index] % 12) == 0)
// note_timbre[timer_index] = 0.75;
// if (((envelope_index[timer_index] % 12) % 4) != 1)
// note_timbre[timer_index] = 0.75;
// break;
// case duty_third_down:
// note_timbre = 0.5;
// if ((envelope_index % 5) == 0)
// note_timbre = 0.75;
// note_timbre[timer_index] = 0.5;
// if ((envelope_index[timer_index] % 5) == 0)
// note_timbre[timer_index] = 0.75;
// break;
// case duty_fifth_third_down:
// note_timbre = 0.5;
// if ((envelope_index % 5) == 0)
// note_timbre = 0.75;
// if ((envelope_index % 3) == 0)
// note_timbre = 0.25;
// note_timbre[timer_index] = 0.5;
// if ((envelope_index[timer_index] % 5) == 0)
// note_timbre[timer_index] = 0.75;
// if ((envelope_index[timer_index] % 3) == 0)
// note_timbre[timer_index] = 0.25;
// break;
#endif

View File

@@ -24,7 +24,7 @@
#ifndef VOICES_H
#define VOICES_H
float voice_envelope(float frequency);
float voice_envelope(float frequency, uint8_t timer_index);
typedef enum {
default_voice,
@@ -45,8 +45,12 @@ typedef enum {
number_of_voices // important that this is last
} voice_type;
void set_voice(voice_type v);
void voice_iterate(void);
void voice_deiterate(void);
void set_all_voices(voice_type v);
void all_voices_iterate(void);
void all_voices_deiterate(void);
void set_voice(voice_type v, uint8_t timer_index);
void voice_iterate(uint8_t timer_index);
void voice_deiterate(uint8_t timer_index);
#endif

View File

@@ -38,13 +38,13 @@ bool process_audio(uint16_t keycode, keyrecord_t *record) {
}
if (keycode == MUV_IN && record->event.pressed) {
voice_iterate();
all_voices_iterate();
PLAY_SONG(voice_change_song);
return false;
}
if (keycode == MUV_DE && record->event.pressed) {
voice_deiterate();
all_voices_deiterate();
PLAY_SONG(voice_change_song);
return false;
}

View File

@@ -28,7 +28,7 @@ bool music_activated = false;
bool midi_activated = false;
uint8_t music_starting_note = 0x0C;
int music_offset = 7;
uint8_t music_mode = MUSIC_MODE_CHROMATIC;
uint8_t music_mode = MUSIC_MODE_MAJOR;
// music sequencer
static bool music_sequence_recording = false;