~pbatch/mnolth

9503c95bea68968a94e013caed8c68c82b779b32 — paul 11 months ago a3f01c9
gestvm LFO demo: wubs

FossilOrigin-Name: 37804167c3d061f81f2e00aa66acd051737446064d90e1fadc66efed7a825dcd
M core/misc.org => core/misc.org +50 -0
@@ 23,6 23,12 @@ a home anywhere else.
#include "bitlang/bitlang.h"
#include "btprnt/btprnt.h"

#ifdef MNODES
#include "ftlist/ftlist.h"
#endif

#include "gestvm/gestvm.h"

<<lilfuncs>>

void lil_load_misc(lil_t lil)


@@ 261,3 267,47 @@ static lil_value_t l_blngex(lil_t lil,
    return NULL;
}
#+END_SRC
* gestvmtablist
Used by GestVM if mnodes are enabled (ftlist is in there).

This will set the table list instance of a gestvm node.

#+NAME: lildefs
#+BEGIN_SRC c
#ifdef MNODES
lil_register(lil, "gestvmtablist", l_gestvmtablist);
#endif
#+END_SRC

#+NAME: lilfuncs
#+BEGIN_SRC c
static lil_value_t l_gestvmtablist(lil_t lil,
                                   size_t argc,
                                   lil_value_t *argv)
{ 
    sk_core *core;
    void *ud;
    int rc;
    sp_ftlist *ftl;
    gestvm *gvm;
    sk_table **tablist;
    int sz;

    SKLIL_ARITY_CHECK(lil, "gestvmtablist", argc, 2);
    core = lil_get_data(lil);

    rc = sk_core_generic_pop(core, &ud);
    SKLIL_ERROR_CHECK(lil, rc, "could not get ftlist");
    ftl = ud;

    rc = sk_core_generic_pop(core, &ud);
    SKLIL_ERROR_CHECK(lil, rc, "could not get gestvm");
    gvm = ud;

    tablist = sp_ftlist_list(ftl);
    sz = sp_ftlist_size(ftl);

    gestvm_tablist(gvm, tablist, sz);
    return NULL;
}
#+END_SRC

A examples/wubs.lil => examples/wubs.lil +99 -0
@@ 0,0 1,99 @@
ftlnew ftl

grab ftl
gensine [tabnew 4096] "10 1"
ftladd zz zz
gestvmnew gvm

gestvmload [grab gvm] cur.rom

phasor 2 0
hold zz
regset zz 0

gestvmnode [grab gvm] [gestvmsym cur.rom mel] [regget 0]
hold zz
regset zz 1

regget 1
add zz [expr 22 + 12 - 0.3]
mtof zz
blsaw zz
mul zz 0.5

regget 1
add zz [expr 22 + 12 + 0.21]
mtof zz
blsaw zz
mul zz 0.5
add zz zz

gestvmnode [grab gvm] [gestvmsym cur.rom filter] [regget 0]
gestvmtablist [gestvmlast [grab gvm]] [grab ftl]
mul zz [param [expr 1 / 255]]
limit zz 0 1
hold zz
regset zz 2

regget 1
add zz [expr 22 + 24 + 7.2]
sine 7 0.1
add zz zz
mtof zz
blsaw zz
regget 2
scale zz 0.1 0.8
mul zz zz
buthp zz 400
add zz zz
buthp zz 200
mul zz [dblin -3]
peakeq zz 500 500 0.2

regget 1
add zz 22
mtof zz
blsaw zz
mul zz 1.5
add zz zz

mul zz [dblin -4]

dup
softclip zz 20
regget 2
scale zz 8000 200
buthp zz zz
mul zz 0.5
add zz zz

regget 2
scale zz 150 2000
butlp zz zz
param [mtof 35]
dup
param 2
peakeq zz zz zz zz

dup
vardelay zz 0 0.1 0.3
dup
bigverb zz zz 0.97 10000
drop
dcblocker zz
buthp zz 200
mul zz [dblin -20]
add zz zz

mul zz [dblin -3]

limit zz -0.99 0.99

unhold [regget 0]

tgate [tick] 38
smoother zz 0.01
mul zz zz

wavout zz wubs.wav
computes 40

