diff options
author | Vito Caputo <vcaputo@pengaru.com> | 2020-02-03 19:50:49 -0800 |
---|---|---|
committer | Vito Caputo <vcaputo@pengaru.com> | 2020-09-26 16:54:25 -0700 |
commit | b3284b7a7cb232b9b6eb0d2b2832647d1df4cd0c (patch) | |
tree | 8089cb1ba0b705888307aa66956eb6721d3ba402 | |
parent | 3fc9031e6b10f6accceb7c00f368e34045bbaca7 (diff) |
modules/signals: WIP experimental signals modulesignals
Playing with libs/sig in 2D
-rw-r--r-- | configure.ac | 1 | ||||
-rw-r--r-- | src/Makefile.am | 2 | ||||
-rw-r--r-- | src/modules/Makefile.am | 2 | ||||
-rw-r--r-- | src/modules/signals/Makefile.am | 3 | ||||
-rw-r--r-- | src/modules/signals/signals.c | 188 | ||||
-rw-r--r-- | src/rototiller.c | 2 |
6 files changed, 196 insertions, 2 deletions
diff --git a/configure.ac b/configure.ac index b75643a..b4bc9af 100644 --- a/configure.ac +++ b/configure.ac @@ -54,6 +54,7 @@ AC_CONFIG_FILES([ src/modules/ray/Makefile src/modules/roto/Makefile src/modules/rtv/Makefile + src/modules/signals/Makefile src/modules/snow/Makefile src/modules/sparkler/Makefile src/modules/spiro/Makefile diff --git a/src/Makefile.am b/src/Makefile.am index 40d3254..94dcee5 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -4,4 +4,4 @@ rototiller_SOURCES = fb.c fb.h fps.c fps.h knobs.h rototiller.c rototiller.h sdl if ENABLE_DRM rototiller_SOURCES += drm_fb.c endif -rototiller_LDADD = modules/compose/libcompose.a modules/drizzle/libdrizzle.a modules/flui2d/libflui2d.a modules/julia/libjulia.a modules/meta2d/libmeta2d.a modules/montage/libmontage.a modules/pixbounce/libpixbounce.a modules/plasma/libplasma.a modules/ray/libray.a modules/roto/libroto.a modules/rtv/librtv.a modules/snow/libsnow.a modules/sparkler/libsparkler.a modules/spiro/libspiro.a modules/stars/libstars.a modules/submit/libsubmit.a modules/swab/libswab.a libs/grid/libgrid.a libs/puddle/libpuddle.a libs/ray/libray.a libs/sig/libsig.a libs/txt/libtxt.a libs/ascii/libascii.a libs/din/libdin.a -lm +rototiller_LDADD = modules/compose/libcompose.a modules/drizzle/libdrizzle.a modules/flui2d/libflui2d.a modules/julia/libjulia.a modules/meta2d/libmeta2d.a modules/montage/libmontage.a modules/pixbounce/libpixbounce.a modules/plasma/libplasma.a modules/ray/libray.a modules/roto/libroto.a modules/rtv/librtv.a modules/signals/libsignals.a modules/snow/libsnow.a modules/sparkler/libsparkler.a modules/spiro/libspiro.a modules/stars/libstars.a modules/submit/libsubmit.a modules/swab/libswab.a libs/grid/libgrid.a libs/puddle/libpuddle.a libs/ray/libray.a libs/sig/libsig.a libs/txt/libtxt.a libs/ascii/libascii.a libs/din/libdin.a -lm diff --git a/src/modules/Makefile.am b/src/modules/Makefile.am index 0f60d29..192e7a3 100644 --- a/src/modules/Makefile.am +++ b/src/modules/Makefile.am @@ -1 +1 @@ -SUBDIRS = compose drizzle flui2d julia meta2d montage pixbounce plasma ray roto rtv snow sparkler spiro stars submit swab +SUBDIRS = compose drizzle flui2d julia meta2d montage pixbounce plasma ray roto rtv signals snow sparkler spiro stars submit swab diff --git a/src/modules/signals/Makefile.am b/src/modules/signals/Makefile.am new file mode 100644 index 0000000..75b6fd8 --- /dev/null +++ b/src/modules/signals/Makefile.am @@ -0,0 +1,3 @@ +noinst_LIBRARIES = libsignals.a +libsignals_a_SOURCES = signals.c +libsignals_a_CPPFLAGS = -I@top_srcdir@/src -I@top_srcdir@/src/libs diff --git a/src/modules/signals/signals.c b/src/modules/signals/signals.c new file mode 100644 index 0000000..2e929c3 --- /dev/null +++ b/src/modules/signals/signals.c @@ -0,0 +1,188 @@ +#include <stdint.h> +#include <stdlib.h> + +#include "fb.h" +#include "rototiller.h" +#include "sig/sig.h" + +/* Copyright (C) 2020 - Vito Caputo <vcaputo@pengaru.com> */ + +/* 2D waveform drawings to exercise libs/sig and explore its ergonomics */ + +#define N_SIGNALS 11 + +typedef struct signals_context_t { + sig_t *signals[N_SIGNALS]; +} signals_context_t; + + +static void * signals_create_context(unsigned ticks, unsigned n_cpus) +{ + signals_context_t *ctxt; + + ctxt = calloc(1, sizeof(signals_context_t)); + if (!ctxt) + return NULL; + + ctxt->signals[0] = sig_new_sin(sig_new_const(.5f)); /* oscillate @ .5hz */ + if (!ctxt->signals[0]) + goto err; + + ctxt->signals[1] = sig_new_sin( /* oscillate */ + sig_new_scale( /* at a scaled frequency */ + sig_new_sin(sig_new_const(.1f)),/* from another oscillator @ .1hz */ + sig_new_const(.2f), /* from .2 */ + sig_new_const(7.f) /* to 7 */ + ) + ); + if (!ctxt->signals[1]) + goto err; + + ctxt->signals[2] = sig_new_lerp( /* interpolate */ + sig_new_sin(sig_new_const(.33f)), /* a .33hz oscillator */ + sig_new_sin(sig_new_const(.15f)), /* and a .15hz oscillator */ + sig_new_sin(sig_new_const(2.f)) /* weighted by a 2hz oscillator */ + ); + if (!ctxt->signals[2]) + goto err; + + ctxt->signals[3] = sig_new_pow( /* raise */ + sig_new_sin(sig_new_const(4.f)), /* a 4hz oscillator */ + sig_new_sin(sig_new_const(.33f)) /* to the power of a .33f hz oscillator */ + ); + if (!ctxt->signals[3]) + goto err; + + ctxt->signals[4] = sig_new_mult( /* multiply */ + sig_new_sin(sig_new_const(4.f)), /* a 4hz oscillator */ + sig_new_sin(sig_new_const(1.f)) /* by a 1hz oscillator */ + ); + if (!ctxt->signals[4]) + goto err; + + ctxt->signals[5] = sig_new_lerp( /* interpolate */ + sig_ref(ctxt->signals[3]), /* signals[3] */ + sig_ref(ctxt->signals[4]), /* signals[4] */ + sig_ref(ctxt->signals[2]) /* weighted by signals[2] */ + ); + if (!ctxt->signals[5]) + goto err; + + ctxt->signals[6] = sig_new_lerp( /* interpolate */ + sig_new_inv(sig_ref(ctxt->signals[5])), /* invert of signals[5] */ + sig_new_pow(sig_ref(ctxt->signals[5]), /* with raised signals[5] */ + sig_ref(ctxt->signals[3])), /* to power of signals[3] */ + sig_ref(ctxt->signals[2]) /* weighted by signals[2] */ + ); + if (!ctxt->signals[6]) + goto err; + + ctxt->signals[7] = sig_new_mult( /* multiply */ + sig_ref(ctxt->signals[6]), /* signals[6] */ + sig_ref(ctxt->signals[5]) /* signals[5] */ + ); + if (!ctxt->signals[7]) + goto err; + + ctxt->signals[8] = sig_new_mult( /* multiply */ + sig_ref(ctxt->signals[1]), /* signals[1] */ + sig_ref(ctxt->signals[7]) /* signals[7] */ + ); + if (!ctxt->signals[8]) + goto err; + + ctxt->signals[9] = sig_new_pow( /* raise */ + sig_ref(ctxt->signals[3]), /* signals[3] */ + sig_new_scale( /* to power of scaled */ + sig_ref(ctxt->signals[7]), /* signals[7] */ + sig_new_const(.1f), /* into range .1f .. */ + sig_new_const(20.f) /* to 20.f */ + ) + ); + if (!ctxt->signals[9]) + goto err; + + ctxt->signals[10] = sig_new_lerp( /* interpolate */ + sig_ref(ctxt->signals[9]), /* signals[9] */ + sig_new_rand(), /* random noise */ + sig_new_lerp( /* weighted by interpolating */ + sig_new_inv( /* inverted ... */ + sig_ref(ctxt->signals[5])),/* signals[5] */ + sig_ref(ctxt->signals[3]), /* and signals[3] */ + sig_ref(ctxt->signals[1]) /* weighted by signals[1] */ + ) + ); + if (!ctxt->signals[10]) + goto err; + + return ctxt; + +err: + for (unsigned i = 0; i < N_SIGNALS; i++) + sig_free(ctxt->signals[i]); + + free(ctxt); + + return NULL; +} + + +static void signals_destroy_context(void *context) +{ + signals_context_t *ctxt = context; + + for (unsigned i = 0; i < N_SIGNALS; i++) + sig_free(ctxt->signals[i]); + + free(ctxt); +} + + +static int signals_fragmenter(void *context, const fb_fragment_t *fragment, unsigned number, fb_fragment_t *res_fragment) +{ + signals_context_t *ctxt = context; + + return fb_fragment_slice_single(fragment, N_SIGNALS, number, res_fragment); +} + + +static void signals_prepare_frame(void *context, unsigned ticks, unsigned n_cpus, fb_fragment_t *fragment, rototiller_fragmenter_t *res_fragmenter) +{ + *res_fragmenter = signals_fragmenter; +} + + +static void signals_render_fragment(void *context, unsigned ticks, unsigned cpu, fb_fragment_t *fragment) +{ + signals_context_t *ctxt = context; + + fb_fragment_zero(fragment); + + if (fragment->number >= N_SIGNALS) + return; + + ticks >>= 2; /* move a bit slower */ + + for (unsigned x = 0, y; x < fragment->width; x++) { + float size = fragment->height - 1; + + /* This needs to compute an offset into fragment->height, + * from a 0-1 range, hence size is height - 1 to not overflow. + */ + y = size - sig_output(ctxt->signals[fragment->number], ticks + x) * size; + + fb_fragment_put_pixel_checked(fragment, fragment->x + x, fragment->y + y, 0xffffffff); + } +} + + +rototiller_module_t signals_module = { + .create_context = signals_create_context, + .destroy_context = signals_destroy_context, + .prepare_frame = signals_prepare_frame, + .render_fragment = signals_render_fragment, + .name = "signals", + .description = "2D Waveforms (threaded)", + .author = "Vito Caputo <vcaputo@pengaru.com>", + .license = "GPLv2", +}; diff --git a/src/rototiller.c b/src/rototiller.c index 48056db..191e087 100644 --- a/src/rototiller.c +++ b/src/rototiller.c @@ -44,6 +44,7 @@ extern rototiller_module_t plasma_module; extern rototiller_module_t ray_module; extern rototiller_module_t roto_module; extern rototiller_module_t rtv_module; +extern rototiller_module_t signals_module; extern rototiller_module_t snow_module; extern rototiller_module_t sparkler_module; extern rototiller_module_t spiro_module; @@ -63,6 +64,7 @@ static const rototiller_module_t *modules[] = { &ray_module, &roto_module, &rtv_module, + &signals_module, &snow_module, &sparkler_module, &spiro_module, |