ampler/draw.c

25 lines
761 B
C

// draw.c
void draw_frame(SDL_Window *w, SDL_Renderer *r, Ampler_state *state) {
SDL_SetRenderDrawColor(r, 0x1D, 0x2B, 0x53, 255);
SDL_RenderClear(r);
SDL_SetRenderDrawColor(r, 0xFF, 0x00, 0x4D, 255);
const space = (44100 * 8) / 512;
for int t = 0; t < arraylen(state -> tracks); t += 1 do
for int x = 0; x < 512; x += 1 do {
const int y = 128 + 256 * t;
const int val = state -> tracks[t][x * space];
SDL_RenderDrawLine(r, y + val / 8, x, y + val, x);
//SDL_RenderDrawPoint(r, y + val, x);
}
if state -> played_audio_last_frame do
for int i = 0; i < arraylen(state -> sounds); i += 1 do {
const int x = (state -> sounds[i].start + state -> sounds[i].pos) / space;
SDL_RenderDrawLine(r, 0, x, 512, x);
}
SDL_RenderPresent(r);
}