working on fixing wave and noise

This commit is contained in:
Samuel Walker 2025-02-03 18:51:49 -07:00
parent e00b81304a
commit 0518c079cc
Signed by: piwalker
GPG Key ID: 616B1928705EA4C9

View File

@ -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_period_timer = ctx.ch3_period_reset;
ctx.ch3_sample = (ctx.ch3_sample + 1) % 32; ctx.ch3_sample = (ctx.ch3_sample + 1) % 32;
if(ctx.ch3_sample & 0b1) { 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 { } 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) { for(;lfsr_timer >= lfsr_clock;lfsr_timer -= lfsr_clock) {
if(lfsr_timer >= lfsr_clock && ctx.ch4_enable) { if(lfsr_timer >= lfsr_clock && ctx.ch4_enable) {
lfsr_timer = 0; lfsr_timer = 0;
ctx.ch4_lfsr = ctx.ch4_lfsr >> 1; u8 new = !((ctx.ch4_lfsr & 0b1) ^ ((ctx.ch4_lfsr >> 1) & 0b1)) & 0b1;
u8 new = (!(ctx.ch4_lfsr & 0b1) ^ ((ctx.ch4_lfsr >> 1)) & 0b1);
ctx.ch4_lfsr |= (new << 15); ctx.ch4_lfsr |= (new << 15);
if(ctx.ch4_lfsr_width) { if(ctx.ch4_lfsr_width) {
ctx.ch4_lfsr |= (new << 7); ctx.ch4_lfsr |= (new << 7);
} }
ctx.ch4_lfsr = ctx.ch4_lfsr >> 1;
//printf("lfsr: %02X, bit: %d\n", ctx.ch4_lfsr, new); //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) { 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); //printf("left: %d\n", ctx.ch3_volume);
} }
if(ctx.ch3_right) { 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);
} }
} }