debug screen
This commit is contained in:
parent
821782e60e
commit
97de875bf2
@ -99,22 +99,22 @@ typedef struct {
|
||||
|
||||
u8 wave_ram[16];
|
||||
|
||||
float sq1_history[4410];
|
||||
float sq1_history[384];
|
||||
u32 sq1_index;
|
||||
|
||||
float sq2_history[4410];
|
||||
float sq2_history[384];
|
||||
u32 sq2_index;
|
||||
|
||||
float ch3_history[4410];
|
||||
float ch3_history[384];
|
||||
u32 ch3_index;
|
||||
|
||||
float ch4_history[4410];
|
||||
float ch4_history[384];
|
||||
u32 ch4_index;
|
||||
|
||||
float left_history[4410];
|
||||
float left_history[384];
|
||||
u32 left_index;
|
||||
|
||||
float right_history[4410];
|
||||
float right_history[384];
|
||||
u32 right_index;
|
||||
|
||||
} audio_context;
|
||||
|
64
lib/audio.c
64
lib/audio.c
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
105
lib/ui.c
105
lib/ui.c
@ -131,12 +131,27 @@ void ui_update() {
|
||||
SDL_UpdateTexture(sdlTexture, NULL, screen->pixels, screen->pitch);
|
||||
SDL_RenderClear(sdlRenderer);
|
||||
SDL_RenderCopy(sdlRenderer, sdlTexture, NULL, NULL);
|
||||
TTF_Font* sans = TTF_OpenFont("Sans.ttf", 24);
|
||||
if ( !sans ) {
|
||||
printf("Failed to load font: %s\n", TTF_GetError());
|
||||
}
|
||||
SDL_Color text_color = {255,255,255};
|
||||
int yOffset = 50;
|
||||
int lastY = (yOffset) + (audio_get_context()->sq1_history[0] * 50);
|
||||
int lastY = (yOffset) - (audio_get_context()->sq1_history[audio_get_context()->sq1_index] * 50);
|
||||
int xOffset = XRES*scale;
|
||||
SDL_Surface* message = TTF_RenderText_Solid(sans, "Square 1", text_color);
|
||||
SDL_Texture* messageTexture = SDL_CreateTextureFromSurface(sdlRenderer, message);
|
||||
SDL_Rect messageRect;
|
||||
messageRect.x = xOffset;
|
||||
messageRect.y = yOffset-50;
|
||||
messageRect.w = 50;
|
||||
messageRect.h = 20;
|
||||
SDL_RenderCopy(sdlRenderer, messageTexture, NULL, &messageRect);
|
||||
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_FreeSurface(message);
|
||||
SDL_DestroyTexture(messageTexture);
|
||||
for(int x = 1; x < 384; x++){
|
||||
int y = (yOffset) - (audio_get_context()->sq1_history[(x + audio_get_context()->sq1_index) % 384] * 50);
|
||||
SDL_RenderDrawLine(sdlRenderer, x-1+xOffset, lastY, x+xOffset, y);
|
||||
lastY = y;
|
||||
if(x+xOffset == SCREEN_WIDTH) {
|
||||
@ -145,10 +160,20 @@ void ui_update() {
|
||||
}
|
||||
|
||||
yOffset = 150;
|
||||
lastY = (yOffset) + (audio_get_context()->sq2_history[0] * 50);
|
||||
lastY = (yOffset) - (audio_get_context()->sq2_history[audio_get_context()->sq2_index] * 50);
|
||||
message = TTF_RenderText_Solid(sans, "Square 2", text_color);
|
||||
messageTexture = SDL_CreateTextureFromSurface(sdlRenderer, message);
|
||||
messageRect.x = xOffset;
|
||||
messageRect.y = yOffset-50;
|
||||
messageRect.w = 50;
|
||||
messageRect.h = 20;
|
||||
SDL_RenderCopy(sdlRenderer, messageTexture, NULL, &messageRect);
|
||||
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_FreeSurface(message);
|
||||
SDL_DestroyTexture(messageTexture);
|
||||
SDL_SetRenderDrawColor(sdlRenderer, 0, 255, 0, 255);
|
||||
for(int x = 1; x < 384; x++){
|
||||
int y = (yOffset) - (audio_get_context()->sq2_history[(x + audio_get_context()->sq2_index) % 384] * 50);
|
||||
SDL_RenderDrawLine(sdlRenderer, x-1+xOffset, lastY, x+xOffset, y);
|
||||
lastY = y;
|
||||
if(x+xOffset == SCREEN_WIDTH) {
|
||||
@ -157,10 +182,21 @@ void ui_update() {
|
||||
}
|
||||
|
||||
yOffset = 250;
|
||||
lastY = (yOffset) + (audio_get_context()->ch3_history[0] * 50);
|
||||
lastY = (yOffset) - (audio_get_context()->ch3_history[audio_get_context()->ch3_index] * 50);
|
||||
message = TTF_RenderText_Solid(sans, "Wave", text_color);
|
||||
messageTexture = SDL_CreateTextureFromSurface(sdlRenderer, message);
|
||||
messageRect.x = xOffset;
|
||||
messageRect.y = yOffset-50;
|
||||
messageRect.w = 50;
|
||||
messageRect.h = 20;
|
||||
SDL_RenderCopy(sdlRenderer, messageTexture, NULL, &messageRect);
|
||||
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_FreeSurface(message);
|
||||
SDL_DestroyTexture(messageTexture);
|
||||
SDL_SetRenderDrawColor(sdlRenderer, 0, 255, 0, 255);
|
||||
SDL_SetRenderDrawColor(sdlRenderer, 0, 255, 0, 255);
|
||||
for(int x = 1; x < 384; x++){
|
||||
int y = (yOffset) - (audio_get_context()->ch3_history[(x + audio_get_context()->ch3_index) % 384] * 50);
|
||||
SDL_RenderDrawLine(sdlRenderer, x-1+xOffset, lastY, x+xOffset, y);
|
||||
lastY = y;
|
||||
if(x+xOffset == SCREEN_WIDTH) {
|
||||
@ -169,10 +205,21 @@ void ui_update() {
|
||||
}
|
||||
|
||||
yOffset = 350;
|
||||
lastY = (yOffset) + (audio_get_context()->ch4_history[0] * 50);
|
||||
lastY = (yOffset) - (audio_get_context()->ch4_history[audio_get_context()->ch4_index] * 50);
|
||||
message = TTF_RenderText_Solid(sans, "Noise", text_color);
|
||||
messageTexture = SDL_CreateTextureFromSurface(sdlRenderer, message);
|
||||
messageRect.x = xOffset;
|
||||
messageRect.y = yOffset-50;
|
||||
messageRect.w = 50;
|
||||
messageRect.h = 20;
|
||||
SDL_RenderCopy(sdlRenderer, messageTexture, NULL, &messageRect);
|
||||
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_FreeSurface(message);
|
||||
SDL_DestroyTexture(messageTexture);
|
||||
SDL_SetRenderDrawColor(sdlRenderer, 0, 255, 0, 255);
|
||||
SDL_SetRenderDrawColor(sdlRenderer, 0, 255, 0, 255);
|
||||
for(int x = 1; x < 384; x++){
|
||||
int y = (yOffset) - (audio_get_context()->ch4_history[(x + audio_get_context()->ch4_index) % 384] * 50);
|
||||
SDL_RenderDrawLine(sdlRenderer, x-1+xOffset, lastY, x+xOffset, y);
|
||||
lastY = y;
|
||||
if(x+xOffset == SCREEN_WIDTH) {
|
||||
@ -181,10 +228,21 @@ void ui_update() {
|
||||
}
|
||||
|
||||
yOffset = 450;
|
||||
lastY = (yOffset) + (audio_get_context()->left_history[0] * 50);
|
||||
lastY = (yOffset) - (audio_get_context()->left_history[audio_get_context()->left_index] * 50);
|
||||
message = TTF_RenderText_Solid(sans, "Left Out", text_color);
|
||||
messageTexture = SDL_CreateTextureFromSurface(sdlRenderer, message);
|
||||
messageRect.x = xOffset;
|
||||
messageRect.y = yOffset-50;
|
||||
messageRect.w = 50;
|
||||
messageRect.h = 20;
|
||||
SDL_RenderCopy(sdlRenderer, messageTexture, NULL, &messageRect);
|
||||
SDL_SetRenderDrawColor(sdlRenderer, 0, 255, 0, 255);
|
||||
SDL_FreeSurface(message);
|
||||
SDL_DestroyTexture(messageTexture);
|
||||
SDL_SetRenderDrawColor(sdlRenderer, 0, 255, 0, 255);
|
||||
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);
|
||||
for(int x = 1; x < 384; x++){
|
||||
int y = (yOffset) - (audio_get_context()->left_history[(x + audio_get_context()->left_index) % 384] * 50);
|
||||
SDL_RenderDrawLine(sdlRenderer, x-1+xOffset, lastY, x+xOffset, y);
|
||||
lastY = y;
|
||||
if(x+xOffset == SCREEN_WIDTH) {
|
||||
@ -193,10 +251,21 @@ void ui_update() {
|
||||
}
|
||||
|
||||
yOffset = 550;
|
||||
lastY = (yOffset) + (audio_get_context()->right_history[0] * 50);
|
||||
lastY = (yOffset) - (audio_get_context()->right_history[audio_get_context()->right_index] * 50);
|
||||
message = TTF_RenderText_Solid(sans, "Right Out", text_color);
|
||||
messageTexture = SDL_CreateTextureFromSurface(sdlRenderer, message);
|
||||
messageRect.x = xOffset;
|
||||
messageRect.y = yOffset-50;
|
||||
messageRect.w = 50;
|
||||
messageRect.h = 20;
|
||||
SDL_RenderCopy(sdlRenderer, messageTexture, NULL, &messageRect);
|
||||
SDL_SetRenderDrawColor(sdlRenderer, 0, 255, 0, 255);
|
||||
SDL_FreeSurface(message);
|
||||
SDL_DestroyTexture(messageTexture);
|
||||
SDL_SetRenderDrawColor(sdlRenderer, 0, 255, 0, 255);
|
||||
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);
|
||||
for(int x = 1; x < 384; x++){
|
||||
int y = (yOffset) - (audio_get_context()->right_history[(x + audio_get_context()->right_index) % 384] * 50);
|
||||
SDL_RenderDrawLine(sdlRenderer, x-1+xOffset, lastY, x+xOffset, y);
|
||||
lastY = y;
|
||||
if(x+xOffset == SCREEN_WIDTH) {
|
||||
|
Loading…
Reference in New Issue
Block a user