ampler/draw.c

71 lines
2.2 KiB
C
Raw Normal View History

2021-12-19 22:44:48 +00:00
// draw.c
void draw_frame(SDL_Window *w, SDL_Renderer *r, Ampler_state *state) {
SDL_SetRenderDrawColor(r, 0x1D, 0x2B, 0x53, 255);
2021-12-24 05:21:23 +00:00
SDL_SetRenderDrawBlendMode(r, SDL_BLENDMODE_BLEND);
SDL_SetRenderDrawColor(r, 10, 10, 10, 20);
SDL_Rect screen = { 0, 0, 512, 512 };
SDL_RenderFillRect(r, &screen);
// SDL_RenderClear(r);
2021-12-23 12:46:00 +00:00
// TODO: DRAW WITH X SCALE FACTOR
// TODO: DRAW SMOLER
SDL_SetRenderDrawColor(r, 0xFF, 0x00, 0x4D, 255);
const space = (44100 * 8) / 512;
2021-12-24 05:21:23 +00:00
const int t = 0; // TODO: DRAW L / R OVERLAPPED IN DIFF COLORS ?
const int wav_h = 128;
if 0 do
foreach_ptr(Sound_src, snd, state -> sounds)
2021-12-24 05:21:23 +00:00
if snd -> state != SND_FREE do {
const int y = wav_h / 2 + (wav_h + 4) * snd_i;
const int top = y - 64, bot = y + 64;
for int x = 0; x < 512 and x * space < snd->track_len; x += 1 do {
const int val = snd -> tracks[t][x * space];
2021-12-24 05:21:23 +00:00
const int sign = val < 0 ? -1 : 1;
SDL_RenderDrawLine(r, x, y + sign, x, y + val / 2);
//SDL_RenderDrawPoint(r, x, y + val / 2);
}
2021-12-23 12:46:00 +00:00
const int x = snd -> pos / space;
2021-12-24 05:21:23 +00:00
if state -> played_audio_last_frame do
SDL_RenderDrawLine(r, x, top, x, bot);
SDL_RenderDrawLine(r, snd->start / space, top, snd->start / space, bot);
SDL_RenderDrawLine(r, snd->end / space, top, snd->end / space, bot);
}
static u8 markov[256][256];
SDL_memset(markov, 0, sizeof markov);
for int x = 0; x < FRAME_SAMPLES - 1; x += 1 do {
u8 cur = state->frame_mix[0][x] + 128;
u8 next = state->frame_mix[0][x + 1] + 128;
markov[cur][255 - next] += 1;
}
for int x = 0; x < 256; x += 1 do {
u8 to = 0;
for int y = 0; y < 255; y += 1 do to += markov[x][y];
markov[x][255] = to;
}
for int x = 0; x < 256; x += 1 do {
u8 to = markov[x][255];
if to == 0 do continue;
for int y = 0; y < 255; y += 1 do
; //markov[x][y] *= to;
}
for int x = 0; x < 256; x += 1 do
for int y = 0; y < 256; y += 1 do {
u8 m = markov[x][y];
const int s = 20;
SDL_SetRenderDrawColor(r, m * s, m * s, m * s, 255);
if m != 0 do {
SDL_RenderDrawPoint(r, x * 2, y * 2);
SDL_RenderDrawPoint(r, x * 2 + 1, y * 2);
SDL_RenderDrawPoint(r, x * 2, y * 2 + 1);
SDL_RenderDrawPoint(r, x * 2 + 1, y * 2 + 1);
}
2021-12-23 12:46:00 +00:00
}
2021-12-20 02:06:02 +00:00
SDL_RenderPresent(r);
2021-12-19 22:44:48 +00:00
}