Improve average windowing, remove smooth overrides

This commit is contained in:
Jarcode
2019-09-11 16:20:04 -07:00
parent 0d48dd059c
commit 6f1680b335
6 changed files with 31 additions and 23 deletions

View File

@@ -658,6 +658,7 @@ static struct gl_bind_src bind_sources[] = {
};
#define window(t, sz) (0.53836 - (0.46164 * cos(TWOPI * (double) t / (double) sz)))
#define window_frame(t, sz) (0.6 - (0.4 * cos(TWOPI * (double) t / (double) sz)))
#define ALLOC_ONCE(u, udata, sz) \
if (*udata == NULL) { \
u = calloc(sz, sizeof(typeof(*u))); \
@@ -762,7 +763,7 @@ void transform_average(struct gl_data* d, void** udata, void* data) {
} while (0)
if (use_window)
DO_AVG(window(f, d->avg_frames - 1));
DO_AVG(window_frame(f, d->avg_frames - 1));
else
DO_AVG(1);
@@ -1259,7 +1260,7 @@ struct glava_renderer* rd_new(const char** paths, const char* entry,
t_count += 2;
}
static const char* fmt = "WARNING: using \"%s\" transform explicitly "
"is deprecated; implied from \"fft\" transform.\n";
"is deprecated (no-op); implied from \"fft\" transform.\n";
if (!strcmp(transform_functions[t].name, "gravity")) {
static bool gravity_warn = false;
if (!gravity_warn) {
@@ -1274,6 +1275,13 @@ struct glava_renderer* rd_new(const char** paths, const char* entry,
avg_warn = true;
}
}
if (!strcmp(transform_functions[t].name, "window")) {
static bool avg_warn = false;
if (!avg_warn) {
fprintf(stderr, fmt, transform_functions[t].name);
avg_warn = true;
}
}
})
},
{ .name = "uniform", .fmt = "ss",
@@ -1723,7 +1731,6 @@ static void bind_1d_fbo(struct sm_fb* sm, size_t sz) {
} else {
/* Just bind our data if it was already allocated and setup */
glBindFramebuffer(GL_FRAMEBUFFER, sm->fbo);
glBindTexture(GL_TEXTURE_1D, sm->tex);
}
}
@@ -2109,6 +2116,8 @@ bool rd_update(struct glava_renderer* r, float* lb, float* rb, size_t bsz, bool
goto bind_uniform;
load_flags[offset] = true;
bool set_opt = false; /* if bind->optimize_fft was set this frame */
/* Only apply transformations if the buffers we were given are newly copied */
if (modified) {
size_t t, tm = 0;
@@ -2116,7 +2125,6 @@ bool rd_update(struct glava_renderer* r, float* lb, float* rb, size_t bsz, bool
.buf = buf, .sz = sz
};
bool set_opt = false; /* if gl->optimize_fft was set this frame */
for (t = 0; t < bind->t_sz; ++t) {
void (*apply)(struct gl_data*, void**, void*) = bind->transformations[t];
if (apply != NULL) {

View File

@@ -16,9 +16,3 @@
1 to enable, 0 to disable. Only works with `xroot` transparency,
and improves performance if disabled. */
#define C_SMOOTH 1
/* Gravity step, overrude frin `smooth_parameters.glsl` */
#request setgravitystep 6.0
/* Smoothing factor, override from `smooth_parameters.glsl` */
#request setsmoothfactor 0.01

View File

@@ -30,11 +30,6 @@
/* Offset (X) of the visualization */
#define CENTER_OFFSET_X 0
/* Gravity step, override from `smooth_parameters.glsl` */
#request setgravitystep 5.0
/* Smoothing factor, override from `smooth_parameters.glsl` */
#request setsmoothfactor 0.02
/* (DEPRECATED) outline color */
#define BAR_OUTLINE OUTLINE
/* (DEPRECATED) outline width (in pixels, set to 0 to disable outline drawing) */

View File

@@ -53,7 +53,7 @@
/* How many frames to queue and run through the average function.
Increasing this value will create latency between the audio and the
animation, but will make for much smoother results. */
#request setavgframes 6
#request setavgframes 5
/* Whether to window frames ran through the average function (new & old
frames are weighted less). This massively helps smoothing out

View File

@@ -19,19 +19,28 @@ in vec4 gl_FragCoord;
#define SAMPLER(I) uniform sampler1D t##I;
#expand SAMPLER _AVG_FRAMES
#define WIN_FUNC window_frame
void main() {
float r = 0;
/* Disable windowing for two frames (distorts results) */
#if _AVG_FRAMES == 2
#define _AVG_WINDOW 0
#endif
/* Use 'shallow' windowing for 3 frames to ensure the first & last
frames have a reasonable amount of weight */
#if _AVG_FRAMES == 3
#define WIN_FUNC window_shallow
#endif
#if _AVG_WINDOW == 0
#define F(I) r += texelFetch(t##I, int(gl_FragCoord.x), 0).r
#else
#define F(I) r += window(I, _AVG_FRAMES - 1) * texelFetch(t##I, int(gl_FragCoord.x), 0).r
#endif
#expand F _AVG_FRAMES
/* For some reason the CPU implementation of gravity/average produces the same output but
with half the amplitude. I can't figure it out right now, so I'm just halfing the results
here to ensure they are uniform.
TODO: fix this */
fragment.r = (r / _AVG_FRAMES) / 2;
fragment.r = r / _AVG_FRAMES;
}

View File

@@ -11,6 +11,8 @@
/* Window value t that resides in range [0, sz] */
#define window(t, sz) (0.53836 - (0.46164 * cos(TWOPI * t / sz)))
#define window_frame(t, sz) (0.6 - (0.4 * cos(TWOPI * t / sz)))
#define window_shallow(t, sz) (0.7 - (0.3 * cos(TWOPI * t / sz)))
/* Do nothing (used as an option for configuration) */
#define linear(x) (x)
/* Take value x that scales linearly between [0, 1) and return its sinusoidal curve */