aboutsummaryrefslogtreecommitdiff
path: root/include/guttersynth.h
diff options
context:
space:
mode:
authorRichard <q@1bpm.net>2025-03-08 14:53:52 +0000
committerRichard <q@1bpm.net>2025-03-08 14:53:52 +0000
commitd8baa01ff91521e113260ef5d5cae272e02162e2 (patch)
tree6b118c71c308d29e517bda60bfbd69f7c4f39cbb /include/guttersynth.h
downloadlibguttersynth-d8baa01ff91521e113260ef5d5cae272e02162e2.tar.gz
libguttersynth-d8baa01ff91521e113260ef5d5cae272e02162e2.tar.bz2
libguttersynth-d8baa01ff91521e113260ef5d5cae272e02162e2.zip
initial
Diffstat (limited to 'include/guttersynth.h')
-rw-r--r--include/guttersynth.h139
1 files changed, 139 insertions, 0 deletions
diff --git a/include/guttersynth.h b/include/guttersynth.h
new file mode 100644
index 0000000..88d874a
--- /dev/null
+++ b/include/guttersynth.h
@@ -0,0 +1,139 @@
+/*
+ * guttersynth.h
+ * Part of libguttersynth
+ *
+ * Copyright Tom Mudd 2019, Richard Knight 2021, 2022
+ *
+ * Ported to C by Richard Knight
+ * from https://github.com/tommmmudd/guttersynthesis by Tom Mudd
+ *
+ */
+
+#ifndef GUTTER_H
+#define GUTTER_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+
+// support for either single or double precision
+#ifndef FLT
+
+#ifdef USE_FLOAT
+#define FLT float
+#else
+#define FLT double
+#endif
+
+#endif
+
+
+// internal/private dcblock state variables
+typedef struct dcblock_session_ {
+ FLT xm1;
+ FLT ym1;
+ FLT r;
+} dcblock_session;
+
+// internal/private state variables
+typedef struct gutter_internal_ {
+ void (*dealloc)(void*);
+ int samplerate;
+ FLT finalY;
+ FLT duffX;
+ FLT duffY;
+ FLT dx;
+ FLT dy;
+ FLT t;
+ FLT* prevX1;
+ FLT* prevX2;
+ FLT* prevY1;
+ FLT* prevY2;
+ FLT* V;
+ FLT* K;
+ FLT* norm;
+ FLT* a0;
+ FLT* a1;
+ FLT* a2;
+ FLT* b1;
+ FLT* b2;
+ FLT* y;
+ dcblock_session dcblock;
+} gutter_internal;
+
+// state with public variables
+typedef struct gutter_state_ {
+ int bankCount;
+ int filterCount;
+
+ FLT gamma;
+ FLT omega;
+ FLT c;
+ FLT dt;
+ FLT singleGain;
+ FLT* gains;
+ FLT* filterFreqs;
+ FLT* Q;
+ int enableAudioInput;
+ int filtersOn;
+ int smoothing;
+ int distortionMethod;
+ gutter_internal gi;
+} gutter_state;
+
+
+// synthesise single sample with input
+FLT gutter_process_input(gutter_state* s, FLT audioInput);
+
+// synthesise single sample
+FLT gutter_process(gutter_state* s);
+
+// synthesise specified number of samples with input
+void gutter_process_input_samples(gutter_state* s, FLT* audioInput, FLT* audioOutput, int nsamps);
+
+// synthesise specified number of samples
+void gutter_process_samples(gutter_state* s, FLT* audioOutput, int nsamps);
+
+// reset state
+void gutter_reset(gutter_state* s);
+
+// clean up memory etc
+void gutter_cleanup(gutter_state* s);
+
+// calculate filter coefficients
+void gutter_calccoeffs(gutter_state* s);
+
+// initialise with custom memory allocator and deallocator
+gutter_state* gutter_init_ca(int bankCount, int filterCount, int samplerate,
+ void* (*allocator)(size_t), void (*deallocator)(void*));
+
+// initialise with standard malloc and free
+gutter_state* gutter_init(int bankCount, int filterCount, int samplerate);
+
+// randomise filters
+void gutter_randomisefilters(gutter_state* s);
+
+// set distortion method
+int gutter_setdistortionmethod(gutter_state* s, int method);
+
+// set frequency of a filter in a bank
+int gutter_setfreq(gutter_state*, int bank, int filter, FLT value);
+
+// set Q of a filter in a bank
+int gutter_setq(gutter_state* s, int bank, int filter, FLT value);
+
+// set gain of a filter in a bank
+int gutter_setgain(gutter_state* s, int bank, int filter, FLT value);
+
+// set Q of all filters
+void gutter_setqall(gutter_state* s, FLT value);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* GUTTER_H */
+