aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--keyboard/atomic/keymaps/pvc/keymap.c44
-rw-r--r--quantum/audio.c14
-rw-r--r--quantum/audio.h17
-rw-r--r--quantum/keymap_common.c4
-rw-r--r--quantum/musical_notes.h7
5 files changed, 39 insertions, 47 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/quantum/audio.c b/quantum/audio.c
index 40d09d62f..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++;
@@ -318,7 +318,7 @@ ISR(TIMER3_COMPA_vect) {
318 return; 318 return;
319 } 319 }
320 } 320 }
321 if (!note_resting && ((int)notes_rest != 0)) { 321 if (!note_resting && (notes_rest > 0)) {
322 note_resting = true; 322 note_resting = true;
323 note_frequency = 0; 323 note_frequency = 0;
324 note_length = notes_rest; 324 note_length = notes_rest;
@@ -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..762c98064 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,16 @@ 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// These macros are used to allow play_notes to play an array of indeterminate
31// length. This works around the limitation of C's sizeof operation on pointers.
32// The global float array for the song must be used here.
33#define NOTE_ARRAY_SIZE(x) ((int)(sizeof(x) / (sizeof(x[0]))))
34#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));
35
36
37#endif \ No newline at end of file
diff --git a/quantum/keymap_common.c b/quantum/keymap_common.c
index 457f70a44..61a51aedb 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, 0); 192 PLAY_NOTE_ARRAY(goodbye, false, 0);
193 #endif 193 #endif
194 _delay_ms(250); 194 _delay_ms(250);
195 #ifdef ATREUS_ASTAR 195 #ifdef ATREUS_ASTAR
@@ -202,7 +202,7 @@ static action_t keycode_to_action(uint16_t keycode)
202 debug_enable = true; 202 debug_enable = true;
203 break; 203 break;
204 case 0x5002 ... 0x50FF: 204 case 0x5002 ... 0x50FF:
205 // MAGIC actions (BOOTMAGIC without the boot) 205 // MAGIC actions (BOOTMAGIC without the boot)
206 if (!eeconfig_is_enabled()) { 206 if (!eeconfig_is_enabled()) {
207 eeconfig_init(); 207 eeconfig_init();
208 } 208 }
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