aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBad Diode <bd@badd10de.dev>2023-05-30 21:52:30 +0200
committerBad Diode <bd@badd10de.dev>2023-05-30 21:52:30 +0200
commitf0ebc747d1b0d8753a1bc0f74b34a3012dd16753 (patch)
tree0c13400b979b88272700f0be07e33a4700a9b36c
parentdc53af3f01c0cbaefe4b330e2dcc2396b5afde47 (diff)
downloadstepper-f0ebc747d1b0d8753a1bc0f74b34a3012dd16753.tar.gz
stepper-f0ebc747d1b0d8753a1bc0f74b34a3012dd16753.zip
Properly handle audio/link sync settings
-rw-r--r--src/gba/gba.h12
-rw-r--r--src/sequencer.c12
-rw-r--r--src/settings.c31
-rw-r--r--src/settings.h12
4 files changed, 60 insertions, 7 deletions
diff --git a/src/gba/gba.h b/src/gba/gba.h
index 2b28295..74b6942 100644
--- a/src/gba/gba.h
+++ b/src/gba/gba.h
@@ -510,10 +510,18 @@ typedef enum {
510} SoundChannel; 510} SoundChannel;
511 511
512inline u16 512inline u16
513sound_volume(SoundChannel channels, u8 volume) { 513sound_volume(SoundChannel channels, u8 volume, u8 pan) {
514 volume = volume & 0x7; 514 volume = volume & 0x7;
515 channels = channels & 0xF; 515 channels = channels & 0xF;
516 return volume | (volume << 0x4) | (channels << 0x8) | (channels << 0xC); 516 u16 right = volume | (channels << 0x8);
517 u16 left = (volume << 0x4) | (channels << 0xC);
518 if (pan == 1) {
519 return left;
520 }
521 if (pan == 2) {
522 return right;
523 }
524 return left | right;
517} 525}
518 526
519// Sound Direct Sound master bits. 527// Sound Direct Sound master bits.
diff --git a/src/sequencer.c b/src/sequencer.c
index d8c5f3f..2ee6b07 100644
--- a/src/sequencer.c
+++ b/src/sequencer.c
@@ -45,7 +45,6 @@ gate_on(void) {
45 irs_set(IRQ_TIMER_3, gate_off); 45 irs_set(IRQ_TIMER_3, gate_off);
46 TIMER_DATA_3 = n_ticks; 46 TIMER_DATA_3 = n_ticks;
47 TIMER_CTRL_3 = TIMER_CTRL_IRQ | TIMER_CTRL_ENABLE | TIMER_CTRL_FREQ_3; 47 TIMER_CTRL_3 = TIMER_CTRL_IRQ | TIMER_CTRL_ENABLE | TIMER_CTRL_FREQ_3;
48 audio_sync_click = true;
49} 48}
50 49
51void 50void
@@ -169,6 +168,12 @@ play_step(void) {
169 case SYNC_OUT_LINK_16: { gate_on(); } break; 168 case SYNC_OUT_LINK_16: { gate_on(); } break;
170 case SYNC_OUT_LINK_8: { if (step_counter % 2 == 0) { gate_on(); } } break; 169 case SYNC_OUT_LINK_8: { if (step_counter % 2 == 0) { gate_on(); } } break;
171 case SYNC_OUT_LINK_4: { if (step_counter % 4 == 0) { gate_on(); } } break; 170 case SYNC_OUT_LINK_4: { if (step_counter % 4 == 0) { gate_on(); } } break;
171 case SYNC_OUT_AUDIO_16: { audio_sync_click = true; } break;
172 case SYNC_OUT_AUDIO_8: { if (step_counter % 2 == 0) { audio_sync_click = true; } } break;
173 case SYNC_OUT_AUDIO_4: { if (step_counter % 4 == 0) { audio_sync_click = true; } } break;
174 case SYNC_OUT_LINK_AUDIO_16: { gate_on(); audio_sync_click = true; } break;
175 case SYNC_OUT_LINK_AUDIO_8: { if (step_counter % 2 == 0) { gate_on(); audio_sync_click = true; } } break;
176 case SYNC_OUT_LINK_AUDIO_4: { if (step_counter % 4 == 0) { gate_on(); audio_sync_click = true; } } break;
172 default: break; 177 default: break;
173 } 178 }
174 step_counter = (step_counter + 1) % 16; 179 step_counter = (step_counter + 1) % 16;
@@ -1033,9 +1038,6 @@ sequencer_init(void) {
1033 1038
1034 // Initialize sound system. 1039 // Initialize sound system.
1035 SOUND_STATUS = SOUND_ENABLE; 1040 SOUND_STATUS = SOUND_ENABLE;
1036 SOUND_DMG_MASTER = sound_volume(SOUND_SQUARE1
1037 | SOUND_SQUARE2
1038 | SOUND_WAVE
1039 | SOUND_NOISE, 3);
1040 init_dsound(); 1041 init_dsound();
1042 set_audio_settings();
1041} 1043}
diff --git a/src/settings.c b/src/settings.c
index d9d890d..b814e1a 100644
--- a/src/settings.c
+++ b/src/settings.c
@@ -14,6 +14,35 @@ draw_settings_cursor(void) {
14} 14}
15 15
16void 16void
17set_audio_settings(void) {
18 switch (settings.sync) {
19 case SYNC_OUT_LINK_AUDIO_4:
20 case SYNC_OUT_LINK_AUDIO_8:
21 case SYNC_OUT_LINK_AUDIO_16:
22 case SYNC_OUT_AUDIO_4:
23 case SYNC_OUT_AUDIO_8:
24 case SYNC_OUT_AUDIO_16: {
25 SOUND_DMG_MASTER = sound_volume(SOUND_SQUARE1
26 | SOUND_SQUARE2
27 | SOUND_WAVE
28 | SOUND_NOISE, 3, 2);
29 SOUND_DSOUND_MASTER =
30 SOUND_DMG100
31 | SOUND_DSOUND_RATIO_A
32 | SOUND_DSOUND_LEFT_A
33 | SOUND_DSOUND_RESET_A;
34 } break;
35 default: {
36 SOUND_DMG_MASTER = sound_volume(SOUND_SQUARE1
37 | SOUND_SQUARE2
38 | SOUND_WAVE
39 | SOUND_NOISE, 3, 0);
40 SOUND_DSOUND_MASTER = SOUND_DMG100;
41 } break;
42 }
43}
44
45void
17handle_settings_input(void) { 46handle_settings_input(void) {
18 if (key_tap(KEY_DOWN)) { 47 if (key_tap(KEY_DOWN)) {
19 if (settings_cursor_loc == (N_SETTINGS - 1)) { 48 if (settings_cursor_loc == (N_SETTINGS - 1)) {
@@ -39,6 +68,7 @@ handle_settings_input(void) {
39 } else { 68 } else {
40 settings.sync++; 69 settings.sync++;
41 } 70 }
71 set_audio_settings();
42 } break; 72 } break;
43 case 1: { 73 case 1: {
44 if ((settings.theme + 1) >= THEME_NUM) { 74 if ((settings.theme + 1) >= THEME_NUM) {
@@ -67,6 +97,7 @@ handle_settings_input(void) {
67 } else { 97 } else {
68 settings.sync--; 98 settings.sync--;
69 } 99 }
100 set_audio_settings();
70 } break; 101 } break;
71 case 1: { 102 case 1: {
72 if (settings.theme == 0) { 103 if (settings.theme == 0) {
diff --git a/src/settings.h b/src/settings.h
index 370c03c..960eabc 100644
--- a/src/settings.h
+++ b/src/settings.h
@@ -8,6 +8,12 @@ typedef enum SyncSetting {
8 SYNC_OUT_LINK_16, 8 SYNC_OUT_LINK_16,
9 SYNC_OUT_LINK_8, 9 SYNC_OUT_LINK_8,
10 SYNC_OUT_LINK_4, 10 SYNC_OUT_LINK_4,
11 SYNC_OUT_AUDIO_16,
12 SYNC_OUT_AUDIO_8,
13 SYNC_OUT_AUDIO_4,
14 SYNC_OUT_LINK_AUDIO_16,
15 SYNC_OUT_LINK_AUDIO_8,
16 SYNC_OUT_LINK_AUDIO_4,
11 SYNC_NUM, 17 SYNC_NUM,
12} SyncSetting; 18} SyncSetting;
13 19
@@ -16,6 +22,12 @@ char * sync_setting_str[] = {
16 "LINK OUT (16)", 22 "LINK OUT (16)",
17 "LINK OUT (8)", 23 "LINK OUT (8)",
18 "LINK OUT (4)", 24 "LINK OUT (4)",
25 "AUDIO OUT (16)",
26 "AUDIO OUT (8)",
27 "AUDIO OUT (4)",
28 "LINK+AUDIO OUT (16)",
29 "LINK+AUDIO OUT (8)",
30 "LINK+AUDIO OUT (4)",
19}; 31};
20 32
21typedef enum ThemeSetting { 33typedef enum ThemeSetting {