Fixing audio glitches with wave and noise channels

This commit is contained in:
2025-02-14 16:44:22 -07:00
parent 8fc7992ca5
commit 96c0196306
7 changed files with 166 additions and 25 deletions

View File

@ -3,6 +3,7 @@
#include <ppu.h>
#include <gamepad.h>
#include <bus.h>
#include <audio.h>
#include <SDL.h>
#include <SDL_ttf.h>
@ -127,10 +128,81 @@ void ui_update() {
SDL_FillRect(screen, &rc, video_buffer[x + (line_num * XRES)]);
}
}
SDL_UpdateTexture(sdlTexture, NULL, screen->pixels, screen->pitch);
SDL_RenderClear(sdlRenderer);
SDL_RenderCopy(sdlRenderer, sdlTexture, NULL, NULL);
int yOffset = 50;
int lastY = (yOffset) + (audio_get_context()->sq1_history[0] * 50);
int xOffset = XRES*scale;
SDL_SetRenderDrawColor(sdlRenderer, 0, 255, 0, 255);
for(int x = 1; x < 882; x++){
int y = (yOffset) + (audio_get_context()->sq1_history[x*5] * 50);
SDL_RenderDrawLine(sdlRenderer, x-1+xOffset, lastY, x+xOffset, y);
lastY = y;
if(x+xOffset == SCREEN_WIDTH) {
break;
}
}
yOffset = 150;
lastY = (yOffset) + (audio_get_context()->sq2_history[0] * 50);
SDL_SetRenderDrawColor(sdlRenderer, 0, 255, 0, 255);
for(int x = 1; x < 882; x++){
int y = (yOffset) + (audio_get_context()->sq2_history[x*5] * 50);
SDL_RenderDrawLine(sdlRenderer, x-1+xOffset, lastY, x+xOffset, y);
lastY = y;
if(x+xOffset == SCREEN_WIDTH) {
break;
}
}
yOffset = 250;
lastY = (yOffset) + (audio_get_context()->ch3_history[0] * 50);
SDL_SetRenderDrawColor(sdlRenderer, 0, 255, 0, 255);
for(int x = 1; x < 882; x++){
int y = (yOffset) + (audio_get_context()->ch3_history[x*5] * 50);
SDL_RenderDrawLine(sdlRenderer, x-1+xOffset, lastY, x+xOffset, y);
lastY = y;
if(x+xOffset == SCREEN_WIDTH) {
break;
}
}
yOffset = 350;
lastY = (yOffset) + (audio_get_context()->ch4_history[0] * 50);
SDL_SetRenderDrawColor(sdlRenderer, 0, 255, 0, 255);
for(int x = 1; x < 882; x++){
int y = (yOffset) + (audio_get_context()->ch4_history[x*5] * 50);
SDL_RenderDrawLine(sdlRenderer, x-1+xOffset, lastY, x+xOffset, y);
lastY = y;
if(x+xOffset == SCREEN_WIDTH) {
break;
}
}
yOffset = 450;
lastY = (yOffset) + (audio_get_context()->left_history[0] * 50);
SDL_SetRenderDrawColor(sdlRenderer, 0, 0, 255, 255);
for(int x = 1; x < 882; x++){
int y = (yOffset) + (audio_get_context()->left_history[x*5] * 50);
SDL_RenderDrawLine(sdlRenderer, x-1+xOffset, lastY, x+xOffset, y);
lastY = y;
if(x+xOffset == SCREEN_WIDTH) {
break;
}
}
yOffset = 550;
lastY = (yOffset) + (audio_get_context()->right_history[0] * 50);
SDL_SetRenderDrawColor(sdlRenderer, 0, 0, 255, 255);
for(int x = 1; x < 882; x++){
int y = (yOffset) + (audio_get_context()->right_history[x*5] * 50);
SDL_RenderDrawLine(sdlRenderer, x-1+xOffset, lastY, x+xOffset, y);
lastY = y;
if(x+xOffset == SCREEN_WIDTH) {
break;
}
}
SDL_RenderPresent(sdlRenderer);
update_debug_window();
@ -142,11 +214,11 @@ void ui_on_key(bool down, u32 key_code) {
if(key_code == SDLK_SPACE && down == true) {
ff = !ff;
if(ff){
target_frame_time = 1000/300;
ppu_get_context()->target_frame_time = 1000/300;
} else {
target_frame_time = 1000/60;
ppu_get_context()->target_frame_time = 1000/60;
}
printf("target frame time: %d\n", target_frame_time);
printf("target frame time: %d\n", ppu_get_context()->target_frame_time);
}
switch(key_code){
case SDLK_z: gamepad_get_state()->b = down; break;