This commit is contained in:
Samuel Walker 2025-02-04 11:45:09 -07:00
parent cf742dba11
commit 645ae2f7d3
Signed by: piwalker
GPG Key ID: BE1F84BF85111255

View File

@ -95,7 +95,7 @@ static int audio_callback(const void* input_uffer, void *output_buffer,
if(ctx.ch3_period_timer >= 0x800) { if(ctx.ch3_period_timer >= 0x800) {
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) == 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;
@ -291,10 +291,10 @@ void audio_tick(){
} }
if(ctx.ch3_len_enable) { if(ctx.ch3_len_enable) {
ctx.ch3_len++; if(ctx.ch3_len >= 255) {
if(ctx.ch3_len >= 256) {
ctx.ch3_enable = false; ctx.ch3_enable = false;
} }
ctx.ch3_len++;
} }
if(ctx.ch4_len_enable) { if(ctx.ch4_len_enable) {
@ -409,12 +409,13 @@ void enable_wave() {
return; return;
} }
ctx.ch3_enable = true; ctx.ch3_enable = true;
if(ctx.ch3_len >= 256) { if(ctx.ch3_len == 255) {
ctx.ch3_len = 0; ctx.ch3_len = 0;
} }
ctx.ch3_sample = 0; ctx.ch3_sample = 0;
ctx.ch3_volume = ctx.ch3_initial_volume; ctx.ch3_volume = ctx.ch3_initial_volume;
ctx.ch3_period_timer = ctx.ch3_period_reset; ctx.ch3_period_timer = ctx.ch3_period_reset;
printf("channel 3 enabled\n");
} }
void enable_noise() { void enable_noise() {
@ -433,7 +434,7 @@ void enable_noise() {
} }
u8 audio_read(u16 address) { u8 audio_read(u16 address) {
printf("read at %02X\n", address); //printf("read at %02X\n", address);
if(address == 0xFF26) { if(address == 0xFF26) {
u8 value = (ctx.audio_enabled << 7) | (ctx.ch4_enable << 3) | (ctx.ch3_enable << 2) | (ctx.sq2_enable << 1) | (ctx.sq1_enable); u8 value = (ctx.audio_enabled << 7) | (ctx.ch4_enable << 3) | (ctx.ch3_enable << 2) | (ctx.sq2_enable << 1) | (ctx.sq1_enable);
return value | 0b01110000; return value | 0b01110000;