100 lines
3.1 KiB
C
100 lines
3.1 KiB
C
// draw.c
|
|
|
|
void draw_snd_waves(SDL_Window *w, SDL_Renderer *r, Ampler_state *state) {
|
|
// TODO: DRAW WITH X SCALE FACTOR
|
|
// TODO: DRAW SMOLER
|
|
SDL_SetRenderDrawColor(r, 0xFF, 0x00, 0x4D, 255);
|
|
const int 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);
|
|
}
|
|
}
|
|
|
|
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*/ FRAME_SAMPLES, 512 };
|
|
SDL_RenderFillRect(r, &screen);
|
|
// SDL_RenderClear(r);
|
|
|
|
//markov_draw(&(state->markov), r);
|
|
//SDL_memset(&(state->markov), 0, sizeof state->markov);
|
|
//markov_gen(&(state->markov), state->frame_mix[1]);
|
|
//markov_draw(&(state->markov), r);
|
|
|
|
SDL_RenderPresent(r);
|
|
}
|
|
|
|
/*
|
|
for int x = 0; x < 256; x += 1 do
|
|
// for int y = 0; y < markov_lens[x]; y += 1 do {
|
|
for int y = 0; y < 256; y += 1 do {
|
|
s32 m = markov[x + y * 256];
|
|
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 {
|
|
const int y2 = 255 - y;
|
|
SDL_RenderDrawPoint(r, x * 2, y2 * 2);
|
|
SDL_RenderDrawPoint(r, x * 2 + 1, y2 * 2);
|
|
SDL_RenderDrawPoint(r, x * 2, y2 * 2 + 1);
|
|
SDL_RenderDrawPoint(r, x * 2 + 1, y2 * 2 + 1);
|
|
}
|
|
}
|
|
*/
|
|
|
|
/*
|
|
for int x = 0; x < FRAME_SAMPLES - 1; x += 1 do {
|
|
// playing
|
|
u8 cur = state->frame_mix[0][x] + 128;
|
|
u8 next = state->frame_mix[0][x + 1] + 128;
|
|
// recing
|
|
//cur = state->frame_rec[0][x] + 128;
|
|
//next = state->frame_rec[0][x + 1] + 128;
|
|
markov[cur + next * 256] += 1;
|
|
}
|
|
|
|
int start_x = 0, end_x = 255;
|
|
|
|
// converts from graph plot to prob table
|
|
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 * 256];
|
|
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++) * 256] = i;
|
|
if x < start_x do start_x = x;
|
|
if x > end_x do end_x = x;
|
|
}
|
|
markov_lens[x] = next;
|
|
}
|
|
}
|
|
*/
|