Changed FFT scaling to use native code and requests

This commit is contained in:
Jarcode
2018-01-12 17:04:03 -08:00
parent 96f40d089e
commit 15ffe975cc
6 changed files with 20 additions and 8 deletions

View File

@@ -364,7 +364,7 @@ struct gl_data {
int fcounter, ucounter, kcounter;
bool print_fps, avg_window, interpolate, force_geometry, copy_desktop;
void** t_data;
float gravity_step, target_spu, fr, ur, smooth_distance, smooth_ratio;
float gravity_step, target_spu, fr, ur, smooth_distance, smooth_ratio, fft_scale, fft_cutoff;
float* interpolate_buf[6];
int geometry[4];
};
@@ -624,6 +624,7 @@ void transform_fft(struct gl_data* d, void** _, void* in) {
for (n = 0; n < s->sz; ++n) {
if (data[n] < 0.0F) data[n] = -data[n];
data[n] = log(data[n] + 1) / 3;
data[n] *= max((((float) n / (float) s->sz) * d->fft_scale) + (1.0F - d->fft_cutoff), 1.0F);
}
}
@@ -680,6 +681,8 @@ struct renderer* rd_new(const char** paths, const char* entry, const char* force
.smooth_ratio = 4,
.bg_tex = 0,
.copy_desktop = true,
.fft_scale = 10.2F,
.fft_cutoff = 0.3F,
.geometry = { 0, 0, 500, 400 }
};
@@ -814,9 +817,13 @@ struct renderer* rd_new(const char** paths, const char* entry, const char* force
{ .name = "setsmooth", .fmt = "f",
.handler = RHANDLER(name, args, { gl->smooth_distance = *(float*) args[0]; }) },
{ .name = "setsmoothratio", .fmt = "f",
.handler = RHANDLER(name, args, { gl->smooth_ratio = *(float*) args[0]; }) },
.handler = RHANDLER(name, args, { gl->smooth_ratio = *(float*) args[0]; }) },
{ .name = "setinterpolate", .fmt = "b",
.handler = RHANDLER(name, args, { gl->interpolate = *(bool*) args[0]; }) },
{ .name = "setfftscale", .fmt = "f",
.handler = RHANDLER(name, args, { gl->fft_scale = *(float*) args[0];}) },
{ .name = "setfftcutoff", .fmt = "f",
.handler = RHANDLER(name, args, { gl->fft_cutoff = *(float*) args[0];}) },
{
.name = "transform", .fmt = "ss",
.handler = RHANDLER(name, args, {

View File

@@ -71,7 +71,7 @@ void main() {
}
#undef smooth_f
v *= AMPLIFY * (1 + p); /* amplify result */
v *= AMPLIFY; /* amplify result */
if (d < v - BAR_OUTLINE_WIDTH) { /* if within range of the reported frequency, draw */
#if BAR_OUTLINE_WIDTH > 0
if (md < (BAR_WIDTH / 2) - BAR_OUTLINE_WIDTH)

View File

@@ -91,9 +91,6 @@ void render_side(in sampler1D tex, float idx) {
s *= clamp((abs((screen.x / 2) - gl_FragCoord.x) / screen.x) * 48, 0.0F, 1.0F);
s *= clamp((min(gl_FragCoord.x, screen.x - gl_FragCoord.x) / screen.x) * 48, 0.0F, 1.0F);
/* amplify higher frequencies */
s *= 1 + BDIST;
/* and finally set fragment color if we are in range */
#if INVERT > 0
float pos = float(screen.y) - gl_FragCoord.y;

View File

@@ -54,7 +54,7 @@ void main() {
float v;
if (idx > 0) v = smooth_f(audio_l); /* left buffer */
else v = smooth_f(audio_r); /* right buffer */
v *= AMPLIFY * (1 + pos); /* amplify and scale with frequency */
v *= AMPLIFY; /* amplify */
#undef smooth_f
d -= C_RADIUS + (float(C_LINE) / 2.0F); /* offset to fragment distance from inner circle */
if (d <= v - BAR_OUTLINE_WIDTH) {

View File

@@ -19,3 +19,12 @@
and lower values reduce the displayed frequencies in a log-like
scale. */
#define SAMPLE_RANGE 0.9
/* Factor for how to scale higher frequencies. Used in a linear equation
which is multiplied by the result of the fft transformation. */
#request setfftscale 10.2
/* Cutoff for the bass end of the audio data when scaling frequencies.
Higher values cause more of the bass frequencies to be skipped when
scaling. */
#request setfftcutoff 0.3

View File

@@ -42,7 +42,6 @@ float smooth_audio(in sampler1D tex, int tex_sz, highp float idx, float r) {
avg += texture(tex, float(s) / float(tex_sz)).r * w;
}
avg /= weight;
avg *= max(idx + 0.7, 1);
return avg;
}