A examples/wubs.tal => examples/wubs.tal +177 -0
@@ 0,0 1,177 @@
%NUM { #24 DEO }
%DEN { #25 DEO }
%NEXT { #26 DEO }
%CURR { #2b DEO }
%NOTE { #3c ADD NEXT }
%BHVR { #27 DEO }
%PARAM { #2c DEO #2d DEO }

|0100

@segments
    &riff32
        #80 CURR
        #03 NUM #02 DEN
        #0c BHVR #00 #00 PARAM
        #80 NEXT
    JMP2r

    &riff12
        #80 CURR
        #01 NUM #02 DEN
        #0c BHVR #00 #00 PARAM
        #80 NEXT
    JMP2r

    &riff11
        #80 CURR
        #01 NUM #01 DEN
        #0c BHVR #00 #00 PARAM
        #80 NEXT
    JMP2r

    &riff41
        #80 CURR
        #04 NUM #01 DEN
        #0c BHVR #00 #00 PARAM
        #80 NEXT
    JMP2r

    &riff21
        #80 CURR
        #02 NUM #01 DEN
        #0c BHVR #00 #00 PARAM
        #80 NEXT
    JMP2r

    &riff31
        #80 CURR
        #03 NUM #01 DEN
        #0c BHVR #00 #00 PARAM
        #80 NEXT
    JMP2r

    &rhy1
        ;segments/riff32 JSR2 BRK
        ;segments/riff32 JSR2 BRK
        ;segments/riff32 JSR2 BRK
        ;segments/riff12 JSR2 BRK
    JMP2r

    &rhy2
        ;segments/riff11 JSR2 BRK
        ;segments/riff41 JSR2 BRK
        ;segments/riff41 JSR2 BRK
        ;segments/riff41 JSR2 BRK
        ;segments/riff41 JSR2 BRK
        ;segments/riff12 JSR2 BRK
    JMP2r

    &rhy3
        ;segments/riff32 JSR2 BRK
        ;segments/riff32 JSR2 BRK
        ;segments/riff32 JSR2 BRK
        ;segments/riff41 JSR2 BRK
        ;segments/riff41 JSR2 BRK
        ;segments/riff21 JSR2 BRK
        ;segments/riff41 JSR2 BRK
        ;segments/riff41 JSR2 BRK
        ;segments/riff21 JSR2 BRK
    JMP2r

    &rhy4
        ;segments/riff41 JSR2 BRK
        ;segments/riff41 JSR2 BRK
        ;segments/riff41 JSR2 BRK
        ;segments/riff41 JSR2 BRK
        ;segments/riff31 JSR2 BRK
        ;segments/riff31 JSR2 BRK
        ;segments/riff31 JSR2 BRK
        ;segments/riff21 JSR2 BRK
        ;segments/riff21 JSR2 BRK
        ;segments/riff11 JSR2 BRK
    JMP2r

    &rhy5
        ;segments/riff21 JSR2 BRK
        ;segments/riff21 JSR2 BRK
        ;segments/riff21 JSR2 BRK
        ;segments/riff21 JSR2 BRK
        ;segments/riff12 JSR2 BRK
    JMP2r

@filter
#80 NEXT BRK

&loop

;segments/rhy1 JSR2
;segments/rhy1 JSR2
;segments/rhy1 JSR2
;segments/rhy2 JSR2

;segments/rhy1 JSR2
;segments/rhy1 JSR2
;segments/rhy1 JSR2
;segments/rhy2 JSR2

;segments/rhy2 JSR2
;segments/rhy3 JSR2
;segments/rhy1 JSR2
;segments/rhy4 JSR2

;segments/rhy2 JSR2
;segments/rhy3 JSR2
;segments/rhy1 JSR2
;segments/rhy5 JSR2

;filter/loop JMP2

@melriffs
    &riff1
        #00 #0c ADD NEXT BRK
        #01 NUM #02 DEN #02 BHVR
        #03 #0c ADD NEXT BRK
        #08 NEXT BRK
        #0a NEXT BRK

        #00 #0c ADD NEXT BRK
        #01 NUM #02 DEN #02 BHVR
        #03 #0c ADD NEXT BRK
        #08 NEXT BRK
        #05 NEXT BRK
        #0b BHVR #30 #00 PARAM
    JMP2r

    &riff2
        #00 #0c ADD NEXT BRK
        #00 BHVR #01 #02 DEN NUM
        #07 #0c ADD NEXT BRK
        #00 BHVR #01 #06 DEN NUM

        #08 NEXT BRK
        #00 BHVR #01 #04 DEN NUM
        #05 NEXT BRK
        #03 BHVR
    JMP2r

    &riff3
        #00 #0c ADD NEXT BRK
        #00 BHVR #01 #02 DEN NUM
        #0c #0c ADD NEXT BRK
        #00 BHVR #01 #06 DEN NUM

        #08 NEXT BRK
        #00 BHVR #01 #04 DEN NUM
        #00 NEXT BRK
        #0a BHVR #01 #02 DEN NUM
        #0c #03 MUL NEXT BRK
        #0a BHVR #01 #02 DEN NUM
    JMP2r

@mel
;melriffs/riff1 JSR2
;melriffs/riff1 JSR2
;melriffs/riff2 JSR2
;melriffs/riff3 JSR2
;mel JMP2

M lib/gestvm/gestvm.c => lib/gestvm/gestvm.c +257 -90
@@ 4,101 4,133 @@
#include <string.h>
#include <unistd.h>
#include <math.h>
#include "sndkit/graforge/graforge.h"
#include "sndkit/core.h"

#include "uxn/uxn.h"
#define GESTVM_PRIV
#include "gestvm.h"

#line 486 "gestvm.org"
#line 489 "gestvm.org"
static SKFLT skewer_tick(gestvm *gvm, SKFLT phs);
#line 559 "gestvm.org"
#line 562 "gestvm.org"
static gestvm_behavior find_skewer(int id);
#line 607 "gestvm.org"
#line 610 "gestvm.org"
static SKFLT s_passthru(gestvm *gvm, SKFLT a);
static SKFLT s_exp_pos(gestvm *gvm, SKFLT a);
static SKFLT s_exp_neg(gestvm *gvm, SKFLT a);
#line 649 "gestvm.org"
#line 652 "gestvm.org"
static SKFLT rephasor_tick(gestvm *gvm, SKFLT phs);
#line 1037 "gestvm.org"
#line 1042 "gestvm.org"
static Uint8 nil_dei(Device *d, Uint8 port);
static void nil_deo(Device *d, Uint8 port);
#line 1071 "gestvm.org"
#line 1076 "gestvm.org"
static void console_deo(Device *d, Uint8 port);
#line 1096 "gestvm.org"
#line 1101 "gestvm.org"
static void gestvm_deo(Device *d, Uint8 port);
#line 1245 "gestvm.org"
#line 1271 "gestvm.org"
static void vm_tick(gestvm *gvm, SKFLT phs);
#line 1382 "gestvm.org"
#line 1428 "gestvm.org"
static SKFLT b_linear(gestvm *gvm, SKFLT a);
#line 1443 "gestvm.org"
static SKFLT b_step(gestvm *gvm, SKFLT a);
#line 1462 "gestvm.org"
static SKFLT b_gliss_medium(gestvm *gvm, SKFLT a);
static SKFLT b_gliss(gestvm *gvm, SKFLT a);
#line 1434 "gestvm.org"
#line 1501 "gestvm.org"
static SKFLT b_gliss_parametric(gestvm *gvm, SKFLT a);
#line 1541 "gestvm.org"
static SKFLT expmap(SKFLT in, SKFLT slope);
static SKFLT b_expon_convex_high(gestvm *gvm, SKFLT a);
static SKFLT b_expon_convex_low(gestvm *gvm, SKFLT a);
static SKFLT b_expon_concave_high(gestvm *gvm, SKFLT a);
static SKFLT b_expon_concave_low(gestvm *gvm, SKFLT a);
#line 1581 "gestvm.org"
static SKFLT interpolate(gestvm *gvm, SKFLT phs);
#line 1453 "gestvm.org"
#line 1605 "gestvm.org"
static gestvm_behavior find_behavior(int id);
#line 1704 "gestvm.org"
#line 1715 "gestvm.org"
static SKFLT scale255(int x);
#line 1903 "gestvm.org"
static void uxn_mass(gestvm *gvm, unsigned char val);
#line 1726 "gestvm.org"
#line 1925 "gestvm.org"
static void uxn_inertia(gestvm *gvm, unsigned char val);
#line 1763 "gestvm.org"
#line 1962 "gestvm.org"
static SKFLT b_gate_rel_25(gestvm *gvm, SKFLT a);
static SKFLT b_gate_rel_50(gestvm *gvm, SKFLT a);
static SKFLT b_gate_rel_125(gestvm *gvm, SKFLT a);
#line 2030 "gestvm.org"
static SKFLT b_tabread(gestvm *gvm, SKFLT a);
#line 177 "gestvm.org"
#line 754 "gestvm.org"
#line 757 "gestvm.org"
int uxn_halt(Uxn *u, Uint8 error, char *name, int id)
{
    /* doing nothing for now */
    fprintf(stderr, "uxn halt %d, %x:  %s\n", error, id, name);
	return 0;
}
#line 177 "gestvm.org"
#line 231 "gestvm.org"
#line 234 "gestvm.org"
void gestvm_init(gestvm *gvm, gestvm_uxn *u)
{
#line 518 "gestvm.org"
#line 521 "gestvm.org"
gestvm_rephasor_init(&gvm->skew);
gestvm_rephasor_scale(&gvm->skew, 1.0);
#line 535 "gestvm.org"
#line 538 "gestvm.org"
gvm->skewdur = 1;
#line 551 "gestvm.org"
#line 554 "gestvm.org"
gvm->update_skewer = 0;
#line 598 "gestvm.org"
#line 601 "gestvm.org"
gvm->skewer = s_passthru;
#line 714 "gestvm.org"
#line 717 "gestvm.org"
gestvm_rephasor_init(&gvm->rephasor);
gestvm_rephasor_scale(&gvm->rephasor, 1.0);
gvm->num = 1;
gvm->den = 1;
gvm->update_rephasor = 0;
gvm->extscale = gvm->pextscale = 1.0;
#line 849 "gestvm.org"
#line 854 "gestvm.org"
gvm->u = u;
#line 1011 "gestvm.org"
#line 1016 "gestvm.org"
gvm->ptr = 0;
#line 1240 "gestvm.org"
#line 1266 "gestvm.org"
gvm->lphs = 999;
#line 1289 "gestvm.org"
#line 1316 "gestvm.org"
gvm->empty_value = 1;
#line 1342 "gestvm.org"
#line 1379 "gestvm.org"
gvm->cur = 0;
gvm->nxt = 0;
#line 1360 "gestvm.org"
#line 1397 "gestvm.org"
gvm->behavior = b_linear;
#line 1375 "gestvm.org"
#line 1412 "gestvm.org"
gvm->a = 0;
#line 1553 "gestvm.org"
#line 1706 "gestvm.org"
{
    int i;
    for (i = 0; i < 4; i++) gvm->params[i] = 0;
    gvm->pselect = 0;
}
#line 1752 "gestvm.org"
gvm->mass = 0;
gvm->inertia = 0;
#line 1800 "gestvm.org"
#line 1999 "gestvm.org"
gvm->interp = 1;
#line 234 "gestvm.org"
}
#line 247 "gestvm.org"
#line 2010 "gestvm.org"
gvm->tablist = NULL;
gvm->ntables = 0;
#line 2074 "gestvm.org"
gvm->adder = 0;
#line 2084 "gestvm.org"
memset(&gvm->wst, 0, sizeof(Stack));
memset(&gvm->rst, 0, sizeof(Stack));
#line 237 "gestvm.org"
}
#line 250 "gestvm.org"
size_t gestvm_sizeof(void)
{
    return sizeof(gestvm);
}
#line 268 "gestvm.org"
#line 271 "gestvm.org"
SKFLT gestvm_tick(gestvm *gvm, SKFLT cnd)
{
    SKFLT out;


@@ 123,7 155,7 @@ SKFLT gestvm_tick(gestvm *gvm, SKFLT cnd)

    return out;
}
#line 347 "gestvm.org"
#line 350 "gestvm.org"
void gestvm_rephasor_scale(gestvm_rephasor *rp, SKFLT scale)
{
    if (scale != rp->s) {


@@ 131,7 163,7 @@ void gestvm_rephasor_scale(gestvm_rephasor *rp, SKFLT scale)
        rp->si = 1.0 / scale;
    }
}
#line 365 "gestvm.org"
#line 368 "gestvm.org"
void gestvm_rephasor_init(gestvm_rephasor *rp)
{
    rp->pr = 0;


@@ 146,7 178,7 @@ void gestvm_rephasor_init(gestvm_rephasor *rp)
    rp->ir = 0.0;
    rp->ic = 0.0;
}
#line 419 "gestvm.org"
#line 422 "gestvm.org"
static SKFLT phasor(SKFLT phs, SKFLT inc)
{
    phs += inc;


@@ 201,7 233,7 @@ SKFLT gestvm_rephasor_tick(gestvm_rephasor *rp, SKFLT ext)

    return out;
}
#line 491 "gestvm.org"
#line 494 "gestvm.org"
static SKFLT skewer_tick(gestvm *gvm, SKFLT phs)
{
    SKFLT out;


@@ 222,7 254,7 @@ static SKFLT skewer_tick(gestvm *gvm, SKFLT phs)

    return out;
}
#line 564 "gestvm.org"
#line 567 "gestvm.org"
static gestvm_behavior find_skewer(int id)
{
    gestvm_behavior s;


@@ 245,22 277,22 @@ static gestvm_behavior find_skewer(int id)

    return s;
}
#line 614 "gestvm.org"
#line 617 "gestvm.org"
static SKFLT s_passthru(gestvm *gvm, SKFLT a)
{
    return a;
}
#line 622 "gestvm.org"
#line 625 "gestvm.org"
static SKFLT s_exp_pos(gestvm *gvm, SKFLT a)
{
    return (1.0 - exp(1.5*a)) / (1.0 - exp(1.5));
}
#line 630 "gestvm.org"
#line 633 "gestvm.org"
static SKFLT s_exp_neg(gestvm *gvm, SKFLT a)
{
    return (1.0 - exp(-1.5*a)) / (1.0 - exp(-1.5));
}
#line 657 "gestvm.org"
#line 660 "gestvm.org"
static SKFLT rephasor_tick(gestvm *gvm, SKFLT phs)
{
    SKFLT out;


@@ 288,18 320,18 @@ static SKFLT rephasor_tick(gestvm *gvm, SKFLT phs)
    out = gestvm_rephasor_tick(&gvm->rephasor, phs);
    return out;
}
#line 732 "gestvm.org"
#line 735 "gestvm.org"
void gestvm_extscale(gestvm *gvm, SKFLT extscale)
{
    gvm->extscale = extscale;
}
#line 796 "gestvm.org"
#line 800 "gestvm.org"
void gestvm_uxn_init(gestvm_uxn *u)
{
    uxn_boot(&u->u);
    u->gvm = NULL;

#line 1056 "gestvm.org"
#line 1061 "gestvm.org"
{
    int i;



@@ 307,20 339,21 @@ void gestvm_uxn_init(gestvm_uxn *u)
        uxn_port(&u->u, i, nil_dei, nil_deo);
    }
}
#line 796 "gestvm.org"
#line 1087 "gestvm.org"
#line 800 "gestvm.org"
#line 1092 "gestvm.org"
uxn_port(&u->u, 0x1, nil_dei, console_deo);
#line 796 "gestvm.org"
#line 1123 "gestvm.org"
#line 800 "gestvm.org"
#line 1128 "gestvm.org"
uxn_port(&u->u, 0x2, nil_dei, gestvm_deo);
#line 804 "gestvm.org"
#line 808 "gestvm.org"

}
#line 814 "gestvm.org"
#line 819 "gestvm.org"
size_t gestvm_uxn_sizeof(void)
{
    return sizeof(gestvm_uxn);
}
#line 828 "gestvm.org"
#line 833 "gestvm.org"
void gestvm_uxn_set(gestvm_uxn *gu, gestvm *gvm)
{
    gu->gvm = gvm;


@@ 330,7 363,7 @@ gestvm *gestvm_uxn_get(gestvm_uxn *gu)
{
    return gu->gvm;
}
#line 869 "gestvm.org"
#line 874 "gestvm.org"
int gestvm_load(gestvm_uxn *gu, const char *rom)
{
	FILE *f;


@@ 363,7 396,7 @@ int gestvm_load(gestvm_uxn *gu, const char *rom)
	if(r < 1) return 1;
	return 0;
}
#line 935 "gestvm.org"
#line 940 "gestvm.org"
unsigned int gestvm_lookup(const char *rom, const char *sym)
{
    unsigned char symlen;


@@ 428,12 461,12 @@ unsigned int gestvm_lookup(const char *rom, const char *sym)

    return addr;
}
#line 1023 "gestvm.org"
#line 1028 "gestvm.org"
void gestvm_pointer(gestvm *gvm, unsigned int ptr)
{
    gvm->ptr = ptr;
}
#line 1043 "gestvm.org"
#line 1048 "gestvm.org"
static void nil_deo(Device *d, Uint8 port)
{
	if(port == 0x1) d->vector = peek16(d->dat, 0x0);


@@ 443,7 476,7 @@ static Uint8 nil_dei(Device *d, Uint8 port)
{
	return d->dat[port];
}
#line 1076 "gestvm.org"
#line 1081 "gestvm.org"
static void console_deo(Device *d, Uint8 port)
{
	if(port == 0x1)


@@ 451,7 484,7 @@ static void console_deo(Device *d, Uint8 port)
	if(port > 0x7)
		write(port - 0x7, (char *)&d->dat[port], 1);
}
#line 1105 "gestvm.org"
#line 1110 "gestvm.org"
static void gestvm_deo(Device *d, Uint8 port)
{
    gestvm_uxn *gu;


@@ 461,19 494,19 @@ static void gestvm_deo(Device *d, Uint8 port)
    gvm = gu->gvm;

    switch (port) {
#line 1130 "gestvm.org"
#line 1135 "gestvm.org"
case 0:
    uxn_mass(gvm, d->dat[port]);
    break;
#line 1137 "gestvm.org"
#line 1142 "gestvm.org"
case 1:
    uxn_inertia(gvm, d->dat[port]);
    break;
#line 1144 "gestvm.org"
#line 1149 "gestvm.org"
case 2:
    gvm->skewer = find_skewer(d->dat[port]);
    break;
#line 1151 "gestvm.org"
#line 1156 "gestvm.org"
case 3: {
    int skewdur = d->dat[port];



@@ 484,7 517,7 @@ case 3: {
    }
    break;
}
#line 1165 "gestvm.org"
#line 1170 "gestvm.org"
case 4: {
    int num;



@@ 496,7 529,7 @@ case 4: {
    }
    break;
}
#line 1180 "gestvm.org"
#line 1185 "gestvm.org"
case 5: {
    int den;



@@ 508,60 541,83 @@ case 5: {
    }
    break;
}
#line 1195 "gestvm.org"
#line 1200 "gestvm.org"
case 6:
    gvm->nxt = (SKFLT) d->dat[port];
    break;
#line 1205 "gestvm.org"
#line 1210 "gestvm.org"
case 7:
    gvm->behavior = find_behavior(d->dat[port]);
    break;
#line 1212 "gestvm.org"
#line 1217 "gestvm.org"
case 10:
    gvm->interp = d->dat[port];
    break;
#line 1115 "gestvm.org"
#line 1224 "gestvm.org"
case 11:
    gvm->cur = (SKFLT) d->dat[port];
    break;
#line 1231 "gestvm.org"
case 12:
    gvm->pselect = d->dat[port];
    break;
#line 1238 "gestvm.org"
case 13:
    gvm->params[gvm->pselect] = d->dat[port];
    break;
#line 1120 "gestvm.org"
        default:
            break;
    }
}
#line 1250 "gestvm.org"
#line 1276 "gestvm.org"
static void vm_tick(gestvm *gvm, SKFLT phs)
{
    if (phs < gvm->lphs) {
        gvm->u->gvm = gvm;
        gvm->cur = gvm->nxt;
        uxn_eval(&gvm->u->u, gvm->ptr);
        /* uxn_eval(&gvm->u->u, gvm->ptr); */
        gestvm_eval(gvm->u, gvm, gvm->ptr);
        gvm->ptr = gvm->u->u.ram.ptr;

#line 1304 "gestvm.org"
#line 1331 "gestvm.org"
if (gvm->empty_value) {
    gvm->empty_value = 0;
    gvm->cur = gvm->nxt;
    uxn_eval(&gvm->u->u, gvm->ptr);
    /* uxn_eval(&gvm->u->u, gvm->ptr); */
    gestvm_eval(gvm->u, gvm, gvm->ptr);
    gvm->ptr = gvm->u->u.ram.ptr;
}
#line 1259 "gestvm.org"
#line 1286 "gestvm.org"
    }

    gvm->lphs = phs;
}
#line 1325 "gestvm.org"
void gestvm_eval(gestvm_uxn *gu, unsigned int addr)
#line 1353 "gestvm.org"
void gestvm_eval(gestvm_uxn *gu, gestvm *gvm, unsigned int addr)
{
    Stack *l_rst, *l_wst;
    l_rst = gu->u.rst;
    l_wst = gu->u.wst;
    if (gvm != NULL) {
        gu->u.rst = &gvm->rst;
        gu->u.wst = &gvm->wst;
    }
    uxn_eval(&gu->u, addr);
    gu->u.rst = l_rst;
    gu->u.wst = l_wst;
}
#line 1390 "gestvm.org"
#line 1433 "gestvm.org"
static SKFLT b_linear(gestvm *gvm, SKFLT a)
{
    return a;
}

#line 1448 "gestvm.org"
static SKFLT b_step(gestvm *gvm, SKFLT a)
{
    return 0;
}

#line 1468 "gestvm.org"
static SKFLT b_gliss_medium(gestvm *gvm, SKFLT a)
{
    if (a < 0.75) {


@@ 588,18 644,68 @@ static SKFLT b_gliss(gestvm *gvm, SKFLT a)

    return a;
}
#line 1439 "gestvm.org"
#line 1506 "gestvm.org"
static SKFLT b_gliss_parametric(gestvm *gvm, SKFLT a)
{
    SKFLT pos;

    pos = scale255(gvm->params[0]);

    if (pos == 1.0) pos = 0.0;
    if (a < pos) {
        a = 0;
    } else {
        a -= pos;
        if (a < 0) a = 0;
        a /= (1.0 - pos);
        a = a * a * a;
    }
    return a;
}
#line 1550 "gestvm.org"
static SKFLT expmap(SKFLT in, SKFLT slope)
{
    return (1 - exp(in*slope)) / (1 - exp(slope));
}

static SKFLT b_expon_convex_high(gestvm *gvm, SKFLT a)
{
    return expmap(a, -4);
}

static SKFLT b_expon_convex_low(gestvm *gvm, SKFLT a)
{

    return expmap(a, -1);
}

static SKFLT b_expon_concave_high(gestvm *gvm, SKFLT a)
{

    return expmap(a, 4);
}

static SKFLT b_expon_concave_low(gestvm *gvm, SKFLT a)
{
    return expmap(a, 1);
}
#line 1586 "gestvm.org"
static SKFLT interpolate(gestvm *gvm, SKFLT phs)
{
    SKFLT a;
    a = gvm->behavior(gvm, phs);
    /* cache interpolation value */
    gvm->a = a;
    if (gvm->interp)
    if (gvm->interp) {
        if (gvm->adder) {
            gvm->adder = 0;
            return gvm->cur + a*gvm->nxt;
        }
        return (1.0 - a)*gvm->cur + a*gvm->nxt;
    }
    return a;
}
#line 1458 "gestvm.org"
#line 1610 "gestvm.org"
static gestvm_behavior find_behavior(int id)
{
    gestvm_behavior b;


@@ 628,13 734,31 @@ static gestvm_behavior find_behavior(int id)
        case 6:
            b = b_gate_rel_50;
            break;
        case 7:
            b = b_expon_convex_low;
            break;
        case 8:
            b = b_expon_convex_high;
            break;
        case 9:
            b = b_expon_concave_low;
            break;
        case 10:
            b = b_expon_concave_high;
            break;
        case 11:
            b = b_gliss_parametric;
            break;
        case 12:
            b = b_tabread;
            break;
        default:
            break;
    }

    return b;
}
#line 1517 "gestvm.org"
#line 1687 "gestvm.org"
void gestvm_get_last_values(gestvm *gvm,
                            SKFLT *x,
                            SKFLT *y,


@@ 644,12 768,18 @@ void gestvm_get_last_values(gestvm *gvm,
    *y = gvm->nxt;
    *a = gvm->a;
}
#line 1592 "gestvm.org"
#line 1720 "gestvm.org"
static const SKFLT oned255 = 1.0 / 255;
static SKFLT scale255(int x)
{
    return (SKFLT)x*oned255;
}
#line 1791 "gestvm.org"
size_t gestvm_weight_sizeof(void)
{
    return sizeof(gestvm_weight);
}
#line 1605 "gestvm.org"
#line 1804 "gestvm.org"
void gestvm_weight_init(gestvm_weight *gw, gestvm *gvm, int sr)
{
    gw->sr = sr;


@@ 660,7 790,7 @@ void gestvm_weight_init(gestvm_weight *gw, gestvm *gvm, int sr)
    gestvm_weight_amppos(gw, 20);
    gestvm_weight_ampneg(gw, 20);
}
#line 1632 "gestvm.org"
#line 1831 "gestvm.org"
void gestvm_weight_amppos(gestvm_weight *gw, SKFLT amp)
{
    gw->amppos = amp;


@@ 670,7 800,7 @@ void gestvm_weight_ampneg(gestvm_weight *gw, SKFLT amp)
{
    gw->ampneg = amp;
}
#line 1652 "gestvm.org"
#line 1851 "gestvm.org"
SKFLT gestvm_weight_tick(gestvm_weight *gw)
{
    SKFLT i;


@@ 711,7 841,7 @@ SKFLT gestvm_weight_tick(gestvm_weight *gw)

    return out;
}
#line 1709 "gestvm.org"
#line 1908 "gestvm.org"
static void uxn_mass(gestvm *gvm, unsigned char val)
{
    SKFLT m;


@@ 725,7 855,7 @@ static void uxn_mass(gestvm *gvm, unsigned char val)

    gvm->mass = m;
}
#line 1731 "gestvm.org"
#line 1930 "gestvm.org"
static void uxn_inertia(gestvm *gvm, unsigned char val)
{
    SKFLT i;


@@ 736,7 866,7 @@ static void uxn_inertia(gestvm *gvm, unsigned char val)

    gvm->inertia = i;
}
#line 1770 "gestvm.org"
#line 1969 "gestvm.org"
static SKFLT b_gate_rel_25(gestvm *gvm, SKFLT a)
{
    return a <= 0.25;


@@ 751,4 881,41 @@ static SKFLT b_gate_rel_125(gestvm *gvm, SKFLT a)
{
    return a <= 0.125;
}
#line 2021 "gestvm.org"
void gestvm_tablist(gestvm *gvm, sk_table **tablist, int ntables)
{
    gvm->tablist = tablist;
    gvm->ntables = ntables;
}
#line 2035 "gestvm.org"
static SKFLT b_tabread(gestvm *gvm, SKFLT a)
{
    SKFLT *data;
    int sz;
    sk_table *tab;
    int ipos;
    SKFLT fpos;

    if (gvm->params[0] < 0 || gvm->params[0] >= gvm->ntables) {
        return 0;
    }

    gvm->adder = 1;

    tab = gvm->tablist[gvm->params[0]];

    data = sk_table_data(tab);
    sz = sk_table_size(tab);

    if (a < 0) a = 0;
    if (a > 1) a = 1;

    fpos = a * (sz - 2);
    ipos = (int)fpos;
    fpos -= ipos;

    a = (1.0 - fpos)*data[ipos] + fpos*data[ipos + 1];

    return a;
}
#line 177 "gestvm.org"

M lib/gestvm/gestvm.h => lib/gestvm/gestvm.h +56 -44
@@ 6,21 6,21 @@
#define SKFLT float
#endif

#line 211 "gestvm.org"
#line 214 "gestvm.org"
typedef struct gestvm gestvm;
#line 308 "gestvm.org"
#line 311 "gestvm.org"
typedef struct gestvm_rephasor gestvm_rephasor;
#line 776 "gestvm.org"
#line 780 "gestvm.org"
typedef struct gestvm_uxn gestvm_uxn;
#line 1350 "gestvm.org"
#line 1387 "gestvm.org"
typedef SKFLT (*gestvm_behavior)(gestvm *, SKFLT);
#line 1565 "gestvm.org"
#line 1764 "gestvm.org"
typedef struct gestvm_weight gestvm_weight;
#line 165 "gestvm.org"

#ifdef GESTVM_PRIV
#line 177 "gestvm.org"
#line 319 "gestvm.org"
#line 322 "gestvm.org"
struct gestvm_rephasor {
    SKFLT pr; /* rephasor */
    SKFLT pc[2]; /* comparison phasor */


@@ 33,50 33,60 @@ struct gestvm_rephasor {
    SKFLT ic; /* comparison rephasor */
};
#line 177 "gestvm.org"
#line 216 "gestvm.org"
#line 219 "gestvm.org"
struct gestvm {
#line 481 "gestvm.org"
#line 484 "gestvm.org"
gestvm_rephasor skew;
#line 530 "gestvm.org"
#line 533 "gestvm.org"
int skewdur;
#line 593 "gestvm.org"
#line 596 "gestvm.org"
gestvm_behavior skewer;
#line 638 "gestvm.org"
#line 641 "gestvm.org"
int update_skewer;
#line 704 "gestvm.org"
#line 707 "gestvm.org"
gestvm_rephasor rephasor;
int num, den;
int update_rephasor;
SKFLT extscale, pextscale;
#line 844 "gestvm.org"
#line 849 "gestvm.org"
gestvm_uxn *u;
#line 1006 "gestvm.org"
#line 1011 "gestvm.org"
unsigned int ptr;
#line 1232 "gestvm.org"
#line 1258 "gestvm.org"
SKFLT lphs;
#line 1284 "gestvm.org"
#line 1311 "gestvm.org"
int empty_value;
#line 1337 "gestvm.org"
#line 1374 "gestvm.org"
SKFLT cur, nxt;
#line 1355 "gestvm.org"
#line 1392 "gestvm.org"
gestvm_behavior behavior;
#line 1370 "gestvm.org"
#line 1407 "gestvm.org"
SKFLT a;
#line 1547 "gestvm.org"
#line 1700 "gestvm.org"
int pselect;
int params[4];
#line 1746 "gestvm.org"
SKFLT inertia;
SKFLT mass;
#line 1795 "gestvm.org"
#line 1994 "gestvm.org"
int interp;
#line 218 "gestvm.org"
#line 2004 "gestvm.org"
sk_table **tablist;
int ntables;
#line 2069 "gestvm.org"
int adder;
#line 2079 "gestvm.org"
Stack rst, wst;
#line 221 "gestvm.org"
};
#line 177 "gestvm.org"
#line 781 "gestvm.org"
#line 785 "gestvm.org"
struct gestvm_uxn {
    Uxn u;
    gestvm *gvm;
};
#line 177 "gestvm.org"
#line 1570 "gestvm.org"
#line 1769 "gestvm.org"
struct gestvm_weight {
    gestvm *gvm;
    int sr;


@@ 90,49 100,51 @@ struct gestvm_weight {
#line 168 "gestvm.org"
#endif

#line 226 "gestvm.org"
#line 229 "gestvm.org"
void gestvm_init(gestvm *gvm, gestvm_uxn *u);
#line 242 "gestvm.org"
#line 245 "gestvm.org"
size_t gestvm_sizeof(void);
#line 259 "gestvm.org"
#line 262 "gestvm.org"
SKFLT gestvm_tick(gestvm *gvm, SKFLT cnd);
#line 337 "gestvm.org"
#line 340 "gestvm.org"
void gestvm_rephasor_scale(gestvm_rephasor *rp, SKFLT scale);
#line 360 "gestvm.org"
#line 363 "gestvm.org"
void gestvm_rephasor_init(gestvm_rephasor *rp);
#line 387 "gestvm.org"
#line 390 "gestvm.org"
SKFLT gestvm_rephasor_tick(gestvm_rephasor *rp, SKFLT ext);
#line 727 "gestvm.org"
#line 730 "gestvm.org"
void gestvm_extscale(gestvm *gvm, SKFLT extscale);
#line 791 "gestvm.org"
#line 795 "gestvm.org"
void gestvm_uxn_init(gestvm_uxn *u);
#line 809 "gestvm.org"
#line 814 "gestvm.org"
size_t gestvm_uxn_sizeof(void);
#line 822 "gestvm.org"
#line 827 "gestvm.org"
void gestvm_uxn_set(gestvm_uxn *gu, gestvm *gvm);
gestvm *gestvm_uxn_get(gestvm_uxn *gu);
#line 856 "gestvm.org"
#line 861 "gestvm.org"
int gestvm_load(gestvm_uxn *gu, const char *rom);
#line 913 "gestvm.org"
#line 918 "gestvm.org"
unsigned int gestvm_lookup(const char *rom, const char *sym);
#line 1018 "gestvm.org"
#line 1023 "gestvm.org"
void gestvm_pointer(gestvm *gvm, unsigned int ptr);
#line 1320 "gestvm.org"
void gestvm_eval(gestvm_uxn *gu, unsigned int addr);
#line 1504 "gestvm.org"
#line 1348 "gestvm.org"
void gestvm_eval(gestvm_uxn *gu, gestvm *gvm, unsigned int addr);
#line 1674 "gestvm.org"
void gestvm_get_last_values(gestvm *gvm,
                            SKFLT *x,
                            SKFLT *y,
                            SKFLT *a);
#line 1587 "gestvm.org"
#line 1786 "gestvm.org"
size_t gestvm_weight_sizeof(void);
#line 1600 "gestvm.org"
#line 1799 "gestvm.org"
void gestvm_weight_init(gestvm_weight *gw, gestvm *gvm, int sr);
#line 1626 "gestvm.org"
#line 1825 "gestvm.org"
void gestvm_weight_amppos(gestvm_weight *gw, SKFLT amp);
void gestvm_weight_ampneg(gestvm_weight *gw, SKFLT amp);
#line 1647 "gestvm.org"
#line 1846 "gestvm.org"
SKFLT gestvm_weight_tick(gestvm_weight *gw);
#line 2016 "gestvm.org"
void gestvm_tablist(gestvm *gvm, sk_table **tablist, int ntables);
#line 171 "gestvm.org"

#endif

M lib/gestvm/l_gestvm.c => lib/gestvm/l_gestvm.c +6 -1
@@ 178,6 178,11 @@ int sk_node_gestvm(sk_core *core, unsigned int ptr)
    return node_gestvm(core, ptr, 0);
}

int sk_node_gestvm_ext(sk_core *core, unsigned int ptr)
{
    return node_gestvm(core, ptr, 1);
}

static lil_value_t l_gestvmnode(lil_t lil,
                                size_t argc,
                                lil_value_t *argv)


@@ 198,7 203,7 @@ static lil_value_t l_gestvmnode(lil_t lil,
    if (argc > 3) {
        rc = sklil_param(core, argv[3]);
        SKLIL_PARAM_CHECK(lil, rc, "gestvmnode");
        rc = node_gestvm(core, ptr, 1);
        rc = sk_node_gestvm_ext(core, ptr);
    } else {
        rc = sk_node_gestvm(core, ptr);
    }

M lib/gestvm/uxn/uxn.c => lib/gestvm/uxn/uxn.c +10 -7
@@ 60,15 60,16 @@ uxn_eval(Uxn *u, Uint16 vec)
	if(!vec || u->dev[0].dat[0xf])
		return 0;
	u->ram.ptr = vec;
	if(u->wst.ptr > 0xf8) u->wst.ptr = 0xf8;
	/* paul: is this causing trouble? */
	/* if(u->wst->ptr > 0xf8) u->wst->ptr = 0xf8; */
	while((instr = u->ram.dat[u->ram.ptr++])) {
		/* Return Mode */
		if(instr & MODE_RETURN) {
			u->src = &u->rst;
			u->dst = &u->wst;
			u->src = u->rst;
			u->dst = u->wst;
		} else {
			u->src = &u->wst;
			u->dst = &u->rst;
			u->src = u->wst;
			u->dst = u->rst;
		}
		/* Keep Mode */
		if(instr & MODE_KEEP) {


@@ 127,8 128,8 @@ uxn_eval(Uxn *u, Uint16 vec)
			case 0x1e: /* EOR */ a = pop(u->src), b = pop(u->src); push(u->src, b ^ a); break;
			case 0x1f: /* SFT */ a = pop8(u->src), b = pop(u->src); push(u->src, b >> (a & 0x0f) << ((a & 0xf0) >> 4)); break;
		}
		if(u->wst.error) return uxn_halt(u, u->wst.error, "Working-stack", instr);
		if(u->rst.error) return uxn_halt(u, u->rst.error, "Return-stack", instr);
		if(u->wst->error) return uxn_halt(u, u->wst->error, "Working-stack", instr);
		if(u->rst->error) return uxn_halt(u, u->rst->error, "Return-stack", instr);
	}
	return 1;
}


@@ 142,6 143,8 @@ uxn_boot(Uxn *u)
	char *cptr = (char *)u;
	for(i = 0; i < sizeof(*u); i++)
		cptr[i] = 0x00;
	u->wst = &u->iwst;
	u->rst = &u->irst;
	return 1;
}


M lib/gestvm/uxn/uxn.h => lib/gestvm/uxn/uxn.h +2 -1
@@ 35,7 35,8 @@ typedef struct Device {
} Device;

typedef struct Uxn {
	Stack wst, rst, *src, *dst;
	Stack *wst, *rst, *src, *dst;
	Stack iwst, irst;
	Memory ram;
	Device dev[16];
} Uxn;