From 0518c079ccb6c22b329e7776d3624f4f07613c78 Mon Sep 17 00:00:00 2001 From: Samuel Walker Date: Mon, 3 Feb 2025 18:51:49 -0700 Subject: [PATCH] working on fixing wave and noise --- lib/audio.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/lib/audio.c b/lib/audio.c index e156f66..1e79b1c 100644 --- a/lib/audio.c +++ b/lib/audio.c @@ -96,9 +96,9 @@ static int audio_callback(const void* input_uffer, void *output_buffer, ctx.ch3_period_timer = ctx.ch3_period_reset; ctx.ch3_sample = (ctx.ch3_sample + 1) % 32; if(ctx.ch3_sample & 0b1) { - ctx.ch3_last_sample = ctx.wave_ram[ctx.ch3_sample << 1] & 0xF; + ctx.ch3_last_sample = ctx.wave_ram[ctx.ch3_sample >> 1] & 0xF; } else { - ctx.ch3_last_sample = ctx.wave_ram[ctx.ch3_sample << 1] >> 4; + ctx.ch3_last_sample = ctx.wave_ram[ctx.ch3_sample >> 1] >> 4; } } } @@ -106,12 +106,12 @@ static int audio_callback(const void* input_uffer, void *output_buffer, for(;lfsr_timer >= lfsr_clock;lfsr_timer -= lfsr_clock) { if(lfsr_timer >= lfsr_clock && ctx.ch4_enable) { lfsr_timer = 0; - ctx.ch4_lfsr = ctx.ch4_lfsr >> 1; - u8 new = (!(ctx.ch4_lfsr & 0b1) ^ ((ctx.ch4_lfsr >> 1)) & 0b1); + u8 new = !((ctx.ch4_lfsr & 0b1) ^ ((ctx.ch4_lfsr >> 1) & 0b1)) & 0b1; ctx.ch4_lfsr |= (new << 15); if(ctx.ch4_lfsr_width) { ctx.ch4_lfsr |= (new << 7); } + ctx.ch4_lfsr = ctx.ch4_lfsr >> 1; //printf("lfsr: %02X, bit: %d\n", ctx.ch4_lfsr, new); } } @@ -134,13 +134,20 @@ static int audio_callback(const void* input_uffer, void *output_buffer, } } - if(ctx.ch3_enable) { + if(ctx.ch3_enable && ctx.ch3_volume != 00) { + u8 shift = 0; + if(ctx.ch3_volume == 0b10) { + shift = 1; + } + if(ctx.ch3_volume == 0b11) { + shift = 2; + } if(ctx.ch3_left) { - left += ((float)ctx.ch3_volume/4.0f) * (((float)(ctx.ch3_last_sample) - 7.5f)/7.5f); + left += (((float)(ctx.ch3_last_sample >> shift) - 7.5f)/7.5f); //printf("left: %d\n", ctx.ch3_volume); } if(ctx.ch3_right) { - right += ((float)ctx.ch3_volume/4.0f) * (((float)(ctx.ch3_last_sample) - 7.5f)/7.5f); + right += (((float)(ctx.ch3_last_sample >> shift) - 7.5f)/7.5f); } }