Unified · Split
| @@ -395,6 +395,37 @@ int sk_param_get(sk_core *core, sk_param *p) · 394 unmodified lines | ||
| 395 | 395 | return 0; |
| 396 | 396 | } |
| 397 | 397 | #+END_SRC |
| 398 | + | |
| 399 | +For situations where only constants are allowed, use | |
| 400 | +=sk_param_get_constant=. | |
| 401 | + | |
| 402 | +#+NAME: funcdefs | |
| 403 | +#+BEGIN_SRC c | |
| 404 | +int sk_param_get_constant(sk_core *core, SKFLT *val); | |
| 405 | +#+END_SRC | |
| 406 | + | |
| 407 | +#+NAME: funcs | |
| 408 | +#+BEGIN_SRC c | |
| 409 | +int sk_param_get_constant(sk_core *core, SKFLT *val) | |
| 410 | +{ | |
| 411 | + sk_stack *stk; | |
| 412 | + sk_stacklet *s; | |
| 413 | + int rc; | |
| 414 | + | |
| 415 | + stk = &core->stack; | |
| 416 | + | |
| 417 | + rc = sk_stack_pop(stk, &s); | |
| 418 | + SK_ERROR_CHECK(rc); | |
| 419 | + | |
| 420 | + if (s->type != SK_TYPE_CONSTANT) { | |
| 421 | + /* Wrong type! */ | |
| 422 | + return 1; | |
| 423 | + } | |
| 424 | + | |
| 425 | + *val = s->f; | |
| 426 | + return 0; | |
| 427 | +} | |
| 428 | +#+END_SRC | |
| 398 | 429 | ** Setting a Parameter |
| 399 | 430 | Set a parameter with =sk_param_set=. |
| 400 | 431 | |
| @@ -922,7 +953,11 @@ int sk_core_table_pop(sk_core *core, sk_table **tab) · 521 unmodified lines | ||
| 922 | 953 | |
| 923 | 954 | SK_ERROR_CHECK(rc); |
| 924 | 955 | |
| 925 | − if (s->type != SK_TYPE_TABLE) return 1; | |
| 956 | + if (s->type != SK_TYPE_TABLE) { | |
| 957 | + printf("uh oh type is %d, %g\n", s->type, s->f); | |
| 958 | + printf("%d items on stack\n", core->stack.pos); | |
| 959 | + return 1; | |
| 960 | + } | |
| 926 | 961 | |
| 927 | 962 | *tab = (sk_table *)s->ptr; |
| 928 | 963 | |
| @@ -6,3 +6,4 @@ include nodes/phasor/config.mk · 5 unmodified lines | ||
| 6 | 6 | include nodes/rephasor/config.mk |
| 7 | 7 | include nodes/tabnew/config.mk |
| 8 | 8 | include nodes/gensine/config.mk |
| 9 | +include nodes/osc/config.mk | |
| @@ -21,10 +21,17 @@ static lil_value_t gensine(lil_t lil, size_t argc, lil_value_t *argv) · 20 unmodified lines | ||
| 21 | 21 | |
| 22 | 22 | if (rc) { |
| 23 | 23 | /* TODO: error handling */ |
| 24 | + printf("uh oh\n"); | |
| 24 | 25 | } |
| 25 | 26 | |
| 26 | 27 | sk_gen_sine(sk_table_data(tab), sk_table_size(tab)); |
| 27 | 28 | |
| 29 | + rc = sk_core_table_push(core, tab); | |
| 30 | + | |
| 31 | + if (rc) { | |
| 32 | + /* TODO: error handling */ | |
| 33 | + } | |
| 34 | + | |
| 28 | 35 | return NULL; |
| 29 | 36 | } |
| 30 | 37 | |
| @@ -13,6 +13,7 @@ void sklil_load_phasor(lil_t lil); · 12 unmodified lines | ||
| 13 | 13 | void sklil_load_rephasor(lil_t lil); |
| 14 | 14 | void sklil_load_tabnew(lil_t lil); |
| 15 | 15 | void sklil_load_gensine(lil_t lil); |
| 16 | +void sklil_load_osc(lil_t lil); | |
| 16 | 17 | |
| 17 | 18 | void sklil_nodes(lil_t lil) |
| 18 | 19 | { |
| @@ -24,6 +25,7 @@ void sklil_nodes(lil_t lil) · 5 unmodified lines | ||
| 24 | 25 | sklil_load_rephasor(lil); |
| 25 | 26 | sklil_load_tabnew(lil); |
| 26 | 27 | sklil_load_gensine(lil); |
| 28 | + sklil_load_osc(lil); | |
| 27 | 29 | } |
| 28 | 30 | |
| 29 | 31 | static lil_value_t computes(lil_t lil, size_t argc, lil_value_t *argv) |
| @@ -37,6 +39,17 @@ static lil_value_t computes(lil_t lil, size_t argc, lil_value_t *argv) · 7 unmodified lines | ||
| 37 | 39 | return NULL; |
| 38 | 40 | } |
| 39 | 41 | |
| 42 | +static lil_value_t param(lil_t lil, size_t argc, lil_value_t *argv) | |
| 43 | +{ | |
| 44 | + sk_core *core; | |
| 45 | + core = lil_get_data(lil); | |
| 46 | + | |
| 47 | + SKLIL_ARITY_CHECK(lil, "param", argc, 1); | |
| 48 | + | |
| 49 | + sklil_param(core, argv[0]); | |
| 50 | + return NULL; | |
| 51 | +} | |
| 52 | + | |
| 40 | 53 | void sklil_loader(lil_t lil) |
| 41 | 54 | { |
| 42 | 55 | sk_core *core; |
| @@ -44,6 +57,7 @@ void sklil_loader(lil_t lil) · 1 unmodified line | ||
| 44 | 57 | lil_set_data(lil, core); |
| 45 | 58 | sklil_nodes(lil); |
| 46 | 59 | lil_register(lil, "computes", computes); |
| 60 | + lil_register(lil, "param", param); | |
| 47 | 61 | } |
| 48 | 62 | |
| 49 | 63 | void sklil_clean(lil_t lil) |
| @@ -0,0 +1,2 @@ | ||
| 1 | +OBJ+=nodes/osc/osc.o | |
| 2 | +OBJ+=nodes/osc/l_osc.o | |
| @@ -0,0 +1,34 @@ | ||
| 1 | +#include <stdlib.h> | |
| 2 | +#include <stdio.h> | |
| 3 | +#include <string.h> | |
| 4 | +#include "lil/lil.h" | |
| 5 | +#include "patchwerk/patchwerk.h" | |
| 6 | +#include "core.h" | |
| 7 | +#include "sklil.h" | |
| 8 | +#include "osc.h" | |
| 9 | + | |
| 10 | +static lil_value_t osc(lil_t lil, size_t argc, lil_value_t *argv) | |
| 11 | +{ | |
| 12 | + sk_core *core; | |
| 13 | + int rc; | |
| 14 | + core = lil_get_data(lil); | |
| 15 | + | |
| 16 | + SKLIL_ARITY_CHECK(lil, "osc", argc, 4); | |
| 17 | + | |
| 18 | + /* skip param 0 */ | |
| 19 | + sklil_param(core, argv[1]); | |
| 20 | + sklil_param(core, argv[2]); | |
| 21 | + sklil_param(core, argv[3]); | |
| 22 | + | |
| 23 | + rc = sk_node_osc(core); | |
| 24 | + | |
| 25 | + if (rc) { | |
| 26 | + /* TODO: error handling */ | |
| 27 | + } | |
| 28 | + return NULL; | |
| 29 | +} | |
| 30 | + | |
| 31 | +void sklil_load_osc(lil_t lil) | |
| 32 | +{ | |
| 33 | + lil_register(lil, "osc", osc); | |
| 34 | +} | |
| @@ -0,0 +1,108 @@ | ||
| 1 | +#include <math.h> | |
| 2 | +#include <stdlib.h> | |
| 3 | +#include <stdint.h> | |
| 4 | +#include "patchwerk.h" | |
| 5 | +#include "core.h" | |
| 6 | +#define SK_OSC_PRIV | |
| 7 | +#include "dsp/osc.h" | |
| 8 | + | |
| 9 | +struct osc_n { | |
| 10 | + pw_cable *freq; | |
| 11 | + pw_cable *amp; | |
| 12 | + pw_cable *out; | |
| 13 | + sk_osc osc; | |
| 14 | +}; | |
| 15 | + | |
| 16 | +static void compute(pw_node *node) | |
| 17 | +{ | |
| 18 | + int blksize; | |
| 19 | + int n; | |
| 20 | + struct osc_n *osc; | |
| 21 | + | |
| 22 | + blksize = pw_node_blksize(node); | |
| 23 | + | |
| 24 | + osc = (struct osc_n *)pw_node_get_data(node); | |
| 25 | + | |
| 26 | + for (n = 0; n < blksize; n++) { | |
| 27 | + PWFLT out, f, a; | |
| 28 | + f = pw_cable_get(osc->freq, n); | |
| 29 | + a = pw_cable_get(osc->amp, n); | |
| 30 | + | |
| 31 | + sk_osc_freq(&osc->osc, f); | |
| 32 | + sk_osc_amp(&osc->osc, a); | |
| 33 | + out = sk_osc_tick(&osc->osc); | |
| 34 | + | |
| 35 | + pw_cable_set(osc->out, n, out); | |
| 36 | + } | |
| 37 | +} | |
| 38 | + | |
| 39 | +static void destroy(pw_node *node) | |
| 40 | +{ | |
| 41 | + pw_patch *patch; | |
| 42 | + int rc; | |
| 43 | + void *ud; | |
| 44 | + rc = pw_node_get_patch(node, &patch); | |
| 45 | + if (rc != PW_OK) return; | |
| 46 | + pw_node_cables_free(node); | |
| 47 | + ud = pw_node_get_data(node); | |
| 48 | + pw_memory_free(patch, &ud); | |
| 49 | +} | |
| 50 | + | |
| 51 | +int sk_node_osc(sk_core *core) | |
| 52 | +{ | |
| 53 | + pw_patch *patch; | |
| 54 | + pw_node *node; | |
| 55 | + int rc; | |
| 56 | + sk_param freq; | |
| 57 | + sk_param amp; | |
| 58 | + void *ud; | |
| 59 | + struct osc_n *osc; | |
| 60 | + int sr; | |
| 61 | + sk_table *tab; | |
| 62 | + SKFLT iphs; | |
| 63 | + | |
| 64 | + rc = sk_param_get_constant(core, &iphs); | |
| 65 | + SK_ERROR_CHECK(rc); | |
| 66 | + | |
| 67 | + rc = sk_param_get(core, &); | |
| 68 | + SK_ERROR_CHECK(rc); | |
| 69 | + | |
| 70 | + rc = sk_param_get(core, &freq); | |
| 71 | + SK_ERROR_CHECK(rc); | |
| 72 | + | |
| 73 | + rc = sk_core_table_pop(core, &tab); | |
| 74 | + SK_ERROR_CHECK(rc); | |
| 75 | + | |
| 76 | + patch = sk_core_patch(core); | |
| 77 | + | |
| 78 | + rc = pw_memory_alloc(patch, sizeof(struct osc_n), &ud); | |
| 79 | + SK_PW_ERROR_CHECK(rc); | |
| 80 | + osc = (struct osc_n *)ud; | |
| 81 | + | |
| 82 | + sr = pw_patch_srate_get(patch); | |
| 83 | + sk_osc_init(&osc->osc, sr, | |
| 84 | + sk_table_data(tab), | |
| 85 | + sk_table_size(tab), | |
| 86 | + iphs); | |
| 87 | + | |
| 88 | + rc = pw_patch_new_node(patch, &node); | |
| 89 | + SK_PW_ERROR_CHECK(rc); | |
| 90 | + | |
| 91 | + rc = pw_node_cables_alloc(node, 3); | |
| 92 | + SK_PW_ERROR_CHECK(rc); | |
| 93 | + | |
| 94 | + pw_node_set_block(node, 2); | |
| 95 | + | |
| 96 | + pw_node_get_cable(node, 0, &osc->freq); | |
| 97 | + pw_node_get_cable(node, 1, &osc->amp); | |
| 98 | + pw_node_get_cable(node, 2, &osc->out); | |
| 99 | + | |
| 100 | + pw_node_set_data(node, osc); | |
| 101 | + pw_node_set_compute(node, compute); | |
| 102 | + pw_node_set_destroy(node, destroy); | |
| 103 | + | |
| 104 | + sk_param_set(core, node, &freq, 0); | |
| 105 | + sk_param_set(core, node, &, 1); | |
| 106 | + sk_param_out(core, node, 2); | |
| 107 | + return 0; | |
| 108 | +} | |
| @@ -0,0 +1,4 @@ | ||
| 1 | +#ifndef SK_NODE_OSC_H | |
| 2 | +#define SK_NODE_OSC_H | |
| 3 | +int sk_node_osc(sk_core *core); | |
| 4 | +#endif | |