aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJack Humbert <jack.humb@gmail.com>2016-04-16 21:31:40 -0400
committerJack Humbert <jack.humb@gmail.com>2016-04-16 21:31:40 -0400
commit41cc35425ab32c9a9492006da8b667d01d32dfa6 (patch)
tree23813e84df2687694ba82adf416f59a9e52e89b9
parent8f4ce501eb41cdd195d61e05c7e9dbe54545e6b9 (diff)
downloadqmk_firmware-41cc35425ab32c9a9492006da8b667d01d32dfa6.tar.gz
qmk_firmware-41cc35425ab32c9a9492006da8b667d01d32dfa6.zip
rests between notes as an argument
-rw-r--r--keyboard/planck/keymaps/default/keymap.c10
-rw-r--r--keyboard/preonic/keymaps/default/keymap.c16
-rw-r--r--quantum/audio.c29
-rw-r--r--quantum/audio.h3
-rw-r--r--quantum/keymap_common.c2
5 files changed, 37 insertions, 23 deletions
diff --git a/keyboard/planck/keymaps/default/keymap.c b/keyboard/planck/keymaps/default/keymap.c
index ede08ad7f..a6edefefd 100644
--- a/keyboard/planck/keymaps/default/keymap.c
+++ b/keyboard/planck/keymaps/default/keymap.c
@@ -194,7 +194,7 @@ const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
194 case _QW: 194 case _QW:
195 if (record->event.pressed) { 195 if (record->event.pressed) {
196 #ifdef AUDIO_ENABLE 196 #ifdef AUDIO_ENABLE
197 play_notes(&tone_qw, 4, false); 197 play_notes(&tone_qw, 4, false, 0);
198 #endif 198 #endif
199 default_layer_set(1UL<<_QW); 199 default_layer_set(1UL<<_QW);
200 } 200 }
@@ -202,7 +202,7 @@ const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
202 case _CM: 202 case _CM:
203 if (record->event.pressed) { 203 if (record->event.pressed) {
204 #ifdef AUDIO_ENABLE 204 #ifdef AUDIO_ENABLE
205 play_notes(&tone_cm, 6, false); 205 play_notes(&tone_cm, 6, false, 0);
206 #endif 206 #endif
207 default_layer_set(1UL<<_CM); 207 default_layer_set(1UL<<_CM);
208 } 208 }
@@ -210,7 +210,7 @@ const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
210 case _DV: 210 case _DV:
211 if (record->event.pressed) { 211 if (record->event.pressed) {
212 #ifdef AUDIO_ENABLE 212 #ifdef AUDIO_ENABLE
213 play_notes(&tone_dv, 8, false); 213 play_notes(&tone_dv, 8, false, 0);
214 #endif 214 #endif
215 default_layer_set(1UL<<_DV); 215 default_layer_set(1UL<<_DV);
216 } 216 }
@@ -254,7 +254,7 @@ const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
254 if (record->event.pressed) { 254 if (record->event.pressed) {
255 #ifdef AUDIO_ENABLE 255 #ifdef AUDIO_ENABLE
256 audio_on(); 256 audio_on();
257 play_notes(&start_up, 5, false); 257 play_notes(&start_up, 5, false, 0);
258 #endif 258 #endif
259 } 259 }
260 break; 260 break;
@@ -265,6 +265,6 @@ const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
265void matrix_init_user(void) { 265void matrix_init_user(void) {
266 #ifdef AUDIO_ENABLE 266 #ifdef AUDIO_ENABLE
267 init_notes(); 267 init_notes();
268 play_notes(&start_up, 5, false); 268 play_notes(&start_up, 5, false, 0);
269 #endif 269 #endif
270} 270}
diff --git a/keyboard/preonic/keymaps/default/keymap.c b/keyboard/preonic/keymaps/default/keymap.c
index 6b6262318..1223793cf 100644
--- a/keyboard/preonic/keymaps/default/keymap.c
+++ b/keyboard/preonic/keymaps/default/keymap.c
@@ -242,7 +242,7 @@ const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
242 case _QWERTY: 242 case _QWERTY:
243 if (record->event.pressed) { 243 if (record->event.pressed) {
244 #ifdef AUDIO_ENABLE 244 #ifdef AUDIO_ENABLE
245 play_notes(&tone_qwerty, 4, false); 245 play_notes(&tone_qwerty, 4, false, 0);
246 #endif 246 #endif
247 persistant_default_layer_set(1UL<<_QWERTY); 247 persistant_default_layer_set(1UL<<_QWERTY);
248 } 248 }
@@ -250,7 +250,7 @@ const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
250 case _COLEMAK: 250 case _COLEMAK:
251 if (record->event.pressed) { 251 if (record->event.pressed) {
252 #ifdef AUDIO_ENABLE 252 #ifdef AUDIO_ENABLE
253 play_notes(&tone_colemak, 6, false); 253 play_notes(&tone_colemak, 6, false, 1);
254 #endif 254 #endif
255 persistant_default_layer_set(1UL<<_COLEMAK); 255 persistant_default_layer_set(1UL<<_COLEMAK);
256 } 256 }
@@ -258,7 +258,7 @@ const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
258 case _DVORAK: 258 case _DVORAK:
259 if (record->event.pressed) { 259 if (record->event.pressed) {
260 #ifdef AUDIO_ENABLE 260 #ifdef AUDIO_ENABLE
261 play_notes(&tone_dvorak, 8, false); 261 play_notes(&tone_dvorak, 8, false, 10);
262 #endif 262 #endif
263 persistant_default_layer_set(1UL<<_DVORAK); 263 persistant_default_layer_set(1UL<<_DVORAK);
264 } 264 }
@@ -302,7 +302,7 @@ const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
302 if (record->event.pressed) { 302 if (record->event.pressed) {
303 #ifdef AUDIO_ENABLE 303 #ifdef AUDIO_ENABLE
304 audio_on(); 304 audio_on();
305 play_notes(&start_up, 4, false); 305 play_notes(&start_up, 4, false, 0);
306 #endif 306 #endif
307 } 307 }
308 break; 308 break;
@@ -317,7 +317,7 @@ const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
317 case 9: 317 case 9:
318 if (record->event.pressed) { 318 if (record->event.pressed) {
319 #ifdef AUDIO_ENABLE 319 #ifdef AUDIO_ENABLE
320 play_notes(&tone_music, 8, false); 320 play_notes(&tone_music, 8, false, 0);
321 layer_on(_MUSIC); 321 layer_on(_MUSIC);
322 #endif 322 #endif
323 } 323 }
@@ -333,9 +333,9 @@ void process_action_user(keyrecord_t *record) {
333 333
334 if (IS_LAYER_ON(_MUSIC)) { 334 if (IS_LAYER_ON(_MUSIC)) {
335 if (record->event.pressed) { 335 if (record->event.pressed) {
336 play_note(((double)261.626)*pow(2.0, -3.0)*pow(2.0,(starting_note + SCALE[record->event.key.col + offset])/12.0+(MATRIX_ROWS - record->event.key.row)), 0xF); 336 play_note(((double)220.0)*pow(2.0, -4.0)*pow(2.0,(starting_note + SCALE[record->event.key.col + offset])/12.0+(MATRIX_ROWS - record->event.key.row)), 0xF);
337 } else { 337 } else {
338 stop_note(((double)261.626)*pow(2.0, -3.0)*pow(2.0,(starting_note + SCALE[record->event.key.col + offset])/12.0+(MATRIX_ROWS - record->event.key.row))); 338 stop_note(((double)220.0)*pow(2.0, -4.0)*pow(2.0,(starting_note + SCALE[record->event.key.col + offset])/12.0+(MATRIX_ROWS - record->event.key.row)));
339 } 339 }
340 } 340 }
341 341
@@ -344,6 +344,6 @@ void process_action_user(keyrecord_t *record) {
344void matrix_init_user(void) { 344void matrix_init_user(void) {
345 #ifdef AUDIO_ENABLE 345 #ifdef AUDIO_ENABLE
346 init_notes(); 346 init_notes();
347 play_notes(&start_up, 4, false); 347 play_notes(&start_up, 4, false, 0);
348 #endif 348 #endif
349} 349}
diff --git a/quantum/audio.c b/quantum/audio.c
index 470dc8e0c..40d09d62f 100644
--- a/quantum/audio.c
+++ b/quantum/audio.c
@@ -61,7 +61,11 @@ uint16_t note_position = 0;
61float (* notes_pointer)[][2]; 61float (* notes_pointer)[][2];
62uint8_t notes_length; 62uint8_t notes_length;
63bool notes_repeat; 63bool notes_repeat;
64float notes_rest;
65bool note_resting = false;
66
64uint8_t current_note = 0; 67uint8_t current_note = 0;
68uint8_t rest_counter = 0;
65 69
66audio_config_t audio_config; 70audio_config_t audio_config;
67 71
@@ -314,13 +318,21 @@ ISR(TIMER3_COMPA_vect) {
314 return; 318 return;
315 } 319 }
316 } 320 }
317 #ifdef PWM_AUDIO 321 if (!note_resting && ((int)notes_rest != 0)) {
318 note_frequency = (*notes_pointer)[current_note][0] / SAMPLE_RATE; 322 note_resting = true;
319 note_length = (*notes_pointer)[current_note][1]; 323 note_frequency = 0;
320 #else 324 note_length = notes_rest;
321 note_frequency = (*notes_pointer)[current_note][0]; 325 current_note--;
322 note_length = (*notes_pointer)[current_note][1] / 4; 326 } else {
323 #endif 327 note_resting = false;
328 #ifdef PWM_AUDIO
329 note_frequency = (*notes_pointer)[current_note][0] / SAMPLE_RATE;
330 note_length = (*notes_pointer)[current_note][1];
331 #else
332 note_frequency = (*notes_pointer)[current_note][0];
333 note_length = (*notes_pointer)[current_note][1] / 4;
334 #endif
335 }
324 note_position = 0; 336 note_position = 0;
325 } 337 }
326 338
@@ -332,7 +344,7 @@ ISR(TIMER3_COMPA_vect) {
332 } 344 }
333} 345}
334 346
335void play_notes(float (*np)[][2], uint8_t n_length, bool n_repeat) { 347void play_notes(float (*np)[][2], uint8_t n_length, bool n_repeat, float n_rest) {
336 348
337if (audio_config.enable) { 349if (audio_config.enable) {
338 350
@@ -343,6 +355,7 @@ if (audio_config.enable) {
343 notes_pointer = np; 355 notes_pointer = np;
344 notes_length = n_length; 356 notes_length = n_length;
345 notes_repeat = n_repeat; 357 notes_repeat = n_repeat;
358 notes_rest = n_rest;
346 359
347 place = 0; 360 place = 0;
348 current_note = 0; 361 current_note = 0;
diff --git a/quantum/audio.h b/quantum/audio.h
index 58270015d..65a6f9434 100644
--- a/quantum/audio.h
+++ b/quantum/audio.h
@@ -2,6 +2,7 @@
2#include <stdbool.h> 2#include <stdbool.h>
3#include <avr/io.h> 3#include <avr/io.h>
4#include <util/delay.h> 4#include <util/delay.h>
5#include "musical_notes.h"
5 6
6typedef union { 7typedef union {
7 uint8_t raw; 8 uint8_t raw;
@@ -20,4 +21,4 @@ void play_note(double freq, int vol);
20void stop_note(double freq); 21void stop_note(double freq);
21void stop_all_notes(); 22void stop_all_notes();
22void init_notes(); 23void init_notes();
23void play_notes(float (*np)[][2], uint8_t n_length, bool n_repeat); 24void play_notes(float (*np)[][2], uint8_t n_length, bool n_repeat, float n_rest);
diff --git a/quantum/keymap_common.c b/quantum/keymap_common.c
index 899437f44..457f70a44 100644
--- a/quantum/keymap_common.c
+++ b/quantum/keymap_common.c
@@ -189,7 +189,7 @@ static action_t keycode_to_action(uint16_t keycode)
189 case RESET: ; // RESET is 0x5000, which is why this is here 189 case RESET: ; // RESET is 0x5000, which is why this is here
190 clear_keyboard(); 190 clear_keyboard();
191 #ifdef AUDIO_ENABLE 191 #ifdef AUDIO_ENABLE
192 play_notes(&goodbye, 3, false); 192 play_notes(&goodbye, 3, false, 0);
193 #endif 193 #endif
194 _delay_ms(250); 194 _delay_ms(250);
195 #ifdef ATREUS_ASTAR 195 #ifdef ATREUS_ASTAR