working on audio tests

This commit is contained in:
Samuel Walker 2025-02-04 17:03:01 -07:00
parent e35f05b94f
commit e2e17ea5db
Signed by: piwalker
GPG Key ID: BE1F84BF85111255

View File

@ -275,10 +275,11 @@ static u32 ticks = 0;
void audio_tick(){
u32 prev_ticks = ticks;
ticks++;
if(!(ticks & 0b1)) {
if((ticks % 2) == 0) {
if(ctx.sq1_len_enable) {
ctx.sq1_len++;
if(ctx.sq1_len >= 64) {
ctx.sq1_len = 0;
ctx.sq1_enable = false;
}
}
@ -286,20 +287,22 @@ void audio_tick(){
if(ctx.sq2_len_enable) {
ctx.sq2_len++;
if(ctx.sq2_len >= 64) {
ctx.sq2_len = 0;
ctx.sq2_enable = false;
}
}
if(ctx.ch3_len_enable) {
if(ctx.ch3_len >= 255) {
ctx.ch3_len++;
if(ctx.ch3_len == 0) {
ctx.ch3_enable = false;
}
ctx.ch3_len++;
}
if(ctx.ch4_len_enable) {
ctx.ch4_len++;
if(ctx.ch4_len >= 64) {
ctx.ch4_len = 0;
ctx.ch4_enable = false;
}
}
@ -369,12 +372,8 @@ void audio_tick(){
}
void enable_square1() {
if(!ctx.ch1_dac){
return;
}
ctx.sq1_enable = true;
if(ctx.sq1_len >= 64) {
ctx.sq1_len = 0;
if(ctx.ch1_dac){
ctx.sq1_enable = true;
}
ctx.sq1_volume = ctx.sq1_initial_volume;
ctx.sq1_env_timer = 0;
@ -677,7 +676,9 @@ void audio_write(u16 address, u8 value){
ctx.sq1_duty = value >> 6;
ctx.sq1_initial_len = value & 0x3F;
ctx.sq1_len = ctx.sq1_initial_len;
printf("initial len: %02X\n", ctx.sq1_initial_len);
static bool unfreeze;
unfreeze = true;
//printf("initial len: %02X\n", ctx.sq1_initial_len);
}
if(address == 0xFF12) {
ctx.sq1_initial_volume = (value >> 4) & 0x0F;
@ -694,8 +695,20 @@ void audio_write(u16 address, u8 value){
ctx.sq1_period_reset = (ctx.sq1_period_reset & 0xF00) | value;
}
if(address == 0xFF14) {
static bool unfreeze;
ctx.sq1_period_reset = (ctx.sq1_period_reset & 0x0FF) | ((value & 0b111) << 8);
ctx.sq1_len_enable = (value & 0x40) == 0x40;
bool len_en = (value & 0x40) == 0x40;
if((ticks % 2) == 0 && ctx.sq1_len != 0 && !ctx.sq1_len_enable && len_en){
ctx.sq1_len++;
if(ctx.sq1_len >= 64) {
ctx.sq1_len = 0;
ctx.sq1_enable = false;
}
} else if(ctx.sq1_len == 0 && (value & 0x80) == 0x80){
printf("Value: %02X\n", value);
ctx.sq1_len = 1;
}
ctx.sq1_len_enable = len_en;
if(value & 0x80) {
enable_square1();
}