aboutsummaryrefslogtreecommitdiff
path: root/quantum
diff options
context:
space:
mode:
Diffstat (limited to 'quantum')
-rw-r--r--quantum/api.c43
-rw-r--r--quantum/audio/audio.c15
-rw-r--r--quantum/audio/voices.c102
-rw-r--r--quantum/audio/voices.h3
-rwxr-xr-xquantum/light_ws2812.h7
-rw-r--r--quantum/process_keycode/process_music.c9
-rw-r--r--quantum/rgblight.c21
-rw-r--r--quantum/rgblight.h3
8 files changed, 165 insertions, 38 deletions
diff --git a/quantum/api.c b/quantum/api.c
index 4ca3b9676..6a7c0a433 100644
--- a/quantum/api.c
+++ b/quantum/api.c
@@ -116,28 +116,29 @@ void process_api(uint16_t length, uint8_t * data) {
116 MT_GET_DATA_ACK(DT_KEYMAP_SIZE, keymap_size, 2); 116 MT_GET_DATA_ACK(DT_KEYMAP_SIZE, keymap_size, 2);
117 break; 117 break;
118 } 118 }
119 case DT_KEYMAP: { 119 // This may be too much
120 uint8_t keymap_data[MATRIX_ROWS * MATRIX_COLS * 4 + 3]; 120 // case DT_KEYMAP: {
121 keymap_data[0] = data[2]; 121 // uint8_t keymap_data[MATRIX_ROWS * MATRIX_COLS * 4 + 3];
122 keymap_data[1] = MATRIX_ROWS; 122 // keymap_data[0] = data[2];
123 keymap_data[2] = MATRIX_COLS; 123 // keymap_data[1] = MATRIX_ROWS;
124 for (int i = 0; i < MATRIX_ROWS; i++) { 124 // keymap_data[2] = MATRIX_COLS;
125 for (int j = 0; j < MATRIX_COLS; j++) { 125 // for (int i = 0; i < MATRIX_ROWS; i++) {
126 keymap_data[3 + (i*MATRIX_COLS*2) + (j*2)] = pgm_read_word(&keymaps[data[2]][i][j]) >> 8; 126 // for (int j = 0; j < MATRIX_COLS; j++) {
127 keymap_data[3 + (i*MATRIX_COLS*2) + (j*2) + 1] = pgm_read_word(&keymaps[data[2]][i][j]) & 0xFF; 127 // keymap_data[3 + (i*MATRIX_COLS*2) + (j*2)] = pgm_read_word(&keymaps[data[2]][i][j]) >> 8;
128 } 128 // keymap_data[3 + (i*MATRIX_COLS*2) + (j*2) + 1] = pgm_read_word(&keymaps[data[2]][i][j]) & 0xFF;
129 } 129 // }
130 MT_GET_DATA_ACK(DT_KEYMAP, keymap_data, MATRIX_ROWS * MATRIX_COLS * 4 + 3); 130 // }
131 // uint8_t keymap_data[5]; 131 // MT_GET_DATA_ACK(DT_KEYMAP, keymap_data, MATRIX_ROWS * MATRIX_COLS * 4 + 3);
132 // keymap_data[0] = data[2]; 132 // // uint8_t keymap_data[5];
133 // keymap_data[1] = data[3]; 133 // // keymap_data[0] = data[2];
134 // keymap_data[2] = data[4]; 134 // // keymap_data[1] = data[3];
135 // keymap_data[3] = pgm_read_word(&keymaps[data[2]][data[3]][data[4]]) >> 8; 135 // // keymap_data[2] = data[4];
136 // keymap_data[4] = pgm_read_word(&keymaps[data[2]][data[3]][data[4]]) & 0xFF; 136 // // keymap_data[3] = pgm_read_word(&keymaps[data[2]][data[3]][data[4]]) >> 8;
137 // // keymap_data[4] = pgm_read_word(&keymaps[data[2]][data[3]][data[4]]) & 0xFF;
137 138
138 // MT_GET_DATA_ACK(DT_KEYMAP, keymap_data, 5); 139 // // MT_GET_DATA_ACK(DT_KEYMAP, keymap_data, 5);
139 break; 140 // break;
140 } 141 // }
141 default: 142 default:
142 break; 143 break;
143 } 144 }
diff --git a/quantum/audio/audio.c b/quantum/audio/audio.c
index ead5fbf3e..2a315fd16 100644
--- a/quantum/audio/audio.c
+++ b/quantum/audio/audio.c
@@ -77,6 +77,7 @@ static bool audio_initialized = false;
77audio_config_t audio_config; 77audio_config_t audio_config;
78 78
79uint16_t envelope_index = 0; 79uint16_t envelope_index = 0;
80bool glissando = true;
80 81
81void audio_init() 82void audio_init()
82{ 83{
@@ -205,13 +206,17 @@ ISR(TIMER3_COMPA_vect)
205 freq = frequencies[voice_place]; 206 freq = frequencies[voice_place];
206 #endif 207 #endif
207 } else { 208 } else {
208 if (frequency != 0 && frequency < frequencies[voices - 1] && frequency < frequencies[voices - 1] * pow(2, -440/frequencies[voices - 1]/12/2)) { 209 if (glissando) {
209 frequency = frequency * pow(2, 440/frequency/12/2); 210 if (frequency != 0 && frequency < frequencies[voices - 1] && frequency < frequencies[voices - 1] * pow(2, -440/frequencies[voices - 1]/12/2)) {
210 } else if (frequency != 0 && frequency > frequencies[voices - 1] && frequency > frequencies[voices - 1] * pow(2, 440/frequencies[voices - 1]/12/2)) { 211 frequency = frequency * pow(2, 440/frequency/12/2);
211 frequency = frequency * pow(2, -440/frequency/12/2); 212 } else if (frequency != 0 && frequency > frequencies[voices - 1] && frequency > frequencies[voices - 1] * pow(2, 440/frequencies[voices - 1]/12/2)) {
213 frequency = frequency * pow(2, -440/frequency/12/2);
214 } else {
215 frequency = frequencies[voices - 1];
216 }
212 } else { 217 } else {
213 frequency = frequencies[voices - 1]; 218 frequency = frequencies[voices - 1];
214 } 219 }
215 220
216 #ifdef VIBRATO_ENABLE 221 #ifdef VIBRATO_ENABLE
217 if (vibrato_strength > 0) { 222 if (vibrato_strength > 0) {
diff --git a/quantum/audio/voices.c b/quantum/audio/voices.c
index 19f7b646e..8326e91ea 100644
--- a/quantum/audio/voices.c
+++ b/quantum/audio/voices.c
@@ -6,6 +6,7 @@
6extern uint16_t envelope_index; 6extern uint16_t envelope_index;
7extern float note_timbre; 7extern float note_timbre;
8extern float polyphony_rate; 8extern float polyphony_rate;
9extern bool glissando;
9 10
10voice_type voice = default_voice; 11voice_type voice = default_voice;
11 12
@@ -27,11 +28,15 @@ float voice_envelope(float frequency) {
27 28
28 switch (voice) { 29 switch (voice) {
29 case default_voice: 30 case default_voice:
31 glissando = true;
30 note_timbre = TIMBRE_50; 32 note_timbre = TIMBRE_50;
31 polyphony_rate = 0; 33 polyphony_rate = 0;
32 break; 34 break;
33 35
36 #ifdef AUDIO_VOICES
37
34 case something: 38 case something:
39 glissando = false;
35 polyphony_rate = 0; 40 polyphony_rate = 0;
36 switch (compensated_index) { 41 switch (compensated_index) {
37 case 0 ... 9: 42 case 0 ... 9:
@@ -43,16 +48,102 @@ float voice_envelope(float frequency) {
43 break; 48 break;
44 49
45 case 20 ... 200: 50 case 20 ... 200:
46 note_timbre = .25 + .125 + pow(((float)compensated_index - 20) / (200 - 20), 2)*.125; 51 note_timbre = .125 + .125;
47 break; 52 break;
48 53
49 default: 54 default:
50 note_timbre = .25; 55 note_timbre = .125;
51 break; 56 break;
52 } 57 }
53 break; 58 break;
54 59
60 case drums:
61 glissando = false;
62 polyphony_rate = 0;
63 // switch (compensated_index) {
64 // case 0 ... 10:
65 // note_timbre = 0.5;
66 // break;
67 // case 11 ... 20:
68 // note_timbre = 0.5 * (21 - compensated_index) / 10;
69 // break;
70 // default:
71 // note_timbre = 0;
72 // break;
73 // }
74 // frequency = (rand() % (int)(frequency * 1.2 - frequency)) + (frequency * 0.8);
75
76 if (frequency < 80.0) {
77
78 } else if (frequency < 160.0) {
79
80 // Bass drum: 60 - 100 Hz
81 frequency = (rand() % (int)(40)) + 60;
82 switch (envelope_index) {
83 case 0 ... 10:
84 note_timbre = 0.5;
85 break;
86 case 11 ... 20:
87 note_timbre = 0.5 * (21 - envelope_index) / 10;
88 break;
89 default:
90 note_timbre = 0;
91 break;
92 }
93
94 } else if (frequency < 320.0) {
95
96
97 // Snare drum: 1 - 2 KHz
98 frequency = (rand() % (int)(1000)) + 1000;
99 switch (envelope_index) {
100 case 0 ... 5:
101 note_timbre = 0.5;
102 break;
103 case 6 ... 20:
104 note_timbre = 0.5 * (21 - envelope_index) / 15;
105 break;
106 default:
107 note_timbre = 0;
108 break;
109 }
110
111 } else if (frequency < 640.0) {
112
113 // Closed Hi-hat: 3 - 5 KHz
114 frequency = (rand() % (int)(2000)) + 3000;
115 switch (envelope_index) {
116 case 0 ... 15:
117 note_timbre = 0.5;
118 break;
119 case 16 ... 20:
120 note_timbre = 0.5 * (21 - envelope_index) / 5;
121 break;
122 default:
123 note_timbre = 0;
124 break;
125 }
126
127 } else if (frequency < 1280.0) {
128
129 // Open Hi-hat: 3 - 5 KHz
130 frequency = (rand() % (int)(2000)) + 3000;
131 switch (envelope_index) {
132 case 0 ... 35:
133 note_timbre = 0.5;
134 break;
135 case 36 ... 50:
136 note_timbre = 0.5 * (51 - envelope_index) / 15;
137 break;
138 default:
139 note_timbre = 0;
140 break;
141 }
142
143 }
144 break;
55 case butts_fader: 145 case butts_fader:
146 glissando = true;
56 polyphony_rate = 0; 147 polyphony_rate = 0;
57 switch (compensated_index) { 148 switch (compensated_index) {
58 case 0 ... 9: 149 case 0 ... 9:
@@ -100,6 +191,7 @@ float voice_envelope(float frequency) {
100 191
101 case duty_osc: 192 case duty_osc:
102 // This slows the loop down a substantial amount, so higher notes may freeze 193 // This slows the loop down a substantial amount, so higher notes may freeze
194 glissando = true;
103 polyphony_rate = 0; 195 polyphony_rate = 0;
104 switch (compensated_index) { 196 switch (compensated_index) {
105 default: 197 default:
@@ -114,6 +206,7 @@ float voice_envelope(float frequency) {
114 break; 206 break;
115 207
116 case duty_octave_down: 208 case duty_octave_down:
209 glissando = true;
117 polyphony_rate = 0; 210 polyphony_rate = 0;
118 note_timbre = (envelope_index % 2) * .125 + .375 * 2; 211 note_timbre = (envelope_index % 2) * .125 + .375 * 2;
119 if ((envelope_index % 4) == 0) 212 if ((envelope_index % 4) == 0)
@@ -122,6 +215,7 @@ float voice_envelope(float frequency) {
122 note_timbre = 0; 215 note_timbre = 0;
123 break; 216 break;
124 case delayed_vibrato: 217 case delayed_vibrato:
218 glissando = true;
125 polyphony_rate = 0; 219 polyphony_rate = 0;
126 note_timbre = TIMBRE_50; 220 note_timbre = TIMBRE_50;
127 #define VOICE_VIBRATO_DELAY 150 221 #define VOICE_VIBRATO_DELAY 150
@@ -176,11 +270,11 @@ float voice_envelope(float frequency) {
176 // note_timbre = 0.25; 270 // note_timbre = 0.25;
177 // break; 271 // break;
178 272
273 #endif
274
179 default: 275 default:
180 break; 276 break;
181 } 277 }
182 278
183 return frequency; 279 return frequency;
184} 280}
185
186
diff --git a/quantum/audio/voices.h b/quantum/audio/voices.h
index b43def3d7..52f7e006d 100644
--- a/quantum/audio/voices.h
+++ b/quantum/audio/voices.h
@@ -11,7 +11,9 @@ float voice_envelope(float frequency);
11 11
12typedef enum { 12typedef enum {
13 default_voice, 13 default_voice,
14 #ifdef AUDIO_VOICES
14 something, 15 something,
16 drums,
15 butts_fader, 17 butts_fader,
16 octave_crunch, 18 octave_crunch,
17 duty_osc, 19 duty_osc,
@@ -22,6 +24,7 @@ typedef enum {
22 // duty_fourth_down, 24 // duty_fourth_down,
23 // duty_third_down, 25 // duty_third_down,
24 // duty_fifth_third_down, 26 // duty_fifth_third_down,
27 #endif
25 number_of_voices // important that this is last 28 number_of_voices // important that this is last
26} voice_type; 29} voice_type;
27 30
diff --git a/quantum/light_ws2812.h b/quantum/light_ws2812.h
index 9498e550e..2f78c20fc 100755
--- a/quantum/light_ws2812.h
+++ b/quantum/light_ws2812.h
@@ -18,13 +18,6 @@
18//#include "ws2812_config.h" 18//#include "ws2812_config.h"
19//#include "i2cmaster.h" 19//#include "i2cmaster.h"
20 20
21#define LIGHT_I2C 1
22#define LIGHT_I2C_ADDR 0x84
23#define LIGHT_I2C_ADDR_WRITE ( (LIGHT_I2C_ADDR<<1) | I2C_WRITE )
24#define LIGHT_I2C_ADDR_READ ( (LIGHT_I2C_ADDR<<1) | I2C_READ )
25
26#define RGBW 1
27
28#ifdef RGBW 21#ifdef RGBW
29 #define LED_TYPE struct cRGBW 22 #define LED_TYPE struct cRGBW
30#else 23#else
diff --git a/quantum/process_keycode/process_music.c b/quantum/process_keycode/process_music.c
index bae43943e..ca68bef6c 100644
--- a/quantum/process_keycode/process_music.c
+++ b/quantum/process_keycode/process_music.c
@@ -115,7 +115,16 @@ bool process_music(uint16_t keycode, keyrecord_t *record) {
115 return false; 115 return false;
116 } 116 }
117 117
118 #ifdef MUSIC_MODE_CHROMATIC
119 float freq = ((float)220.0)*pow(2.0, -5.0)*pow(2.0,(music_starting_note + record->event.key.col + music_offset)/12.0+(MATRIX_ROWS - record->event.key.row));
120 #elif defined(MUSIC_MODE_GUITAR)
121 float freq = ((float)220.0)*pow(2.0, -5.0)*pow(2.0,(music_starting_note + record->event.key.col + music_offset)/12.0+(float)(MATRIX_ROWS - record->event.key.row + 7)*5.0/12);
122 #elif defined(MUSIC_MODE_VIOLIN)
123 float freq = ((float)220.0)*pow(2.0, -5.0)*pow(2.0,(music_starting_note + record->event.key.col + music_offset)/12.0+(float)(MATRIX_ROWS - record->event.key.row + 5)*7.0/12);
124 #else
118 float freq = ((float)220.0)*pow(2.0, -5.0)*pow(2.0,(music_starting_note + SCALE[record->event.key.col + music_offset])/12.0+(MATRIX_ROWS - record->event.key.row)); 125 float freq = ((float)220.0)*pow(2.0, -5.0)*pow(2.0,(music_starting_note + SCALE[record->event.key.col + music_offset])/12.0+(MATRIX_ROWS - record->event.key.row));
126 #endif
127
119 if (record->event.pressed) { 128 if (record->event.pressed) {
120 play_note(freq, 0xF); 129 play_note(freq, 0xF);
121 if (music_sequence_recording) { 130 if (music_sequence_recording) {
diff --git a/quantum/rgblight.c b/quantum/rgblight.c
index 625971e0f..6e335a483 100644
--- a/quantum/rgblight.c
+++ b/quantum/rgblight.c
@@ -449,6 +449,9 @@ void rgblight_task(void) {
449 } else if (rgblight_config.mode >= 21 && rgblight_config.mode <= 23) { 449 } else if (rgblight_config.mode >= 21 && rgblight_config.mode <= 23) {
450 // mode = 21 to 23, knight mode 450 // mode = 21 to 23, knight mode
451 rgblight_effect_knight(rgblight_config.mode - 21); 451 rgblight_effect_knight(rgblight_config.mode - 21);
452 } else {
453 // mode = 24, christmas mode
454 rgblight_effect_christmas();
452 } 455 }
453 } 456 }
454} 457}
@@ -594,4 +597,22 @@ void rgblight_effect_knight(uint8_t interval) {
594 } 597 }
595} 598}
596 599
600
601void rgblight_effect_christmas(void) {
602 static uint16_t current_offset = 0;
603 static uint16_t last_timer = 0;
604 uint16_t hue;
605 uint8_t i;
606 if (timer_elapsed(last_timer) < 1000) {
607 return;
608 }
609 last_timer = timer_read();
610 current_offset = (current_offset + 1) % 2;
611 for (i = 0; i < RGBLED_NUM; i++) {
612 hue = 0 + ((RGBLED_NUM * (i + current_offset)) % 2) * 80;
613 sethsv(hue, rgblight_config.sat, rgblight_config.val, (LED_TYPE *)&led[i]);
614 }
615 rgblight_set();
616}
617
597#endif 618#endif
diff --git a/quantum/rgblight.h b/quantum/rgblight.h
index aa1d026e0..ceb624692 100644
--- a/quantum/rgblight.h
+++ b/quantum/rgblight.h
@@ -2,7 +2,7 @@
2#define RGBLIGHT_H 2#define RGBLIGHT_H
3 3
4#ifdef RGBLIGHT_ANIMATIONS 4#ifdef RGBLIGHT_ANIMATIONS
5 #define RGBLIGHT_MODES 23 5 #define RGBLIGHT_MODES 24
6#else 6#else
7 #define RGBLIGHT_MODES 1 7 #define RGBLIGHT_MODES 1
8#endif 8#endif
@@ -98,5 +98,6 @@ void rgblight_effect_rainbow_mood(uint8_t interval);
98void rgblight_effect_rainbow_swirl(uint8_t interval); 98void rgblight_effect_rainbow_swirl(uint8_t interval);
99void rgblight_effect_snake(uint8_t interval); 99void rgblight_effect_snake(uint8_t interval);
100void rgblight_effect_knight(uint8_t interval); 100void rgblight_effect_knight(uint8_t interval);
101void rgblight_effect_christmas(void);
101 102
102#endif 103#endif