ampler/draw.c

96 lines
2.9 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);
2021-12-24 07:37:18 +00:00
SDL_SetRenderDrawBlendMode(r, SDL_BLENDMODE_NONE);
SDL_SetRenderDrawColor(r, 10, 10, 10, 40);
2021-12-24 05:21:23 +00:00
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);
2021-12-27 05:29:16 +00:00
const int 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;
cur = state->frame_rec[0][x] + 128;
next = state->frame_rec[0][x + 1] + 128;
2021-12-24 07:37:18 +00:00
markov[cur][next] += 1;
2021-12-24 05:21:23 +00:00
}
2021-12-24 07:37:18 +00:00
/*
2021-12-24 05:21:23 +00:00
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;
}
2021-12-24 07:37:18 +00:00
*/
int start_x = 255, end_x = 0;
2021-12-24 05:21:23 +00:00
for int x = 0; x < 256; x += 1 do {
2021-12-24 07:37:18 +00:00
// for each colum
// copy into temp col, store how filed, col is
// go over each thing, fill coll in Idx number of times
// for remainder of col fill with re-roll value
u8 temp[256] = { 0 }; // amount of each dest, by index
for int i = 0; i < 256; i++
do temp[i] = markov[x][i];
s32 next = 0;
for int i = 0; i < 256; i++ do
for int j = 0; j < temp[i] and next < 256; j++ do {
markov[x][next++] = i;
if x < start_x do start_x = x;
if x > end_x do end_x = x;
}
2021-12-24 05:21:23 +00:00
}
2021-12-24 07:37:18 +00:00
//for int x = 0; x < 256; x++ do markov[x][0] = x, markov[0][x] = x;
for int x = start_x; x < end_x; x += 1 do
2021-12-24 05:21:23 +00:00
for int y = 0; y < 256; y += 1 do {
2021-12-24 07:37:18 +00:00
s32 m = markov[x][255 - y];
SDL_SetRenderDrawColor(r,
m >= 10 ? m : 0,
MIN(255, m < 4 ? m * 100 : 0),
MIN(255, m < 10 and m >= 4 ? m * 100 : 0), 255);
2021-12-24 05:21:23 +00:00
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
}