From dc53af3f01c0cbaefe4b330e2dcc2396b5afde47 Mon Sep 17 00:00:00 2001 From: Bad Diode Date: Tue, 30 May 2023 21:30:44 +0200 Subject: Add initial audio sync --- src/gba/gba.h | 8 ++++---- src/main.c | 27 +++++++++++++++------------ src/sequencer.c | 37 +++++++++++++++++++------------------ 3 files changed, 38 insertions(+), 34 deletions(-) diff --git a/src/gba/gba.h b/src/gba/gba.h index f726b72..2b28295 100644 --- a/src/gba/gba.h +++ b/src/gba/gba.h @@ -522,12 +522,12 @@ sound_volume(SoundChannel channels, u8 volume) { #define SOUND_DMG100 0x2 #define SOUND_DSOUND_RATIO_A (1 << 0x2) #define SOUND_DSOUND_RATIO_B (1 << 0x3) -#define SOUND_DSOUND_LEFT_A (1 << 0x8) -#define SOUND_DSOUND_RIGHT_A (1 << 0x9) +#define SOUND_DSOUND_RIGHT_A (1 << 0x8) +#define SOUND_DSOUND_LEFT_A (1 << 0x9) #define SOUND_DSOUND_TIMER_A (1 << 0xA) #define SOUND_DSOUND_RESET_A (1 << 0xB) -#define SOUND_DSOUND_LEFT_B (1 << 0xC) -#define SOUND_DSOUND_RIGHT_B (1 << 0xD) +#define SOUND_DSOUND_RIGHT_B (1 << 0xC) +#define SOUND_DSOUND_LEFT_B (1 << 0xD) #define SOUND_DSOUND_TIMER_B (1 << 0xE) #define SOUND_DSOUND_RESET_B (1 << 0xF) diff --git a/src/main.c b/src/main.c index f0fc7c3..0d4056a 100644 --- a/src/main.c +++ b/src/main.c @@ -13,7 +13,7 @@ WITH REGARD TO THIS SOFTWARE. // // UI tweaks. // + Theming support, with a number of pre-configured themes and custom colors. -// - Add more default themes +// + Add more default themes // - Add custom user themes // - Notification support for feedback when doing some operations // (copying/pasting) @@ -23,7 +23,7 @@ WITH REGARD TO THIS SOFTWARE. // // Quality of life improvements. // + Add a settings page to change some configuration parameters. -// - Change the cursor, the line is difficult to see. +// + Change the cursor, the line is difficult to see. (Option to thick cursor) // - When not on play mode, adjusting a note or a parameter triggers the sound. // This could get annoying, so maybe it should be a configuration option to // enable it? @@ -33,25 +33,24 @@ WITH REGARD TO THIS SOFTWARE. // // Advanced // + Sync via CV by using the link cable. -// - Audio sync by panning left the sound and using right as a click (or +// + Audio sync by panning left the sound and using right as a click (or // viceversa, needs to check the standard.) -// - Sync via MIDI via arduinoboy or something similar. -// - Add an FM channel using Direct Sound. +// - Allow "marking" several trigs to be able to copy/paste them and/or adjust +// their parameters. // - Per trig note probability. // - Add an envelope to ch3, would need to work with a timer in order to make // it work I think. -// - Allow "marking" several trigs to be able to copy/paste them and/or adjust -// their parameters. +// - Sync via MIDI via arduinoboy or something similar. // // Bugfixes +// + Pattern chaining seems off, it plays the first note of the pattern before +// switching +// + Memory corruption when trying to load a save file. Regression due to +// removal of filesystem.c // - Sound can get hung up sometimes, but I can't reproduce when this happens. // Not sure if this is an emulator thing or happens also in hardware. // - Cursor can stay in position instead of dissapering, again I can't // reproduce this right now, just happened randomly. Needs investigation. -// + Pattern chaining seems off, it plays the first note of the pattern before -// switching -// + Memory corruption when trying to load a save file. Regression due to -// removal of filesystem.c // #include "gba/gba.h" @@ -59,6 +58,7 @@ WITH REGARD TO THIS SOFTWARE. #include "renderer_m0.c" #include "globals.c" #include "settings.c" +#include "dsound.c" #include "sequencer.c" #define PROF_ENABLE 0 @@ -166,6 +166,9 @@ update(void) { set_time(patterns[current_pattern].bpm); update_bpm = false; } + if (audio_sync_click) { + play_click(); + } } int @@ -178,7 +181,7 @@ main(void) { // Register interrupts. irq_init(); - irs_set(IRQ_VBLANK, irs_stub); + irs_set(IRQ_VBLANK, sound_vsync); // Initialize sequencer. sequencer_init(); diff --git a/src/sequencer.c b/src/sequencer.c index b295730..d8c5f3f 100644 --- a/src/sequencer.c +++ b/src/sequencer.c @@ -26,9 +26,9 @@ gate_off(void) { | SIO_SI_OUT(0) | SIO_SO_OUT(1) | SIO_SC(0) - | SIO_SD(1) + | SIO_SD(0) | SIO_SO(0); - TIMER_CTRL_1 = 0; + TIMER_CTRL_3 = 0; } void @@ -39,12 +39,13 @@ gate_on(void) { | SIO_SI_OUT(0) | SIO_SO_OUT(1) | SIO_SC(1) - | SIO_SD(1) - | SIO_SO(0); + | SIO_SD(0) + | SIO_SO(1); int n_ticks = -244181 / 600; - irs_set(IRQ_TIMER_1, gate_off); - TIMER_DATA_1 = n_ticks; - TIMER_CTRL_1 = TIMER_CTRL_IRQ | TIMER_CTRL_ENABLE | TIMER_CTRL_FREQ_3; + irs_set(IRQ_TIMER_3, gate_off); + TIMER_DATA_3 = n_ticks; + TIMER_CTRL_3 = TIMER_CTRL_IRQ | TIMER_CTRL_ENABLE | TIMER_CTRL_FREQ_3; + audio_sync_click = true; } void @@ -183,9 +184,9 @@ set_time(int bpm) { // We have to operate on integer values, so the numbers have been // precalculated to `n_ticks = 244181 / bmp` int n_ticks = -244181 / bpm; - irs_set(IRQ_TIMER_0, play_step); - TIMER_DATA_0 = n_ticks; - TIMER_CTRL_0 = TIMER_CTRL_IRQ | TIMER_CTRL_ENABLE | TIMER_CTRL_FREQ_3; + irs_set(IRQ_TIMER_2, play_step); + TIMER_DATA_2 = n_ticks; + TIMER_CTRL_2 = TIMER_CTRL_IRQ | TIMER_CTRL_ENABLE | TIMER_CTRL_FREQ_3; } TriggerNote * @@ -296,7 +297,7 @@ void stop_playing(void) { play_status = 0; step_counter = 0; - TIMER_CTRL_0 = 0; + TIMER_CTRL_2 = 0; SOUND_SQUARE1_CTRL = 0; SOUND_SQUARE2_CTRL = 0; SOUND_WAVE_CTRL = 0; @@ -308,7 +309,7 @@ void toggle_playing(void) { play_status ^= 1; step_counter = 0; - if ((TIMER_CTRL_0 & TIMER_CTRL_ENABLE) == 0) { + if ((TIMER_CTRL_2 & TIMER_CTRL_ENABLE) == 0) { if (current_pattern != next_pattern) { current_pattern = next_pattern; redraw_pattern_buttons = true; @@ -316,7 +317,7 @@ toggle_playing(void) { set_time(patterns[current_pattern].bpm); play_step(); } else { - TIMER_CTRL_0 ^= TIMER_CTRL_ENABLE; + TIMER_CTRL_2 ^= TIMER_CTRL_ENABLE; SOUND_SQUARE1_CTRL = 0; SOUND_SQUARE2_CTRL = 0; SOUND_WAVE_CTRL = 0; @@ -328,7 +329,7 @@ toggle_playing(void) { void pause_playing(void) { play_status ^= 1; - if ((TIMER_CTRL_0 & TIMER_CTRL_ENABLE) == 0) { + if ((TIMER_CTRL_2 & TIMER_CTRL_ENABLE) == 0) { if (current_pattern != next_pattern && step_counter == 0) { current_pattern = next_pattern; redraw_pattern_buttons = true; @@ -336,7 +337,7 @@ pause_playing(void) { set_time(patterns[current_pattern].bpm); play_step(); } else { - TIMER_CTRL_0 ^= TIMER_CTRL_ENABLE; + TIMER_CTRL_2 ^= TIMER_CTRL_ENABLE; SOUND_SQUARE1_CTRL = 0; SOUND_SQUARE2_CTRL = 0; SOUND_WAVE_CTRL = 0; @@ -414,7 +415,7 @@ handle_right_col_selection(void) { patterns[pattern_selection_loc].bpm + bpm_inc, 10, 300); - if ((TIMER_CTRL_0 & TIMER_CTRL_ENABLE) != 0 + if ((TIMER_CTRL_2 & TIMER_CTRL_ENABLE) != 0 && current_pattern == pattern_selection_loc) { set_time(patterns[current_pattern].bpm); } @@ -432,7 +433,7 @@ handle_right_col_selection(void) { patterns[pattern_selection_loc].bpm + bpm_inc, 10, 300); - if ((TIMER_CTRL_0 & TIMER_CTRL_ENABLE) != 0 + if ((TIMER_CTRL_2 & TIMER_CTRL_ENABLE) != 0 && current_pattern == pattern_selection_loc) { set_time(patterns[current_pattern].bpm); } @@ -1036,5 +1037,5 @@ sequencer_init(void) { | SOUND_SQUARE2 | SOUND_WAVE | SOUND_NOISE, 3); - SOUND_DSOUND_MASTER = SOUND_DMG100; + init_dsound(); } -- cgit v1.2.1