Skip to content

Instantly share code, notes, and snippets.

@jarcode-foss
Created December 3, 2017 21:54
Show Gist options
  • Save jarcode-foss/c5eebdda3624a0066060c0abca6db8b0 to your computer and use it in GitHub Desktop.
Save jarcode-foss/c5eebdda3624a0066060c0abca6db8b0 to your computer and use it in GitHub Desktop.
#define E 2.7182818284590452353
void transform_smooth(struct gl_data* d, void** udaa, void* data) {
struct gl_sampler_data* s = (struct gl_sampler_data*) data;
float* b = s->buf;
size_t sz = s->sz;
for (int t = 0; t < sz; ++t) {
float
db = log(t), /* buffer index on log10 scale (db) */
v = b[t], /* value at this position */
avg = 0; /* adj value averages (weighted) */
/* Calculate real indexes for sampling at this position, since the
distance is specified in scalar values */
int smin = (int) floor(powf(E, max(db - d->smooth_distance, 0)));
int smax = min((int) ceil(powf(E, db + d->smooth_distance)), sz - 1);
int count = 0;
for (int s = smin; s <= smax; ++s) {
if (b[s]) {
avg += b[s] /* / abs(powf(10, db + (t - s))) */;
count++;
}
}
avg /= count;
b[t] = avg;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment