half way through audio test 2

This commit is contained in:
Samuel Walker 2025-02-03 23:09:12 -07:00
parent 91b7d704cd
commit cf742dba11
Signed by: piwalker
GPG Key ID: 616B1928705EA4C9
2 changed files with 39 additions and 6 deletions

View File

@ -15,6 +15,10 @@ typedef struct {
bool ch4_left;
bool ch4_right;
bool ch1_dac;
bool ch2_dac;
bool ch4_dac;
u8 volume_left;
u8 volume_right;
bool vin_left;

View File

@ -281,7 +281,6 @@ void audio_tick(){
if(ctx.sq1_len >= 64) {
ctx.sq1_enable = false;
}
printf("Len: %02X\n", ctx.sq1_len);
}
if(ctx.sq2_len_enable) {
@ -370,9 +369,12 @@ void audio_tick(){
}
void enable_square1() {
if(!ctx.ch1_dac){
return;
}
ctx.sq1_enable = true;
if(ctx.sq1_len >= 64) {
ctx.sq1_len = ctx.sq1_initial_len;
ctx.sq1_len = 0;
}
ctx.sq1_volume = ctx.sq1_initial_volume;
ctx.sq1_env_timer = 0;
@ -387,9 +389,12 @@ void enable_square1() {
}
void enable_square2() {
if(!ctx.ch2_dac){
return;
}
ctx.sq2_enable = true;
if(ctx.sq2_len >= 64) {
ctx.sq2_len = ctx.sq2_initial_len;
ctx.sq2_len = 0;
}
ctx.sq2_volume = ctx.sq2_initial_volume;
ctx.sq2_env_timer = 0;
@ -400,9 +405,12 @@ void enable_square2() {
}
void enable_wave() {
if(!ctx.ch3_dac){
return;
}
ctx.ch3_enable = true;
if(ctx.ch3_len >= 256) {
ctx.ch3_len = ctx.ch3_initial_len;
ctx.ch3_len = 0;
}
ctx.ch3_sample = 0;
ctx.ch3_volume = ctx.ch3_initial_volume;
@ -410,9 +418,12 @@ void enable_wave() {
}
void enable_noise() {
if(!ctx.ch4_dac){
return;
}
ctx.ch4_enable = true;
if(ctx.ch4_len >= 64) {
ctx.ch4_len = ctx.ch4_initial_len;
ctx.ch4_len = 0;
}
ctx.ch4_env_timer = 0;
ctx.ch4_env_direction = ctx.ch4_env_direction_buffer;
@ -539,6 +550,9 @@ u8 audio_read(u16 address) {
}
void reset_buffers(){
ctx.ch1_dac = 0;
ctx.ch2_dac = 0;
ctx.ch3_dac = 0;
ctx.ch1_left = 0;
ctx.ch1_right = 0;
ctx.ch2_left = 0;
@ -668,6 +682,12 @@ void audio_write(u16 address, u8 value){
ctx.sq1_initial_volume = (value >> 4) & 0x0F;
ctx.sq1_env_direction_buffer = (value & 0x8) == 0x8;
ctx.sq1_env_pace_buffer = value & 0b111;
if(ctx.sq1_env_direction_buffer == 0 && ctx.sq1_initial_volume == 0) {
ctx.sq1_enable = false;
ctx.ch1_dac = false;
} else {
ctx.ch1_dac = true;
}
}
if(address == 0xFF13) {
ctx.sq1_period_reset = (ctx.sq1_period_reset & 0xF00) | value;
@ -690,8 +710,11 @@ void audio_write(u16 address, u8 value){
ctx.sq2_initial_volume = (value >> 4) & 0x0F;
ctx.sq2_env_direction_buffer = (value & 0x8) == 0x8;
ctx.sq2_env_pace_buffer = value & 0b111;
if(ctx.sq2_env_direction == 0 && ctx.sq2_initial_volume == 0) {
if(ctx.sq2_env_direction_buffer == 0 && ctx.sq2_initial_volume == 0) {
ctx.sq2_enable = false;
ctx.ch2_dac = false;
} else {
ctx.ch2_dac = true;
}
}
if(address == 0xFF18) {
@ -744,6 +767,12 @@ void audio_write(u16 address, u8 value){
ctx.ch4_initial_volume = (value >> 4) & 0x0F;
ctx.ch4_env_direction_buffer = (value & 0x8) == 0x8;
ctx.ch4_env_pace_buffer = value & 0b111;
if(ctx.ch4_env_direction_buffer == 0 && ctx.ch4_initial_volume == 0) {
ctx.ch4_enable = false;
ctx.ch4_dac = false;
} else {
ctx.ch4_dac = true;
}
}
if(address == 0xFF22) {