]> git.donarmstrong.com Git - qmk_firmware.git/commitdiff
fixes audio prescaler to emit correct freq
authorJack Humbert <jack.humb@gmail.com>
Sun, 17 Apr 2016 00:26:02 +0000 (20:26 -0400)
committerJack Humbert <jack.humb@gmail.com>
Sun, 17 Apr 2016 00:26:02 +0000 (20:26 -0400)
keyboard/preonic/keymaps/default/keymap.c
quantum/audio.c
quantum/keymap_common.c

index e1f9b620292a7028d297dee0fcbb391ae1d1e415..6b626231802e8634a4c9b8bc3ea0c6e0f3e45278 100644 (file)
@@ -186,48 +186,48 @@ const uint16_t PROGMEM fn_actions[] = {
 
 #ifdef AUDIO_ENABLE
 float start_up[][2] = {
-  {440.0*pow(2.0,(50)/12.0), 20},
-  {440.0*pow(2.0,(62)/12.0), 8},
-  {440.0*pow(2.0,(54)/12.0), 20},
-  {440.0*pow(2.0,(62)/12.0), 8}
+  {440.0*pow(2.0,(14)/12.0), 20},
+  {440.0*pow(2.0,(26)/12.0), 8},
+  {440.0*pow(2.0,(18)/12.0), 20},
+  {440.0*pow(2.0,(26)/12.0), 8}
 };
 
 float tone_qwerty[][2] = {
-  {440.0*pow(2.0,(59)/12.0), 8},
-  {440.0*pow(2.0,(60)/12.0), 8},
+  {440.0*pow(2.0,(23)/12.0), 8},
+  {440.0*pow(2.0,(24)/12.0), 8},
   {0, 4},
-  {440.0*pow(2.0,(67)/12.0), 16}
+  {440.0*pow(2.0,(31)/12.0), 16}
 };
 
 float tone_colemak[][2] = {
-  {440.0*pow(2.0,(59)/12.0), 8},
-  {440.0*pow(2.0,(60)/12.0), 8},
+  {440.0*pow(2.0,(23)/12.0), 8},
+  {440.0*pow(2.0,(24)/12.0), 8},
   {0, 4},
-  {440.0*pow(2.0,(67)/12.0), 12},
+  {440.0*pow(2.0,(31)/12.0), 12},
   {0, 4},
-  {440.0*pow(2.0,(71)/12.0), 12}
+  {440.0*pow(2.0,(35)/12.0), 12}
 };
 
 float tone_dvorak[][2] = {
-  {440.0*pow(2.0,(59)/12.0), 8},
-  {440.0*pow(2.0,(60)/12.0), 8},
+  {440.0*pow(2.0,(23)/12.0), 8},
+  {440.0*pow(2.0,(24)/12.0), 8},
   {0, 4},
-  {440.0*pow(2.0,(67)/12.0), 8},
+  {440.0*pow(2.0,(31)/12.0), 8},
   {0, 4},
-  {440.0*pow(2.0,(69)/12.0), 8},
+  {440.0*pow(2.0,(33)/12.0), 8},
   {0, 4},
-  {440.0*pow(2.0,(67)/12.0), 8}
+  {440.0*pow(2.0,(31)/12.0), 8}
 };
 
 float tone_music[][2] = {
-  {440.0*pow(2.0,(48)/12.0), 8},
-  {440.0*pow(2.0,(50)/12.0), 8},
-  {440.0*pow(2.0,(52)/12.0), 8},
-  {440.0*pow(2.0,(53)/12.0), 8},
-  {440.0*pow(2.0,(55)/12.0), 8},
-  {440.0*pow(2.0,(57)/12.0), 8},
-  {440.0*pow(2.0,(59)/12.0), 8},
-  {440.0*pow(2.0,(60)/12.0), 8}
+  {440.0*pow(2.0,(12)/12.0), 8},
+  {440.0*pow(2.0,(14)/12.0), 8},
+  {440.0*pow(2.0,(16)/12.0), 8},
+  {440.0*pow(2.0,(17)/12.0), 8},
+  {440.0*pow(2.0,(19)/12.0), 8},
+  {440.0*pow(2.0,(21)/12.0), 8},
+  {440.0*pow(2.0,(23)/12.0), 8},
+  {440.0*pow(2.0,(24)/12.0), 8}
 };
 #endif
 
@@ -333,9 +333,9 @@ void process_action_user(keyrecord_t *record) {
 
   if (IS_LAYER_ON(_MUSIC)) {
     if (record->event.pressed) {
-        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);
+        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);
     } else {
-        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)));
+        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)));
     }
   }
 
index 5edcccdbe10784813b88ceb8183a9ffdc9f5a93a..470dc8e0c77bae9646311f0e68e0f7f003f144ca 100644 (file)
@@ -12,6 +12,8 @@
 
 #define PI 3.14159265
 
+#define CPU_PRESCALER 8
+
 // #define PWM_AUDIO
 
 #ifdef PWM_AUDIO
@@ -244,12 +246,12 @@ ISR(TIMER3_COMPA_vect) {
                 // ICR3 = (int)(((double)F_CPU) / frequency); // Set max to the period
                 // OCR3A = (int)(((double)F_CPU) / frequency) >> 1; // Set compare to half the period
                 voice_place %= voices;
-                if (place > (frequencies[voice_place] / 500)) {
+                if (place > (frequencies[voice_place] / 50)) {
                     voice_place = (voice_place + 1) % voices;
                     place = 0.0;
                 }
-                ICR3 = (int)(((double)F_CPU) / frequencies[voice_place]); // Set max to the period
-                OCR3A = (int)(((double)F_CPU) / frequencies[voice_place]) >> 1 * duty_place; // Set compare to half the period
+                ICR3 = (int)(((double)F_CPU) / (frequencies[voice_place] * CPU_PRESCALER)); // Set max to the period
+                OCR3A = (int)(((double)F_CPU) / (frequencies[voice_place] * CPU_PRESCALER)) >> 1 * duty_place; // Set compare to half the period
                 place++;
                 // if (duty_counter > (frequencies[voice_place] / 500)) {
                 //     duty_place = (duty_place % 3) + 1;
@@ -281,8 +283,8 @@ ISR(TIMER3_COMPA_vect) {
                 place -= SINE_LENGTH;
         #else
             if (note_frequency > 0) {
-                ICR3 = (int)(((double)F_CPU) / note_frequency); // Set max to the period
-                OCR3A = (int)(((double)F_CPU) / note_frequency) >> 1; // Set compare to half the period
+                ICR3 = (int)(((double)F_CPU) / (note_frequency * CPU_PRESCALER)); // Set max to the period
+                OCR3A = (int)(((double)F_CPU) / (note_frequency * CPU_PRESCALER)) >> 1; // Set compare to half the period
             } else {
                 ICR3 = 0;
                 OCR3A = 0;
index b919166853e9109a396f355d220b97c08e6aacd2..899437f4470d846074e08d26fce26c09c8f6c56c 100644 (file)
@@ -35,9 +35,9 @@ extern keymap_config_t keymap_config;
     #include "audio.h"
 
     float goodbye[][2] = {
-        {440.0*pow(2.0,(67)/12.0), 8},
-        {440.0*pow(2.0,(60)/12.0), 8},
-        {440.0*pow(2.0,(55)/12.0), 12},
+        {440.0*pow(2.0,(31)/12.0), 8},
+        {440.0*pow(2.0,(24)/12.0), 8},
+        {440.0*pow(2.0,(19)/12.0), 12},
     };
 #endif