diff options
Diffstat (limited to 'quantum/audio.c')
| -rw-r--r-- | quantum/audio.c | 12 |
1 files changed, 7 insertions, 5 deletions
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; |
