Browse Source

reduce timer freq to 256Hz and also set volume of noise channel properly

Thomas B 1 month ago
parent
commit
39f9fb1269
2 changed files with 7 additions and 9 deletions
  1. 2
    2
      src/sound.c
  2. 5
    7
      src/timer.c

+ 2
- 2
src/sound.c View File

@@ -99,14 +99,14 @@ static void play_drum(enum drums drum) NONBANKED {
99 99
     switch (drum) {
100 100
         case dKick:
101 101
             NR41_REG = 0x2F; // length timer, higher value is shorter time (up to 0x3F)
102
-            NR42_REG = 0xF0; // initially full volume, no volume changes over time
102
+            NR42_REG = (conf_get()->music_vol << 4) | 0x00; // initially full volume, no volume changes over time
103 103
             NR43_REG = 0x11; // frequency distribution
104 104
             NR44_REG = 0xC0; // trigger and enable length
105 105
             break;
106 106
 
107 107
         case dSnare:
108 108
             NR41_REG = 0x00; // length timer, higher value is shorter time (up to 0x3F)
109
-            NR42_REG = 0xF1; // initially full volume, then fade sound out
109
+            NR42_REG = (conf_get()->music_vol << 4) | 0x01; // initially full volume, then fade sound out
110 110
             NR43_REG = 0x46; // frequency distribution
111 111
             NR44_REG = 0xC0; // trigger and enable length
112 112
             break;

+ 5
- 7
src/timer.c View File

@@ -24,11 +24,9 @@
24 24
 static uint16_t count = 0;
25 25
 
26 26
 static void timer_isr(void) NONBANKED {
27
-    if ((count & 0x03) == 0) {
28
-        sample_isr();
29
-    }
27
+    sample_isr();
30 28
     snd_play();
31
-    count++;
29
+    count += 4;
32 30
 }
33 31
 
34 32
 void timer_init(void) BANKED {
@@ -36,11 +34,11 @@ void timer_init(void) BANKED {
36 34
         count = 0;
37 35
         add_TIM(timer_isr);
38 36
         if (_cpu == CGB_TYPE) {
39
-            TMA_REG = 0x100 - 131; // 131.072kHz / 131 = ~1000Hz
37
+            TMA_REG = 0x100 - 128; // 32.768kHz / 128 = 256Hz
40 38
         } else {
41
-            TMA_REG = 0x100 - 65; // 65.536kHz / 65 = ~1008Hz
39
+            TMA_REG = 0x100 - 64; // 16.384kHz / 64 = 256Hz
42 40
         }
43
-        TAC_REG = TACF_65KHZ | TACF_START;
41
+        TAC_REG = TACF_16KHZ | TACF_START;
44 42
 
45 43
         set_interrupts(TIM_IFLAG | VBL_IFLAG);
46 44
     }

Loading…
Cancel
Save