diff options
author | Jack Humbert <jack.humb@gmail.com> | 2016-04-16 20:26:02 -0400 |
---|---|---|
committer | Jack Humbert <jack.humb@gmail.com> | 2016-04-16 20:26:02 -0400 |
commit | c83aa16f1d614c1c10f7597a67ffb9f2ae871951 (patch) | |
tree | 6d61c4f255c4ddbc98085a9758693a877e5190b5 | |
parent | b8d2e66638409066661e7dd3c66473d583256ec5 (diff) | |
download | qmk_firmware-c83aa16f1d614c1c10f7597a67ffb9f2ae871951.tar.gz qmk_firmware-c83aa16f1d614c1c10f7597a67ffb9f2ae871951.zip |
fixes audio prescaler to emit correct freq
-rw-r--r-- | keyboard/preonic/keymaps/default/keymap.c | 52 | ||||
-rw-r--r-- | quantum/audio.c | 12 | ||||
-rw-r--r-- | quantum/keymap_common.c | 6 |
3 files changed, 36 insertions, 34 deletions
diff --git a/keyboard/preonic/keymaps/default/keymap.c b/keyboard/preonic/keymaps/default/keymap.c index e1f9b6202..6b6262318 100644 --- a/keyboard/preonic/keymaps/default/keymap.c +++ b/keyboard/preonic/keymaps/default/keymap.c | |||
@@ -186,48 +186,48 @@ const uint16_t PROGMEM fn_actions[] = { | |||
186 | 186 | ||
187 | #ifdef AUDIO_ENABLE | 187 | #ifdef AUDIO_ENABLE |
188 | float start_up[][2] = { | 188 | float start_up[][2] = { |
189 | {440.0*pow(2.0,(50)/12.0), 20}, | 189 | {440.0*pow(2.0,(14)/12.0), 20}, |
190 | {440.0*pow(2.0,(62)/12.0), 8}, | 190 | {440.0*pow(2.0,(26)/12.0), 8}, |
191 | {440.0*pow(2.0,(54)/12.0), 20}, | 191 | {440.0*pow(2.0,(18)/12.0), 20}, |
192 | {440.0*pow(2.0,(62)/12.0), 8} | 192 | {440.0*pow(2.0,(26)/12.0), 8} |
193 | }; | 193 | }; |
194 | 194 | ||
195 | float tone_qwerty[][2] = { | 195 | float tone_qwerty[][2] = { |
196 | {440.0*pow(2.0,(59)/12.0), 8}, | 196 | {440.0*pow(2.0,(23)/12.0), 8}, |
197 | {440.0*pow(2.0,(60)/12.0), 8}, | 197 | {440.0*pow(2.0,(24)/12.0), 8}, |
198 | {0, 4}, | 198 | {0, 4}, |
199 | {440.0*pow(2.0,(67)/12.0), 16} | 199 | {440.0*pow(2.0,(31)/12.0), 16} |
200 | }; | 200 | }; |
201 | 201 | ||
202 | float tone_colemak[][2] = { | 202 | float tone_colemak[][2] = { |
203 | {440.0*pow(2.0,(59)/12.0), 8}, | 203 | {440.0*pow(2.0,(23)/12.0), 8}, |
204 | {440.0*pow(2.0,(60)/12.0), 8}, | 204 | {440.0*pow(2.0,(24)/12.0), 8}, |
205 | {0, 4}, | 205 | {0, 4}, |
206 | {440.0*pow(2.0,(67)/12.0), 12}, | 206 | {440.0*pow(2.0,(31)/12.0), 12}, |
207 | {0, 4}, | 207 | {0, 4}, |
208 | {440.0*pow(2.0,(71)/12.0), 12} | 208 | {440.0*pow(2.0,(35)/12.0), 12} |
209 | }; | 209 | }; |
210 | 210 | ||
211 | float tone_dvorak[][2] = { | 211 | float tone_dvorak[][2] = { |
212 | {440.0*pow(2.0,(59)/12.0), 8}, | 212 | {440.0*pow(2.0,(23)/12.0), 8}, |
213 | {440.0*pow(2.0,(60)/12.0), 8}, | 213 | {440.0*pow(2.0,(24)/12.0), 8}, |
214 | {0, 4}, | 214 | {0, 4}, |
215 | {440.0*pow(2.0,(67)/12.0), 8}, | 215 | {440.0*pow(2.0,(31)/12.0), 8}, |
216 | {0, 4}, | 216 | {0, 4}, |
217 | {440.0*pow(2.0,(69)/12.0), 8}, | 217 | {440.0*pow(2.0,(33)/12.0), 8}, |
218 | {0, 4}, | 218 | {0, 4}, |
219 | {440.0*pow(2.0,(67)/12.0), 8} | 219 | {440.0*pow(2.0,(31)/12.0), 8} |
220 | }; | 220 | }; |
221 | 221 | ||
222 | float tone_music[][2] = { | 222 | float tone_music[][2] = { |
223 | {440.0*pow(2.0,(48)/12.0), 8}, | 223 | {440.0*pow(2.0,(12)/12.0), 8}, |
224 | {440.0*pow(2.0,(50)/12.0), 8}, | 224 | {440.0*pow(2.0,(14)/12.0), 8}, |
225 | {440.0*pow(2.0,(52)/12.0), 8}, | 225 | {440.0*pow(2.0,(16)/12.0), 8}, |
226 | {440.0*pow(2.0,(53)/12.0), 8}, | 226 | {440.0*pow(2.0,(17)/12.0), 8}, |
227 | {440.0*pow(2.0,(55)/12.0), 8}, | 227 | {440.0*pow(2.0,(19)/12.0), 8}, |
228 | {440.0*pow(2.0,(57)/12.0), 8}, | 228 | {440.0*pow(2.0,(21)/12.0), 8}, |
229 | {440.0*pow(2.0,(59)/12.0), 8}, | 229 | {440.0*pow(2.0,(23)/12.0), 8}, |
230 | {440.0*pow(2.0,(60)/12.0), 8} | 230 | {440.0*pow(2.0,(24)/12.0), 8} |
231 | }; | 231 | }; |
232 | #endif | 232 | #endif |
233 | 233 | ||
@@ -333,9 +333,9 @@ void process_action_user(keyrecord_t *record) { | |||
333 | 333 | ||
334 | if (IS_LAYER_ON(_MUSIC)) { | 334 | if (IS_LAYER_ON(_MUSIC)) { |
335 | if (record->event.pressed) { | 335 | if (record->event.pressed) { |
336 | play_note(((double)261.626)*pow(2.0, -2.0)*pow(2.0,(starting_note + SCALE[record->event.key.col + offset])/12.0+(MATRIX_ROWS - record->event.key.row)), 0xF); | 336 | play_note(((double)261.626)*pow(2.0, -3.0)*pow(2.0,(starting_note + SCALE[record->event.key.col + offset])/12.0+(MATRIX_ROWS - record->event.key.row)), 0xF); |
337 | } else { | 337 | } else { |
338 | stop_note(((double)261.626)*pow(2.0, -2.0)*pow(2.0,(starting_note + SCALE[record->event.key.col + offset])/12.0+(MATRIX_ROWS - record->event.key.row))); | 338 | stop_note(((double)261.626)*pow(2.0, -3.0)*pow(2.0,(starting_note + SCALE[record->event.key.col + offset])/12.0+(MATRIX_ROWS - record->event.key.row))); |
339 | } | 339 | } |
340 | } | 340 | } |
341 | 341 | ||
diff --git a/quantum/audio.c b/quantum/audio.c index 5edcccdbe..470dc8e0c 100644 --- a/quantum/audio.c +++ b/quantum/audio.c | |||
@@ -12,6 +12,8 @@ | |||
12 | 12 | ||
13 | #define PI 3.14159265 | 13 | #define PI 3.14159265 |
14 | 14 | ||
15 | #define CPU_PRESCALER 8 | ||
16 | |||
15 | // #define PWM_AUDIO | 17 | // #define PWM_AUDIO |
16 | 18 | ||
17 | #ifdef PWM_AUDIO | 19 | #ifdef PWM_AUDIO |
@@ -244,12 +246,12 @@ ISR(TIMER3_COMPA_vect) { | |||
244 | // ICR3 = (int)(((double)F_CPU) / frequency); // Set max to the period | 246 | // ICR3 = (int)(((double)F_CPU) / frequency); // Set max to the period |
245 | // 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 |
246 | voice_place %= voices; | 248 | voice_place %= voices; |
247 | if (place > (frequencies[voice_place] / 500)) { | 249 | if (place > (frequencies[voice_place] / 50)) { |
248 | voice_place = (voice_place + 1) % voices; | 250 | voice_place = (voice_place + 1) % voices; |
249 | place = 0.0; | 251 | place = 0.0; |
250 | } | 252 | } |
251 | ICR3 = (int)(((double)F_CPU) / frequencies[voice_place]); // Set max to the period | 253 | ICR3 = (int)(((double)F_CPU) / (frequencies[voice_place] * CPU_PRESCALER)); // Set max to the period |
252 | OCR3A = (int)(((double)F_CPU) / frequencies[voice_place]) >> 1 * duty_place; // Set compare to half the period | 254 | OCR3A = (int)(((double)F_CPU) / (frequencies[voice_place] * CPU_PRESCALER)) >> 1 * duty_place; // Set compare to half the period |
253 | place++; | 255 | place++; |
254 | // if (duty_counter > (frequencies[voice_place] / 500)) { | 256 | // if (duty_counter > (frequencies[voice_place] / 500)) { |
255 | // duty_place = (duty_place % 3) + 1; | 257 | // duty_place = (duty_place % 3) + 1; |
@@ -281,8 +283,8 @@ ISR(TIMER3_COMPA_vect) { | |||
281 | place -= SINE_LENGTH; | 283 | place -= SINE_LENGTH; |
282 | #else | 284 | #else |
283 | if (note_frequency > 0) { | 285 | if (note_frequency > 0) { |
284 | ICR3 = (int)(((double)F_CPU) / note_frequency); // Set max to the period | 286 | ICR3 = (int)(((double)F_CPU) / (note_frequency * CPU_PRESCALER)); // Set max to the period |
285 | OCR3A = (int)(((double)F_CPU) / note_frequency) >> 1; // Set compare to half the period | 287 | OCR3A = (int)(((double)F_CPU) / (note_frequency * CPU_PRESCALER)) >> 1; // Set compare to half the period |
286 | } else { | 288 | } else { |
287 | ICR3 = 0; | 289 | ICR3 = 0; |
288 | OCR3A = 0; | 290 | OCR3A = 0; |
diff --git a/quantum/keymap_common.c b/quantum/keymap_common.c index b91916685..899437f44 100644 --- a/quantum/keymap_common.c +++ b/quantum/keymap_common.c | |||
@@ -35,9 +35,9 @@ extern keymap_config_t keymap_config; | |||
35 | #include "audio.h" | 35 | #include "audio.h" |
36 | 36 | ||
37 | float goodbye[][2] = { | 37 | float goodbye[][2] = { |
38 | {440.0*pow(2.0,(67)/12.0), 8}, | 38 | {440.0*pow(2.0,(31)/12.0), 8}, |
39 | {440.0*pow(2.0,(60)/12.0), 8}, | 39 | {440.0*pow(2.0,(24)/12.0), 8}, |
40 | {440.0*pow(2.0,(55)/12.0), 12}, | 40 | {440.0*pow(2.0,(19)/12.0), 12}, |
41 | }; | 41 | }; |
42 | #endif | 42 | #endif |
43 | 43 | ||