From 8fc7992ca5d8c49c3bc11cc66f30e84134965324 Mon Sep 17 00:00:00 2001 From: Samuel Walker Date: Thu, 13 Feb 2025 14:16:37 -0700 Subject: [PATCH] Working on audio tests --- .gitignore | 1 + lib/audio.c | 18 +++++++++++------- lib/cpu.c | 2 +- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index bca203e..1dd4e48 100644 --- a/.gitignore +++ b/.gitignore @@ -11,6 +11,7 @@ compile_commands.json CTestTestfile.cmake _deps build/ +.cache/ # ---> C++ # Prerequisites diff --git a/lib/audio.c b/lib/audio.c index 6dbaa41..829feb2 100644 --- a/lib/audio.c +++ b/lib/audio.c @@ -279,8 +279,8 @@ void sq1_sweep() { //overflow check if(ctx.sq1_calc_period > 0x7FF) { ctx.sq1_enable = false; - } -} + } +} static int change = 1; static u32 ticks = 0; @@ -373,9 +373,13 @@ void audio_tick(){ } if((prev_ticks & (1 << 1)) && !(ticks & (1 << 1)) && ctx.sq1_sweep_enabled) { - ctx.sq1_sweep_timer++; - if((ctx.sq1_sweep_timer >= ctx.sq1_sweep_pace && ctx.sq1_sweep_pace > 0) || (ctx.sq1_sweep_timer >= 8 && ctx.sq1_sweep_pace == 0)) { - ctx.sq1_sweep_timer = 0; + ctx.sq1_sweep_timer--; + if(ctx.sq1_sweep_pace == 0) { + printf("sweep enabled without sweep pace\n"); + } + if(ctx.sq1_sweep_timer <= 0){//(ctx.sq1_sweep_timer >= ctx.sq1_sweep_pace && ctx.sq1_sweep_pace > 0) || (ctx.sq1_sweep_timer >= 8 && ctx.sq1_sweep_pace == 0)) { + printf("sweep trigger Period: %d, Timer: %d\n", ctx.sq1_sweep_pace, ctx.sq1_sweep_timer); + ctx.sq1_sweep_timer = ctx.sq1_sweep_pace != 0 ? ctx.sq1_sweep_pace : 8; if(ctx.sq1_enable && ctx.sq1_sweep_pace > 0 && ctx.sq1_sweep_enabled){ sq1_sweep(); if(ctx.sq1_calc_period <= 0x7FF && ctx.sq1_sweep_step != 0) { @@ -395,10 +399,9 @@ void enable_square1() { ctx.sq1_volume = ctx.sq1_initial_volume; ctx.sq1_env_timer = 0; ctx.sq1_sweep_period = ctx.sq1_period_reset; - ctx.sq1_sweep_timer = 0; + ctx.sq1_sweep_timer = ctx.sq1_sweep_pace != 0 ? ctx.sq1_sweep_pace : 8; ctx.sq1_env_direction = ctx.sq1_env_direction_buffer; ctx.sq1_env_pace = ctx.sq1_env_pace_buffer; - ctx.sq1_sweep_enabled = ((ctx.sq1_sweep_pace != 0) || (ctx.sq1_sweep_step != 0)); if(ctx.sq1_sweep_step != 0) { sq1_sweep(); } @@ -681,6 +684,7 @@ void audio_write(u16 address, u8 value){ ctx.sq1_sweep_pace = (value >> 4) & 0b111; ctx.sq1_sweep_direction = value & 0x08; ctx.sq1_sweep_step = value & 0b111; + ctx.sq1_sweep_enabled = ((ctx.sq1_sweep_pace != 0) || (ctx.sq1_sweep_step != 0)); } if(address == 0xFF11) { ctx.sq1_duty = value >> 6; diff --git a/lib/cpu.c b/lib/cpu.c index bf8aac7..143781f 100644 --- a/lib/cpu.c +++ b/lib/cpu.c @@ -119,4 +119,4 @@ void cpu_set_ie_register(u8 ie){ void cpu_request_interrupt(interrupt_type t) { ctx.int_flags |= t; -} \ No newline at end of file +}