aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorLudvig Gunne Lindström <ludviggunnelindstrom@gmail.com>2026-07-17 11:42:57 +0200
committerLudvig Gunne Lindström <ludviggunnelindstrom@gmail.com>2026-11-08 14:05:19 +0100
commitfd27bacdd9c97f696938b12d2a437da4e514c26f (patch)
tree2d676bb280b35420a2c105676b0e66fe5b91958d /include
downloadmelisma-archive.tar.gz
Diffstat (limited to 'include')
-rw-r--r--include/melisma.h130
-rw-r--r--include/melisma/ring.h40
2 files changed, 170 insertions, 0 deletions
diff --git a/include/melisma.h b/include/melisma.h
new file mode 100644
index 0000000..11133ec
--- /dev/null
+++ b/include/melisma.h
@@ -0,0 +1,130 @@
+/*
+ * melisma - extensible and scriptable audio engine
+ * Copyright (C) 2026 Ludvig Gunne Lindström
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+#ifndef MELISMA_H_INCLUDED
+#define MELISMA_H_INCLUDED
+
+#include <lua.h>
+#include <stddef.h>
+#include <sys/poll.h>
+
+#define MELISMA_VERSION "0.1.0"
+#define ml_check_version() ml__check_version(MELISMA_VERSION)
+void ml__check_version(const char *s);
+
+/* Lua metatable tags for builtin types */
+#define MELISMA_NODE_TYPENAME "node"
+#define MELISMA_INPUT_CHANNEL_TYPENAME "input channel"
+#define MELISMA_OUTPUT_CHANNEL_TYPENAME "output channel"
+
+/* Structure passed to each nodes processing function */
+struct ml_proc_args
+{
+ /* Implementation specific data */
+ void *userp;
+
+ /* Number of frames to process */
+ size_t nframes;
+
+ /* Number of input buffers */
+ size_t icnt;
+
+ /* Number of output buffers */
+ size_t ocnt;
+
+ /* List of input buffers */
+ float *const *in;
+
+ /* List of output buffers */
+ float **out;
+};
+typedef struct ml_proc_args ml_proc_args;
+
+/* A node in the audio graph */
+typedef struct ml_node ml_node;
+
+/* An input/output channel of a node */
+typedef struct ml_channel ml_channel;
+
+/* Processing function called for each active node */
+typedef void (*ml_proc_fn)(const ml_proc_args*);
+
+/* Handler for pending IO operations */
+typedef void (*ml_io_handler)(int,int,void*);
+
+/* Create a new node */
+ml_node *ml_create_node(ml_proc_fn proc, void *userp);
+
+/* Add a label to a node */
+#ifdef __GNUC__
+__attribute__((format(printf,2,3)))
+#endif
+void ml_label_node(ml_node *node, const char *fmt, ...);
+
+/* Get a pointer to the root node in the audio graph */
+ml_node *ml_get_root_node(void);
+
+/* Get the user data pointer from a node */
+void *ml_get_userp(ml_node *node);
+
+/* Add an input channel to a node */
+ml_channel *ml_add_input(ml_node *node);
+
+/* Add an output channel to a node */
+ml_channel *ml_add_output(ml_node *node);
+
+/* Get a node input channel by index */
+ml_channel *ml_get_input(ml_node *node, size_t i);
+
+/* Get a node output channel by index */
+ml_channel *ml_get_output(ml_node *node, size_t i);
+
+/* Get the number of input channels for a node */
+size_t ml_num_inputs(ml_node *node);
+
+/* Get the number of output channels for a node */
+size_t ml_num_outputs(ml_node *node);
+
+/* Connect two channels */
+void ml_connect(ml_channel *src, ml_channel *dst);
+
+/* Get the current sample rate */
+unsigned long ml_sample_rate(void);
+
+/* Install a new IO handler for the given file descriptor.
+ * Flags are a combination of POLLIN, POLLOUT etc. */
+void ml_add_io_handler(int fd, int flags, ml_io_handler hdl, void *args);
+
+/* Remove a previously installed IO handler */
+void ml_remove_io_handler(int fd);
+
+typedef long ml_event_id;
+typedef struct
+{
+ ml_event_id id;
+ unsigned long seq;
+} ml_event_handle;
+
+/* Schedule an event from a Lua C function, t samples from the end
+ * of the current processing window. */
+ml_event_handle ml_schedule_event(unsigned long t, int fn, int arg);
+
+/* Cancel a scheduled event from a Lua C function. */
+void ml_cancel_event(const ml_event_handle *hdl);
+
+#endif
diff --git a/include/melisma/ring.h b/include/melisma/ring.h
new file mode 100644
index 0000000..d69e993
--- /dev/null
+++ b/include/melisma/ring.h
@@ -0,0 +1,40 @@
+/*
+ * melisma - extensible and scriptable audio engine
+ * Copyright (C) 2026 Ludvig Gunne Lindström
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+#ifndef RING_H
+#define RING_H
+
+#include <stdint.h>
+#include <stdatomic.h>
+
+typedef struct ml_ring ml_ring;
+
+ml_ring *ml_ring_init(size_t len);
+void ml_ring_free(ml_ring *r);
+int ml_ring_empty(ml_ring *r);
+int ml_ring_has_space(ml_ring *r, size_t len);
+int ml_ring_put(ml_ring *r, uint8_t c);
+int ml_ring_get(ml_ring *r, uint8_t *c);
+size_t ml_ring_write(ml_ring *r, const void *ptr, size_t len);
+size_t ml_ring_read(ml_ring *r, void *ptr, size_t len);
+void ml_ring_put_blocking(ml_ring *r, uint8_t c);
+uint8_t ml_ring_get_blocking(ml_ring *r);
+void ml_ring_write_blocking(ml_ring *r, const void *ptr, size_t len);
+void ml_ring_read_blocking(ml_ring *r, void *ptr, size_t len);
+
+#endif