aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--keyboard/atomic/keymaps/pvc/keymap.c44
-rw-r--r--keyboard/planck/keymaps/default/keymap.c10
-rw-r--r--keyboard/preonic/keymaps/default/keymap.c15
-rw-r--r--quantum/audio.c12
-rw-r--r--quantum/audio.h23
-rw-r--r--quantum/keymap_common.c4
-rw-r--r--quantum/musical_notes.h7
7 files changed, 54 insertions, 61 deletions
diff --git a/keyboard/atomic/keymaps/pvc/keymap.c b/keyboard/atomic/keymaps/pvc/keymap.c
index 229708344..c2081f525 100644
--- a/keyboard/atomic/keymaps/pvc/keymap.c
+++ b/keyboard/atomic/keymaps/pvc/keymap.c
@@ -75,8 +75,6 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
75 }, 75 },
76}; 76};
77 77
78#define IS_LAYER_ON(layer) (layer_state & (1UL << (layer)))
79#define IS_LAYER_OFF(layer) (!IS_LAYER_ON(layer))
80 78
81#ifdef AUDIO_ENABLE 79#ifdef AUDIO_ENABLE
82 80
@@ -201,24 +199,14 @@ Q_NOTE(_B8 ) ,
201}; 199};
202 200
203float tone_rs[][2] = { 201float tone_rs[][2] = {
204Q_NOTE(_F8 ) , 202Q_NOTE(_A4 ) ,
205Q_NOTE(_G8 ) , 203Q_NOTE(_A4 ) ,
206Q_NOTE(_GS8 ) , 204Q_NOTE(_A4 ) ,
207Q_NOTE(_A8 ) , 205Q_NOTE(_A4 ) ,
208Q_NOTE(_AS8 ) , 206Q_NOTE(_AS8 ) ,
209Q_NOTE(_B8 ) , 207Q_NOTE(_B8 ) ,
210}; 208};
211 209
212float tone_fn[][2] = {
213 {440.0*pow(2.0,(59)/12.0), 8},
214 {440.0*pow(2.0,(60)/12.0), 8},
215 {0, 4},
216 {440.0*pow(2.0,(67)/12.0), 16},
217 {0, 4},
218 {440.0*pow(2.0,(69)/12.0), 16},
219 {0, 4},
220 {440.0*pow(2.0,(67)/12.0), 16}
221};
222#endif 210#endif
223 211
224void update_quad_layer(uint8_t layer1, uint8_t layer2, uint8_t layer3, uint8_t layer4, bool order) 212void update_quad_layer(uint8_t layer1, uint8_t layer2, uint8_t layer3, uint8_t layer4, bool order)
@@ -253,18 +241,18 @@ void update_quad_layer(uint8_t layer1, uint8_t layer2, uint8_t layer3, uint8_t l
253const uint16_t PROGMEM fn_actions[] = { 241const uint16_t PROGMEM fn_actions[] = {
254}; 242};
255 243
256#define ARRAY_SIZE(x) ((sizeof x) / (sizeof *x)) 244//#define MUSIC_ARRAY_SIZE(x) (((int)(sizeof(x) / (sizeof(x[0][0])))) / 2)
257 245
258const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt) 246const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
259{ 247{
248
260 // MACRODOWN only works in this function 249 // MACRODOWN only works in this function
261 switch(id) { 250 switch(id) {
262 case M_LW: 251 case M_LW:
263 if (record->event.pressed) { 252 if (record->event.pressed) {
264 #ifdef AUDIO_ENABLE 253 #ifdef AUDIO_ENABLE
265 println("PlayNotes LW"); 254 println("PlayNotes LW");
266 print_val_hex32(ARRAY_SIZE(tone_lw)); 255 PLAY_NOTE_ARRAY(tone_lw, false, STACCATO);
267 play_notes(&tone_lw, 96, false);
268 #endif 256 #endif
269 layer_on(_LW); 257 layer_on(_LW);
270 update_tri_layer(_LW, _RS, _FN); 258 update_tri_layer(_LW, _RS, _FN);
@@ -277,7 +265,7 @@ const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
277 if (record->event.pressed) { 265 if (record->event.pressed) {
278 #ifdef AUDIO_ENABLE 266 #ifdef AUDIO_ENABLE
279 println("PlayNotes RS"); 267 println("PlayNotes RS");
280 play_notes(&tone_rs, 6, false); 268 PLAY_NOTE_ARRAY(tone_rs, false, LEGATO);
281 #endif 269 #endif
282 layer_on(_RS); 270 layer_on(_RS);
283 update_tri_layer(_LW, _RS, _FN); 271 update_tri_layer(_LW, _RS, _FN);
@@ -295,33 +283,19 @@ const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
295#ifdef AUDIO_ENABLE 283#ifdef AUDIO_ENABLE
296float start_up[][2] = { 284float start_up[][2] = {
297Q_NOTE(_E4 ) , 285Q_NOTE(_E4 ) ,
298{0,1} ,
299Q_NOTE(_E4 ) , 286Q_NOTE(_E4 ) ,
300{0,1} ,
301Q_NOTE(_F4 ) , 287Q_NOTE(_F4 ) ,
302{0,1} ,
303Q_NOTE(_G4 ) , 288Q_NOTE(_G4 ) ,
304{0,1} ,
305Q_NOTE(_G4 ) , 289Q_NOTE(_G4 ) ,
306{0,1} ,
307Q_NOTE(_F4 ) , 290Q_NOTE(_F4 ) ,
308{0,1} ,
309Q_NOTE(_E4 ) , 291Q_NOTE(_E4 ) ,
310{0,1} ,
311Q_NOTE(_D4 ) , 292Q_NOTE(_D4 ) ,
312{0,1} ,
313Q_NOTE(_C4 ) , 293Q_NOTE(_C4 ) ,
314{0,1} ,
315Q_NOTE(_C4 ) , 294Q_NOTE(_C4 ) ,
316{0,1} ,
317Q_NOTE(_D4 ) , 295Q_NOTE(_D4 ) ,
318{0,1} ,
319Q_NOTE(_E4 ) , 296Q_NOTE(_E4 ) ,
320{0,1} ,
321H_NOTE(_E4 ) , 297H_NOTE(_E4 ) ,
322{0,1} ,
323Q_NOTE(_D4 ) , 298Q_NOTE(_D4 ) ,
324{0,1} ,
325H_NOTE(_D4 ) , 299H_NOTE(_D4 ) ,
326}; 300};
327#endif 301#endif
@@ -329,7 +303,7 @@ H_NOTE(_D4 ) ,
329void matrix_init_user(void) { 303void matrix_init_user(void) {
330 #ifdef AUDIO_ENABLE 304 #ifdef AUDIO_ENABLE
331 init_notes(); 305 init_notes();
332 play_notes(&start_up, 29, false); 306 PLAY_NOTE_ARRAY(start_up, false, STACCATO);
333 println("Matrix Init"); 307 println("Matrix Init");
334 #endif 308 #endif
335} 309}
diff --git a/keyboard/planck/keymaps/default/keymap.c b/keyboard/planck/keymaps/default/keymap.c
index 5591b337d..207af2a1d 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, false, 0); 197 PLAY_NOTE_ARRAY(tone_qw, 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, false, 0); 205 PLAY_NOTE_ARRAY(tone_cm, 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, false, 0); 213 PLAY_NOTE_ARRAY(tone_dv, 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, false, 0); 257 PLAY_NOTE_ARRAY(start_up, 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, false, 0); 268 PLAY_NOTE_ARRAY(start_up, 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 c7b6b89f2..48bc72dab 100644
--- a/keyboard/preonic/keymaps/default/keymap.c
+++ b/keyboard/preonic/keymaps/default/keymap.c
@@ -3,11 +3,6 @@
3#include "eeconfig.h" 3#include "eeconfig.h"
4#ifdef AUDIO_ENABLE 4#ifdef AUDIO_ENABLE
5 #include "audio.h" 5 #include "audio.h"
6 #define SCALE (int []){ 0 + (12*0), 2 + (12*0), 4 + (12*0), 5 + (12*0), 7 + (12*0), 9 + (12*0), 11 + (12*0), \
7 0 + (12*1), 2 + (12*1), 4 + (12*1), 5 + (12*1), 7 + (12*1), 9 + (12*1), 11 + (12*1), \
8 0 + (12*2), 2 + (12*2), 4 + (12*2), 5 + (12*2), 7 + (12*2), 9 + (12*2), 11 + (12*2), \
9 0 + (12*3), 2 + (12*3), 4 + (12*3), 5 + (12*3), 7 + (12*3), 9 + (12*3), 11 + (12*3), \
10 0 + (12*4), 2 + (12*4), 4 + (12*4), 5 + (12*4), 7 + (12*4), 9 + (12*4), 11 + (12*4), }
11#endif 6#endif
12 7
13// Each layer gets a name for readability, which is then used in the keymap matrix below. 8// Each layer gets a name for readability, which is then used in the keymap matrix below.
@@ -242,7 +237,7 @@ const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
242 case _QWERTY: 237 case _QWERTY:
243 if (record->event.pressed) { 238 if (record->event.pressed) {
244 #ifdef AUDIO_ENABLE 239 #ifdef AUDIO_ENABLE
245 play_notes(&tone_qwerty, false, 0); 240 PLAY_NOTE_ARRAY(tone_qwerty, false, 0);
246 #endif 241 #endif
247 persistant_default_layer_set(1UL<<_QWERTY); 242 persistant_default_layer_set(1UL<<_QWERTY);
248 } 243 }
@@ -250,7 +245,7 @@ const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
250 case _COLEMAK: 245 case _COLEMAK:
251 if (record->event.pressed) { 246 if (record->event.pressed) {
252 #ifdef AUDIO_ENABLE 247 #ifdef AUDIO_ENABLE
253 play_notes(&tone_colemak, false, 0); 248 PLAY_NOTE_ARRAY(tone_colemak, false, 0);
254 #endif 249 #endif
255 persistant_default_layer_set(1UL<<_COLEMAK); 250 persistant_default_layer_set(1UL<<_COLEMAK);
256 } 251 }
@@ -258,7 +253,7 @@ const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
258 case _DVORAK: 253 case _DVORAK:
259 if (record->event.pressed) { 254 if (record->event.pressed) {
260 #ifdef AUDIO_ENABLE 255 #ifdef AUDIO_ENABLE
261 play_notes(&tone_dvorak, false, 0); 256 PLAY_NOTE_ARRAY(tone_dvorak, false, 0);
262 #endif 257 #endif
263 persistant_default_layer_set(1UL<<_DVORAK); 258 persistant_default_layer_set(1UL<<_DVORAK);
264 } 259 }
@@ -302,7 +297,7 @@ const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
302 if (record->event.pressed) { 297 if (record->event.pressed) {
303 #ifdef AUDIO_ENABLE 298 #ifdef AUDIO_ENABLE
304 audio_on(); 299 audio_on();
305 play_notes(&start_up, false, 0); 300 PLAY_NOTE_ARRAY(start_up, false, 0);
306 #endif 301 #endif
307 } 302 }
308 break; 303 break;
@@ -317,7 +312,7 @@ const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
317 case 9: 312 case 9:
318 if (record->event.pressed) { 313 if (record->event.pressed) {
319 #ifdef AUDIO_ENABLE 314 #ifdef AUDIO_ENABLE
320 play_notes(&tone_music, false, 0); 315 PLAY_NOTE_ARRAY(tone_music, false, 0);
321 layer_on(_MUSIC); 316 layer_on(_MUSIC);
322 #endif 317 #endif
323 } 318 }
diff --git a/quantum/audio.c b/quantum/audio.c
index 773edfd8e..90f3c5a13 100644
--- a/quantum/audio.c
+++ b/quantum/audio.c
@@ -181,7 +181,7 @@ void init_notes() {
181 DDRC |= _BV(PORTC6); 181 DDRC |= _BV(PORTC6);
182 182
183 TIMSK3 &= ~_BV(OCIE3A); // Turn off 3A interputs 183 TIMSK3 &= ~_BV(OCIE3A); // Turn off 3A interputs
184 184
185 TCCR3A = 0x0; // Options not needed 185 TCCR3A = 0x0; // Options not needed
186 TCCR3B = _BV(CS31) | _BV(CS30) | _BV(WGM32); // 64th prescaling and CTC 186 TCCR3B = _BV(CS31) | _BV(CS30) | _BV(WGM32); // 64th prescaling and CTC
187 OCR3A = SAMPLE_DIVIDER - 1; // Correct count/compare, related to sample playback 187 OCR3A = SAMPLE_DIVIDER - 1; // Correct count/compare, related to sample playback
@@ -202,14 +202,14 @@ ISR(TIMER3_COMPA_vect) {
202 if (voices == 1) { 202 if (voices == 1) {
203 // SINE 203 // SINE
204 OCR4A = pgm_read_byte(&sinewave[(uint16_t)place]) >> 2; 204 OCR4A = pgm_read_byte(&sinewave[(uint16_t)place]) >> 2;
205 205
206 // SQUARE 206 // SQUARE
207 // if (((int)place) >= 1024){ 207 // if (((int)place) >= 1024){
208 // OCR4A = 0xFF >> 2; 208 // OCR4A = 0xFF >> 2;
209 // } else { 209 // } else {
210 // OCR4A = 0x00; 210 // OCR4A = 0x00;
211 // } 211 // }
212 212
213 // SAWTOOTH 213 // SAWTOOTH
214 // OCR4A = (int)place / 4; 214 // OCR4A = (int)place / 4;
215 215
@@ -298,9 +298,9 @@ ISR(TIMER3_COMPA_vect) {
298 298
299 note_position++; 299 note_position++;
300 bool end_of_note = false; 300 bool end_of_note = false;
301 if (ICR3 > 0) 301 if (ICR3 > 0)
302 end_of_note = (note_position >= (note_length / ICR3 * 0xFFFF)); 302 end_of_note = (note_position >= (note_length / ICR3 * 0xFFFF));
303 else 303 else
304 end_of_note = (note_position >= (note_length * 0x7FF)); 304 end_of_note = (note_position >= (note_length * 0x7FF));
305 if (end_of_note) { 305 if (end_of_note) {
306 current_note++; 306 current_note++;
@@ -412,7 +412,7 @@ if (audio_config.enable && voices < 8) {
412 if (frequency != 0) { 412 if (frequency != 0) {
413 double starting_f = frequency; 413 double starting_f = frequency;
414 if (frequency < freq) { 414 if (frequency < freq) {
415 for (double f = starting_f; f <= freq; f += ((freq - starting_f) / 2000.0)) { 415 for (double f = starting_f; f <= freq; f += ((freq - starting_f) / 2000.0)) {
416 frequency = f; 416 frequency = f;
417 } 417 }
418 } else if (frequency > freq) { 418 } else if (frequency > freq) {
diff --git a/quantum/audio.h b/quantum/audio.h
index 65a6f9434..e1bc23ffe 100644
--- a/quantum/audio.h
+++ b/quantum/audio.h
@@ -4,6 +4,9 @@
4#include <util/delay.h> 4#include <util/delay.h>
5#include "musical_notes.h" 5#include "musical_notes.h"
6 6
7#ifndef AUDIO_H
8#define AUDIO_H
9
7typedef union { 10typedef union {
8 uint8_t raw; 11 uint8_t raw;
9 struct { 12 struct {
@@ -19,6 +22,22 @@ void audio_off(void);
19void play_sample(uint8_t * s, uint16_t l, bool r); 22void play_sample(uint8_t * s, uint16_t l, bool r);
20void play_note(double freq, int vol); 23void play_note(double freq, int vol);
21void stop_note(double freq); 24void stop_note(double freq);
22void stop_all_notes(); 25void stop_all_notes(void);
23void init_notes(); 26void init_notes(void);
24void play_notes(float (*np)[][2], uint8_t n_length, bool n_repeat, float n_rest); 27void play_notes(float (*np)[][2], uint8_t n_length, bool n_repeat, float n_rest);
28
29
30#define SCALE (int []){ 0 + (12*0), 2 + (12*0), 4 + (12*0), 5 + (12*0), 7 + (12*0), 9 + (12*0), 11 + (12*0), \
31 0 + (12*1), 2 + (12*1), 4 + (12*1), 5 + (12*1), 7 + (12*1), 9 + (12*1), 11 + (12*1), \
32 0 + (12*2), 2 + (12*2), 4 + (12*2), 5 + (12*2), 7 + (12*2), 9 + (12*2), 11 + (12*2), \
33 0 + (12*3), 2 + (12*3), 4 + (12*3), 5 + (12*3), 7 + (12*3), 9 + (12*3), 11 + (12*3), \
34 0 + (12*4), 2 + (12*4), 4 + (12*4), 5 + (12*4), 7 + (12*4), 9 + (12*4), 11 + (12*4), }
35
36// These macros are used to allow play_notes to play an array of indeterminate
37// length. This works around the limitation of C's sizeof operation on pointers.
38// The global float array for the song must be used here.
39#define NOTE_ARRAY_SIZE(x) ((int)(sizeof(x) / (sizeof(x[0]))))
40#define PLAY_NOTE_ARRAY(note_array, note_repeat, note_rest_style) play_notes(&note_array, NOTE_ARRAY_SIZE((note_array)), (note_repeat), (note_rest_style));
41
42
43#endif \ No newline at end of file
diff --git a/quantum/keymap_common.c b/quantum/keymap_common.c
index 8f35521a2..02d3c74be 100644
--- a/quantum/keymap_common.c
+++ b/quantum/keymap_common.c
@@ -191,7 +191,7 @@ static action_t keycode_to_action(uint16_t keycode)
191 case RESET: ; // RESET is 0x5000, which is why this is here 191 case RESET: ; // RESET is 0x5000, which is why this is here
192 clear_keyboard(); 192 clear_keyboard();
193 #ifdef AUDIO_ENABLE 193 #ifdef AUDIO_ENABLE
194 play_notes(&goodbye_tune, false, 0); 194 PLAY_NOTE_ARRAY(goodbye_tune, false, 0);
195 #endif 195 #endif
196 _delay_ms(250); 196 _delay_ms(250);
197 #ifdef ATREUS_ASTAR 197 #ifdef ATREUS_ASTAR
@@ -204,7 +204,7 @@ static action_t keycode_to_action(uint16_t keycode)
204 debug_enable = true; 204 debug_enable = true;
205 break; 205 break;
206 case 0x5002 ... 0x50FF: 206 case 0x5002 ... 0x50FF:
207 // MAGIC actions (BOOTMAGIC without the boot) 207 // MAGIC actions (BOOTMAGIC without the boot)
208 if (!eeconfig_is_enabled()) { 208 if (!eeconfig_is_enabled()) {
209 eeconfig_init(); 209 eeconfig_init();
210 } 210 }
diff --git a/quantum/musical_notes.h b/quantum/musical_notes.h
index 79f04fd98..837f6a069 100644
--- a/quantum/musical_notes.h
+++ b/quantum/musical_notes.h
@@ -9,7 +9,7 @@
9#define WHOLE_NOTE(note) {(NOTE##note), 64} 9#define WHOLE_NOTE(note) {(NOTE##note), 64}
10#define HALF_NOTE(note) {(NOTE##note), 32} 10#define HALF_NOTE(note) {(NOTE##note), 32}
11#define QUARTER_NOTE(note) {(NOTE##note), 16} 11#define QUARTER_NOTE(note) {(NOTE##note), 16}
12#define EIGTH_NOTE(note) {(NOTE##note), 8} 12#define EIGHTH_NOTE(note) {(NOTE##note), 8}
13#define SIXTEENTH_NOTE(note) {(NOTE##note), 4} 13#define SIXTEENTH_NOTE(note) {(NOTE##note), 4}
14 14
15// Note Types Short 15// Note Types Short
@@ -19,6 +19,11 @@
19#define E_NOTE(n) EIGTH_NOTE(n) 19#define E_NOTE(n) EIGTH_NOTE(n)
20#define S_NOTE(n) SIXTEENTH_NOTE(n) 20#define S_NOTE(n) SIXTEENTH_NOTE(n)
21 21
22// Note Styles
23// Staccato makes sure there is a rest between each note. Think: TA TA TA
24// Legato makes notes flow together. Think: TAAA
25#define STACCATO 0.01
26#define LEGATO 0
22 27
23// Notes - # = Octave 28// Notes - # = Octave
24#define NOTE_REST 0.00 29#define NOTE_REST 0.00