made visualiser even cooler
parent
5909dad9f8
commit
2b5eeb09f3
3
ampler.c
3
ampler.c
|
@ -30,7 +30,10 @@ Ampler_state *init() {
|
|||
puts(SDL_GetError());
|
||||
|
||||
// TODO: iterate a directory to load samples
|
||||
load_sample(state, "haunted.wav");
|
||||
load_sample(state, "mix.wav");
|
||||
load_sample(state, "loop2.wav");
|
||||
load_sample(state, "loop.wav");
|
||||
load_sample(state, "chord.wav");
|
||||
|
||||
puts("init.");
|
||||
|
|
2
ampler.h
2
ampler.h
|
@ -34,6 +34,8 @@ for int N##_i = 0; N##_i == 0; N##_i = 1 do \
|
|||
for TYPE *N = &((ARRAY)[N##_i]); N != NULL; N = NULL do \
|
||||
for ; N##_i < arraylen(ARRAY); N##_i += 1, N = &((ARRAY)[N##_i]) do
|
||||
|
||||
#define MIN(a, b) ((a) < (b) ? (a) : (b))
|
||||
|
||||
#define SAMPLE_RATE (44100)
|
||||
#define CHANNELS (2)
|
||||
#define FRAME_SAMPLES (SAMPLE_RATE / 60)
|
||||
|
|
10
audio.c
10
audio.c
|
@ -7,6 +7,16 @@ void trigger_sounds(Ampler_state *state) {
|
|||
// TODO: Check sound names
|
||||
// TODO: func to decode orca numbers
|
||||
|
||||
foreach_ptr(Sound_src, s, state -> sounds)
|
||||
if s->state == SND_LOOPING do {
|
||||
// THIS IS ALL JUST So I PLAY WITH THIS LOOP
|
||||
// s->speed = 1.65f;
|
||||
// s->note_speed = 0.84f;
|
||||
// f32 sp = 0.9f;
|
||||
// s->start = (s->track_len / 10) * sp;
|
||||
// s->end = (s->track_len / 10) * (sp + 0.2f);
|
||||
}
|
||||
|
||||
// TODO: NOTE SPEED
|
||||
foreach_ptr(Udp_msg, m, state -> messages)
|
||||
if m -> state == MSG_TRIGGER do
|
||||
|
|
41
draw.c
41
draw.c
|
@ -4,7 +4,8 @@ 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_SetRenderDrawColor(r, 10, 10, 10, 20);
|
||||
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);
|
||||
|
@ -39,25 +40,45 @@ void draw_frame(SDL_Window *w, SDL_Renderer *r, Ampler_state *state) {
|
|||
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;
|
||||
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 {
|
||||
u8 to = markov[x][255];
|
||||
if to == 0 do continue;
|
||||
for int y = 0; y < 255; y += 1 do
|
||||
; //markov[x][y] *= to;
|
||||
// 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 += 1 do
|
||||
//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 {
|
||||
u8 m = markov[x][y];
|
||||
const int s = 20;
|
||||
SDL_SetRenderDrawColor(r, m * s, m * s, m * s, 255);
|
||||
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);
|
||||
|
|
Loading…
Reference in New Issue