debug screen

This commit is contained in:
2025-02-15 12:52:04 -07:00
parent 821782e60e
commit 97de875bf2
3 changed files with 128 additions and 53 deletions

View File

@ -26,6 +26,9 @@ static float lfsr_clock = LFSR_BASE_CLOCK;
static float left_cap = 0.0f;
static float right_cap = 0.0f;
static int history_timer = 0;
const int history_interval = 5;
const u8 square_sample_00[8] = {
0x0,
0xF,
@ -115,7 +118,7 @@ static int audio_callback(const void* input_uffer, void *output_buffer,
}
lfsr_timer += TIME_PER_SAMPLE;
for(;lfsr_timer >= lfsr_clock;lfsr_timer -= lfsr_clock) {
if(lfsr_timer >= lfsr_clock && ctx.ch4_enable) {
if(ctx.ch4_enable) {
lfsr_timer = 0;
u8 new = !((ctx.ch4_lfsr & 0b1) ^ ((ctx.ch4_lfsr >> 1) & 0b1)) & 0b1;
ctx.ch4_lfsr |= (new << 15);
@ -183,7 +186,7 @@ static int audio_callback(const void* input_uffer, void *output_buffer,
if(ctx.ch3_volume == 0b11) {
shift = 2;
}
ch3_val = (((float)(ctx.ch3_last_sample >> shift) - 7.5f)/15.0f);
ch3_val = (((float)(ctx.ch3_last_sample >> shift) - 7.5f)/7.5f);
if(ctx.ch3_left) {
left += ch3_val;
//printf("left: %d\n", ctx.ch3_volume);
@ -221,25 +224,6 @@ static int audio_callback(const void* input_uffer, void *output_buffer,
}
}
}
ctx.sq1_history[ctx.sq1_index++] = sq1_val;
if (ctx.sq1_index == 4410) {
ctx.sq1_index = 0;
}
ctx.sq2_history[ctx.sq2_index++] = sq2_val;
if (ctx.sq2_index == 4410) {
ctx.sq2_index = 0;
}
ctx.ch3_history[ctx.ch3_index++] = ch3_val;
if (ctx.ch3_index == 4410) {
ctx.ch3_index = 0;
}
ctx.ch4_history[ctx.ch4_index++] = ch4_val;
if (ctx.ch4_index == 4410) {
ctx.ch4_index = 0;
}
u8 left_vol = ctx.volume_left == 0 ? 1 : ctx.volume_left;
u8 right_vol = ctx.volume_right == 0 ? 1 : ctx.volume_right;
left *= (float)left_vol/7.0f;
@ -266,14 +250,37 @@ static int audio_callback(const void* input_uffer, void *output_buffer,
if(left_out < -1.0f) {
printf("Uh Oh! %f\n", left_out);
}
ctx.left_history[ctx.left_index++] = left_out;
if (ctx.left_index == 4410) {
ctx.left_index = 0;
}
history_timer++;
if(history_timer >= history_interval){
history_timer = 0;
ctx.sq1_history[ctx.sq1_index++] = sq1_val;
if (ctx.sq1_index == 384) {
ctx.sq1_index = 0;
}
ctx.right_history[ctx.right_index++] = right_out;
if (ctx.right_index == 4410) {
ctx.right_index = 0;
ctx.sq2_history[ctx.sq2_index++] = sq2_val;
if (ctx.sq2_index == 384) {
ctx.sq2_index = 0;
}
ctx.ch3_history[ctx.ch3_index++] = ch3_val;
if (ctx.ch3_index == 384) {
ctx.ch3_index = 0;
}
ctx.ch4_history[ctx.ch4_index++] = ch4_val;
if (ctx.ch4_index == 384) {
ctx.ch4_index = 0;
}
ctx.left_history[ctx.left_index++] = left_out;
if (ctx.left_index == 384) {
ctx.left_index = 0;
}
ctx.right_history[ctx.right_index++] = right_out;
if (ctx.right_index == 384) {
ctx.right_index = 0;
}
}
*out++ = left_out;
@ -457,7 +464,6 @@ void audio_tick(){
if(ctx.ch4_volume > 15)
ctx.ch4_volume = 15;
}
//printf("sq2 vol: %01X\n", ctx.sq2_volume);
}
}