note sliding - on right now

master
Jack Humbert 2016-04-18 21:01:48 -04:00
parent 89a78f4a11
commit e49712b559
3 changed files with 63 additions and 45 deletions

View File

@ -14,8 +14,9 @@
#define _DVORAK 2
#define _LOWER 3
#define _RAISE 4
#define _ADJUST 5
#define _MUSIC 6
#define _ADJUST 6
#define _MUSIC 7
#define _STOPPER 5
// Macro name shortcuts
#define QWERTY M(_QWERTY)
@ -172,7 +173,19 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
{_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______},
{_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______},
{_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______}
},
/* Stopper
*
*/
[_STOPPER] = {
{XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX},
{XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX},
{XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX},
{XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX},
{XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, LOWER, XXXXXXX, RAISE, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX}
}
};
const uint16_t PROGMEM fn_actions[] = {
@ -225,6 +238,7 @@ float tone_music[][2] = {
{440.0*pow(2.0,(24)/12.0), 8}
};
float ode_to_joy[][2] = SONG(ODE_TO_JOY);
float goodbye[][2] = SONG(GOODBYE_SOUND);
#endif
void persistant_default_layer_set(uint16_t default_layer) {
@ -306,6 +320,7 @@ const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
if (record->event.pressed) {
#ifdef AUDIO_ENABLE
layer_off(_MUSIC);
layer_off(_STOPPER);
stop_all_notes();
#endif
}
@ -317,6 +332,7 @@ const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
set_tempo(150);
PLAY_NOTE_ARRAY(ode_to_joy, false, .25);
layer_on(_MUSIC);
layer_on(_STOPPER);
#endif
}
break;
@ -345,3 +361,9 @@ void matrix_init_user(void) {
PLAY_NOTE_ARRAY(start_up, false, 0);
#endif
}
void play_goodbye_tone()
{
PLAY_NOTE_ARRAY(goodbye, false, 0);
_delay_ms(2000);
}

View File

@ -65,6 +65,7 @@ uint8_t notes_count;
bool notes_repeat;
float notes_rest;
bool note_resting = false;
int note_flipper = 0;
uint8_t current_note = 0;
uint8_t rest_counter = 0;
@ -127,6 +128,9 @@ void stop_note(double freq) {
voices--;
if (voices < 0)
voices = 0;
if (voice_place >= voices) {
voice_place = 0;
}
if (voices == 0) {
#ifdef PWM_AUDIO
TIMSK3 &= ~_BV(OCIE3A);
@ -137,25 +141,6 @@ void stop_note(double freq) {
frequency = 0;
volume = 0;
note = false;
} else {
double freq = frequencies[voices - 1];
int vol = volumes[voices - 1];
double starting_f = frequency;
if (frequency < freq) {
sliding = true;
for (double f = starting_f; f <= freq; f += ((freq - starting_f) / 2000.0)) {
frequency = f;
}
sliding = false;
} else if (frequency > freq) {
sliding = true;
for (double f = starting_f; f >= freq; f -= ((starting_f - freq) / 2000.0)) {
frequency = f;
}
sliding = false;
}
frequency = freq;
volume = vol;
}
}
}
@ -248,16 +233,41 @@ ISR(TIMER3_COMPA_vect) {
OCR4A = sum;
}
#else
if (frequency > 0) {
if (frequencies[voice_place] > 0) {
// if (frequencies[voice_place] > 880.0) {
// if (note_flipper == 100) {
// note_flipper = 0;
// return;
// }
// note_flipper++;
// } else {
// note_flipper = 0;
// }
// ICR3 = (int)(((double)F_CPU) / frequency); // Set max to the period
// OCR3A = (int)(((double)F_CPU) / frequency) >> 1; // Set compare to half the period
double freq;
if (false) {
voice_place %= voices;
if (place > (frequencies[voice_place] / 50)) {
voice_place = (voice_place + 1) % voices;
place = 0.0;
}
ICR3 = (int)(((double)F_CPU) / (frequencies[voice_place] * CPU_PRESCALER)); // Set max to the period
OCR3A = (int)((((double)F_CPU) / (frequencies[voice_place] * CPU_PRESCALER)) * note_timbre); // Set compare to half the period
freq = frequencies[voice_place];
} else {
if (frequency != 0) {
if (frequency < frequencies[voices - 1]) {
frequency = frequency * 1.01454533494;
} else if (frequency > frequencies[voices - 1]) {
frequency = frequency * 0.98566319864;
}
} else {
frequency = frequencies[voices - 1];
}
freq = frequency;
}
ICR3 = (int)(((double)F_CPU) / (freq * CPU_PRESCALER)); // Set max to the period
OCR3A = (int)((((double)F_CPU) / (freq * CPU_PRESCALER)) * note_timbre); // Set compare to half the period
//OCR3A = (int)(((double)F_CPU) / (frequencies[voice_place] * CPU_PRESCALER)) >> 1 * duty_place; // Set compare to half the period
place++;
// if (duty_counter > (frequencies[voice_place] / 500)) {
@ -413,23 +423,8 @@ if (audio_config.enable && voices < 8) {
freq = freq / SAMPLE_RATE;
#endif
if (freq > 0) {
if (frequency != 0) {
double starting_f = frequency;
if (frequency < freq) {
for (double f = starting_f; f <= freq; f += ((freq - starting_f) / 2000.0)) {
frequency = f;
}
} else if (frequency > freq) {
for (double f = starting_f; f >= freq; f -= ((starting_f - freq) / 2000.0)) {
frequency = f;
}
}
}
frequency = freq;
volume = vol;
frequencies[voices] = frequency;
volumes[voices] = volume;
frequencies[voices] = freq;
volumes[voices] = vol;
voices++;
}

View File

@ -184,6 +184,7 @@ static action_t keycode_to_action(uint16_t keycode)
case RESET: ; // RESET is 0x5000, which is why this is here
clear_keyboard();
#ifdef AUDIO_ENABLE
stop_all_notes();
play_goodbye_tone();
#endif
_delay_ms(250);