shithub: neindaw

Download patch

ref: 503d29c4e565dcc5c36c1dee563913147dd0e85d
author: Sigrid Haflínudóttir <ftrvxmtrx@gmail.com>
date: Sat Dec 28 13:09:19 EST 2019

trying things out

--- /dev/null
+++ b/.gitignore
@@ -1,0 +1,3 @@
+*.6
+6.*
+*.dsp.c
--- /dev/null
+++ b/README.md
@@ -1,0 +1,6 @@
+# faust9p
+
+Tools to compile [FAUST](https://faust.grame.fr) DSP code to a 9p
+server, provide UI to control DSP, etc.
+
+WIP, nothing to look at yet
--- /dev/null
+++ b/arch.c
@@ -1,0 +1,58 @@
+/*
+Plan 9 C architecture for Faust.  This provides a file system with UI
+elements exported as files and directories.
+*/
+
+#include <u.h>
+#include <libc.h>
+#include "uiglue.h"
+
+#define max(x,y) (((x) > (y)) ? (x) : (y))
+#define min(x,y) (((x) < (y)) ? (x) : (y))
+
+<<includeIntrinsic>>
+<<includeclass>>
+
+#define DSP mydsp
+
+#include "dspf.h"
+
+static DSPf dspf = {
+	.new = newmydsp,
+	.init = instanceInitmydsp,
+	.delete = deletemydsp,
+	.metadata = metadatamydsp,
+	.num_in = getNumInputsmydsp,
+	.num_out = getNumOutputsmydsp,
+	.clear = instanceClearmydsp,
+	.reset_ui = instanceResetUserInterfacemydsp,
+	.build_ui = buildUserInterfacemydsp,
+	.compute = computemydsp,
+};
+
+static void
+usage(char *prog)
+{
+	print("usage: %s [-s SAMPLE_RATE]\n", prog);
+	exits("usage");
+}
+
+void
+main(int argc, char **argv)
+{
+	int sample_rate;
+
+	sample_rate = 44100;
+	ARGBEGIN{
+	case 's':
+		sample_rate = atoi(ARGF());
+		break;
+	default:
+		usage(argv[0]);
+	}ARGEND
+
+	classInitmydsp(sample_rate);
+	build_fs(&dspf);
+
+	exits(nil);
+}
--- /dev/null
+++ b/dspf.h
@@ -1,0 +1,14 @@
+typedef struct {
+	DSP *(*new)(void);
+	void (*init)(DSP *dsp, int sample_rate);
+	void (*delete)(DSP *dsp);
+	void (*metadata)(MetaGlue *glue);
+	int (*num_in)(DSP *dsp);
+	int (*num_out)(DSP *dsp);
+	void (*clear)(DSP *dsp);
+	void (*reset_ui)(DSP *dsp);
+	void (*build_ui)(DSP *dsp, UIGlue *glue);
+	void (*compute)(DSP *dsp, int count, FAUSTFLOAT **in, FAUSTFLOAT **out);
+}DSPf;
+
+void build_fs(void *dspf);
--- /dev/null
+++ b/faust9p.sh
@@ -1,0 +1,4 @@
+#!/bin/sh
+set -e
+
+faust -lang c -a arch.c $@ -o /dev/stdout | sed 's/new\([^(]*\)() /new\1(void) /'
--- /dev/null
+++ b/fs.c
@@ -1,0 +1,46 @@
+#include <u.h>
+#include <libc.h>
+#include "uiglue.h"
+typedef struct DSP DSP;
+#include "dspf.h"
+
+typedef struct {
+	void *metaInterface;
+	void (*declare)(void *metaInterface, const char *key, const char *value);
+}MetaGlue;
+
+static char *meta = nil;
+static int metalen = 0;
+
+static void
+addmeta(void *metaInterface, const char *k, const char *v)
+{
+	int klen, vlen;
+
+	USED(metaInterface);
+
+	if (strchr(k, '/') != nil) /* ignore library-specific meta */ 
+		return;
+
+	klen = strlen(k);
+	vlen = strlen(v);
+	meta = realloc(meta, metalen + klen + 1 + vlen + 2);
+	strcpy(meta+metalen, k);
+	metalen += klen;
+	meta[metalen++] = '\t';
+	strcpy(meta+metalen, v);
+	metalen += vlen;
+	meta[metalen++] = '\n';
+	meta[metalen] = 0;
+}
+
+void
+build_fs(void *dspf)
+{
+	DSPf *f;
+	MetaGlue mg;
+
+	f = dspf;
+	mg.declare = addmeta;
+	f->metadata(&mg);
+}
--- /dev/null
+++ b/gen.sh
@@ -1,0 +1,7 @@
+#!/bin/sh
+set -e
+
+for i in *.dsp; do
+	class=$(grep -o declare.*name.* kick_drum.dsp | head -1 | sed 's/^[^"]*//g;s/[^A-Za-z0-9]//g')
+	./faust9p.sh -cn $class $i > $i.c
+done
--- /dev/null
+++ b/kick_drum.dsp
@@ -1,0 +1,15 @@
+// Simple kick drum
+declare name "Kick Drum";
+declare group "synthesis";
+import("stdfaust.lib");
+
+aFreq = vslider("h:a/[0]frequency", 100, 10, 200, 5);
+aA = vslider("h:a/[1]attack", 0.001, 0.00001, 0.2, 0.001);
+aD = vslider("h:a/[2]delay", 0.01, 0.00001, 1.0, 0.001);
+aR = vslider("h:a/[3]release", 0.001, 0.00001, 1.0, 0.001);
+bA = vslider("h:b/[0]attack", 0.001, 0.00001, 0.2, 0.001);
+bFreq = checkbox("h:control/[1]b enable") * vslider("h:b/[1]frequency", 200, -400, 400, 5);
+bR = vslider("h:b/[2]release", 0.001, 0.00001, 0.2, 0.001);
+gate = button("h:control/[0]gate");
+
+process = os.oscsin(aFreq + bFreq*en.ar(bA, bR, gate)) * en.adsr(aA, aD, 0.000001, aR, gate) <: _, _;
--- /dev/null
+++ b/math.h
@@ -1,0 +1,3 @@
+#define sinf sin
+#define cosf cos
+#define floorf floor
--- /dev/null
+++ b/mkfile
@@ -1,0 +1,11 @@
+</$objtype/mkfile
+
+TARG=kick_drum
+BIN=/$objtype/bin
+OFILES=\
+	fs.$O\
+	kick_drum.dsp.$O\
+
+default:V:	all
+
+</sys/src/cmd/mkone
--- /dev/null
+++ b/uiglue.h
@@ -1,0 +1,24 @@
+#ifndef FAUSTFLOAT
+#define FAUSTFLOAT float
+#endif
+
+typedef struct {
+	void *uiInterface;
+	void (*openTabBox)(void *uiInterface, const char *label);
+	void (*openHorizontalBox) (void *uiInterface, const char *label);
+	void (*openVerticalBox)(void *uiInterface, const char *label);
+	void (*closeBox)(void *uiInterface);
+	void (*addButton)(void *uiInterface, const char *label, FAUSTFLOAT *zone);
+	void (*addCheckButton)(void *uiInterface, const char *label, FAUSTFLOAT *zone);
+	void (*addVerticalSlider)(void *uiInterface, const char *label, FAUSTFLOAT *zone, FAUSTFLOAT init, FAUSTFLOAT min, FAUSTFLOAT max, FAUSTFLOAT step);
+	void (*addHorizontalSlider)(void *uiInterface, const char *label, FAUSTFLOAT *zone, FAUSTFLOAT init, FAUSTFLOAT min, FAUSTFLOAT max, FAUSTFLOAT step);
+	void (*addNumEntry)(void *uiInterface, const char *label, FAUSTFLOAT *zone, FAUSTFLOAT init, FAUSTFLOAT min, FAUSTFLOAT max, FAUSTFLOAT step);
+	void (*addHorizontalBargraph)(void *uiInterface, const char *label, FAUSTFLOAT *zone, FAUSTFLOAT min, FAUSTFLOAT max);
+	void (*addVerticalBargraph)(void *uiInterface, const char *label, FAUSTFLOAT *zone, FAUSTFLOAT min, FAUSTFLOAT max);
+	void (*declare)(void *uiInterface, FAUSTFLOAT *zone, const char *key, const char *value);
+}UIGlue;
+
+typedef struct {
+	void *metaInterface;
+	void (*declare)(void *metaInterface, const char *key, const char *value);
+}MetaGlue;