aboutsummaryrefslogtreecommitdiff
path: root/quantum
diff options
context:
space:
mode:
Diffstat (limited to 'quantum')
-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
4 files changed, 35 insertions, 11 deletions
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