diff options
Diffstat (limited to 'quantum')
-rw-r--r-- | quantum/audio.c | 81 | ||||
-rw-r--r-- | quantum/keymap_common.c | 1 |
2 files changed, 39 insertions, 43 deletions
diff --git a/quantum/audio.c b/quantum/audio.c index 69c58ca6c..6a5d43013 100644 --- a/quantum/audio.c +++ b/quantum/audio.c | |||
@@ -65,6 +65,7 @@ uint8_t notes_count; | |||
65 | bool notes_repeat; | 65 | bool notes_repeat; |
66 | float notes_rest; | 66 | float notes_rest; |
67 | bool note_resting = false; | 67 | bool note_resting = false; |
68 | int note_flipper = 0; | ||
68 | 69 | ||
69 | uint8_t current_note = 0; | 70 | uint8_t current_note = 0; |
70 | uint8_t rest_counter = 0; | 71 | uint8_t rest_counter = 0; |
@@ -127,6 +128,9 @@ void stop_note(double freq) { | |||
127 | voices--; | 128 | voices--; |
128 | if (voices < 0) | 129 | if (voices < 0) |
129 | voices = 0; | 130 | voices = 0; |
131 | if (voice_place >= voices) { | ||
132 | voice_place = 0; | ||
133 | } | ||
130 | if (voices == 0) { | 134 | if (voices == 0) { |
131 | #ifdef PWM_AUDIO | 135 | #ifdef PWM_AUDIO |
132 | TIMSK3 &= ~_BV(OCIE3A); | 136 | TIMSK3 &= ~_BV(OCIE3A); |
@@ -137,25 +141,6 @@ void stop_note(double freq) { | |||
137 | frequency = 0; | 141 | frequency = 0; |
138 | volume = 0; | 142 | volume = 0; |
139 | note = false; | 143 | note = false; |
140 | } else { | ||
141 | double freq = frequencies[voices - 1]; | ||
142 | int vol = volumes[voices - 1]; | ||
143 | double starting_f = frequency; | ||
144 | if (frequency < freq) { | ||
145 | sliding = true; | ||
146 | for (double f = starting_f; f <= freq; f += ((freq - starting_f) / 2000.0)) { | ||
147 | frequency = f; | ||
148 | } | ||
149 | sliding = false; | ||
150 | } else if (frequency > freq) { | ||
151 | sliding = true; | ||
152 | for (double f = starting_f; f >= freq; f -= ((starting_f - freq) / 2000.0)) { | ||
153 | frequency = f; | ||
154 | } | ||
155 | sliding = false; | ||
156 | } | ||
157 | frequency = freq; | ||
158 | volume = vol; | ||
159 | } | 144 | } |
160 | } | 145 | } |
161 | } | 146 | } |
@@ -248,16 +233,41 @@ ISR(TIMER3_COMPA_vect) { | |||
248 | OCR4A = sum; | 233 | OCR4A = sum; |
249 | } | 234 | } |
250 | #else | 235 | #else |
251 | if (frequency > 0) { | 236 | if (frequencies[voice_place] > 0) { |
237 | // if (frequencies[voice_place] > 880.0) { | ||
238 | // if (note_flipper == 100) { | ||
239 | // note_flipper = 0; | ||
240 | // return; | ||
241 | // } | ||
242 | // note_flipper++; | ||
243 | // } else { | ||
244 | // note_flipper = 0; | ||
245 | // } | ||
252 | // ICR3 = (int)(((double)F_CPU) / frequency); // Set max to the period | 246 | // ICR3 = (int)(((double)F_CPU) / frequency); // Set max to the period |
253 | // OCR3A = (int)(((double)F_CPU) / frequency) >> 1; // Set compare to half the period | 247 | // OCR3A = (int)(((double)F_CPU) / frequency) >> 1; // Set compare to half the period |
254 | voice_place %= voices; | 248 | |
255 | if (place > (frequencies[voice_place] / 50)) { | 249 | double freq; |
256 | voice_place = (voice_place + 1) % voices; | 250 | if (false) { |
257 | place = 0.0; | 251 | voice_place %= voices; |
252 | if (place > (frequencies[voice_place] / 50)) { | ||
253 | voice_place = (voice_place + 1) % voices; | ||
254 | place = 0.0; | ||
255 | } | ||
256 | freq = frequencies[voice_place]; | ||
257 | } else { | ||
258 | if (frequency != 0) { | ||
259 | if (frequency < frequencies[voices - 1]) { | ||
260 | frequency = frequency * 1.01454533494; | ||
261 | } else if (frequency > frequencies[voices - 1]) { | ||
262 | frequency = frequency * 0.98566319864; | ||
263 | } | ||
264 | } else { | ||
265 | frequency = frequencies[voices - 1]; | ||
266 | } | ||
267 | freq = frequency; | ||
258 | } | 268 | } |
259 | ICR3 = (int)(((double)F_CPU) / (frequencies[voice_place] * CPU_PRESCALER)); // Set max to the period | 269 | ICR3 = (int)(((double)F_CPU) / (freq * CPU_PRESCALER)); // Set max to the period |
260 | OCR3A = (int)((((double)F_CPU) / (frequencies[voice_place] * CPU_PRESCALER)) * note_timbre); // Set compare to half the period | 270 | OCR3A = (int)((((double)F_CPU) / (freq * CPU_PRESCALER)) * note_timbre); // Set compare to half the period |
261 | //OCR3A = (int)(((double)F_CPU) / (frequencies[voice_place] * CPU_PRESCALER)) >> 1 * duty_place; // Set compare to half the period | 271 | //OCR3A = (int)(((double)F_CPU) / (frequencies[voice_place] * CPU_PRESCALER)) >> 1 * duty_place; // Set compare to half the period |
262 | place++; | 272 | place++; |
263 | // if (duty_counter > (frequencies[voice_place] / 500)) { | 273 | // if (duty_counter > (frequencies[voice_place] / 500)) { |
@@ -413,23 +423,8 @@ if (audio_config.enable && voices < 8) { | |||
413 | freq = freq / SAMPLE_RATE; | 423 | freq = freq / SAMPLE_RATE; |
414 | #endif | 424 | #endif |
415 | if (freq > 0) { | 425 | if (freq > 0) { |
416 | if (frequency != 0) { | 426 | frequencies[voices] = freq; |
417 | double starting_f = frequency; | 427 | volumes[voices] = vol; |
418 | if (frequency < freq) { | ||
419 | for (double f = starting_f; f <= freq; f += ((freq - starting_f) / 2000.0)) { | ||
420 | frequency = f; | ||
421 | } | ||
422 | } else if (frequency > freq) { | ||
423 | for (double f = starting_f; f >= freq; f -= ((starting_f - freq) / 2000.0)) { | ||
424 | frequency = f; | ||
425 | } | ||
426 | } | ||
427 | } | ||
428 | frequency = freq; | ||
429 | volume = vol; | ||
430 | |||
431 | frequencies[voices] = frequency; | ||
432 | volumes[voices] = volume; | ||
433 | voices++; | 428 | voices++; |
434 | } | 429 | } |
435 | 430 | ||
diff --git a/quantum/keymap_common.c b/quantum/keymap_common.c index 4ee290ad0..43debf4ef 100644 --- a/quantum/keymap_common.c +++ b/quantum/keymap_common.c | |||
@@ -184,6 +184,7 @@ static action_t keycode_to_action(uint16_t keycode) | |||
184 | case RESET: ; // RESET is 0x5000, which is why this is here | 184 | case RESET: ; // RESET is 0x5000, which is why this is here |
185 | clear_keyboard(); | 185 | clear_keyboard(); |
186 | #ifdef AUDIO_ENABLE | 186 | #ifdef AUDIO_ENABLE |
187 | stop_all_notes(); | ||
187 | play_goodbye_tone(); | 188 | play_goodbye_tone(); |
188 | #endif | 189 | #endif |
189 | _delay_ms(250); | 190 | _delay_ms(250); |