Compare commits

...

11 Commits

Author SHA1 Message Date
skullY
0dda5b8541 Add songs to Clueboard 66% Hotswap 2018-03-15 16:56:15 -07:00
skullY
ccb75398c2 Add support for clueboard hotswap audio 2018-03-15 16:44:20 -07:00
skullY
8b15168d0c Make audio debugging easier 2018-03-15 16:40:15 -07:00
skullY
ac36c24e65 Merge remote-tracking branch 'origin/master' into clueboard_hotswap 2018-03-15 16:38:44 -07:00
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
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
13 changed files with 703 additions and 172 deletions

View File

@ -26,7 +26,7 @@
/* Speaker configuration
*/
//#define SPEAKER_PIN B7 // FIXME: find the correct name for this define
#define B7_AUDIO
/* Backlight configuration
*/

View File

@ -6,6 +6,30 @@
#define _FL 1
#define _CL 2
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 PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
/* Keymap _BL: Base Layer (Default Layer)
*/
@ -30,7 +54,67 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
[_CL] = LAYOUT(
BL_STEP,RGB_M_P,RGB_M_B,RGB_M_R,RGB_M_SW,RGB_M_SN,RGB_M_K,RGB_M_X,RGB_M_G,_______,_______,_______,_______, RGB_TOG, RGB_VAI, \
_______,_______,_______,_______,RESET, _______,_______,_______,_______,_______,_______,_______,_______,_______, RGB_VAD, \
_______,_______,MO(_CL),_______,_______,_______,_______,_______,_______,_______,_______,_______, _______, \
_______,_______,MO(_CL),_______,S_BSKTC,S_ODEJY,S_RCKBY,S_DOEDR,S_SCALE,S_ONEUP,S_COIN, S_SONIC, S_ZELDA, \
_______,MO(_FL),_______,_______,_______,_______,_______,_______,_______,_______,_______,_______,MO(_FL),_______, RGB_SAI, \
_______,_______,_______, RGB_MOD,RGB_MOD, _______,_______,MO(_FL),_______,RGB_HUD,RGB_SAD,RGB_HUI),
};
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

@ -6,6 +6,7 @@ ARCH = AVR8
F_USB = $(F_CPU)
OPT_DEFS += -DINTERRUPT_CONTROL_ENDPOINT
OPT_DEFS += -DBOOTLOADER_SIZE=4096
EXTRAFLAGS += -flto
# Build Options
# comment out to disable the options.
@ -14,9 +15,9 @@ BOOTMAGIC_ENABLE = no # Virtual DIP switch configuration(+1000)
MOUSEKEY_ENABLE = no # Mouse keys(+4700)
EXTRAKEY_ENABLE = yes # Audio control and System control(+450)
CONSOLE_ENABLE = yes # Console for debug(+400)
COMMAND_ENABLE = yes # Commands for debug and configuration
COMMAND_ENABLE = no # Commands for debug and configuration
NKRO_ENABLE = yes # USB Nkey Rollover - if this doesn't work, see here: https://github.com/tmk/tmk_keyboard/wiki/FAQ#nkro-doesnt-work
AUDIO_ENABLE = no
AUDIO_ENABLE = yes
RGBLIGHT_ENABLE = yes # Enable keyboard underlight functionality
MIDI_ENABLE = no # MIDI controls
UNICODE_ENABLE = no # Unicode

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

@ -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;
@ -200,7 +247,7 @@ void audio_init()
void stop_all_notes()
{
dprintf("audio stop all notes");
dprintf("audio stop all notes\n");
if (!audio_initialized) {
audio_init();
@ -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
@ -233,7 +280,7 @@ void stop_all_notes()
void stop_note(float freq)
{
dprintf("audio stop note freq=%d", (int)freq);
dprintf("audio stop note freq=%d\n", (int)freq);
if (playing_note) {
if (!audio_initialized) {
@ -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);
}
@ -620,7 +679,7 @@ ISR(TIMER1_COMPA_vect)
void play_note(float freq, int vol) {
dprintf("audio play note freq=%d vol=%d", (int)freq, vol);
dprintf("audio play note freq=%d vol=%d\n", (int)freq, vol);
if (!audio_initialized) {
audio_init();
@ -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

@ -47,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;
@ -69,8 +69,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)
@ -241,7 +241,7 @@ static const dacsample_t dac_buffer_2[DAC_BUFFER_SIZE] = {
* DAC streaming callback.
*/
size_t nx = 0, ny = 0, nz = 0;
static void end_cb1(DACDriver *dacp, dacsample_t *buffer, size_t n) {
static void end_cb1(DACDriver *dacp, const dacsample_t *buffer, size_t n) {
(void)dacp;
@ -434,7 +434,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)) {
@ -457,16 +457,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 (GET_CHANNEL_1_FREQ != (uint16_t)freq_alt) {
UPDATE_CHANNEL_1_FREQ(freq_alt);
}
//note_timbre;
} else {
STOP_CHANNEL_1();
if (GET_CHANNEL_2_FREQ != (uint16_t)freq_alt) {
UPDATE_CHANNEL_2_FREQ(freq_alt);
}
@ -492,7 +498,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)) {
@ -515,17 +521,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 (GET_CHANNEL_2_FREQ != (uint16_t)freq) {
UPDATE_CHANNEL_2_FREQ(freq);
if (GET_CHANNEL_1_FREQ != (uint16_t)freq) {
UPDATE_CHANNEL_1_FREQ(freq);
}
@ -545,10 +553,10 @@ 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 (GET_CHANNEL_1_FREQ != (uint16_t)freq) {
@ -597,7 +605,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);
}
@ -628,7 +636,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;
@ -762,8 +771,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

@ -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;