92 lines
2.8 KiB
C
92 lines
2.8 KiB
C
// draw.c
|
|
|
|
void draw_frame(SDL_Window *w, SDL_Renderer *r, Ampler_state *state) {
|
|
SDL_SetRenderDrawColor(r, 0x1D, 0x2B, 0x53, 255);
|
|
|
|
SDL_SetRenderDrawBlendMode(r, SDL_BLENDMODE_BLEND);
|
|
SDL_SetRenderDrawBlendMode(r, SDL_BLENDMODE_NONE);
|
|
SDL_SetRenderDrawColor(r, 10, 10, 10, 40);
|
|
SDL_Rect screen = { 0, 0, 512, 512 };
|
|
SDL_RenderFillRect(r, &screen);
|
|
// SDL_RenderClear(r);
|
|
|
|
// TODO: DRAW WITH X SCALE FACTOR
|
|
// TODO: DRAW SMOLER
|
|
SDL_SetRenderDrawColor(r, 0xFF, 0x00, 0x4D, 255);
|
|
const space = (44100 * 8) / 512;
|
|
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)
|
|
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];
|
|
const int sign = val < 0 ? -1 : 1;
|
|
SDL_RenderDrawLine(r, x, y + sign, x, y + val / 2);
|
|
//SDL_RenderDrawPoint(r, x, y + val / 2);
|
|
}
|
|
|
|
const int x = snd -> pos / space;
|
|
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][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;
|
|
}
|
|
*/
|
|
|
|
int start_x = 255, end_x = 0;
|
|
|
|
for int x = 0; x < 256; x += 1 do {
|
|
// 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;
|
|
}
|
|
}
|
|
|
|
//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
|
|
for int y = 0; y < 256; y += 1 do {
|
|
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);
|
|
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);
|
|
}
|
|
}
|
|
|
|
SDL_RenderPresent(r);
|
|
}
|