updates to preonic default, music mode integrated
parent
142ce47698
commit
86169833c5
|
@ -1,31 +1,40 @@
|
||||||
#include "preonic.h"
|
#include "preonic.h"
|
||||||
#include "action_layer.h"
|
#include "action_layer.h"
|
||||||
|
#include "eeconfig.h"
|
||||||
#ifdef AUDIO_ENABLE
|
#ifdef AUDIO_ENABLE
|
||||||
#include "audio.h"
|
#include "audio.h"
|
||||||
|
#define SCALE (int []){ 0 + (12*0), 2 + (12*0), 4 + (12*0), 5 + (12*0), 7 + (12*0), 9 + (12*0), 11 + (12*0), \
|
||||||
|
0 + (12*1), 2 + (12*1), 4 + (12*1), 5 + (12*1), 7 + (12*1), 9 + (12*1), 11 + (12*1), \
|
||||||
|
0 + (12*2), 2 + (12*2), 4 + (12*2), 5 + (12*2), 7 + (12*2), 9 + (12*2), 11 + (12*2), \
|
||||||
|
0 + (12*3), 2 + (12*3), 4 + (12*3), 5 + (12*3), 7 + (12*3), 9 + (12*3), 11 + (12*3), \
|
||||||
|
0 + (12*4), 2 + (12*4), 4 + (12*4), 5 + (12*4), 7 + (12*4), 9 + (12*4), 11 + (12*4), }
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Each layer gets a name for readability, which is then used in the keymap matrix below.
|
// Each layer gets a name for readability, which is then used in the keymap matrix below.
|
||||||
// The underscores don't mean anything - you can have a layer called STUFF or any other name.
|
// The underscores don't mean anything - you can have a layer called STUFF or any other name.
|
||||||
// Layer names don't all need to be of the same length, obviously, and you can also skip them
|
// Layer names don't all need to be of the same length, obviously, and you can also skip them
|
||||||
// entirely and just use numbers.
|
// entirely and just use numbers.
|
||||||
#define _QW 0
|
#define _QWERTY 0
|
||||||
#define _CM 1
|
#define _COLEMAK 1
|
||||||
#define _DV 2
|
#define _DVORAK 2
|
||||||
#define _LW 3
|
#define _LOWER 3
|
||||||
#define _RS 4
|
#define _RAISE 4
|
||||||
#define _AD 5
|
#define _ADJUST 5
|
||||||
|
#define _MUSIC 6
|
||||||
|
|
||||||
// Macro name shortcuts
|
// Macro name shortcuts
|
||||||
#define QWERTY M(_QW)
|
#define QWERTY M(_QWERTY)
|
||||||
#define COLEMAK M(_CM)
|
#define COLEMAK M(_COLEMAK)
|
||||||
#define DVORAK M(_DV)
|
#define DVORAK M(_DVORAK)
|
||||||
#define LOWER M(_LW)
|
#define LOWER M(_LOWER)
|
||||||
#define RAISE M(_RS)
|
#define RAISE M(_RAISE)
|
||||||
#define M_BL 5
|
#define M_BL 5
|
||||||
#ifdef AUDIO_ENABLE
|
#ifdef AUDIO_ENABLE
|
||||||
#define AUD_OFF M(6)
|
#define AUD_OFF M(6)
|
||||||
#define AUD_ON M(7)
|
#define AUD_ON M(7)
|
||||||
#endif
|
#endif
|
||||||
|
#define MUS_OFF M(8)
|
||||||
|
#define MUS_ON M(9)
|
||||||
|
|
||||||
// Fillers to make layering more clear
|
// Fillers to make layering more clear
|
||||||
#define _______ KC_TRNS
|
#define _______ KC_TRNS
|
||||||
|
@ -46,7 +55,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
|
||||||
* | Brite| Ctrl | Alt | GUI |Lower | Space |Raise | Left | Down | Up |Right |
|
* | Brite| Ctrl | Alt | GUI |Lower | Space |Raise | Left | Down | Up |Right |
|
||||||
* `-----------------------------------------------------------------------------------'
|
* `-----------------------------------------------------------------------------------'
|
||||||
*/
|
*/
|
||||||
[_QW] = {
|
[_QWERTY] = {
|
||||||
{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_GRV, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_BSPC},
|
||||||
{KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_DEL},
|
{KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_DEL},
|
||||||
{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_ESC, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT},
|
||||||
|
@ -67,7 +76,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
|
||||||
* | Brite| Ctrl | Alt | GUI |Lower | Space |Raise | Left | Down | Up |Right |
|
* | Brite| Ctrl | Alt | GUI |Lower | Space |Raise | Left | Down | Up |Right |
|
||||||
* `-----------------------------------------------------------------------------------'
|
* `-----------------------------------------------------------------------------------'
|
||||||
*/
|
*/
|
||||||
[_CM] = {
|
[_COLEMAK] = {
|
||||||
{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_GRV, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_BSPC},
|
||||||
{KC_TAB, KC_Q, KC_W, KC_F, KC_P, KC_G, KC_J, KC_L, KC_U, KC_Y, KC_SCLN, KC_DEL},
|
{KC_TAB, KC_Q, KC_W, KC_F, KC_P, KC_G, KC_J, KC_L, KC_U, KC_Y, KC_SCLN, KC_DEL},
|
||||||
{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_ESC, KC_A, KC_R, KC_S, KC_T, KC_D, KC_H, KC_N, KC_E, KC_I, KC_O, KC_QUOT},
|
||||||
|
@ -88,7 +97,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
|
||||||
* | Brite| Ctrl | Alt | GUI |Lower | Space |Raise | Left | Down | Up |Right |
|
* | Brite| Ctrl | Alt | GUI |Lower | Space |Raise | Left | Down | Up |Right |
|
||||||
* `-----------------------------------------------------------------------------------'
|
* `-----------------------------------------------------------------------------------'
|
||||||
*/
|
*/
|
||||||
[_DV] = {
|
[_DVORAK] = {
|
||||||
{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_GRV, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_BSPC},
|
||||||
{KC_TAB, KC_QUOT, KC_COMM, KC_DOT, KC_P, KC_Y, KC_F, KC_G, KC_C, KC_R, KC_L, KC_DEL},
|
{KC_TAB, KC_QUOT, KC_COMM, KC_DOT, KC_P, KC_Y, KC_F, KC_G, KC_C, KC_R, KC_L, KC_DEL},
|
||||||
{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_ESC, KC_A, KC_O, KC_E, KC_U, KC_I, KC_D, KC_H, KC_T, KC_N, KC_S, KC_SLSH},
|
||||||
|
@ -109,7 +118,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
|
||||||
* | | | | | | | | Next | Vol- | Vol+ | Play |
|
* | | | | | | | | Next | Vol- | Vol+ | Play |
|
||||||
* `-----------------------------------------------------------------------------------'
|
* `-----------------------------------------------------------------------------------'
|
||||||
*/
|
*/
|
||||||
[_LW] = {
|
[_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_TILD, KC_EXLM, KC_AT, KC_HASH, KC_DLR, KC_PERC, KC_CIRC, KC_AMPR, KC_ASTR, KC_LPRN, KC_RPRN, KC_BSPC},
|
||||||
{KC_TILD, KC_EXLM, KC_AT, KC_HASH, KC_DLR, KC_PERC, KC_CIRC, KC_AMPR, KC_ASTR, KC_LPRN, KC_RPRN, KC_DEL},
|
{KC_TILD, KC_EXLM, KC_AT, KC_HASH, KC_DLR, KC_PERC, KC_CIRC, KC_AMPR, KC_ASTR, KC_LPRN, KC_RPRN, KC_DEL},
|
||||||
{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_DEL, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_UNDS, KC_PLUS, KC_LCBR, KC_RCBR, KC_PIPE},
|
||||||
|
@ -130,7 +139,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
|
||||||
* | | | | | | | | Next | Vol- | Vol+ | Play |
|
* | | | | | | | | Next | Vol- | Vol+ | Play |
|
||||||
* `-----------------------------------------------------------------------------------'
|
* `-----------------------------------------------------------------------------------'
|
||||||
*/
|
*/
|
||||||
[_RS] = {
|
[_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_GRV, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_BSPC},
|
||||||
{KC_GRV, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_DEL},
|
{KC_GRV, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_DEL},
|
||||||
{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_DEL, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_MINS, KC_EQL, KC_LBRC, KC_RBRC, KC_BSLS},
|
||||||
|
@ -151,10 +160,21 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
|
||||||
* | | | | | | | | | | | |
|
* | | | | | | | | | | | |
|
||||||
* `-----------------------------------------------------------------------------------'
|
* `-----------------------------------------------------------------------------------'
|
||||||
*/
|
*/
|
||||||
[_AD] = {
|
[_ADJUST] = {
|
||||||
{KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12},
|
{KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12},
|
||||||
{_______, RESET, _______, _______, _______, _______, _______, _______, _______, _______, _______, KC_DEL},
|
{_______, RESET, _______, _______, _______, _______, _______, _______, _______, _______, _______, KC_DEL},
|
||||||
{_______, _______, _______, AUD_ON, AUD_OFF, _______, _______, QWERTY, COLEMAK, DVORAK, _______, _______},
|
{_______, _______, _______, AUD_ON, AUD_OFF, _______, _______, QWERTY, COLEMAK, DVORAK, _______, _______},
|
||||||
|
{_______, _______, _______, MUS_ON, MUS_OFF, _______, _______, _______, _______, _______, _______, _______},
|
||||||
|
{_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______}
|
||||||
|
},
|
||||||
|
|
||||||
|
/* Music (reserved for process_action_user)
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
[_MUSIC] = {
|
||||||
|
{_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______},
|
||||||
|
{_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______},
|
||||||
|
{_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______},
|
||||||
{_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______},
|
{_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______},
|
||||||
{_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______}
|
{_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______}
|
||||||
}
|
}
|
||||||
|
@ -166,24 +186,20 @@ const uint16_t PROGMEM fn_actions[] = {
|
||||||
|
|
||||||
#ifdef AUDIO_ENABLE
|
#ifdef AUDIO_ENABLE
|
||||||
float start_up[][2] = {
|
float start_up[][2] = {
|
||||||
{440.0*pow(2.0,(55)/12.0), 12},
|
{440.0*pow(2.0,(50)/12.0), 20},
|
||||||
{0, 2},
|
{440.0*pow(2.0,(62)/12.0), 8},
|
||||||
{440.0*pow(2.0,(67)/12.0), 8},
|
{440.0*pow(2.0,(54)/12.0), 20},
|
||||||
{440.0*pow(2.0,(64)/12.0), 8},
|
{440.0*pow(2.0,(62)/12.0), 8}
|
||||||
{440.0*pow(2.0,(55)/12.0), 8},
|
|
||||||
{440.0*pow(2.0,(67)/12.0), 12},
|
|
||||||
{0, 2},
|
|
||||||
{440.0*pow(2.0,(67)/12.0), 12}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
float tone_qw[][2] = {
|
float tone_qwerty[][2] = {
|
||||||
{440.0*pow(2.0,(59)/12.0), 8},
|
{440.0*pow(2.0,(59)/12.0), 8},
|
||||||
{440.0*pow(2.0,(60)/12.0), 8},
|
{440.0*pow(2.0,(60)/12.0), 8},
|
||||||
{0, 4},
|
{0, 4},
|
||||||
{440.0*pow(2.0,(67)/12.0), 16}
|
{440.0*pow(2.0,(67)/12.0), 16}
|
||||||
};
|
};
|
||||||
|
|
||||||
float tone_cm[][2] = {
|
float tone_colemak[][2] = {
|
||||||
{440.0*pow(2.0,(59)/12.0), 8},
|
{440.0*pow(2.0,(59)/12.0), 8},
|
||||||
{440.0*pow(2.0,(60)/12.0), 8},
|
{440.0*pow(2.0,(60)/12.0), 8},
|
||||||
{0, 4},
|
{0, 4},
|
||||||
|
@ -192,7 +208,7 @@ float tone_cm[][2] = {
|
||||||
{440.0*pow(2.0,(71)/12.0), 12}
|
{440.0*pow(2.0,(71)/12.0), 12}
|
||||||
};
|
};
|
||||||
|
|
||||||
float tone_dv[][2] = {
|
float tone_dvorak[][2] = {
|
||||||
{440.0*pow(2.0,(59)/12.0), 8},
|
{440.0*pow(2.0,(59)/12.0), 8},
|
||||||
{440.0*pow(2.0,(60)/12.0), 8},
|
{440.0*pow(2.0,(60)/12.0), 8},
|
||||||
{0, 4},
|
{0, 4},
|
||||||
|
@ -202,53 +218,66 @@ float tone_dv[][2] = {
|
||||||
{0, 4},
|
{0, 4},
|
||||||
{440.0*pow(2.0,(67)/12.0), 8}
|
{440.0*pow(2.0,(67)/12.0), 8}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
float tone_music[][2] = {
|
||||||
|
{440.0*pow(2.0,(48)/12.0), 8},
|
||||||
|
{440.0*pow(2.0,(50)/12.0), 8},
|
||||||
|
{440.0*pow(2.0,(52)/12.0), 8},
|
||||||
|
{440.0*pow(2.0,(53)/12.0), 8},
|
||||||
|
{440.0*pow(2.0,(55)/12.0), 8},
|
||||||
|
{440.0*pow(2.0,(57)/12.0), 8},
|
||||||
|
{440.0*pow(2.0,(59)/12.0), 8},
|
||||||
|
{440.0*pow(2.0,(60)/12.0), 8}
|
||||||
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
|
const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
|
||||||
{
|
{
|
||||||
// MACRODOWN only works in this function
|
|
||||||
switch(id) {
|
switch(id) {
|
||||||
case _QW:
|
case _QWERTY:
|
||||||
if (record->event.pressed) {
|
if (record->event.pressed) {
|
||||||
#ifdef AUDIO_ENABLE
|
#ifdef AUDIO_ENABLE
|
||||||
play_notes(&tone_qw, 4, false);
|
play_notes(&tone_qwerty, 4, false);
|
||||||
#endif
|
#endif
|
||||||
default_layer_set(1UL<<_QW);
|
eeconfig_write_default_layer(1UL<<_QWERTY);
|
||||||
|
default_layer_set(1UL<<_QWERTY);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case _CM:
|
case _COLEMAK:
|
||||||
if (record->event.pressed) {
|
if (record->event.pressed) {
|
||||||
#ifdef AUDIO_ENABLE
|
#ifdef AUDIO_ENABLE
|
||||||
play_notes(&tone_cm, 6, false);
|
play_notes(&tone_colemak, 6, false);
|
||||||
#endif
|
#endif
|
||||||
default_layer_set(1UL<<_CM);
|
eeconfig_write_default_layer(1UL<<_COLEMAK);
|
||||||
|
default_layer_set(1UL<<_COLEMAK);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case _DV:
|
case _DVORAK:
|
||||||
if (record->event.pressed) {
|
if (record->event.pressed) {
|
||||||
#ifdef AUDIO_ENABLE
|
#ifdef AUDIO_ENABLE
|
||||||
play_notes(&tone_dv, 8, false);
|
play_notes(&tone_dvorak, 8, false);
|
||||||
#endif
|
#endif
|
||||||
default_layer_set(1UL<<_DV);
|
eeconfig_write_default_layer(1UL<<_DVORAK);
|
||||||
|
default_layer_set(1UL<<_DVORAK);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case _LW:
|
case _LOWER:
|
||||||
if (record->event.pressed) {
|
if (record->event.pressed) {
|
||||||
layer_on(_LW);
|
layer_on(_LOWER);
|
||||||
update_tri_layer(_LW, _RS, _AD);
|
update_tri_layer(_LOWER, _RAISE, _ADJUST);
|
||||||
} else {
|
} else {
|
||||||
layer_off(_LW);
|
layer_off(_LOWER);
|
||||||
update_tri_layer(_LW, _RS, _AD);
|
update_tri_layer(_LOWER, _RAISE, _ADJUST);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case _RS:
|
case _RAISE:
|
||||||
if (record->event.pressed) {
|
if (record->event.pressed) {
|
||||||
layer_on(_RS);
|
layer_on(_RAISE);
|
||||||
update_tri_layer(_LW, _RS, _AD);
|
update_tri_layer(_LOWER, _RAISE, _ADJUST);
|
||||||
} else {
|
} else {
|
||||||
layer_off(_RS);
|
layer_off(_RAISE);
|
||||||
update_tri_layer(_LW, _RS, _AD);
|
update_tri_layer(_LOWER, _RAISE, _ADJUST);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case M_BL:
|
case M_BL:
|
||||||
|
@ -272,7 +301,23 @@ const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
|
||||||
if (record->event.pressed) {
|
if (record->event.pressed) {
|
||||||
#ifdef AUDIO_ENABLE
|
#ifdef AUDIO_ENABLE
|
||||||
audio_on();
|
audio_on();
|
||||||
play_notes(&start_up, 7, false);
|
play_notes(&start_up, 4, false);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 8:
|
||||||
|
if (record->event.pressed) {
|
||||||
|
#ifdef AUDIO_ENABLE
|
||||||
|
layer_off(_MUSIC);
|
||||||
|
stop_all_notes();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 9:
|
||||||
|
if (record->event.pressed) {
|
||||||
|
#ifdef AUDIO_ENABLE
|
||||||
|
play_notes(&tone_music, 8, false);
|
||||||
|
layer_on(_MUSIC);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -280,9 +325,24 @@ const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
|
||||||
return MACRO_NONE;
|
return MACRO_NONE;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
uint8_t starting_note = 0x0C;
|
||||||
|
int offset = 7;
|
||||||
|
|
||||||
|
void process_action_user(keyrecord_t *record) {
|
||||||
|
|
||||||
|
if (IS_LAYER_ON(_MUSIC)) {
|
||||||
|
if (record->event.pressed) {
|
||||||
|
play_note(((double)261.626)*pow(2.0, -2.0)*pow(2.0,(starting_note + SCALE[record->event.key.col + offset])/12.0+(MATRIX_ROWS - record->event.key.row)), 0xF);
|
||||||
|
} else {
|
||||||
|
stop_note(((double)261.626)*pow(2.0, -2.0)*pow(2.0,(starting_note + SCALE[record->event.key.col + offset])/12.0+(MATRIX_ROWS - record->event.key.row)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
void matrix_init_user(void) {
|
void matrix_init_user(void) {
|
||||||
#ifdef AUDIO_ENABLE
|
#ifdef AUDIO_ENABLE
|
||||||
init_notes();
|
init_notes();
|
||||||
play_notes(&start_up, 7, false);
|
play_notes(&start_up, 4, false);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,6 +32,8 @@ int voice_place = 0;
|
||||||
double frequency = 0;
|
double frequency = 0;
|
||||||
int volume = 0;
|
int volume = 0;
|
||||||
long position = 0;
|
long position = 0;
|
||||||
|
int duty_place = 1;
|
||||||
|
int duty_counter = 0;
|
||||||
|
|
||||||
double frequencies[8] = {0, 0, 0, 0, 0, 0, 0, 0};
|
double frequencies[8] = {0, 0, 0, 0, 0, 0, 0, 0};
|
||||||
int volumes[8] = {0, 0, 0, 0, 0, 0, 0, 0};
|
int volumes[8] = {0, 0, 0, 0, 0, 0, 0, 0};
|
||||||
|
@ -98,6 +100,7 @@ void stop_all_notes() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void stop_note(double freq) {
|
void stop_note(double freq) {
|
||||||
|
if (note) {
|
||||||
#ifdef PWM_AUDIO
|
#ifdef PWM_AUDIO
|
||||||
freq = freq / SAMPLE_RATE;
|
freq = freq / SAMPLE_RATE;
|
||||||
#endif
|
#endif
|
||||||
|
@ -146,6 +149,7 @@ void stop_note(double freq) {
|
||||||
frequency = freq;
|
frequency = freq;
|
||||||
volume = vol;
|
volume = vol;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void init_notes() {
|
void init_notes() {
|
||||||
|
@ -239,13 +243,19 @@ ISR(TIMER3_COMPA_vect) {
|
||||||
if (frequency > 0) {
|
if (frequency > 0) {
|
||||||
// ICR3 = (int)(((double)F_CPU) / frequency); // Set max to the period
|
// ICR3 = (int)(((double)F_CPU) / frequency); // Set max to the period
|
||||||
// OCR3A = (int)(((double)F_CPU) / frequency) >> 1; // Set compare to half the period
|
// OCR3A = (int)(((double)F_CPU) / frequency) >> 1; // Set compare to half the period
|
||||||
if (place > 10) {
|
voice_place %= voices;
|
||||||
|
if (place > (frequencies[voice_place] / 500)) {
|
||||||
voice_place = (voice_place + 1) % voices;
|
voice_place = (voice_place + 1) % voices;
|
||||||
place = 0.0;
|
place = 0.0;
|
||||||
}
|
}
|
||||||
ICR3 = (int)(((double)F_CPU) / frequencies[voice_place]); // Set max to the period
|
ICR3 = (int)(((double)F_CPU) / frequencies[voice_place]); // Set max to the period
|
||||||
OCR3A = (int)(((double)F_CPU) / frequencies[voice_place]) >> 1; // Set compare to half the period
|
OCR3A = (int)(((double)F_CPU) / frequencies[voice_place]) >> 1 * duty_place; // Set compare to half the period
|
||||||
place++;
|
place++;
|
||||||
|
// if (duty_counter > (frequencies[voice_place] / 500)) {
|
||||||
|
// duty_place = (duty_place % 3) + 1;
|
||||||
|
// duty_counter = 0;
|
||||||
|
// }
|
||||||
|
// duty_counter++;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
@ -375,7 +385,7 @@ if (audio_config.enable) {
|
||||||
|
|
||||||
void play_note(double freq, int vol) {
|
void play_note(double freq, int vol) {
|
||||||
|
|
||||||
if (audio_config.enable) {
|
if (audio_config.enable && voices < 8) {
|
||||||
|
|
||||||
if (notes)
|
if (notes)
|
||||||
stop_all_notes();
|
stop_all_notes();
|
||||||
|
|
Loading…
Reference in New Issue