summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorXANTRONIX Development2022-01-31 13:03:45 -0500
committerXANTRONIX Development2022-01-31 13:03:45 -0500
commit300f39e19369d44d3217bf1122d1feeaef4a0f5d (patch)
tree20beb967288817c26d976c8cbe462847aa63b859 /src
parentd8e3d3fc0fb6e4f88f3e3c789575e38a74a01299 (diff)
downloadxas-300f39e19369d44d3217bf1122d1feeaef4a0f5d.tar.gz
xas-300f39e19369d44d3217bf1122d1feeaef4a0f5d.tar.bz2
xas-300f39e19369d44d3217bf1122d1feeaef4a0f5d.zip
I really don't like the fact that this compiles
Diffstat (limited to 'src')
-rw-r--r--src/Makefile4
-rw-r--r--src/synth.c46
2 files changed, 48 insertions, 2 deletions
diff --git a/src/Makefile b/src/Makefile
index d638619..a8853be 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -7,9 +7,9 @@ CC = $(CROSS)cc
CFLAGS += -I$(INCLUDE_PATH)
LDFLAGS +=
-HEADERS = audio.h mixer.h riff.h
+HEADERS = audio.h mixer.h synth.h riff.h
-OBJS = audio.o mixer.o riff.o
+OBJS = audio.o mixer.o synth.o riff.o
VERSION_MAJOR = 0
VERSION_MINOR = 0.1
diff --git a/src/synth.c b/src/synth.c
new file mode 100644
index 0000000..96c6d83
--- /dev/null
+++ b/src/synth.c
@@ -0,0 +1,46 @@
+#include <stdlib.h>
+
+#include <xas/synth.h>
+
+xas_synth *xas_synth_new(size_t sample_rate,
+ xas_synth_callback_sample sample,
+ xas_synth_callback_destroy destroy,
+ void *ctx) {
+ xas_synth *synth;
+
+ if ((synth = malloc(sizeof(*synth))) == NULL) {
+ goto error_malloc_synth;
+ }
+
+ synth->sample_rate = sample_rate;
+ synth->sample = sample;
+ synth->destroy = destroy;
+ synth->ctx = ctx;
+
+ return synth;
+
+error_malloc_synth:
+ return NULL;
+}
+
+void xas_synth_destroy(xas_synth *synth) {
+ if (synth->destroy) {
+ synth->destroy(synth, synth->ctx);
+ }
+}
+
+int16_t xas_synth_sample(xas_synth *synth) {
+ return synth->sample(synth, synth->ctx);
+}
+
+ssize_t xas_synth_fill(xas_synth *synth,
+ int16_t *samples,
+ size_t count) {
+ size_t i;
+
+ for (i=0; i<count; i++) {
+ samples[i] = synth->sample(synth, synth->ctx);
+ }
+
+ return count;
+}