Fixed audio waveforms

This commit is contained in:
Samuel Walker 2025-02-18 17:51:53 -07:00
parent a094e5123b
commit 59162135bb
Signed by: piwalker
GPG Key ID: 616B1928705EA4C9

View File

@ -461,7 +461,7 @@ void audio_sample_tick() {
shift = 2; shift = 2;
} }
ch3_val = -1; ch3_val = -1;
if(ctx.ch3_enable) { if(ctx.ch3_enable && (ctx.ch3_left || ctx.ch3_right)) {
ch3_val = (((float)(ctx.ch3_last_sample >> shift) - 7.5f)/7.5f); ch3_val = (((float)(ctx.ch3_last_sample >> shift) - 7.5f)/7.5f);
if(ctx.ch3_left) { if(ctx.ch3_left) {
left += ch3_val; left += ch3_val;
@ -505,28 +505,6 @@ void audio_sample_tick() {
u8 right_vol = ctx.volume_right == 0 ? 1 : ctx.volume_right; u8 right_vol = ctx.volume_right == 0 ? 1 : ctx.volume_right;
left *= (float)left_vol/7.0f; left *= (float)left_vol/7.0f;
right *= (float)right_vol/7.0f; right *= (float)right_vol/7.0f;
if(period_tick % 100 == 0){
ctx.sq1_history[ctx.sq1_index++] = sq1_val;
if (ctx.sq1_index == 384) {
ctx.sq1_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;
}
}
smooth_left = smooth_left - (LPF_Beta * (smooth_left - left)); smooth_left = smooth_left - (LPF_Beta * (smooth_left - left));
smooth_right = smooth_right - (LPF_Beta * (smooth_right - right)); smooth_right = smooth_right - (LPF_Beta * (smooth_right - right));
cycles_needed += SAMPLES_PER_AUDIO_TICK; cycles_needed += SAMPLES_PER_AUDIO_TICK;
@ -542,6 +520,7 @@ void audio_sample_tick() {
//} //}
cycles_needed -= 1; cycles_needed -= 1;
bool dacs = ctx.ch1_dac || ctx.ch2_dac || ctx.ch3_dac || ctx.ch4_dac; bool dacs = ctx.ch1_dac || ctx.ch2_dac || ctx.ch3_dac || ctx.ch4_dac;
float left_out = 0; float left_out = 0;
float right_out = 0; float right_out = 0;
@ -575,6 +554,39 @@ void audio_sample_tick() {
//ctx.ch4_audio_buffer[(ctx.sq1_write_index)] = (ctx.ch4_lfsr & 0b1) ? (float)(ctx.ch4_volume-7.5f)/7.5f : -1.0f; //ctx.ch4_audio_buffer[(ctx.sq1_write_index)] = (ctx.ch4_lfsr & 0b1) ? (float)(ctx.ch4_volume-7.5f)/7.5f : -1.0f;
ctx.sq1_write_index = (ctx.sq1_write_index + 1); ctx.sq1_write_index = (ctx.sq1_write_index + 1);
//ctx.buffer_cnt++; //ctx.buffer_cnt++;
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.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;
}
}
if(ctx.sq1_write_index == FRAMES_PER_BUFFER) { if(ctx.sq1_write_index == FRAMES_PER_BUFFER) {
ctx.sq1_write_index = 0; ctx.sq1_write_index = 0;
float *data[2]; float *data[2];