diff --git a/configure.ac b/configure.ac
index 2adc6af..ff0d9cb 100644
--- a/configure.ac
+++ b/configure.ac
@@ -95,6 +95,8 @@ AM_CONDITIONAL([ENABLE_PORTAUDIO], [test x"$enable_portaudio" = x"true"])
PKG_CHECK_MODULES([GLFW3], [glfw3],
[enable_glfw3=true],
[enable_glfw3=false])
+AC_SUBST([GLFW3_CFLAGS])
+AC_SUBST([GLFW3_LIBS])
AM_CONDITIONAL([ENABLE_GLFW3], [test x"$enable_glfw3" = x"true"])
LIBS=
@@ -124,8 +126,12 @@ AC_CONFIG_FILES([Makefile])
AC_CONFIG_FILES([cli/Makefile])
AC_CONFIG_FILES([gtk/Makefile])
AC_CONFIG_FILES([lib/Makefile])
+AC_CONFIG_FILES([lib/dynamic/Makefile])
+AC_CONFIG_FILES([lib/glfw3/Makefile])
+AC_CONFIG_FILES([lib/portaudio/Makefile])
AC_CONFIG_FILES([lib/signal/Makefile])
AC_CONFIG_FILES([lib/sndio/Makefile])
+AC_CONFIG_FILES([lib/synth/Makefile])
AC_CONFIG_FILES([librtbuf/Makefile])
AC_OUTPUT
diff --git a/lib/Makefile.am b/lib/Makefile.am
index 2b9139a..4fbcc6a 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -5,7 +5,7 @@ rtbuf_libdir = $(libdir)/rtbuf
rtbuf_lib_LTLIBRARIES =
lib_LTLIBRARIES =
-SUBDIRS = . signal sndio # dynamic glfw3 portaudio reverb sndio synth
+SUBDIRS = . signal dynamic glfw3 portaudio sndio synth # reverb
# music
@@ -14,10 +14,13 @@ music_type: music_type.c include/rtbuf/music.h
include/rtbuf/music_type.h: music_type
./music_type > include/rtbuf/music_type.h
CLEANFILES += music_type include/rtbuf/music_type.h
+music.lo: include/rtbuf/music_type.h
-rtbuf_lib_LTLIBRARIES += music.la
-music_la_LIBADD = ${MUSIC_LIBS} ../librtbuf/librtbuf.la
-music_la_LDFLAGS = -no-undefined -module
+lib_LTLIBRARIES += librtbuf_music.la
+librtbuf_music_la_LIBADD = ${MUSIC_LIBS} ../librtbuf/librtbuf.la
+librtbuf_music_la_LDFLAGS = -no-undefined -module
+librtbuf_music_la_SOURCES = \
+ music.c
rtbuf_include_HEADERS += \
include/rtbuf/music.h \
@@ -31,10 +34,9 @@ portaudio_type: portaudio_type.c include/rtbuf/portaudio.h
include/rtbuf/portaudio_type.h: portaudio_type
./portaudio_type > include/rtbuf/portaudio_type.h
CLEANFILES += portaudio_type include/rtbuf/portaudio_type.h
-portaudio.lo: include/rtbuf/portaudio_type.h
+all-local: include/rtbuf/portaudio_type.h
endif # ENABLE_PORTAUDIO
-
# reverb
reverb_type: reverb_type.c include/rtbuf/reverb.h
@@ -81,4 +83,4 @@ synth_type: synth_type.c include/rtbuf/synth.h include/rtbuf/music_type.h includ
include/rtbuf/synth_type.h: synth_type
./synth_type > include/rtbuf/synth_type.h
CLEANFILES += synth_type include/rtbuf/synth_type.h
-synth.lo: include/rtbuf/synth_type.h
+all-local: include/rtbuf/synth_type.h
diff --git a/lib/dynamic.c b/lib/dynamic.c
deleted file mode 100644
index aa986b1..0000000
--- a/lib/dynamic.c
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Copyright 2018 Thomas de Grivel <thoxdg@gmail.com> +33614550127
- *
- * Permission to use, copy, modify, and distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
- * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- */
-
-#include "rtbuf.h"
-#include "rtbuf_lib.h"
-#include "rtbuf_signal.h"
-#include "rtbuf_signal_type.h"
-#include "rtbuf_dynamic.h"
-
-s_rtbuf_lib_proc_in g_rtbuf_dynamic_limiter_in[] = {
- { "signal" , RTBUF_SIGNAL_TYPE, 0.0, -1.0, 1.0 },
- { "gain" , RTBUF_SIGNAL_TYPE, 1.0, 0.0, 1.0 },
- { "treshold", RTBUF_SIGNAL_TYPE, 0.9, 0.0, 1.0 },
- { "attack" , RTBUF_SIGNAL_TYPE, 0.1, 0.0, 1.0 },
- { "release" , RTBUF_SIGNAL_TYPE, 1.0, 0.0, 1.0 },
- { 0, 0, 0.0, 0.0, 0.0 } };
-
-s_rtbuf_lib_proc_out g_rtbuf_dynamic_limiter_out[] = {
- { "signal", RTBUF_SIGNAL_TYPE },
- { "ratio" , RTBUF_SIGNAL_SAMPLE_TYPE },
- { 0, 0 } };
-
-const char *rtbuf_lib_name = "dynamic";
-unsigned long rtbuf_lib_ver = RTBUF_LIB_VER;
-s_rtbuf_lib_proc rtbuf_lib_proc[] = {
- { "limiter", rtbuf_dynamic_limiter, rtbuf_dynamic_limiter_start, 0,
- g_rtbuf_dynamic_limiter_in, g_rtbuf_dynamic_limiter_out },
- { 0, 0, 0, 0, 0, 0 } };
diff --git a/lib/dynamic/Makefile.am b/lib/dynamic/Makefile.am
new file mode 100644
index 0000000..a2753fc
--- /dev/null
+++ b/lib/dynamic/Makefile.am
@@ -0,0 +1,9 @@
+CLEANFILES =
+rtbuf_includedir = $(includedir)/rtbuf/dynamic
+rtbuf_include_HEADERS =
+rtbuf_libdir = $(libdir)/rtbuf/dynamic
+rtbuf_lib_LTLIBRARIES =
+
+rtbuf_lib_LTLIBRARIES += limiter.la
+limiter_la_LDFLAGS = -no-undefined -module -shared
+limiter_la_LIBADD = ../librtbuf_signal.la
diff --git a/lib/dynamic/limiter.c b/lib/dynamic/limiter.c
index 82c5943..f890345 100644
--- a/lib/dynamic/limiter.c
+++ b/lib/dynamic/limiter.c
@@ -16,8 +16,24 @@
*/
#include <math.h>
-#include "rtbuf.h"
-#include "rtbuf_dynamic.h"
+#include <rtbuf/rtbuf.h>
+#include <rtbuf/lib.h>
+#include <rtbuf/signal.h>
+#include <rtbuf/signal_type.h>
+#include <rtbuf/dynamic.h>
+
+s_rtbuf_lib_proc_in rtbuf_dynamic_limiter_in[] = {
+ { "signal" , RTBUF_SIGNAL_TYPE, 0.0, -1.0, 1.0 },
+ { "gain" , RTBUF_SIGNAL_TYPE, 1.0, 0.0, 1.0 },
+ { "treshold", RTBUF_SIGNAL_TYPE, 0.9, 0.0, 1.0 },
+ { "attack" , RTBUF_SIGNAL_TYPE, 0.1, 0.0, 1.0 },
+ { "release" , RTBUF_SIGNAL_TYPE, 1.0, 0.0, 1.0 },
+ { 0, 0, 0.0, 0.0, 0.0 }};
+
+s_rtbuf_lib_proc_out rtbuf_dynamic_limiter_out[] = {
+ { "signal", RTBUF_SIGNAL_TYPE },
+ { "ratio" , RTBUF_SIGNAL_SAMPLE_TYPE },
+ { 0, 0 }};
int rtbuf_dynamic_limiter (s_rtbuf *rtb)
{
@@ -74,3 +90,13 @@ int rtbuf_dynamic_limiter_start (s_rtbuf *rtb)
data->ratio = 1.0;
return 0;
}
+
+s_rtbuf_lib_proc rtbuf_lib_proc =
+ { "limiter",
+ rtbuf_dynamic_limiter,
+ rtbuf_dynamic_limiter_start,
+ 0,
+ rtbuf_dynamic_limiter_in,
+ rtbuf_dynamic_limiter_out };
+
+unsigned long rtbuf_lib_ver = RTBUF_LIB_VER;
diff --git a/lib/glfw3/Makefile.am b/lib/glfw3/Makefile.am
new file mode 100644
index 0000000..7398016
--- /dev/null
+++ b/lib/glfw3/Makefile.am
@@ -0,0 +1,15 @@
+CLEANFILES =
+rtbuf_includedir = $(includedir)/rtbuf/glfw3
+rtbuf_include_HEADERS =
+rtbuf_libdir = $(libdir)/rtbuf/glfw3
+rtbuf_lib_LTLIBRARIES =
+
+rtbuf_lib_LTLIBRARIES += keyboard.la
+keyboard_la_CPPFLAGS = ${GLFW3_CFLAGS}
+keyboard_la_LDFLAGS = -no-undefined -module -shared
+keyboard_la_LIBADD = ${GLFW3_LIBS} ../librtbuf_music.la ../librtbuf_signal.la
+
+rtbuf_lib_LTLIBRARIES += oscilloscope.la
+oscilloscope_la_CPPFLAGS = ${GLFW3_CFLAGS}
+oscilloscope_la_LDFLAGS = -no-undefined -module -shared
+oscilloscope_la_LIBADD = ${GLFW3_LIBS} ../librtbuf_signal.la
diff --git a/lib/glfw3/keyboard.c b/lib/glfw3/keyboard.c
new file mode 100644
index 0000000..0dbc65c
--- /dev/null
+++ b/lib/glfw3/keyboard.c
@@ -0,0 +1,307 @@
+/*
+ * Copyright 2018 Thomas de Grivel <thoxdg@gmail.com> +33614550127
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <math.h>
+#include <stdio.h>
+#include <string.h>
+#include <strings.h>
+#include <rtbuf/rtbuf.h>
+#include <rtbuf/lib.h>
+#include <rtbuf/signal.h>
+#include <rtbuf/signal_type.h>
+#include <rtbuf/music.h>
+#include <rtbuf/music_type.h>
+#include <rtbuf/glfw3.h>
+
+float ceilf (float x);
+
+#define RTBUF_GLFW3_KEYBOARD_WIDTH 512
+#define RTBUF_GLFW3_KEYBOARD_HEIGHT 256
+
+s_rtbuf_lib_proc_out rtbuf_glfw3_keyboard_out[] = {
+ RTBUF_MUSIC_NOTES_OUT("note"),
+ { "window", "void*" },
+ { "octave", "unsigned int" },
+ { 0, 0 } };
+
+int rtbuf_lib_init (s_rtbuf_lib *lib)
+{
+ (void) lib;
+ rtbuf_music_init();
+ glfwInit();
+ return 0;
+}
+
+double scancode_frequency (int scancode, unsigned int octave)
+{
+ int note = -1;
+ double freq = 0.0;
+ printf("scancode %i\n", scancode);
+ switch (scancode) {
+ case 52: note = 0; break; /* C */
+ case 39: note = 1; break;
+ case 53: note = 2; break; /* D */
+ case 40: note = 3; break;
+ case 54: note = 4; break; /* E */
+ case 55: note = 5; break; /* F */
+ case 42: note = 6; break;
+ case 56: note = 7; break; /* G */
+ case 43: note = 8; break;
+ case 57: note = 9; break; /* A */
+ case 44: note = 10; break;
+ case 58: note = 11; break; /* B */
+ case 59: /* C */
+ case 24: note = 12; break;
+ case 46:
+ case 11: note = 13; break;
+ case 60: /* D */
+ case 25: note = 14; break;
+ case 47:
+ case 12: note = 15; break;
+ case 61: /* E */
+ case 26: note = 16; break;
+ case 27: note = 17; break; /* F */
+ case 14: note = 18; break;
+ case 28: note = 19; break; /* G */
+ case 15: note = 20; break;
+ case 29: note = 21; break; /* A */
+ case 16: note = 22; break;
+ case 30: note = 23; break; /* B */
+ case 31: note = 24; break; /* C */
+ case 18: note = 25; break;
+ case 32: note = 26; break; /* D */
+ case 19: note = 27; break;
+ case 33: note = 28; break; /* E */
+ case 34: note = 29; break; /* F */
+ case 21: note = 30; break;
+ case 35: note = 31; break; /* G */
+ }
+ if (note >= 0)
+ freq = rtbuf_music_note_frequency(octave, note);
+ return freq;
+}
+
+static int find_note (s_rtbuf_music_notes *notes, double freq)
+{
+ unsigned int i = 0;
+ unsigned int n = notes->note_n;
+ while (i < RTBUF_MUSIC_NOTE_MAX && n > 0) {
+ s_rtbuf_music_note *note = ¬es->note[i];
+ if (note->velocity > 0.0 && note->start >= 0.0 && note->stop < 0.0) {
+ if (freq == notes->note[i].freq)
+ return i;
+ n--;
+ }
+ i++;
+ }
+ return -1;
+}
+
+void rtbuf_glfw3_keyboard_key (GLFWwindow *w, int key,
+ int scancode, int action,
+ int mods)
+{
+ int i;
+ double freq;
+ s_rtbuf_music_note *note;
+ s_rtbuf *rtb = (s_rtbuf*) glfwGetWindowUserPointer(w);
+ s_rtbuf_glfw3_keyboard_data *data;
+ s_rtbuf_music_notes *notes;
+ data = (s_rtbuf_glfw3_keyboard_data*) rtb->data;
+ notes = &data->notes;
+ (void) key;
+ (void) mods;
+ switch (action) {
+ case GLFW_RELEASE:
+ freq = scancode_frequency(scancode, data->octave);
+ if ((i = find_note(notes, freq)) >= 0)
+ notes->note[i].stop = 0.0;
+ break;
+ case GLFW_PRESS:
+ freq = scancode_frequency(scancode, data->octave);
+ if ((i = rtbuf_music_notes_new(notes, 1.0)) < 0)
+ break;
+ note = ¬es->note[i];
+ note->freq = freq;
+ note->start = 0.0;
+ note->stop = -1.0;
+ break;
+ case GLFW_REPEAT:
+ break;
+ }
+}
+
+void rtbuf_glfw3_keyboard_size (GLFWwindow *w, int width,
+ int height)
+{
+ (void) w;
+ glViewport(0, 0, width, height);
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+ glOrtho(0.0f, 1.0f, 0.0f, 1.0f, 1.0f, -1.0f);
+ glMatrixMode(GL_MODELVIEW);
+ glLoadIdentity();
+}
+
+static
+void rtbuf_glfw3_keyboard_draw_panel (float y1, float y2)
+{
+ glColor3f(0.5f, 0.5f, 0.5f);
+ glBegin(GL_QUAD_STRIP);
+ glVertex2f(0.0f, y1);
+ glVertex2f(0.0f, y2);
+ glVertex2f(1.0f, y1);
+ glVertex2f(1.0f, y2);
+ glEnd();
+}
+
+static
+void rtbuf_glfw3_keyboard_draw_white (unsigned int i, float n,
+ float y1, float y2)
+{
+ float x = (float) i / n;
+ glBegin(GL_LINE_STRIP);
+ glVertex2f(x, y1);
+ glVertex2f(x, y2);
+ i++;
+ x = (float) i / n;
+ glVertex2f(x, y2);
+ glVertex2f(x, y1);
+ glEnd();
+}
+
+static
+void rtbuf_glfw3_keyboard_draw_black (unsigned int i, float n,
+ float y1, float y2)
+{
+ float x1 = (i - 1.0f / 3.0f) / n;
+ float x2 = (i + 1.0f / 3.0f) / n;
+ glBegin(GL_QUAD_STRIP);
+ glVertex2f(x1, y1);
+ glVertex2f(x1, y2);
+ glVertex2f(x2, y1);
+ glVertex2f(x2, y2);
+ glEnd();
+}
+
+void rtbuf_glfw3_keyboard_draw (GLFWwindow *w)
+{
+ float y_buttons = 0.75f;
+ float y_black = 0.36f;
+ unsigned int notes = 32;
+ float n = ceilf((notes + 1) * 7 / 12);
+ unsigned int i = 0;
+ unsigned int j = 0;
+ glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
+ glClear(GL_COLOR_BUFFER_BIT);
+ rtbuf_glfw3_keyboard_draw_panel(1.0f, y_buttons);
+ glColor3f(0.0f, 0.0f, 0.0f);
+ while (i < notes) {
+ int k = i % 12;
+ if (k == 1 || k == 3 || k == 6 || k == 8 || k == 10)
+ rtbuf_glfw3_keyboard_draw_black(j, n, y_buttons, y_black);
+ else
+ rtbuf_glfw3_keyboard_draw_white(j++, n, y_buttons, 0.0f);
+ i++;
+ }
+ glfwSwapBuffers(w);
+}
+
+void rtbuf_glfw3_keyboard_close (GLFWwindow *window)
+{
+ s_rtbuf *rtb = (s_rtbuf*) glfwGetWindowUserPointer(window);
+ s_rtbuf_glfw3_keyboard_data* data = (s_rtbuf_glfw3_keyboard_data*)
+ rtb->data;
+ glfwDestroyWindow(window);
+ data->window = 0;
+}
+
+GLFWwindow * rtbuf_glfw3_keyboard_window (s_rtbuf *rtb)
+{
+ GLFWwindow *window = glfwCreateWindow(RTBUF_GLFW3_KEYBOARD_WIDTH,
+ RTBUF_GLFW3_KEYBOARD_HEIGHT,
+ "rtbuf_glfw3_keyboard",
+ NULL, NULL);
+ if (!window) {
+ rtbuf_err("glfw3_keyboard: glfwCreateWindow failed");
+ return 0;
+ }
+ glfwMakeContextCurrent(window);
+ glfwSetWindowUserPointer(window, rtb);
+ glfwSetKeyCallback(window, rtbuf_glfw3_keyboard_key);
+ glfwSetWindowCloseCallback(window, rtbuf_glfw3_keyboard_close);
+ glfwSetWindowSizeCallback(window, rtbuf_glfw3_keyboard_size);
+ glfwSetWindowRefreshCallback(window,
+ rtbuf_glfw3_keyboard_draw);
+ glfwShowWindow(window);
+ rtbuf_glfw3_keyboard_size(window, RTBUF_GLFW3_KEYBOARD_WIDTH,
+ RTBUF_GLFW3_KEYBOARD_HEIGHT);
+ return window;
+}
+
+int rtbuf_glfw3_keyboard_start (s_rtbuf *rtb)
+{
+ s_rtbuf_glfw3_keyboard_data *data;
+ assert(rtb->proc->out_bytes == sizeof(*data));
+ data = (s_rtbuf_glfw3_keyboard_data*) rtb->data;
+ if (!data->window &&
+ !(data->window = rtbuf_glfw3_keyboard_window(rtb)))
+ return -1;
+ data->octave = 3;
+ return 0;
+}
+
+int rtbuf_glfw3_keyboard_stop (s_rtbuf *rtb)
+{
+ s_rtbuf_glfw3_keyboard_data *data;
+ data = (s_rtbuf_glfw3_keyboard_data*) rtb->data;
+ rtbuf_music_notes_delete_all(&data->notes);
+ return 0;
+}
+
+int rtbuf_glfw3_keyboard (s_rtbuf *rtb)
+{
+ s_rtbuf_glfw3_keyboard_data *data;
+ unsigned int i = 0;
+ unsigned int n;
+ data = (s_rtbuf_glfw3_keyboard_data*) rtb->data;
+ if (!data->window)
+ return -1;
+ n = data->notes.note_n;
+ while (i < RTBUF_MUSIC_NOTE_MAX && n > 0) {
+ s_rtbuf_music_note *note = &data->notes.note[i];
+ if (note->velocity > 0.0) {
+ assert(note->start >= 0.0);
+ rtbuf_music_note_dt(note, RTBUF_SIGNAL_DT);
+ if (note->stop > RTBUF_MUSIC_RELEASE_MAX)
+ rtbuf_music_notes_delete(&data->notes, i);
+ n--;
+ }
+ i++;
+ }
+ glfwPollEvents();
+ return 0;
+}
+
+s_rtbuf_lib_proc rtbuf_lib_proc =
+ { "keyboard",
+ rtbuf_glfw3_keyboard,
+ rtbuf_glfw3_keyboard_start,
+ rtbuf_glfw3_keyboard_stop,
+ 0,
+ rtbuf_glfw3_keyboard_out };
+
+unsigned long rtbuf_lib_ver = RTBUF_LIB_VER;
diff --git a/lib/glfw3/oscilloscope.c b/lib/glfw3/oscilloscope.c
new file mode 100644
index 0000000..555e48f
--- /dev/null
+++ b/lib/glfw3/oscilloscope.c
@@ -0,0 +1,131 @@
+/*
+ * Copyright 2018 Thomas de Grivel <thoxdg@gmail.com> +33614550127
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <rtbuf/rtbuf.h>
+#include <rtbuf/lib.h>
+#include <rtbuf/signal.h>
+#include <rtbuf/signal_type.h>
+#include <rtbuf/music.h>
+#include <rtbuf/music_type.h>
+#include <rtbuf/glfw3.h>
+
+s_rtbuf_lib_proc_in rtbuf_glfw3_oscilloscope_in[] = {
+ { "black", RTBUF_SIGNAL_TYPE, 0.0, -1.0, 1.0 },
+ { "red" , RTBUF_SIGNAL_TYPE, 0.0, -1.0, 1.0 },
+ { "green", RTBUF_SIGNAL_TYPE, 0.0, -1.0, 1.0 },
+ { "blue" , RTBUF_SIGNAL_TYPE, 0.0, -1.0, 1.0 },
+ { 0, 0, 0.0, 0.0, 0.0 } };
+
+s_rtbuf_lib_proc_out rtbuf_glfw3_oscilloscope_out[] = {
+ { "window", "void*" },
+ { 0, 0 } };
+
+int rtbuf_lib_init (s_rtbuf_lib *lib)
+{
+ (void) lib;
+ glfwInit();
+ return 0;
+}
+
+void rtbuf_glfw3_oscilloscope_size (GLFWwindow *w, int width,
+ int height)
+{
+ (void) w;
+ glViewport(0, 0, width, height);
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+ glOrtho(0.0f, 1.0f, 0.0f, 1.0f, 1.0f, -1.0f);
+ glMatrixMode(GL_MODELVIEW);
+ glLoadIdentity();
+}
+
+void rtbuf_glfw3_oscilloscope_draw (GLFWwindow *window)
+{
+ s_rtbuf *rtb = (s_rtbuf*) glfwGetWindowUserPointer(window);
+ s_rtbuf_signal_fun in[4];
+ const float color[4][3] = { { 0.0f, 0.0f, 0.0f },
+ { 1.0f, 0.0f, 0.0f },
+ { 0.0f, 1.0f, 0.0f },
+ { 0.0f, 0.0f, 1.0f } };
+ unsigned int i = 0;
+ unsigned int j;
+ assert(rtb);
+ for (j = 0; j < 4; j++)
+ rtbuf_signal_fun(rtb, j, &in[j]);
+ glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
+ glClear(GL_COLOR_BUFFER_BIT);
+ for (j = 0; j < 4; j++) {
+ glColor3f(color[j][0], color[j][1], color[j][2]);
+ glBegin(GL_LINE_STRIP);
+ for (i = 0; i < RTBUF_SIGNAL_SAMPLES; i++) {
+ float x = (double) i / RTBUF_SIGNAL_SAMPLES;
+ float s = in[j].sample_fun(in[j].signal, i);
+ glVertex2f(x, s / 4.0f + 0.5f);
+ }
+ glEnd();
+ }
+ glfwSwapBuffers(window);
+}
+
+GLFWwindow * rtbuf_glfw3_oscilloscope_window (s_rtbuf *rtb)
+{
+ GLFWwindow *window = glfwCreateWindow(512, 512,
+ "rtbuf_glfw3_oscilloscope",
+ NULL, NULL);
+ if (!window) {
+ rtbuf_err("glfw3_oscilloscope: glfwCreateWindow failed");
+ return 0;
+ }
+ glfwMakeContextCurrent(window);
+ glfwSetWindowUserPointer(window, rtb);
+ glfwSetWindowSizeCallback(window, rtbuf_glfw3_oscilloscope_size);
+ glfwSetWindowRefreshCallback(window, rtbuf_glfw3_oscilloscope_draw);
+ glfwShowWindow(window);
+ return window;
+}
+
+int rtbuf_glfw3_oscilloscope_start (s_rtbuf *rtb)
+{
+ s_rtbuf_glfw3_oscilloscope_data *data;
+ assert(rtb->proc->out_bytes == sizeof(*data));
+ data = (s_rtbuf_glfw3_oscilloscope_data*) rtb->data;
+ if (!data->window &&
+ !(data->window = rtbuf_glfw3_oscilloscope_window(rtb)))
+ return -1;
+ return 0;
+}
+
+int rtbuf_glfw3_oscilloscope (s_rtbuf *rtb)
+{
+ s_rtbuf_glfw3_oscilloscope_data *data;
+ assert(rtb);
+ assert(rtb->data);
+ assert(rtb->proc);
+ data = (s_rtbuf_glfw3_oscilloscope_data*) rtb->data;
+ rtbuf_glfw3_oscilloscope_draw(data->window);
+ glfwPollEvents();
+ return 0;
+}
+
+s_rtbuf_lib_proc rtbuf_lib_proc =
+ { "oscilloscope",
+ rtbuf_glfw3_oscilloscope,
+ rtbuf_glfw3_oscilloscope_start,
+ 0,
+ rtbuf_glfw3_oscilloscope_in,
+ rtbuf_glfw3_oscilloscope_out };
+
+unsigned long rtbuf_lib_ver = RTBUF_LIB_VER;
diff --git a/lib/glfw3/rtbuf_glfw3.c b/lib/glfw3/rtbuf_glfw3.c
deleted file mode 100644
index 6470431..0000000
--- a/lib/glfw3/rtbuf_glfw3.c
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * Copyright 2018 Thomas de Grivel <thoxdg@gmail.com> +33614550127
- *
- * Permission to use, copy, modify, and distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
- * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- */
-
-#include "rtbuf.h"
-#include "rtbuf_lib.h"
-#include "rtbuf_signal.h"
-#include "rtbuf_signal_type.h"
-#include "rtbuf_music.h"
-#include "rtbuf_music_type.h"
-#include "rtbuf_glfw3.h"
-
-s_rtbuf_lib_proc_out g_rtbuf_glfw3_keyboard_out[] = {
- RTBUF_MUSIC_NOTES_OUT("note"),
- { "window", "void*" },
- { "octave", "unsigned int" },
- { 0, 0 } };
-
-s_rtbuf_lib_proc_in g_rtbuf_glfw3_oscilloscope_in[] = {
- { "black", RTBUF_SIGNAL_TYPE, 0.0, -1.0, 1.0 },
- { "red" , RTBUF_SIGNAL_TYPE, 0.0, -1.0, 1.0 },
- { "green", RTBUF_SIGNAL_TYPE, 0.0, -1.0, 1.0 },
- { "blue" , RTBUF_SIGNAL_TYPE, 0.0, -1.0, 1.0 },
- { 0, 0, 0.0, 0.0, 0.0 } };
-
-s_rtbuf_lib_proc_out g_rtbuf_glfw3_oscilloscope_out[] = {
- { "window", "void*" },
- { 0, 0 } };
-
-const char *rtbuf_lib_name = "glfw3";
-unsigned long rtbuf_lib_ver = RTBUF_LIB_VER;
-s_rtbuf_lib_proc rtbuf_lib_proc[] = {
- { "keyboard", rtbuf_glfw3_keyboard, rtbuf_glfw3_keyboard_start,
- rtbuf_glfw3_keyboard_stop, 0, g_rtbuf_glfw3_keyboard_out },
- { "oscilloscope", rtbuf_glfw3_oscilloscope,
- rtbuf_glfw3_oscilloscope_start, 0, g_rtbuf_glfw3_oscilloscope_in,
- g_rtbuf_glfw3_oscilloscope_out },
- { 0, 0, 0, 0, 0, 0 } };
-
-int rtbuf_lib_init (s_rtbuf_lib *lib)
-{
- (void) lib;
- rtbuf_music_init();
- glfwInit();
- return 0;
-}
diff --git a/lib/glfw3/rtbuf_glfw3.h b/lib/glfw3/rtbuf_glfw3.h
deleted file mode 100644
index 1d89890..0000000
--- a/lib/glfw3/rtbuf_glfw3.h
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * Copyright 2018 Thomas de Grivel <thoxdg@gmail.com> +33614550127
- *
- * Permission to use, copy, modify, and distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
- * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- */
-#ifndef RTBUF_GLFW3_H
-#define RTBUF_GLFW3_H
-
-#include <GLFW/glfw3.h>
-#include "rtbuf.h"
-#include "rtbuf_music.h"
-
-#pragma pack(push,1)
-typedef struct rtbuf_glfw3_keyboard_data {
- s_rtbuf_music_notes notes;
- GLFWwindow *window;
- unsigned int octave;
-} s_rtbuf_glfw3_keyboard_data;
-#pragma pack(pop)
-
-int rtbuf_glfw3_keyboard (s_rtbuf *rtb);
-int rtbuf_glfw3_keyboard_start (s_rtbuf *rtb);
-int rtbuf_glfw3_keyboard_stop (s_rtbuf *rtb);
-
-enum {
- RTBUF_GLFW3_OSCILLOSCOPE_IN_BLACK,
- RTBUF_GLFW3_OSCILLOSCOPE_IN_RED,
- RTBUF_GLFW3_OSCILLOSCOPE_IN_GREEN,
- RTBUF_GLFW3_OSCILLOSCOPE_IN_BLUE,
- RTBUF_GLFW3_OSCILLOSCOPE_INS
-};
-
-#pragma pack(push,1)
-typedef struct rtbuf_glfw3_oscilloscope_data {
- GLFWwindow *window;
-} s_rtbuf_glfw3_oscilloscope_data;
-#pragma pack(pop)
-
-int rtbuf_glfw3_oscilloscope (s_rtbuf *rtb);
-int rtbuf_glfw3_oscilloscope_start (s_rtbuf *rtb);
-
-#endif
diff --git a/lib/glfw3/rtbuf_glfw3_keyboard.c b/lib/glfw3/rtbuf_glfw3_keyboard.c
deleted file mode 100644
index 80b88f2..0000000
--- a/lib/glfw3/rtbuf_glfw3_keyboard.c
+++ /dev/null
@@ -1,281 +0,0 @@
-/*
- * Copyright 2018 Thomas de Grivel <thoxdg@gmail.com> +33614550127
- *
- * Permission to use, copy, modify, and distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
- * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- */
-
-#include <math.h>
-#include <stdio.h>
-#include <string.h>
-#include <strings.h>
-#include "rtbuf.h"
-#include "rtbuf_signal.h"
-#include "rtbuf_music.h"
-#include "rtbuf_music_type.h"
-#include "rtbuf_glfw3.h"
-
-float ceilf (float x);
-
-#define RTBUF_GLFW3_KEYBOARD_WIDTH 512
-#define RTBUF_GLFW3_KEYBOARD_HEIGHT 256
-
-double scancode_frequency (int scancode, unsigned int octave)
-{
- int note = -1;
- double freq = 0.0;
- printf("scancode %i\n", scancode);
- switch (scancode) {
- case 52: note = 0; break; /* C */
- case 39: note = 1; break;
- case 53: note = 2; break; /* D */
- case 40: note = 3; break;
- case 54: note = 4; break; /* E */
- case 55: note = 5; break; /* F */
- case 42: note = 6; break;
- case 56: note = 7; break; /* G */
- case 43: note = 8; break;
- case 57: note = 9; break; /* A */
- case 44: note = 10; break;
- case 58: note = 11; break; /* B */
- case 59: /* C */
- case 24: note = 12; break;
- case 46:
- case 11: note = 13; break;
- case 60: /* D */
- case 25: note = 14; break;
- case 47:
- case 12: note = 15; break;
- case 61: /* E */
- case 26: note = 16; break;
- case 27: note = 17; break; /* F */
- case 14: note = 18; break;
- case 28: note = 19; break; /* G */
- case 15: note = 20; break;
- case 29: note = 21; break; /* A */
- case 16: note = 22; break;
- case 30: note = 23; break; /* B */
- case 31: note = 24; break; /* C */
- case 18: note = 25; break;
- case 32: note = 26; break; /* D */
- case 19: note = 27; break;
- case 33: note = 28; break; /* E */
- case 34: note = 29; break; /* F */
- case 21: note = 30; break;
- case 35: note = 31; break; /* G */
- }
- if (note >= 0)
- freq = rtbuf_music_note_frequency(octave, note);
- return freq;
-}
-
-static int find_note (s_rtbuf_music_notes *notes, double freq)
-{
- unsigned int i = 0;
- unsigned int n = notes->note_n;
- while (i < RTBUF_MUSIC_NOTE_MAX && n > 0) {
- s_rtbuf_music_note *note = ¬es->note[i];
- if (note->velocity > 0.0 && note->start >= 0.0 && note->stop < 0.0) {
- if (freq == notes->note[i].freq)
- return i;
- n--;
- }
- i++;
- }
- return -1;
-}
-
-void rtbuf_glfw3_keyboard_key (GLFWwindow *w, int key,
- int scancode, int action,
- int mods)
-{
- int i;
- double freq;
- s_rtbuf_music_note *note;
- s_rtbuf *rtb = (s_rtbuf*) glfwGetWindowUserPointer(w);
- s_rtbuf_glfw3_keyboard_data *data;
- s_rtbuf_music_notes *notes;
- data = (s_rtbuf_glfw3_keyboard_data*) rtb->data;
- notes = &data->notes;
- (void) key;
- (void) mods;
- switch (action) {
- case GLFW_RELEASE:
- freq = scancode_frequency(scancode, data->octave);
- if ((i = find_note(notes, freq)) >= 0)
- notes->note[i].stop = 0.0;
- break;
- case GLFW_PRESS:
- freq = scancode_frequency(scancode, data->octave);
- if ((i = rtbuf_music_notes_new(notes, 1.0)) < 0)
- break;
- note = ¬es->note[i];
- note->freq = freq;
- note->start = 0.0;
- note->stop = -1.0;
- break;
- case GLFW_REPEAT:
- break;
- }
-}
-
-void rtbuf_glfw3_keyboard_size (GLFWwindow *w, int width,
- int height)
-{
- (void) w;
- glViewport(0, 0, width, height);
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- glOrtho(0.0f, 1.0f, 0.0f, 1.0f, 1.0f, -1.0f);
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
-}
-
-static
-void rtbuf_glfw3_keyboard_draw_panel (float y1, float y2)
-{
- glColor3f(0.5f, 0.5f, 0.5f);
- glBegin(GL_QUAD_STRIP);
- glVertex2f(0.0f, y1);
- glVertex2f(0.0f, y2);
- glVertex2f(1.0f, y1);
- glVertex2f(1.0f, y2);
- glEnd();
-}
-
-static
-void rtbuf_glfw3_keyboard_draw_white (unsigned int i, float n,
- float y1, float y2)
-{
- float x = (float) i / n;
- glBegin(GL_LINE_STRIP);
- glVertex2f(x, y1);
- glVertex2f(x, y2);
- i++;
- x = (float) i / n;
- glVertex2f(x, y2);
- glVertex2f(x, y1);
- glEnd();
-}
-
-static
-void rtbuf_glfw3_keyboard_draw_black (unsigned int i, float n,
- float y1, float y2)
-{
- float x1 = (i - 1.0f / 3.0f) / n;
- float x2 = (i + 1.0f / 3.0f) / n;
- glBegin(GL_QUAD_STRIP);
- glVertex2f(x1, y1);
- glVertex2f(x1, y2);
- glVertex2f(x2, y1);
- glVertex2f(x2, y2);
- glEnd();
-}
-
-void rtbuf_glfw3_keyboard_draw (GLFWwindow *w)
-{
- float y_buttons = 0.75f;
- float y_black = 0.36f;
- unsigned int notes = 32;
- float n = ceilf((notes + 1) * 7 / 12);
- unsigned int i = 0;
- unsigned int j = 0;
- glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
- glClear(GL_COLOR_BUFFER_BIT);
- rtbuf_glfw3_keyboard_draw_panel(1.0f, y_buttons);
- glColor3f(0.0f, 0.0f, 0.0f);
- while (i < notes) {
- int k = i % 12;
- if (k == 1 || k == 3 || k == 6 || k == 8 || k == 10)
- rtbuf_glfw3_keyboard_draw_black(j, n, y_buttons, y_black);
- else
- rtbuf_glfw3_keyboard_draw_white(j++, n, y_buttons, 0.0f);
- i++;
- }
- glfwSwapBuffers(w);
-}
-
-void rtbuf_glfw3_keyboard_close (GLFWwindow *window)
-{
- s_rtbuf *rtb = (s_rtbuf*) glfwGetWindowUserPointer(window);
- s_rtbuf_glfw3_keyboard_data* data = (s_rtbuf_glfw3_keyboard_data*)
- rtb->data;
- glfwDestroyWindow(window);
- data->window = 0;
-}
-
-GLFWwindow * rtbuf_glfw3_keyboard_window (s_rtbuf *rtb)
-{
- GLFWwindow *window = glfwCreateWindow(RTBUF_GLFW3_KEYBOARD_WIDTH,
- RTBUF_GLFW3_KEYBOARD_HEIGHT,
- "rtbuf_glfw3_keyboard",
- NULL, NULL);
- if (!window) {
- rtbuf_err("glfw3_keyboard: glfwCreateWindow failed");
- return 0;
- }
- glfwMakeContextCurrent(window);
- glfwSetWindowUserPointer(window, rtb);
- glfwSetKeyCallback(window, rtbuf_glfw3_keyboard_key);
- glfwSetWindowCloseCallback(window, rtbuf_glfw3_keyboard_close);
- glfwSetWindowSizeCallback(window, rtbuf_glfw3_keyboard_size);
- glfwSetWindowRefreshCallback(window,
- rtbuf_glfw3_keyboard_draw);
- glfwShowWindow(window);
- rtbuf_glfw3_keyboard_size(window, RTBUF_GLFW3_KEYBOARD_WIDTH,
- RTBUF_GLFW3_KEYBOARD_HEIGHT);
- return window;
-}
-
-int rtbuf_glfw3_keyboard_start (s_rtbuf *rtb)
-{
- s_rtbuf_glfw3_keyboard_data *data;
- assert(rtb->proc->out_bytes == sizeof(*data));
- data = (s_rtbuf_glfw3_keyboard_data*) rtb->data;
- if (!data->window &&
- !(data->window = rtbuf_glfw3_keyboard_window(rtb)))
- return -1;
- data->octave = 3;
- return 0;
-}
-
-int rtbuf_glfw3_keyboard_stop (s_rtbuf *rtb)
-{
- s_rtbuf_glfw3_keyboard_data *data;
- data = (s_rtbuf_glfw3_keyboard_data*) rtb->data;
- rtbuf_music_notes_delete_all(&data->notes);
- return 0;
-}
-
-int rtbuf_glfw3_keyboard (s_rtbuf *rtb)
-{
- s_rtbuf_glfw3_keyboard_data *data;
- unsigned int i = 0;
- unsigned int n;
- data = (s_rtbuf_glfw3_keyboard_data*) rtb->data;
- if (!data->window)
- return -1;
- n = data->notes.note_n;
- while (i < RTBUF_MUSIC_NOTE_MAX && n > 0) {
- s_rtbuf_music_note *note = &data->notes.note[i];
- if (note->velocity > 0.0) {
- assert(note->start >= 0.0);
- rtbuf_music_note_dt(note, RTBUF_SIGNAL_DT);
- if (note->stop > RTBUF_MUSIC_RELEASE_MAX)
- rtbuf_music_notes_delete(&data->notes, i);
- n--;
- }
- i++;
- }
- glfwPollEvents();
- return 0;
-}
diff --git a/lib/glfw3/rtbuf_glfw3_oscilloscope.c b/lib/glfw3/rtbuf_glfw3_oscilloscope.c
deleted file mode 100644
index 2be4650..0000000
--- a/lib/glfw3/rtbuf_glfw3_oscilloscope.c
+++ /dev/null
@@ -1,99 +0,0 @@
-/*
- * Copyright 2018 Thomas de Grivel <thoxdg@gmail.com> +33614550127
- *
- * Permission to use, copy, modify, and distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
- * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- */
-
-#include "rtbuf.h"
-#include "rtbuf_signal.h"
-#include "rtbuf_glfw3.h"
-
-void rtbuf_glfw3_oscilloscope_size (GLFWwindow *w, int width,
- int height)
-{
- (void) w;
- glViewport(0, 0, width, height);
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- glOrtho(0.0f, 1.0f, 0.0f, 1.0f, 1.0f, -1.0f);
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
-}
-
-void rtbuf_glfw3_oscilloscope_draw (GLFWwindow *window)
-{
- s_rtbuf *rtb = (s_rtbuf*) glfwGetWindowUserPointer(window);
- s_rtbuf_signal_fun in[4];
- const float color[4][3] = { { 0.0f, 0.0f, 0.0f },
- { 1.0f, 0.0f, 0.0f },
- { 0.0f, 1.0f, 0.0f },
- { 0.0f, 0.0f, 1.0f } };
- unsigned int i = 0;
- unsigned int j;
- assert(rtb);
- for (j = 0; j < 4; j++)
- rtbuf_signal_fun(rtb, j, &in[j]);
- glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
- glClear(GL_COLOR_BUFFER_BIT);
- for (j = 0; j < 4; j++) {
- glColor3f(color[j][0], color[j][1], color[j][2]);
- glBegin(GL_LINE_STRIP);
- for (i = 0; i < RTBUF_SIGNAL_SAMPLES; i++) {
- float x = (double) i / RTBUF_SIGNAL_SAMPLES;
- float s = in[j].sample_fun(in[j].signal, i);
- glVertex2f(x, s / 4.0f + 0.5f);
- }
- glEnd();
- }
- glfwSwapBuffers(window);
-}
-
-GLFWwindow * rtbuf_glfw3_oscilloscope_window (s_rtbuf *rtb)
-{
- GLFWwindow *window = glfwCreateWindow(512, 512,
- "rtbuf_glfw3_oscilloscope",
- NULL, NULL);
- if (!window) {
- rtbuf_err("glfw3_oscilloscope: glfwCreateWindow failed");
- return 0;
- }
- glfwMakeContextCurrent(window);
- glfwSetWindowUserPointer(window, rtb);
- glfwSetWindowSizeCallback(window, rtbuf_glfw3_oscilloscope_size);
- glfwSetWindowRefreshCallback(window, rtbuf_glfw3_oscilloscope_draw);
- glfwShowWindow(window);
- return window;
-}
-
-int rtbuf_glfw3_oscilloscope_start (s_rtbuf *rtb)
-{
- s_rtbuf_glfw3_oscilloscope_data *data;
- assert(rtb->proc->out_bytes == sizeof(*data));
- data = (s_rtbuf_glfw3_oscilloscope_data*) rtb->data;
- if (!data->window &&
- !(data->window = rtbuf_glfw3_oscilloscope_window(rtb)))
- return -1;
- return 0;
-}
-
-int rtbuf_glfw3_oscilloscope (s_rtbuf *rtb)
-{
- s_rtbuf_glfw3_oscilloscope_data *data;
- assert(rtb);
- assert(rtb->data);
- assert(rtb->proc);
- data = (s_rtbuf_glfw3_oscilloscope_data*) rtb->data;
- rtbuf_glfw3_oscilloscope_draw(data->window);
- glfwPollEvents();
- return 0;
-}
diff --git a/lib/glfw3/rtbuf_glfw3_type.c b/lib/glfw3/rtbuf_glfw3_type.c
deleted file mode 100644
index bf8d3ef..0000000
--- a/lib/glfw3/rtbuf_glfw3_type.c
+++ /dev/null
@@ -1,18 +0,0 @@
-
-#include <stdio.h>
-#include "rtbuf.h"
-#include "rtbuf_glfw3.h"
-
-int main ()
-{
- printf("/* file generated by rtbuf_glfw3_type */\n");
- printf("#ifndef RTBUF_GLFW3_TYPE_H\n"
- "#define RTBUF_GLFW3_TYPE_H\n"
- "\n");
- printf("#define RTBUF_GLFW3_SAMPLES_TYPE RTBUF_GLFW3_SAMPLE_TYPE"
- " \"[%u]\"\n",
- RTBUF_GLFW3_SAMPLES);
- printf("\n"
- "#endif\n");
- return 0;
-}
diff --git a/lib/include/rtbuf/dynamic.h b/lib/include/rtbuf/dynamic.h
index c821900..f3e71e2 100644
--- a/lib/include/rtbuf/dynamic.h
+++ b/lib/include/rtbuf/dynamic.h
@@ -32,7 +32,4 @@ typedef struct rtbuf_dynamic_limiter_data {
t_rtbuf_signal_sample ratio;
} s_rtbuf_dynamic_limiter_data;
-int rtbuf_dynamic_limiter (s_rtbuf *rtb);
-int rtbuf_dynamic_limiter_start (s_rtbuf *rtb);
-
#endif
diff --git a/lib/include/rtbuf/glfw3.h b/lib/include/rtbuf/glfw3.h
new file mode 100644
index 0000000..ddb1f81
--- /dev/null
+++ b/lib/include/rtbuf/glfw3.h
@@ -0,0 +1,45 @@
+/*
+ * Copyright 2018 Thomas de Grivel <thoxdg@gmail.com> +33614550127
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+#ifndef RTBUF_GLFW3_H
+#define RTBUF_GLFW3_H
+
+#include <GLFW/glfw3.h>
+#include <rtbuf/rtbuf.h>
+#include <rtbuf/music.h>
+
+#pragma pack(push,1)
+typedef struct rtbuf_glfw3_keyboard_data {
+ s_rtbuf_music_notes notes;
+ GLFWwindow *window;
+ unsigned int octave;
+} s_rtbuf_glfw3_keyboard_data;
+#pragma pack(pop)
+
+enum {
+ RTBUF_GLFW3_OSCILLOSCOPE_IN_BLACK,
+ RTBUF_GLFW3_OSCILLOSCOPE_IN_RED,
+ RTBUF_GLFW3_OSCILLOSCOPE_IN_GREEN,
+ RTBUF_GLFW3_OSCILLOSCOPE_IN_BLUE,
+ RTBUF_GLFW3_OSCILLOSCOPE_INS
+};
+
+#pragma pack(push,1)
+typedef struct rtbuf_glfw3_oscilloscope_data {
+ GLFWwindow *window;
+} s_rtbuf_glfw3_oscilloscope_data;
+#pragma pack(pop)
+
+#endif
diff --git a/lib/include/rtbuf/portaudio.h b/lib/include/rtbuf/portaudio.h
new file mode 100644
index 0000000..74a7a61
--- /dev/null
+++ b/lib/include/rtbuf/portaudio.h
@@ -0,0 +1,60 @@
+/*
+ * Copyright 2018 Thomas de Grivel <thoxdg@gmail.com> +33614550127
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+#ifndef RTBUF_PORTAUDIO_H
+#define RTBUF_PORTAUDIO_H
+
+#include <portaudio.h>
+#include <rtbuf/signal.h>
+
+enum {
+ RTBUF_PORTAUDIO_LEFT = 0,
+ RTBUF_PORTAUDIO_RIGHT,
+ RTBUF_PORTAUDIO_CHANNELS
+};
+
+#define RTBUF_PORTAUDIO_SAMPLE_TYPE "short"
+#define RTBUF_PORTAUDIO_SAMPLES \
+ (RTBUF_PORTAUDIO_CHANNELS * RTBUF_SIGNAL_SAMPLES)
+
+typedef short t_rtbuf_portaudio_sample;
+typedef t_rtbuf_portaudio_sample t_rtbuf_portaudio_samples[RTBUF_PORTAUDIO_SAMPLES];
+
+typedef struct rtbuf_portaudio_input_data {
+ t_rtbuf_signal signal[RTBUF_PORTAUDIO_CHANNELS];
+ t_rtbuf_portaudio_samples samples;
+} s_rtbuf_portaudio_input_data;
+
+int rtbuf_portaudio_input (s_rtbuf *rtb);
+int rtbuf_portaudio_input_start (s_rtbuf *rtb);
+int rtbuf_portaudio_input_stop (s_rtbuf *rtb);
+
+typedef struct rtbuf_portaudio_output_reserved {
+ PaStream *stream;
+} s_rtbuf_portaudio_output_reserved;
+
+typedef struct rtbuf_portaudio_output_data {
+ t_rtbuf_portaudio_samples samples;
+ s_rtbuf_portaudio_output_reserved reserved;
+} s_rtbuf_portaudio_output_data;
+
+#define RTBUF_PORTAUDIO_OUTPUT_RESERVED_SIZE \
+ sizeof(s_rtbuf_portaudio_output_reserved)
+
+int rtbuf_portaudio_output (s_rtbuf *rtb);
+int rtbuf_portaudio_output_start (s_rtbuf *rtb);
+int rtbuf_portaudio_output_stop (s_rtbuf *rtb);
+
+#endif
diff --git a/lib/include/rtbuf/synth.h b/lib/include/rtbuf/synth.h
new file mode 100644
index 0000000..2a8616a
--- /dev/null
+++ b/lib/include/rtbuf/synth.h
@@ -0,0 +1,79 @@
+/*
+ * Copyright 2018 Thomas de Grivel <thoxdg@gmail.com> +33614550127
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+#ifndef RTBUF_SYNTH_H
+#define RTBUF_SYNTH_H
+
+#include <rtbuf/rtbuf.h>
+#include <rtbuf/music.h>
+#include <rtbuf/music_type.h>
+#include <rtbuf/signal.h>
+#include <rtbuf/synth_type.h>
+
+/* adsr */
+
+enum {
+ RTBUF_MUSIC_NOTE_IN_ENUM(RTBUF_SYNTH_ADSR_IN),
+ RTBUF_SYNTH_ADSR_IN_ATTACK,
+ RTBUF_SYNTH_ADSR_IN_DECAY,
+ RTBUF_SYNTH_ADSR_IN_SUSTAIN,
+ RTBUF_SYNTH_ADSR_IN_RELEASE,
+ RTBUF_SYNTH_ADSR_IN_N
+};
+
+enum {
+ RTBUF_SYNTH_ENVELOPE_STATE_NOT_STARTED = 0,
+ RTBUF_SYNTH_ENVELOPE_STATE_STARTED,
+ RTBUF_SYNTH_ENVELOPE_STATE_ENDED
+};
+
+#pragma pack(push,1)
+typedef struct rtbuf_synth_adsr_data {
+ t_rtbuf_signal signal;
+ int state;
+} s_rtbuf_synth_adsr_data;
+#pragma pack(pop)
+
+int rtbuf_synth_adsr (s_rtbuf *rtb);
+int rtbuf_synth_adsr_start (s_rtbuf *rtb);
+
+/* synth */
+
+enum {
+ RTBUF_SYNTH_SYNTH_IN_ENVELOPE = 0,
+ RTBUF_SYNTH_SYNTH_IN_OSCILLATOR,
+ RTBUF_SYNTH_SYNTH_IN_NOTES,
+ RTBUF_SYNTH_NOTES_IN_ENUM(RTBUF_SYNTH_SYNTH_IN_NOTE),
+ RTBUF_SYNTH_SYNTH_IN_N
+};
+
+#define RTBUF_SYNTH_SYNTH_IN_NOTE_ENVELOPE(i) \
+ (RTBUF_SYNTH_SYNTH_IN_NOTE_0_ENVELOPE + 2 * i)
+
+#define RTBUF_SYNTH_SYNTH_IN_NOTE_OSCILLATOR(i) \
+ (RTBUF_SYNTH_SYNTH_IN_NOTE_0_OSCILLATOR + 2 * i)
+
+#pragma pack(push,1)
+typedef struct rtbuf_synth_synth_data
+{
+ t_rtbuf_signal signal;
+ unsigned int note_n;
+} s_rtbuf_synth_synth_data;
+#pragma pack(pop)
+
+int rtbuf_synth_synth (s_rtbuf *rtb);
+int rtbuf_synth_synth_start (s_rtbuf *rtb);
+
+#endif /* RTBUF_SYNTH_H */
diff --git a/lib/portaudio/Makefile.am b/lib/portaudio/Makefile.am
index 4fb7871..a2aa5f0 100644
--- a/lib/portaudio/Makefile.am
+++ b/lib/portaudio/Makefile.am
@@ -1,10 +1,13 @@
-
CLEANFILES =
rtbuf_includedir = $(includedir)/rtbuf/portaudio
rtbuf_include_HEADERS =
rtbuf_libdir = $(libdir)/rtbuf/portaudio
rtbuf_lib_LTLIBRARIES =
+rtbuf_lib_LTLIBRARIES += input.la
+input_la_LDFLAGS = -no-undefined -module -shared
+input_la_LIBADD = ${PORTAUDIO_LIBS} ../librtbuf_signal.la
+
rtbuf_lib_LTLIBRARIES += output.la
output_la_LDFLAGS = -no-undefined -module -shared
-output_la_LIBADD = ${SIGNAL_LIBS} ../librtbuf_signal.la
+output_la_LIBADD = ${PORTAUDIO_LIBS} ../librtbuf_signal.la
diff --git a/lib/portaudio/input.c b/lib/portaudio/input.c
new file mode 100644
index 0000000..ad93383
--- /dev/null
+++ b/lib/portaudio/input.c
@@ -0,0 +1,64 @@
+/*
+ * Copyright 2018 Thomas de Grivel <thoxdg@gmail.com> +33614550127
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <portaudio.h>
+#include <stdio.h>
+#include <strings.h>
+#include <rtbuf/rtbuf.h>
+#include <rtbuf/lib.h>
+#include <rtbuf/signal.h>
+#include <rtbuf/signal_type.h>
+#include <rtbuf/portaudio.h>
+#include <rtbuf/portaudio_type.h>
+
+s_rtbuf_lib_proc_out rtbuf_portaudio_input_out[] = {
+ { "left", RTBUF_SIGNAL_TYPE },
+ { "right", RTBUF_SIGNAL_TYPE },
+ { "samples", RTBUF_PORTAUDIO_SAMPLES_TYPE },
+ { 0, 0 }};
+
+int rtbuf_portaudio_input (s_rtbuf *rtb)
+{
+ /*
+ s_portaudio_input_data *data = (s_portaudio_input_data*) rtb->data;
+ */
+ (void) rtb;
+ return 0;
+}
+
+int rtbuf_portaudio_input_start (s_rtbuf *rtb)
+{
+ s_rtbuf_portaudio_input_data *data;
+ assert(rtb->proc->out_bytes == sizeof(*data));
+ data = (s_rtbuf_portaudio_input_data*) rtb->data;
+ return 0;
+}
+
+int rtbuf_portaudio_input_stop (s_rtbuf *rtb)
+{
+ (void) rtb;
+ return 0;
+}
+
+s_rtbuf_lib_proc rtbuf_lib_proc =
+ { "input",
+ rtbuf_portaudio_input,
+ rtbuf_portaudio_input_start,
+ rtbuf_portaudio_input_stop,
+ 0,
+ rtbuf_portaudio_input_out };
+
+unsigned long rtbuf_lib_ver = RTBUF_LIB_VER;
diff --git a/lib/portaudio/output.c b/lib/portaudio/output.c
new file mode 100644
index 0000000..e5895ec
--- /dev/null
+++ b/lib/portaudio/output.c
@@ -0,0 +1,133 @@
+/*
+ * Copyright 2018 Thomas de Grivel <thoxdg@gmail.com> +33614550127
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <limits.h>
+#include <portaudio.h>
+#include <stdio.h>
+#include <strings.h>
+#include <rtbuf/rtbuf.h>
+#include <rtbuf/lib.h>
+#include <rtbuf/signal.h>
+#include <rtbuf/signal_type.h>
+#include <rtbuf/portaudio.h>
+#include <rtbuf/portaudio_type.h>
+
+int g_initialized = 0;
+
+s_rtbuf_lib_proc_in rtbuf_portaudio_output_in[] = {
+ { "left", RTBUF_SIGNAL_TYPE, 0.0, -1.0, 1.0 },
+ { "right", RTBUF_SIGNAL_TYPE, 0.0, -1.0, 1.0 },
+ { 0, 0, 0.0, 0.0, 0.0 }};
+
+s_rtbuf_lib_proc_out rtbuf_portaudio_output_out[] = {
+ { "samples", RTBUF_PORTAUDIO_SAMPLES_TYPE },
+ { "reserved", RTBUF_PORTAUDIO_OUTPUT_RESERVED_TYPE },
+ { 0, 0 }};
+
+int rtbuf_portaudio_output_start (s_rtbuf *rtb)
+{
+ s_rtbuf_portaudio_output_data *data;
+ PaError err;
+ assert(rtb->proc->out_bytes == sizeof(*data));
+ data = (s_rtbuf_portaudio_output_data*) rtb->data;
+ if (!g_initialized) {
+ if (Pa_Initialize() != paNoError)
+ return rtbuf_err("portaudio_output_start: Pa_Initialize() failed");
+ g_initialized = 1;
+ }
+ err = Pa_OpenDefaultStream(&data->reserved.stream, /* stream pointer */
+ 0, /* input channels */
+ RTBUF_PORTAUDIO_CHANNELS, /* output channels */
+ paInt16, /* sample format */
+ RTBUF_SIGNAL_SAMPLERATE, /* sample rate */
+ RTBUF_SIGNAL_SAMPLES, /* frames per buffer */
+ NULL, /* stream callback */
+ NULL); /* user data */
+ if (err != paNoError) {
+ rtbuf_err(Pa_GetErrorText(err));
+ return rtbuf_err("portaudio_output_start: Pa_OpenDefaultStream() failed");
+ }
+ err = Pa_StartStream(data->reserved.stream);
+ if (err != paNoError) {
+ rtbuf_err(Pa_GetErrorText(err));
+ return rtbuf_err("portaudio output start: Pa_StartStream() failed");
+ }
+ return 0;
+}
+
+int rtbuf_portaudio_output_stop (s_rtbuf *rtb)
+{
+ s_rtbuf_portaudio_output_data *data;
+ data = (s_rtbuf_portaudio_output_data*) rtb->data;
+ if (data->reserved.stream) {
+ Pa_StopStream(data->reserved.stream);
+ Pa_CloseStream(data->reserved.stream);
+ data->reserved.stream = 0;
+ }
+ return 0;
+}
+
+int rtbuf_portaudio_output (s_rtbuf *rtb)
+{
+ s_rtbuf_signal_fun in[RTBUF_PORTAUDIO_CHANNELS];
+ s_rtbuf_portaudio_output_data *data;
+ short *sample;
+ unsigned int i = 0;
+ unsigned int j = 0;
+ PaError err;
+ assert(rtb);
+ assert(rtb->data);
+ assert(rtb->proc);
+ while (j < RTBUF_PORTAUDIO_CHANNELS) {
+ rtbuf_signal_fun(rtb, j, &in[j]);
+ j++;
+ }
+ data = (s_rtbuf_portaudio_output_data*) rtb->data;
+ sample = data->samples;
+ /* printf("portaudio_output"); */
+ while (i < RTBUF_SIGNAL_SAMPLES) {
+ j = 0;
+ while (j < RTBUF_PORTAUDIO_CHANNELS) {
+ double in_ = in[j].sample_fun(in[j].signal, i);
+ in_ = clamp(-1.0, in_, 1.0);
+ if (in_ < 0.0)
+ in_ *= -SHRT_MIN;
+ else
+ in_ *= SHRT_MAX;
+ *sample = (short) in_;
+ sample++;
+ j++;
+ }
+ i++;
+ }
+ err = Pa_WriteStream(data->reserved.stream, data->samples, RTBUF_SIGNAL_SAMPLES);
+ if (err != paNoError) {
+ rtbuf_err(Pa_GetErrorText(err));
+ rtbuf_err("portaudio output: Pa_WriteStream failed");
+ }
+ /* printf("\n"); */
+ return 0;
+}
+
+s_rtbuf_lib_proc rtbuf_lib_proc =
+ { "output",
+ rtbuf_portaudio_output,
+ rtbuf_portaudio_output_start,
+ rtbuf_portaudio_output_stop,
+ rtbuf_portaudio_output_in,
+ rtbuf_portaudio_output_out };
+
+unsigned long rtbuf_lib_ver = RTBUF_LIB_VER;
diff --git a/lib/portaudio/rtbuf_portaudio.c b/lib/portaudio/rtbuf_portaudio.c
deleted file mode 100644
index 338014b..0000000
--- a/lib/portaudio/rtbuf_portaudio.c
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * Copyright 2018 Thomas de Grivel <thoxdg@gmail.com> +33614550127
- *
- * Permission to use, copy, modify, and distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
- * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- */
-
-#include <portaudio.h>
-#include <stdio.h>
-#include <strings.h>
-#include "rtbuf.h"
-#include "rtbuf_lib.h"
-#include "rtbuf_signal.h"
-#include "rtbuf_signal_type.h"
-#include "rtbuf_portaudio.h"
-#include "rtbuf_portaudio_type.h"
-
-s_rtbuf_lib_proc_out g_rtbuf_portaudio_input_out[] = {
- { "left", RTBUF_SIGNAL_TYPE },
- { "right", RTBUF_SIGNAL_TYPE },
- { "samples", RTBUF_PORTAUDIO_SAMPLES_TYPE },
- { 0, 0 } };
-
-s_rtbuf_lib_proc_in g_rtbuf_portaudio_output_in[] = {
- { "left", RTBUF_SIGNAL_TYPE, 0.0, -1.0, 1.0 },
- { "right", RTBUF_SIGNAL_TYPE, 0.0, -1.0, 1.0 },
- { 0, 0, 0.0, 0.0, 0.0 } };
-
-s_rtbuf_lib_proc_out g_rtbuf_portaudio_output_out[] = {
- { "samples", RTBUF_PORTAUDIO_SAMPLES_TYPE },
- { "reserved", RTBUF_PORTAUDIO_OUTPUT_RESERVED_TYPE },
- { 0, 0 } };
-
-const char *rtbuf_lib_name = "portaudio";
-unsigned long rtbuf_lib_ver = RTBUF_LIB_VER;
-s_rtbuf_lib_proc rtbuf_lib_proc[] = {
- { "input", rtbuf_portaudio_input, rtbuf_portaudio_input_start,
- rtbuf_portaudio_input_stop, 0, g_rtbuf_portaudio_input_out },
- { "output", rtbuf_portaudio_output, rtbuf_portaudio_output_start,
- rtbuf_portaudio_output_stop, g_rtbuf_portaudio_output_in,
- g_rtbuf_portaudio_output_out },
- { 0, 0, 0, 0, 0, 0 } };
diff --git a/lib/portaudio/rtbuf_portaudio.h b/lib/portaudio/rtbuf_portaudio.h
deleted file mode 100644
index 13e044b..0000000
--- a/lib/portaudio/rtbuf_portaudio.h
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * Copyright 2018 Thomas de Grivel <thoxdg@gmail.com> +33614550127
- *
- * Permission to use, copy, modify, and distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
- * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- */
-#ifndef RTBUF_PORTAUDIO_H
-#define RTBUF_PORTAUDIO_H
-
-#include <portaudio.h>
-#include "rtbuf_signal.h"
-
-enum {
- RTBUF_PORTAUDIO_LEFT = 0,
- RTBUF_PORTAUDIO_RIGHT,
- RTBUF_PORTAUDIO_CHANNELS
-};
-
-#define RTBUF_PORTAUDIO_SAMPLE_TYPE "short"
-#define RTBUF_PORTAUDIO_SAMPLES \
- (RTBUF_PORTAUDIO_CHANNELS * RTBUF_SIGNAL_SAMPLES)
-
-typedef short t_rtbuf_portaudio_sample;
-typedef t_rtbuf_portaudio_sample t_rtbuf_portaudio_samples[RTBUF_PORTAUDIO_SAMPLES];
-
-typedef struct rtbuf_portaudio_input_data {
- t_rtbuf_signal signal[RTBUF_PORTAUDIO_CHANNELS];
- t_rtbuf_portaudio_samples samples;
-} s_rtbuf_portaudio_input_data;
-
-int rtbuf_portaudio_input (s_rtbuf *rtb);
-int rtbuf_portaudio_input_start (s_rtbuf *rtb);
-int rtbuf_portaudio_input_stop (s_rtbuf *rtb);
-
-typedef struct rtbuf_portaudio_output_reserved {
- PaStream *stream;
-} s_rtbuf_portaudio_output_reserved;
-
-typedef struct rtbuf_portaudio_output_data {
- t_rtbuf_portaudio_samples samples;
- s_rtbuf_portaudio_output_reserved reserved;
-} s_rtbuf_portaudio_output_data;
-
-#define RTBUF_PORTAUDIO_OUTPUT_RESERVED_SIZE \
- sizeof(s_rtbuf_portaudio_output_reserved)
-
-int rtbuf_portaudio_output (s_rtbuf *rtb);
-int rtbuf_portaudio_output_start (s_rtbuf *rtb);
-int rtbuf_portaudio_output_stop (s_rtbuf *rtb);
-
-#endif
diff --git a/lib/portaudio/rtbuf_portaudio_input.c b/lib/portaudio/rtbuf_portaudio_input.c
deleted file mode 100644
index 6ee5709..0000000
--- a/lib/portaudio/rtbuf_portaudio_input.c
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * Copyright 2018 Thomas de Grivel <thoxdg@gmail.com> +33614550127
- *
- * Permission to use, copy, modify, and distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
- * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- */
-
-#include <portaudio.h>
-#include <stdio.h>
-#include <strings.h>
-#include "rtbuf.h"
-#include "rtbuf_signal.h"
-#include "rtbuf_portaudio.h"
-
-int rtbuf_portaudio_input (s_rtbuf *rtb)
-{
- /*
- s_portaudio_input_data *data = (s_portaudio_input_data*) rtb->data;
- */
- (void) rtb;
- return 0;
-}
-
-int rtbuf_portaudio_input_start (s_rtbuf *rtb)
-{
- s_rtbuf_portaudio_input_data *data;
- assert(rtb->proc->out_bytes == sizeof(*data));
- data = (s_rtbuf_portaudio_input_data*) rtb->data;
- return 0;
-}
-
-int rtbuf_portaudio_input_stop (s_rtbuf *rtb)
-{
- (void) rtb;
- return 0;
-}
diff --git a/lib/portaudio/rtbuf_portaudio_output.c b/lib/portaudio/rtbuf_portaudio_output.c
deleted file mode 100644
index 0d210b6..0000000
--- a/lib/portaudio/rtbuf_portaudio_output.c
+++ /dev/null
@@ -1,109 +0,0 @@
-/*
- * Copyright 2018 Thomas de Grivel <thoxdg@gmail.com> +33614550127
- *
- * Permission to use, copy, modify, and distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
- * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- */
-
-#include <limits.h>
-#include <portaudio.h>
-#include <stdio.h>
-#include <strings.h>
-#include "rtbuf.h"
-#include "rtbuf_portaudio.h"
-
-int g_initialized = 0;
-
-int rtbuf_portaudio_output_start (s_rtbuf *rtb)
-{
- s_rtbuf_portaudio_output_data *data;
- PaError err;
- assert(rtb->proc->out_bytes == sizeof(*data));
- data = (s_rtbuf_portaudio_output_data*) rtb->data;
- if (!g_initialized) {
- if (Pa_Initialize() != paNoError)
- return rtbuf_err("portaudio_output_start: Pa_Initialize() failed");
- g_initialized = 1;
- }
- err = Pa_OpenDefaultStream(&data->reserved.stream, /* stream pointer */
- 0, /* input channels */
- RTBUF_PORTAUDIO_CHANNELS, /* output channels */
- paInt16, /* sample format */
- RTBUF_SIGNAL_SAMPLERATE, /* sample rate */
- RTBUF_SIGNAL_SAMPLES, /* frames per buffer */
- NULL, /* stream callback */
- NULL); /* user data */
- if (err != paNoError) {
- rtbuf_err(Pa_GetErrorText(err));
- return rtbuf_err("portaudio_output_start: Pa_OpenDefaultStream() failed");
- }
- err = Pa_StartStream(data->reserved.stream);
- if (err != paNoError) {
- rtbuf_err(Pa_GetErrorText(err));
- return rtbuf_err("portaudio output start: Pa_StartStream() failed");
- }
- return 0;
-}
-
-int rtbuf_portaudio_output_stop (s_rtbuf *rtb)
-{
- s_rtbuf_portaudio_output_data *data;
- data = (s_rtbuf_portaudio_output_data*) rtb->data;
- if (data->reserved.stream) {
- Pa_StopStream(data->reserved.stream);
- Pa_CloseStream(data->reserved.stream);
- data->reserved.stream = 0;
- }
- return 0;
-}
-
-int rtbuf_portaudio_output (s_rtbuf *rtb)
-{
- s_rtbuf_signal_fun in[RTBUF_PORTAUDIO_CHANNELS];
- s_rtbuf_portaudio_output_data *data;
- short *sample;
- unsigned int i = 0;
- unsigned int j = 0;
- PaError err;
- assert(rtb);
- assert(rtb->data);
- assert(rtb->proc);
- while (j < RTBUF_PORTAUDIO_CHANNELS) {
- rtbuf_signal_fun(rtb, j, &in[j]);
- j++;
- }
- data = (s_rtbuf_portaudio_output_data*) rtb->data;
- sample = data->samples;
- /* printf("portaudio_output"); */
- while (i < RTBUF_SIGNAL_SAMPLES) {
- j = 0;
- while (j < RTBUF_PORTAUDIO_CHANNELS) {
- double in_ = in[j].sample_fun(in[j].signal, i);
- in_ = clamp(-1.0, in_, 1.0);
- if (in_ < 0.0)
- in_ *= -SHRT_MIN;
- else
- in_ *= SHRT_MAX;
- *sample = (short) in_;
- sample++;
- j++;
- }
- i++;
- }
- err = Pa_WriteStream(data->reserved.stream, data->samples, RTBUF_SIGNAL_SAMPLES);
- if (err != paNoError) {
- rtbuf_err(Pa_GetErrorText(err));
- rtbuf_err("portaudio output: Pa_WriteStream failed");
- }
- /* printf("\n"); */
- return 0;
-}
diff --git a/lib/portaudio/rtbuf_portaudio_type.c b/lib/portaudio/rtbuf_portaudio_type.c
deleted file mode 100644
index 3bef91f..0000000
--- a/lib/portaudio/rtbuf_portaudio_type.c
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * Copyright 2018 Thomas de Grivel <thoxdg@gmail.com> +33614550127
- *
- * Permission to use, copy, modify, and distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
- * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- */
-
-#include <stdio.h>
-#include "rtbuf.h"
-#include "rtbuf_portaudio.h"
-
-int main ()
-{
- printf("/* file generated by rtbuf_portaudio_type */\n");
- printf("#ifndef RTBUF_PORTAUDIO_TYPE_H\n"
- "#define RTBUF_PORTAUDIO_TYPE_H\n"
- "\n");
- printf("#define RTBUF_PORTAUDIO_SAMPLES_TYPE RTBUF_PORTAUDIO_SAMPLE_TYPE"
- " \"[%u]\"\n",
- RTBUF_PORTAUDIO_SAMPLES);
- printf("#define RTBUF_PORTAUDIO_OUTPUT_RESERVED_TYPE"
- " \"char[%u]\"\n",
- (unsigned int) RTBUF_PORTAUDIO_OUTPUT_RESERVED_SIZE);
- printf("\n"
- "#endif\n");
- return 0;
-}
diff --git a/lib/portaudio_type.c b/lib/portaudio_type.c
new file mode 100644
index 0000000..e3f7724
--- /dev/null
+++ b/lib/portaudio_type.c
@@ -0,0 +1,36 @@
+/*
+ * Copyright 2018 Thomas de Grivel <thoxdg@gmail.com> +33614550127
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <stdio.h>
+#include <rtbuf/rtbuf.h>
+#include <rtbuf/portaudio.h>
+
+int main ()
+{
+ printf("/* file generated by rtbuf_portaudio_type */\n");
+ printf("#ifndef RTBUF_PORTAUDIO_TYPE_H\n"
+ "#define RTBUF_PORTAUDIO_TYPE_H\n"
+ "\n");
+ printf("#define RTBUF_PORTAUDIO_SAMPLES_TYPE RTBUF_PORTAUDIO_SAMPLE_TYPE"
+ " \"[%u]\"\n",
+ RTBUF_PORTAUDIO_SAMPLES);
+ printf("#define RTBUF_PORTAUDIO_OUTPUT_RESERVED_TYPE"
+ " \"char[%u]\"\n",
+ (unsigned int) RTBUF_PORTAUDIO_OUTPUT_RESERVED_SIZE);
+ printf("\n"
+ "#endif\n");
+ return 0;
+}
diff --git a/lib/signal.c b/lib/signal.c
index 96fd843..32edcb6 100644
--- a/lib/signal.c
+++ b/lib/signal.c
@@ -1,5 +1,5 @@
/*
- * Copyright 2018 Thomas de Grivel <thoxdg@gmail.com> +33614550127
+ * Copyright 2018 Thomas de Grivel <thoxdg@gmail.com>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
@@ -27,344 +27,6 @@ const double g_rtbuf_signal_sample_half = 0.5;
const double g_rtbuf_signal_sample_one = 1.0;
const double g_rtbuf_signal_default_frequency = 220.0;
-s_rtbuf_lib_proc_in g_rtbuf_signal_bandpass2_in[] = {
- { "signal", RTBUF_SIGNAL_TYPE, 0.0, -1.0, 1.0 },
- { "cutoff", RTBUF_SIGNAL_TYPE, 400.0, 0.0, RTBUF_SIGNAL_SAMPLERATE / 2.0 },
- { "qfactor", RTBUF_SIGNAL_TYPE, 1.0, 0.0, 1000.0 },
- { 0, 0, 0.0, 0.0, 0.0 } };
-
-s_rtbuf_lib_proc_out g_rtbuf_signal_bandpass2_out[] = {
- { "signal", RTBUF_SIGNAL_TYPE },
- { "x1", RTBUF_SIGNAL_SAMPLE_TYPE },
- { "x2", RTBUF_SIGNAL_SAMPLE_TYPE },
- { "x3", RTBUF_SIGNAL_SAMPLE_TYPE },
- { "x4", RTBUF_SIGNAL_SAMPLE_TYPE },
- { "y1", RTBUF_SIGNAL_SAMPLE_TYPE },
- { "y2", RTBUF_SIGNAL_SAMPLE_TYPE },
- { "y3", RTBUF_SIGNAL_SAMPLE_TYPE },
- { "y4", RTBUF_SIGNAL_SAMPLE_TYPE },
- { 0, 0 } };
-
-s_rtbuf_lib_proc_in g_rtbuf_signal_delay_in[] = {
- { "signal", RTBUF_SIGNAL_TYPE, 0.0, -1.0, 1.0 },
- { "delay", RTBUF_SIGNAL_TYPE, 0.4, 0.0, RTBUF_SIGNAL_DELAY_MAX },
- { "feedback", RTBUF_SIGNAL_TYPE, 0.5, 0.0, 1.0 },
- { 0, 0, 0.0, 0.0, 0.0 } };
-
-s_rtbuf_lib_proc_out g_rtbuf_signal_delay_out[] = {
- { "signal", RTBUF_SIGNAL_TYPE },
- { "in", RTBUF_SIGNAL_DELAY_TYPE },
- { "pos", "unsigned int" },
- { 0, 0 } };
-
-s_rtbuf_lib_proc_in g_rtbuf_signal_equalizer10_in[] = {
- { "signal", RTBUF_SIGNAL_TYPE, 0.0, -1.0, 1.0 },
- { "amp32", RTBUF_SIGNAL_TYPE, 1.0, 0.0, 2.0 },
- { "amp64", RTBUF_SIGNAL_TYPE, 1.0, 0.0, 2.0 },
- { "amp128", RTBUF_SIGNAL_TYPE, 1.0, 0.0, 2.0 },
- { "amp256", RTBUF_SIGNAL_TYPE, 1.0, 0.0, 2.0 },
- { "amp512", RTBUF_SIGNAL_TYPE, 1.0, 0.0, 2.0 },
- { "amp1k", RTBUF_SIGNAL_TYPE, 1.0, 0.0, 2.0 },
- { "amp2k", RTBUF_SIGNAL_TYPE, 1.0, 0.0, 2.0 },
- { "amp4k", RTBUF_SIGNAL_TYPE, 1.0, 0.0, 2.0 },
- { "amp8k", RTBUF_SIGNAL_TYPE, 1.0, 0.0, 2.0 },
- { "amp16k", RTBUF_SIGNAL_TYPE, 1.0, 0.0, 2.0 },
- { 0, 0, 0.0, 0.0, 0.0 } };
-
-s_rtbuf_lib_proc_out g_rtbuf_signal_equalizer10_out[] = {
- { "signal", RTBUF_SIGNAL_TYPE },
- { "signal32", RTBUF_SIGNAL_TYPE },
- { "signal64", RTBUF_SIGNAL_TYPE },
- { "signal128", RTBUF_SIGNAL_TYPE },
- { "signal256", RTBUF_SIGNAL_TYPE },
- { "signal512", RTBUF_SIGNAL_TYPE },
- { "signal1k", RTBUF_SIGNAL_TYPE },
- { "signal2k", RTBUF_SIGNAL_TYPE },
- { "signal4k", RTBUF_SIGNAL_TYPE },
- { "signal8k", RTBUF_SIGNAL_TYPE },
- { "signal16k", RTBUF_SIGNAL_TYPE },
- { "x1", RTBUF_SIGNAL_SAMPLE_TYPE },
- { "x2", RTBUF_SIGNAL_SAMPLE_TYPE },
- { "x3", RTBUF_SIGNAL_SAMPLE_TYPE },
- { "x4", RTBUF_SIGNAL_SAMPLE_TYPE },
- { "y0_1", RTBUF_SIGNAL_SAMPLE_TYPE },
- { "y0_2", RTBUF_SIGNAL_SAMPLE_TYPE },
- { "y0_3", RTBUF_SIGNAL_SAMPLE_TYPE },
- { "y0_4", RTBUF_SIGNAL_SAMPLE_TYPE },
- { "y1_1", RTBUF_SIGNAL_SAMPLE_TYPE },
- { "y1_2", RTBUF_SIGNAL_SAMPLE_TYPE },
- { "y1_3", RTBUF_SIGNAL_SAMPLE_TYPE },
- { "y1_4", RTBUF_SIGNAL_SAMPLE_TYPE },
- { "y2_1", RTBUF_SIGNAL_SAMPLE_TYPE },
- { "y2_2", RTBUF_SIGNAL_SAMPLE_TYPE },
- { "y2_3", RTBUF_SIGNAL_SAMPLE_TYPE },
- { "y2_4", RTBUF_SIGNAL_SAMPLE_TYPE },
- { "y3_1", RTBUF_SIGNAL_SAMPLE_TYPE },
- { "y3_2", RTBUF_SIGNAL_SAMPLE_TYPE },
- { "y3_3", RTBUF_SIGNAL_SAMPLE_TYPE },
- { "y3_4", RTBUF_SIGNAL_SAMPLE_TYPE },
- { "y4_1", RTBUF_SIGNAL_SAMPLE_TYPE },
- { "y4_2", RTBUF_SIGNAL_SAMPLE_TYPE },
- { "y4_3", RTBUF_SIGNAL_SAMPLE_TYPE },
- { "y4_4", RTBUF_SIGNAL_SAMPLE_TYPE },
- { "y5_1", RTBUF_SIGNAL_SAMPLE_TYPE },
- { "y5_2", RTBUF_SIGNAL_SAMPLE_TYPE },
- { "y5_3", RTBUF_SIGNAL_SAMPLE_TYPE },
- { "y5_4", RTBUF_SIGNAL_SAMPLE_TYPE },
- { "y6_1", RTBUF_SIGNAL_SAMPLE_TYPE },
- { "y6_2", RTBUF_SIGNAL_SAMPLE_TYPE },
- { "y6_3", RTBUF_SIGNAL_SAMPLE_TYPE },
- { "y6_4", RTBUF_SIGNAL_SAMPLE_TYPE },
- { "y7_1", RTBUF_SIGNAL_SAMPLE_TYPE },
- { "y7_2", RTBUF_SIGNAL_SAMPLE_TYPE },
- { "y7_3", RTBUF_SIGNAL_SAMPLE_TYPE },
- { "y7_4", RTBUF_SIGNAL_SAMPLE_TYPE },
- { "y8_1", RTBUF_SIGNAL_SAMPLE_TYPE },
- { "y8_2", RTBUF_SIGNAL_SAMPLE_TYPE },
- { "y8_3", RTBUF_SIGNAL_SAMPLE_TYPE },
- { "y8_4", RTBUF_SIGNAL_SAMPLE_TYPE },
- { "y9_1", RTBUF_SIGNAL_SAMPLE_TYPE },
- { "y9_2", RTBUF_SIGNAL_SAMPLE_TYPE },
- { "y9_3", RTBUF_SIGNAL_SAMPLE_TYPE },
- { "y9_4", RTBUF_SIGNAL_SAMPLE_TYPE },
- { 0, 0 } };
-
-s_rtbuf_lib_proc_in g_rtbuf_signal_flanger_in[] = {
- { "signal", RTBUF_SIGNAL_TYPE, 0.0, -1.0, 1.0 },
- { "frequency", RTBUF_SIGNAL_TYPE, 0.5, 0.0, RTBUF_SIGNAL_SAMPLERATE / 2.0 },
- { "amplitude", RTBUF_SIGNAL_TYPE, 0.02, 0.0, 1.0 },
- { "delay", RTBUF_SIGNAL_TYPE, 0.0001, 0.0, 1.0 },
- { "feedback", RTBUF_SIGNAL_TYPE, 0.01, 0.0, 1.0 },
- { 0, 0, 0.0, 0.0, 0.0 } };
-
-s_rtbuf_lib_proc_out g_rtbuf_signal_flanger_out[] = {
- { "signal", RTBUF_SIGNAL_TYPE },
- { "phase", "double" },
- { "in", RTBUF_SIGNAL_FLANGER_TYPE },
- { "pos", "unsigned int" },
- { "ds", "unsigned int" },
- { 0, 0 } };
-
-s_rtbuf_lib_proc_in g_rtbuf_signal_hipass_in[] = {
- { "signal", RTBUF_SIGNAL_TYPE, 0.0, -1.0, 1.0 },
- { "cutoff", RTBUF_SIGNAL_TYPE, 8000.0, 0.0, RTBUF_SIGNAL_SAMPLERATE / 2.0 },
- { 0, 0, 0.0, 0.0, 0.0 } };
-
-s_rtbuf_lib_proc_out g_rtbuf_signal_hipass_out[] = {
- { "signal", RTBUF_SIGNAL_TYPE },
- { "x", RTBUF_SIGNAL_SAMPLE_TYPE },
- { "y", RTBUF_SIGNAL_SAMPLE_TYPE },
- { 0, 0 } };
-
-s_rtbuf_lib_proc_in g_rtbuf_signal_hipass2_in[] = {
- { "signal", RTBUF_SIGNAL_TYPE, 0.0, -1.0, 1.0 },
- { "cutoff", RTBUF_SIGNAL_TYPE, 8000.0, 0.0, RTBUF_SIGNAL_SAMPLERATE / 2.0 },
- { 0, 0, 0.0, 0.0, 0.0 } };
-
-s_rtbuf_lib_proc_out g_rtbuf_signal_hipass2_out[] = {
- { "signal", RTBUF_SIGNAL_TYPE },
- { "x1", RTBUF_SIGNAL_SAMPLE_TYPE },
- { "x2", RTBUF_SIGNAL_SAMPLE_TYPE },
- { "y1", RTBUF_SIGNAL_SAMPLE_TYPE },
- { "y2", RTBUF_SIGNAL_SAMPLE_TYPE },
- { 0, 0 } };
-
-s_rtbuf_lib_proc_in g_rtbuf_signal_hipass3_in[] = {
- { "signal", RTBUF_SIGNAL_TYPE, 0.0, -1.0, 1.0 },
- { "cutoff", RTBUF_SIGNAL_TYPE, 8000.0, 0.0, RTBUF_SIGNAL_SAMPLERATE / 2.0 },
- { 0, 0, 0.0, 0.0, 0.0 } };
-
-s_rtbuf_lib_proc_out g_rtbuf_signal_hipass3_out[] = {
- { "signal", RTBUF_SIGNAL_TYPE },
- { "x1", RTBUF_SIGNAL_SAMPLE_TYPE },
- { "x2", RTBUF_SIGNAL_SAMPLE_TYPE },
- { "x3", RTBUF_SIGNAL_SAMPLE_TYPE },
- { "y1", RTBUF_SIGNAL_SAMPLE_TYPE },
- { "y2", RTBUF_SIGNAL_SAMPLE_TYPE },
- { "y3", RTBUF_SIGNAL_SAMPLE_TYPE },
- { 0, 0 } };
-
-s_rtbuf_lib_proc_in g_rtbuf_signal_hipass4_in[] = {
- { "signal", RTBUF_SIGNAL_TYPE, 0.0, -1.0, 1.0 },
- { "cutoff", RTBUF_SIGNAL_TYPE, 8000.0, 0.0, RTBUF_SIGNAL_SAMPLERATE / 2.0 },
- { 0, 0, 0.0, 0.0, 0.0 } };
-
-s_rtbuf_lib_proc_out g_rtbuf_signal_hipass4_out[] = {
- { "signal", RTBUF_SIGNAL_TYPE },
- { "x1", RTBUF_SIGNAL_SAMPLE_TYPE },
- { "x2", RTBUF_SIGNAL_SAMPLE_TYPE },
- { "x3", RTBUF_SIGNAL_SAMPLE_TYPE },
- { "x4", RTBUF_SIGNAL_SAMPLE_TYPE },
- { "y1", RTBUF_SIGNAL_SAMPLE_TYPE },
- { "y2", RTBUF_SIGNAL_SAMPLE_TYPE },
- { "y3", RTBUF_SIGNAL_SAMPLE_TYPE },
- { "y4", RTBUF_SIGNAL_SAMPLE_TYPE },
- { 0, 0 } };
-
-s_rtbuf_lib_proc_in g_rtbuf_signal_hipass5_in[] = {
- { "signal", RTBUF_SIGNAL_TYPE, 0.0, -1.0, 1.0 },
- { "cutoff", RTBUF_SIGNAL_TYPE, 400.0, 0.0, RTBUF_SIGNAL_SAMPLERATE / 2.0 },
- { 0, 0, 0.0, 0.0, 0.0 } };
-
-s_rtbuf_lib_proc_out g_rtbuf_signal_hipass5_out[] = {
- { "signal", RTBUF_SIGNAL_TYPE },
- { "x1", RTBUF_SIGNAL_SAMPLE_TYPE },
- { "x2", RTBUF_SIGNAL_SAMPLE_TYPE },
- { "x3", RTBUF_SIGNAL_SAMPLE_TYPE },
- { "x4", RTBUF_SIGNAL_SAMPLE_TYPE },
- { "x5", RTBUF_SIGNAL_SAMPLE_TYPE },
- { "y1", RTBUF_SIGNAL_SAMPLE_TYPE },
- { "y2", RTBUF_SIGNAL_SAMPLE_TYPE },
- { "y3", RTBUF_SIGNAL_SAMPLE_TYPE },
- { "y4", RTBUF_SIGNAL_SAMPLE_TYPE },
- { "y5", RTBUF_SIGNAL_SAMPLE_TYPE },
- { 0, 0 } };
-
-s_rtbuf_lib_proc_in g_rtbuf_signal_lowpass_in[] = {
- { "signal", RTBUF_SIGNAL_TYPE, 0.0, -1.0, 1.0 },
- { "cutoff", RTBUF_SIGNAL_TYPE, 400.0, 0.0, RTBUF_SIGNAL_SAMPLERATE / 2.0 },
- { 0, 0, 0.0, 0.0, 0.0 } };
-
-s_rtbuf_lib_proc_out g_rtbuf_signal_lowpass_out[] = {
- { "signal", RTBUF_SIGNAL_TYPE },
- { "x", RTBUF_SIGNAL_SAMPLE_TYPE },
- { "y", RTBUF_SIGNAL_SAMPLE_TYPE },
- { 0, 0 } };
-
-s_rtbuf_lib_proc_in g_rtbuf_signal_lowpass2_in[] = {
- { "signal", RTBUF_SIGNAL_TYPE, 0.0, -1.0, 1.0 },
- { "cutoff", RTBUF_SIGNAL_TYPE, 400.0, 0.0, RTBUF_SIGNAL_SAMPLERATE / 2.0 },
- { 0, 0, 0.0, 0.0, 0.0 } };
-
-s_rtbuf_lib_proc_out g_rtbuf_signal_lowpass2_out[] = {
- { "signal", RTBUF_SIGNAL_TYPE },
- { "x1", RTBUF_SIGNAL_SAMPLE_TYPE },
- { "x2", RTBUF_SIGNAL_SAMPLE_TYPE },
- { "y1", RTBUF_SIGNAL_SAMPLE_TYPE },
- { "y2", RTBUF_SIGNAL_SAMPLE_TYPE },
- { 0, 0 } };
-
-s_rtbuf_lib_proc_in g_rtbuf_signal_lowpass3_in[] = {
- { "signal", RTBUF_SIGNAL_TYPE, 0.0, -1.0, 1.0 },
- { "cutoff", RTBUF_SIGNAL_TYPE, 400.0, 0.0, RTBUF_SIGNAL_SAMPLERATE / 2.0 },
- { 0, 0, 0.0, 0.0, 0.0 } };
-
-s_rtbuf_lib_proc_out g_rtbuf_signal_lowpass3_out[] = {
- { "signal", RTBUF_SIGNAL_TYPE },
- { "x1", RTBUF_SIGNAL_SAMPLE_TYPE },
- { "x2", RTBUF_SIGNAL_SAMPLE_TYPE },
- { "x3", RTBUF_SIGNAL_SAMPLE_TYPE },
- { "y1", RTBUF_SIGNAL_SAMPLE_TYPE },
- { "y2", RTBUF_SIGNAL_SAMPLE_TYPE },
- { "y3", RTBUF_SIGNAL_SAMPLE_TYPE },
- { 0, 0 } };
-
-s_rtbuf_lib_proc_in g_rtbuf_signal_lowpass4_in[] = {
- { "signal", RTBUF_SIGNAL_TYPE, 0.0, -1.0, 1.0 },
- { "cutoff", RTBUF_SIGNAL_TYPE, 400.0, 0.0, RTBUF_SIGNAL_SAMPLERATE / 2.0 },
- { 0, 0, 0.0, 0.0, 0.0 } };
-
-s_rtbuf_lib_proc_out g_rtbuf_signal_lowpass4_out[] = {
- { "signal", RTBUF_SIGNAL_TYPE },
- { "x1", RTBUF_SIGNAL_SAMPLE_TYPE },
- { "x2", RTBUF_SIGNAL_SAMPLE_TYPE },
- { "x3", RTBUF_SIGNAL_SAMPLE_TYPE },
- { "x4", RTBUF_SIGNAL_SAMPLE_TYPE },
- { "y1", RTBUF_SIGNAL_SAMPLE_TYPE },
- { "y2", RTBUF_SIGNAL_SAMPLE_TYPE },
- { "y3", RTBUF_SIGNAL_SAMPLE_TYPE },
- { "y4", RTBUF_SIGNAL_SAMPLE_TYPE },
- { 0, 0 } };
-
-s_rtbuf_lib_proc_in g_rtbuf_signal_lowpass5_in[] = {
- { "signal", RTBUF_SIGNAL_TYPE, 0.0, -1.0, 1.0 },
- { "cutoff", RTBUF_SIGNAL_TYPE, 400.0, 0.0, RTBUF_SIGNAL_SAMPLERATE / 2.0 },
- { 0, 0, 0.0, 0.0, 0.0 } };
-
-s_rtbuf_lib_proc_out g_rtbuf_signal_lowpass5_out[] = {
- { "signal", RTBUF_SIGNAL_TYPE },
- { "x1", RTBUF_SIGNAL_SAMPLE_TYPE },
- { "x2", RTBUF_SIGNAL_SAMPLE_TYPE },
- { "x3", RTBUF_SIGNAL_SAMPLE_TYPE },
- { "x4", RTBUF_SIGNAL_SAMPLE_TYPE },
- { "x5", RTBUF_SIGNAL_SAMPLE_TYPE },
- { "y1", RTBUF_SIGNAL_SAMPLE_TYPE },
- { "y2", RTBUF_SIGNAL_SAMPLE_TYPE },
- { "y3", RTBUF_SIGNAL_SAMPLE_TYPE },
- { "y4", RTBUF_SIGNAL_SAMPLE_TYPE },
- { "y5", RTBUF_SIGNAL_SAMPLE_TYPE },
- { 0, 0 } };
-
-s_rtbuf_lib_proc_in g_rtbuf_signal_sawtooth_in[] = {
- { "frequency", RTBUF_SIGNAL_TYPE, 220.0, 0.0, RTBUF_SIGNAL_SAMPLERATE / 2.0 },
- { "amplitude", RTBUF_SIGNAL_TYPE, 1.0, 0.0, 1.0 },
- { 0, 0, 0.0, 0.0, 0.0 } };
-
-s_rtbuf_lib_proc_out g_rtbuf_signal_sawtooth_out[] = {
- { "signal", RTBUF_SIGNAL_TYPE },
- { "phase", "double" },
- { 0, 0 } };
-
-s_rtbuf_lib_proc_in g_rtbuf_signal_sinus_in[] = {
- { "frequency", RTBUF_SIGNAL_TYPE, 220.0, 0.0, RTBUF_SIGNAL_SAMPLERATE / 2.0 },
- { "amplitude", RTBUF_SIGNAL_TYPE, 1.0, 0.0, 1.0 },
- { 0, 0, 0.0, 0.0, 0.0 } };
-
-s_rtbuf_lib_proc_out g_rtbuf_signal_sinus_out[] = {
- { "signal", RTBUF_SIGNAL_TYPE },
- { "phase", "double" },
- { 0, 0 } };
-
-s_rtbuf_lib_proc_in g_rtbuf_signal_square_in[] = {
- { "frequency", RTBUF_SIGNAL_TYPE, 220.0, 0.0, RTBUF_SIGNAL_SAMPLERATE / 2.0 },
- { "amplitude", RTBUF_SIGNAL_TYPE, 1.0, 0.0, 1.0 },
- { "pulse", RTBUF_SIGNAL_TYPE, 0.5, 0.0, 1.0 },
- { 0, 0, 0.0, 0.0, 0.0 } };
-
-s_rtbuf_lib_proc_out g_rtbuf_signal_square_out[] = {
- { "signal", RTBUF_SIGNAL_TYPE },
- { "phase", "double" },
- { 0, 0 } };
-
-const char *rtbuf_lib_name = "signal";
-unsigned long rtbuf_lib_ver = RTBUF_LIB_VER;
-s_rtbuf_lib_proc rtbuf_lib_proc[] = {
- { "bandpass2", rtbuf_signal_bandpass2, rtbuf_signal_bandpass2_start, 0,
- g_rtbuf_signal_bandpass2_in, g_rtbuf_signal_bandpass2_out },
- { "delay", rtbuf_signal_delay, rtbuf_signal_delay_start, 0,
- g_rtbuf_signal_delay_in, g_rtbuf_signal_delay_out },
- { "equalizer10", rtbuf_signal_equalizer10, rtbuf_signal_equalizer10_start, 0,
- g_rtbuf_signal_equalizer10_in, g_rtbuf_signal_equalizer10_out },
- { "flanger", rtbuf_signal_flanger, rtbuf_signal_flanger_start, 0,
- g_rtbuf_signal_flanger_in, g_rtbuf_signal_flanger_out },
- { "hipass", rtbuf_signal_hipass, rtbuf_signal_hipass_start, 0,
- g_rtbuf_signal_hipass_in, g_rtbuf_signal_hipass_out },
- { "hipass2", rtbuf_signal_hipass2, rtbuf_signal_hipass2_start, 0,
- g_rtbuf_signal_hipass2_in, g_rtbuf_signal_hipass2_out },
- { "hipass3", rtbuf_signal_hipass3, rtbuf_signal_hipass3_start, 0,
- g_rtbuf_signal_hipass3_in, g_rtbuf_signal_hipass3_out },
- { "hipass4", rtbuf_signal_hipass4, rtbuf_signal_hipass4_start, 0,
- g_rtbuf_signal_hipass4_in, g_rtbuf_signal_hipass4_out },
- { "hipass5", rtbuf_signal_hipass5, rtbuf_signal_hipass5_start, 0,
- g_rtbuf_signal_hipass5_in, g_rtbuf_signal_hipass5_out },
- { "lowpass", rtbuf_signal_lowpass, rtbuf_signal_lowpass_start, 0,
- g_rtbuf_signal_lowpass_in, g_rtbuf_signal_lowpass_out },
- { "lowpass2", rtbuf_signal_lowpass2, rtbuf_signal_lowpass2_start, 0,
- g_rtbuf_signal_lowpass2_in, g_rtbuf_signal_lowpass2_out },
- { "lowpass3", rtbuf_signal_lowpass3, rtbuf_signal_lowpass3_start, 0,
- g_rtbuf_signal_lowpass3_in, g_rtbuf_signal_lowpass3_out },
- { "lowpass4", rtbuf_signal_lowpass4, rtbuf_signal_lowpass4_start, 0,
- g_rtbuf_signal_lowpass4_in, g_rtbuf_signal_lowpass4_out },
- { "lowpass5", rtbuf_signal_lowpass5, rtbuf_signal_lowpass5_start, 0,
- g_rtbuf_signal_lowpass5_in, g_rtbuf_signal_lowpass5_out },
- { "sawtooth", rtbuf_signal_sawtooth, rtbuf_signal_sawtooth_start, 0,
- g_rtbuf_signal_sawtooth_in, g_rtbuf_signal_sawtooth_out },
- { "sinus", rtbuf_signal_sinus, rtbuf_signal_sinus_start, 0,
- g_rtbuf_signal_sinus_in, g_rtbuf_signal_sinus_out },
- { "square", rtbuf_signal_square, rtbuf_signal_square_start, 0,
- g_rtbuf_signal_square_in, g_rtbuf_signal_square_out },
- { 0, 0, 0, 0, 0, 0 } };
-
void rtbuf_signal_zero (t_rtbuf_signal_sample *signal)
{
assert(signal);
diff --git a/lib/signal/Makefile.am b/lib/signal/Makefile.am
index 60866e9..a9c24ba 100644
--- a/lib/signal/Makefile.am
+++ b/lib/signal/Makefile.am
@@ -7,68 +7,68 @@ rtbuf_lib_LTLIBRARIES =
rtbuf_lib_LTLIBRARIES += bandpass2.la
bandpass2_la_LDFLAGS = -no-undefined -module -shared
-bandpass2_la_LIBADD = ${SIGNAL_LIBS} ../librtbuf_signal.la
+bandpass2_la_LIBADD = ../librtbuf_signal.la
rtbuf_lib_LTLIBRARIES += delay.la
delay_la_LDFLAGS = -no-undefined -module
-delay_la_LIBADD = ${SIGNAL_LIBS} ../librtbuf_signal.la
+delay_la_LIBADD = ../librtbuf_signal.la
rtbuf_lib_LTLIBRARIES += equalizer10.la
equalizer10_la_LDFLAGS = -no-undefined -module
-equalizer10_la_LIBADD = ${SIGNAL_LIBS} ../librtbuf_signal.la
+equalizer10_la_LIBADD = ../librtbuf_signal.la
rtbuf_lib_LTLIBRARIES += flanger.la
flanger_la_LDFLAGS = -no-undefined -module
-flanger_la_LIBADD = ${SIGNAL_LIBS} ../librtbuf_signal.la
+flanger_la_LIBADD = ../librtbuf_signal.la
rtbuf_lib_LTLIBRARIES += hipass.la
hipass_la_LDFLAGS = -no-undefined -module
-hipass_la_LIBADD = ${SIGNAL_LIBS} ../librtbuf_signal.la
+hipass_la_LIBADD = ../librtbuf_signal.la
rtbuf_lib_LTLIBRARIES += hipass2.la
hipass2_la_LDFLAGS = -no-undefined -module
-hipass2_la_LIBADD = ${SIGNAL_LIBS} ../librtbuf_signal.la
+hipass2_la_LIBADD = ../librtbuf_signal.la
rtbuf_lib_LTLIBRARIES += hipass3.la
hipass3_la_LDFLAGS = -no-undefined -module
-hipass3_la_LIBADD = ${SIGNAL_LIBS} ../librtbuf_signal.la
+hipass3_la_LIBADD = ../librtbuf_signal.la
rtbuf_lib_LTLIBRARIES += hipass4.la
hipass4_la_LDFLAGS = -no-undefined -module
-hipass4_la_LIBADD = ${SIGNAL_LIBS} ../librtbuf_signal.la
+hipass4_la_LIBADD = ../librtbuf_signal.la
rtbuf_lib_LTLIBRARIES += hipass5.la
hipass5_la_LDFLAGS = -no-undefined -module
-hipass5_la_LIBADD = ${SIGNAL_LIBS} ../librtbuf_signal.la
+hipass5_la_LIBADD = ../librtbuf_signal.la
rtbuf_lib_LTLIBRARIES += lowpass.la
lowpass_la_LDFLAGS = -no-undefined -module
-lowpass_la_LIBADD = ${SIGNAL_LIBS} ../librtbuf_signal.la
+lowpass_la_LIBADD = ../librtbuf_signal.la
rtbuf_lib_LTLIBRARIES += lowpass2.la
lowpass2_la_LDFLAGS = -no-undefined -module
-lowpass2_la_LIBADD = ${SIGNAL_LIBS} ../librtbuf_signal.la
+lowpass2_la_LIBADD = ../librtbuf_signal.la
rtbuf_lib_LTLIBRARIES += lowpass3.la
lowpass3_la_LDFLAGS = -no-undefined -module
-lowpass3_la_LIBADD = ${SIGNAL_LIBS} ../librtbuf_signal.la
+lowpass3_la_LIBADD = ../librtbuf_signal.la
rtbuf_lib_LTLIBRARIES += lowpass4.la
lowpass4_la_LDFLAGS = -no-undefined -module
-lowpass4_la_LIBADD = ${SIGNAL_LIBS} ../librtbuf_signal.la
+lowpass4_la_LIBADD = ../librtbuf_signal.la
rtbuf_lib_LTLIBRARIES += lowpass5.la
lowpass5_la_LDFLAGS = -no-undefined -module
-lowpass5_la_LIBADD = ${SIGNAL_LIBS} ../librtbuf_signal.la
+lowpass5_la_LIBADD = ../librtbuf_signal.la
rtbuf_lib_LTLIBRARIES += sawtooth.la
sawtooth_la_LDFLAGS = -no-undefined -module
-sawtooth_la_LIBADD = ${SIGNAL_LIBS} ../librtbuf_signal.la
+sawtooth_la_LIBADD = ../librtbuf_signal.la
rtbuf_lib_LTLIBRARIES += sinus.la
sinus_la_LDFLAGS = -no-undefined -module
-sinus_la_LIBADD = ${SIGNAL_LIBS} ../librtbuf_signal.la
+sinus_la_LIBADD = ../librtbuf_signal.la
rtbuf_lib_LTLIBRARIES += square.la
square_la_LDFLAGS = -no-undefined -module
-square_la_LIBADD = ${SIGNAL_LIBS} ../librtbuf_signal.la
+square_la_LIBADD = ../librtbuf_signal.la
diff --git a/lib/signal/delay.c b/lib/signal/delay.c
index 202af98..4bed8b7 100644
--- a/lib/signal/delay.c
+++ b/lib/signal/delay.c
@@ -17,7 +17,21 @@
#include <stdio.h>
#include <strings.h>
#include <rtbuf/rtbuf.h>
+#include <rtbuf/lib.h>
#include <rtbuf/signal.h>
+#include <rtbuf/signal_type.h>
+
+s_rtbuf_lib_proc_in rtbuf_signal_delay_in[] = {
+ { "signal", RTBUF_SIGNAL_TYPE, 0.0, -1.0, 1.0 },
+ { "delay", RTBUF_SIGNAL_TYPE, 0.4, 0.0, RTBUF_SIGNAL_DELAY_MAX },
+ { "feedback", RTBUF_SIGNAL_TYPE, 0.5, 0.0, 1.0 },
+ { 0, 0, 0.0, 0.0, 0.0 } };
+
+s_rtbuf_lib_proc_out rtbuf_signal_delay_out[] = {
+ { "signal", RTBUF_SIGNAL_TYPE },
+ { "in", RTBUF_SIGNAL_DELAY_TYPE },
+ { "pos", "unsigned int" },
+ { 0, 0 } };
int rtbuf_signal_delay_start (s_rtbuf *rtb)
{
@@ -55,3 +69,13 @@ int rtbuf_signal_delay (s_rtbuf *rtb)
}
return 0;
}
+
+s_rtbuf_lib_proc rtbuf_lib_proc =
+ { "delay",
+ rtbuf_signal_delay,
+ rtbuf_signal_delay_start,
+ 0,
+ rtbuf_signal_delay_in,
+ rtbuf_signal_delay_out };
+
+unsigned long rtbuf_lib_ver = RTBUF_LIB_VER;
diff --git a/lib/signal/equalizer10.c b/lib/signal/equalizer10.c
index 8aa54b8..5baf3c1 100644
--- a/lib/signal/equalizer10.c
+++ b/lib/signal/equalizer10.c
@@ -52,7 +52,81 @@ q: 2
*/
#include <math.h>
#include <rtbuf/rtbuf.h>
+#include <rtbuf/lib.h>
#include <rtbuf/signal.h>
+#include <rtbuf/signal_type.h>
+
+s_rtbuf_lib_proc_in rtbuf_signal_equalizer10_in[] = {
+ { "signal", RTBUF_SIGNAL_TYPE, 0.0, -1.0, 1.0 },
+ { "amp32", RTBUF_SIGNAL_TYPE, 1.0, 0.0, 2.0 },
+ { "amp64", RTBUF_SIGNAL_TYPE, 1.0, 0.0, 2.0 },
+ { "amp128", RTBUF_SIGNAL_TYPE, 1.0, 0.0, 2.0 },
+ { "amp256", RTBUF_SIGNAL_TYPE, 1.0, 0.0, 2.0 },
+ { "amp512", RTBUF_SIGNAL_TYPE, 1.0, 0.0, 2.0 },
+ { "amp1k", RTBUF_SIGNAL_TYPE, 1.0, 0.0, 2.0 },
+ { "amp2k", RTBUF_SIGNAL_TYPE, 1.0, 0.0, 2.0 },
+ { "amp4k", RTBUF_SIGNAL_TYPE, 1.0, 0.0, 2.0 },
+ { "amp8k", RTBUF_SIGNAL_TYPE, 1.0, 0.0, 2.0 },
+ { "amp16k", RTBUF_SIGNAL_TYPE, 1.0, 0.0, 2.0 },
+ { 0, 0, 0.0, 0.0, 0.0 } };
+
+s_rtbuf_lib_proc_out rtbuf_signal_equalizer10_out[] = {
+ { "signal", RTBUF_SIGNAL_TYPE },
+ { "signal32", RTBUF_SIGNAL_TYPE },
+ { "signal64", RTBUF_SIGNAL_TYPE },
+ { "signal128", RTBUF_SIGNAL_TYPE },
+ { "signal256", RTBUF_SIGNAL_TYPE },
+ { "signal512", RTBUF_SIGNAL_TYPE },
+ { "signal1k", RTBUF_SIGNAL_TYPE },
+ { "signal2k", RTBUF_SIGNAL_TYPE },
+ { "signal4k", RTBUF_SIGNAL_TYPE },
+ { "signal8k", RTBUF_SIGNAL_TYPE },
+ { "signal16k", RTBUF_SIGNAL_TYPE },
+ { "x1", RTBUF_SIGNAL_SAMPLE_TYPE },
+ { "x2", RTBUF_SIGNAL_SAMPLE_TYPE },
+ { "x3", RTBUF_SIGNAL_SAMPLE_TYPE },
+ { "x4", RTBUF_SIGNAL_SAMPLE_TYPE },
+ { "y0_1", RTBUF_SIGNAL_SAMPLE_TYPE },
+ { "y0_2", RTBUF_SIGNAL_SAMPLE_TYPE },
+ { "y0_3", RTBUF_SIGNAL_SAMPLE_TYPE },
+ { "y0_4", RTBUF_SIGNAL_SAMPLE_TYPE },
+ { "y1_1", RTBUF_SIGNAL_SAMPLE_TYPE },
+ { "y1_2", RTBUF_SIGNAL_SAMPLE_TYPE },
+ { "y1_3", RTBUF_SIGNAL_SAMPLE_TYPE },
+ { "y1_4", RTBUF_SIGNAL_SAMPLE_TYPE },
+ { "y2_1", RTBUF_SIGNAL_SAMPLE_TYPE },
+ { "y2_2", RTBUF_SIGNAL_SAMPLE_TYPE },
+ { "y2_3", RTBUF_SIGNAL_SAMPLE_TYPE },
+ { "y2_4", RTBUF_SIGNAL_SAMPLE_TYPE },
+ { "y3_1", RTBUF_SIGNAL_SAMPLE_TYPE },
+ { "y3_2", RTBUF_SIGNAL_SAMPLE_TYPE },
+ { "y3_3", RTBUF_SIGNAL_SAMPLE_TYPE },
+ { "y3_4", RTBUF_SIGNAL_SAMPLE_TYPE },
+ { "y4_1", RTBUF_SIGNAL_SAMPLE_TYPE },
+ { "y4_2", RTBUF_SIGNAL_SAMPLE_TYPE },
+ { "y4_3", RTBUF_SIGNAL_SAMPLE_TYPE },
+ { "y4_4", RTBUF_SIGNAL_SAMPLE_TYPE },
+ { "y5_1", RTBUF_SIGNAL_SAMPLE_TYPE },
+ { "y5_2", RTBUF_SIGNAL_SAMPLE_TYPE },
+ { "y5_3", RTBUF_SIGNAL_SAMPLE_TYPE },
+ { "y5_4", RTBUF_SIGNAL_SAMPLE_TYPE },
+ { "y6_1", RTBUF_SIGNAL_SAMPLE_TYPE },
+ { "y6_2", RTBUF_SIGNAL_SAMPLE_TYPE },
+ { "y6_3", RTBUF_SIGNAL_SAMPLE_TYPE },
+ { "y6_4", RTBUF_SIGNAL_SAMPLE_TYPE },
+ { "y7_1", RTBUF_SIGNAL_SAMPLE_TYPE },
+ { "y7_2", RTBUF_SIGNAL_SAMPLE_TYPE },
+ { "y7_3", RTBUF_SIGNAL_SAMPLE_TYPE },
+ { "y7_4", RTBUF_SIGNAL_SAMPLE_TYPE },
+ { "y8_1", RTBUF_SIGNAL_SAMPLE_TYPE },
+ { "y8_2", RTBUF_SIGNAL_SAMPLE_TYPE },
+ { "y8_3", RTBUF_SIGNAL_SAMPLE_TYPE },
+ { "y8_4", RTBUF_SIGNAL_SAMPLE_TYPE },
+ { "y9_1", RTBUF_SIGNAL_SAMPLE_TYPE },
+ { "y9_2", RTBUF_SIGNAL_SAMPLE_TYPE },
+ { "y9_3", RTBUF_SIGNAL_SAMPLE_TYPE },
+ { "y9_4", RTBUF_SIGNAL_SAMPLE_TYPE },
+ { 0, 0 } };
double sqrt2_3 = 0.0;
double sqrt2_5;
@@ -301,3 +375,13 @@ int rtbuf_signal_equalizer10 (s_rtbuf *rtb)
}
return 0;
}
+
+s_rtbuf_lib_proc rtbuf_lib_proc =
+ { "equalizer10",
+ rtbuf_signal_equalizer10,
+ rtbuf_signal_equalizer10_start,
+ 0,
+ rtbuf_signal_equalizer10_in,
+ rtbuf_signal_equalizer10_out };
+
+unsigned long rtbuf_lib_ver = RTBUF_LIB_VER;
diff --git a/lib/signal/flanger.c b/lib/signal/flanger.c
index da103f4..490ead4 100644
--- a/lib/signal/flanger.c
+++ b/lib/signal/flanger.c
@@ -20,7 +20,25 @@
#include <string.h>
#include <strings.h>
#include <rtbuf/rtbuf.h>
+#include <rtbuf/lib.h>
#include <rtbuf/signal.h>
+#include <rtbuf/signal_type.h>
+
+s_rtbuf_lib_proc_in rtbuf_signal_flanger_in[] = {
+ { "signal", RTBUF_SIGNAL_TYPE, 0.0, -1.0, 1.0 },
+ { "frequency", RTBUF_SIGNAL_TYPE, 0.5, 0.0, RTBUF_SIGNAL_SAMPLERATE / 2.0 },
+ { "amplitude", RTBUF_SIGNAL_TYPE, 0.02, 0.0, 1.0 },
+ { "delay", RTBUF_SIGNAL_TYPE, 0.0001, 0.0, 1.0 },
+ { "feedback", RTBUF_SIGNAL_TYPE, 0.01, 0.0, 1.0 },
+ { 0, 0, 0.0, 0.0, 0.0 } };
+
+s_rtbuf_lib_proc_out rtbuf_signal_flanger_out[] = {
+ { "signal", RTBUF_SIGNAL_TYPE },
+ { "phase", "double" },
+ { "in", RTBUF_SIGNAL_FLANGER_TYPE },
+ { "pos", "unsigned int" },
+ { "ds", "unsigned int" },
+ { 0, 0 } };
int rtbuf_signal_flanger_start (s_rtbuf *rtb)
{
@@ -73,3 +91,13 @@ int rtbuf_signal_flanger (s_rtbuf *rtb)
}
return 0;
}
+
+s_rtbuf_lib_proc rtbuf_lib_proc =
+ { "flanger",
+ rtbuf_signal_flanger,
+ rtbuf_signal_flanger_start,
+ 0,
+ rtbuf_signal_flanger_in,
+ rtbuf_signal_flanger_out };
+
+unsigned long rtbuf_lib_ver = RTBUF_LIB_VER;
diff --git a/lib/signal/hipass.c b/lib/signal/hipass.c
index 2f2a3a3..d34595e 100644
--- a/lib/signal/hipass.c
+++ b/lib/signal/hipass.c
@@ -16,7 +16,20 @@
#include <math.h>
#include <rtbuf/rtbuf.h>
+#include <rtbuf/lib.h>
#include <rtbuf/signal.h>
+#include <rtbuf/signal_type.h>
+
+s_rtbuf_lib_proc_in rtbuf_signal_hipass_in[] = {
+ { "signal", RTBUF_SIGNAL_TYPE, 0.0, -1.0, 1.0 },
+ { "cutoff", RTBUF_SIGNAL_TYPE, 8000.0, 0.0, RTBUF_SIGNAL_SAMPLERATE / 2.0 },
+ { 0, 0, 0.0, 0.0, 0.0 } };
+
+s_rtbuf_lib_proc_out rtbuf_signal_hipass_out[] = {
+ { "signal", RTBUF_SIGNAL_TYPE },
+ { "x", RTBUF_SIGNAL_SAMPLE_TYPE },
+ { "y", RTBUF_SIGNAL_SAMPLE_TYPE },
+ { 0, 0 } };
int rtbuf_signal_hipass_start (s_rtbuf *rtb)
{
@@ -49,3 +62,13 @@ int rtbuf_signal_hipass (s_rtbuf *rtb)
}
return 0;
}
+
+s_rtbuf_lib_proc rtbuf_lib_proc =
+ { "hipass",
+ rtbuf_signal_hipass,
+ rtbuf_signal_hipass_start,
+ 0,
+ rtbuf_signal_hipass_in,
+ rtbuf_signal_hipass_out };
+
+unsigned long rtbuf_lib_ver = RTBUF_LIB_VER;
diff --git a/lib/signal/hipass2.c b/lib/signal/hipass2.c
index 3ac072a..55116c5 100644
--- a/lib/signal/hipass2.c
+++ b/lib/signal/hipass2.c
@@ -16,7 +16,22 @@
#include <math.h>
#include <rtbuf/rtbuf.h>
+#include <rtbuf/lib.h>
#include <rtbuf/signal.h>
+#include <rtbuf/signal_type.h>
+
+s_rtbuf_lib_proc_in rtbuf_signal_hipass2_in[] = {
+ { "signal", RTBUF_SIGNAL_TYPE, 0.0, -1.0, 1.0 },
+ { "cutoff", RTBUF_SIGNAL_TYPE, 8000.0, 0.0, RTBUF_SIGNAL_SAMPLERATE / 2.0 },
+ { 0, 0, 0.0, 0.0, 0.0 } };
+
+s_rtbuf_lib_proc_out rtbuf_signal_hipass2_out[] = {
+ { "signal", RTBUF_SIGNAL_TYPE },
+ { "x1", RTBUF_SIGNAL_SAMPLE_TYPE },
+ { "x2", RTBUF_SIGNAL_SAMPLE_TYPE },
+ { "y1", RTBUF_SIGNAL_SAMPLE_TYPE },
+ { "y2", RTBUF_SIGNAL_SAMPLE_TYPE },
+ { 0, 0 } };
int rtbuf_signal_hipass2_start (s_rtbuf *rtb)
{
@@ -61,3 +76,13 @@ int rtbuf_signal_hipass2 (s_rtbuf *rtb)
}
return 0;
}
+
+s_rtbuf_lib_proc rtbuf_lib_proc =
+ { "hipass2",
+ rtbuf_signal_hipass2,
+ rtbuf_signal_hipass2_start,
+ 0,
+ rtbuf_signal_hipass2_in,
+ rtbuf_signal_hipass2_out };
+
+unsigned long rtbuf_lib_ver = RTBUF_LIB_VER;
diff --git a/lib/signal/hipass3.c b/lib/signal/hipass3.c
index 6bd2907..a5c743a 100644
--- a/lib/signal/hipass3.c
+++ b/lib/signal/hipass3.c
@@ -42,7 +42,24 @@ y: (8 F³ ((x - x3) + 3 (x2 - x1)) - (a y3 + b y2 + c y1)) / d
*/
#include <math.h>
#include <rtbuf/rtbuf.h>
+#include <rtbuf/lib.h>
#include <rtbuf/signal.h>
+#include <rtbuf/signal_type.h>
+
+s_rtbuf_lib_proc_in rtbuf_signal_hipass3_in[] = {
+ { "signal", RTBUF_SIGNAL_TYPE, 0.0, -1.0, 1.0 },
+ { "cutoff", RTBUF_SIGNAL_TYPE, 8000.0, 0.0, RTBUF_SIGNAL_SAMPLERATE / 2.0 },
+ { 0, 0, 0.0, 0.0, 0.0 } };
+
+s_rtbuf_lib_proc_out rtbuf_signal_hipass3_out[] = {
+ { "signal", RTBUF_SIGNAL_TYPE },
+ { "x1", RTBUF_SIGNAL_SAMPLE_TYPE },
+ { "x2", RTBUF_SIGNAL_SAMPLE_TYPE },
+ { "x3", RTBUF_SIGNAL_SAMPLE_TYPE },
+ { "y1", RTBUF_SIGNAL_SAMPLE_TYPE },
+ { "y2", RTBUF_SIGNAL_SAMPLE_TYPE },
+ { "y3", RTBUF_SIGNAL_SAMPLE_TYPE },
+ { 0, 0 } };
int rtbuf_signal_hipass3_start (s_rtbuf *rtb)
{
@@ -102,3 +119,13 @@ int rtbuf_signal_hipass3 (s_rtbuf *rtb)
}
return 0;
}
+
+s_rtbuf_lib_proc rtbuf_lib_proc =
+ { "hipass3",
+ rtbuf_signal_hipass3,
+ rtbuf_signal_hipass3_start,
+ 0,
+ rtbuf_signal_hipass3_in,
+ rtbuf_signal_hipass3_out };
+
+unsigned long rtbuf_lib_ver = RTBUF_LIB_VER;
diff --git a/lib/signal/hipass4.c b/lib/signal/hipass4.c
index 6608258..fddb130 100644
--- a/lib/signal/hipass4.c
+++ b/lib/signal/hipass4.c
@@ -47,7 +47,26 @@ y: f4 (16 (x4 + x) - 64 (x3 + x1) + 96 x2 - (e y4 + d y3 + c y2 + b y1)) / a $
*/
#include <math.h>
#include <rtbuf/rtbuf.h>
+#include <rtbuf/lib.h>
#include <rtbuf/signal.h>
+#include <rtbuf/signal_type.h>
+
+s_rtbuf_lib_proc_in rtbuf_signal_hipass4_in[] = {
+ { "signal", RTBUF_SIGNAL_TYPE, 0.0, -1.0, 1.0 },
+ { "cutoff", RTBUF_SIGNAL_TYPE, 8000.0, 0.0, RTBUF_SIGNAL_SAMPLERATE / 2.0 },
+ { 0, 0, 0.0, 0.0, 0.0 } };
+
+s_rtbuf_lib_proc_out rtbuf_signal_hipass4_out[] = {
+ { "signal", RTBUF_SIGNAL_TYPE },
+ { "x1", RTBUF_SIGNAL_SAMPLE_TYPE },
+ { "x2", RTBUF_SIGNAL_SAMPLE_TYPE },
+ { "x3", RTBUF_SIGNAL_SAMPLE_TYPE },
+ { "x4", RTBUF_SIGNAL_SAMPLE_TYPE },
+ { "y1", RTBUF_SIGNAL_SAMPLE_TYPE },
+ { "y2", RTBUF_SIGNAL_SAMPLE_TYPE },
+ { "y3", RTBUF_SIGNAL_SAMPLE_TYPE },
+ { "y4", RTBUF_SIGNAL_SAMPLE_TYPE },
+ { 0, 0 } };
int rtbuf_signal_hipass4_start (s_rtbuf *rtb)
{
@@ -124,3 +143,13 @@ int rtbuf_signal_hipass4 (s_rtbuf *rtb)
}
return 0;
}
+
+s_rtbuf_lib_proc rtbuf_lib_proc =
+ { "hipass4",
+ rtbuf_signal_hipass4,
+ rtbuf_signal_hipass4_start,
+ 0,
+ rtbuf_signal_hipass4_in,
+ rtbuf_signal_hipass4_out };
+
+unsigned long rtbuf_lib_ver = RTBUF_LIB_VER;
diff --git a/lib/signal/hipass5.c b/lib/signal/hipass5.c
index 1d1af99..30ffeac 100644
--- a/lib/signal/hipass5.c
+++ b/lib/signal/hipass5.c
@@ -59,7 +59,28 @@ y: (f5 (32 (x - x5) + 160 (x4 - x1) + 320 (x2 - x3)) - (b y1 + c y2 + d y3 + e y
*/
#include <math.h>
#include <rtbuf/rtbuf.h>
+#include <rtbuf/lib.h>
#include <rtbuf/signal.h>
+#include <rtbuf/signal_type.h>
+
+s_rtbuf_lib_proc_in rtbuf_signal_hipass5_in[] = {
+ { "signal", RTBUF_SIGNAL_TYPE, 0.0, -1.0, 1.0 },
+ { "cutoff", RTBUF_SIGNAL_TYPE, 400.0, 0.0, RTBUF_SIGNAL_SAMPLERATE / 2.0 },
+ { 0, 0, 0.0, 0.0, 0.0 } };
+
+s_rtbuf_lib_proc_out rtbuf_signal_hipass5_out[] = {
+ { "signal", RTBUF_SIGNAL_TYPE },
+ { "x1", RTBUF_SIGNAL_SAMPLE_TYPE },
+ { "x2", RTBUF_SIGNAL_SAMPLE_TYPE },
+ { "x3", RTBUF_SIGNAL_SAMPLE_TYPE },
+ { "x4", RTBUF_SIGNAL_SAMPLE_TYPE },
+ { "x5", RTBUF_SIGNAL_SAMPLE_TYPE },
+ { "y1", RTBUF_SIGNAL_SAMPLE_TYPE },
+ { "y2", RTBUF_SIGNAL_SAMPLE_TYPE },
+ { "y3", RTBUF_SIGNAL_SAMPLE_TYPE },
+ { "y4", RTBUF_SIGNAL_SAMPLE_TYPE },
+ { "y5", RTBUF_SIGNAL_SAMPLE_TYPE },
+ { 0, 0 } };
int rtbuf_signal_hipass5_start (s_rtbuf *rtb)
{
@@ -146,3 +167,13 @@ int rtbuf_signal_hipass5 (s_rtbuf *rtb)
}
return 0;
}
+
+s_rtbuf_lib_proc rtbuf_lib_proc =
+ { "hipass5",
+ rtbuf_signal_hipass5,
+ rtbuf_signal_hipass5_start,
+ 0,
+ rtbuf_signal_hipass5_in,
+ rtbuf_signal_hipass5_out };
+
+unsigned long rtbuf_lib_ver = RTBUF_LIB_VER;
diff --git a/lib/signal/lowpass.c b/lib/signal/lowpass.c
index 3f1ee54..6b70532 100644
--- a/lib/signal/lowpass.c
+++ b/lib/signal/lowpass.c
@@ -17,7 +17,20 @@
#include <math.h>
#include <rtbuf/rtbuf.h>
+#include <rtbuf/lib.h>
#include <rtbuf/signal.h>
+#include <rtbuf/signal_type.h>
+
+s_rtbuf_lib_proc_in rtbuf_signal_lowpass_in[] = {
+ { "signal", RTBUF_SIGNAL_TYPE, 0.0, -1.0, 1.0 },
+ { "cutoff", RTBUF_SIGNAL_TYPE, 400.0, 0.0, RTBUF_SIGNAL_SAMPLERATE / 2.0 },
+ { 0, 0, 0.0, 0.0, 0.0 } };
+
+s_rtbuf_lib_proc_out rtbuf_signal_lowpass_out[] = {
+ { "signal", RTBUF_SIGNAL_TYPE },
+ { "x", RTBUF_SIGNAL_SAMPLE_TYPE },
+ { "y", RTBUF_SIGNAL_SAMPLE_TYPE },
+ { 0, 0 } };
int rtbuf_signal_lowpass_start (s_rtbuf *rtb)
{
@@ -49,3 +62,13 @@ int rtbuf_signal_lowpass (s_rtbuf *rtb)
}
return 0;
}
+
+s_rtbuf_lib_proc rtbuf_lib_proc =
+ { "lowpass",
+ rtbuf_signal_lowpass,
+ rtbuf_signal_lowpass_start,
+ 0,
+ rtbuf_signal_lowpass_in,
+ rtbuf_signal_lowpass_out };
+
+unsigned long rtbuf_lib_ver = RTBUF_LIB_VER;
diff --git a/lib/signal/lowpass2.c b/lib/signal/lowpass2.c
index 877fb35..659c9b8 100644
--- a/lib/signal/lowpass2.c
+++ b/lib/signal/lowpass2.c
@@ -21,7 +21,22 @@ H: 1/B2 $
*/
#include <math.h>
#include <rtbuf/rtbuf.h>
+#include <rtbuf/lib.h>
#include <rtbuf/signal.h>
+#include <rtbuf/signal_type.h>
+
+s_rtbuf_lib_proc_in rtbuf_signal_lowpass2_in[] = {
+ { "signal", RTBUF_SIGNAL_TYPE, 0.0, -1.0, 1.0 },
+ { "cutoff", RTBUF_SIGNAL_TYPE, 400.0, 0.0, RTBUF_SIGNAL_SAMPLERATE / 2.0 },
+ { 0, 0, 0.0, 0.0, 0.0 } };
+
+s_rtbuf_lib_proc_out rtbuf_signal_lowpass2_out[] = {
+ { "signal", RTBUF_SIGNAL_TYPE },
+ { "x1", RTBUF_SIGNAL_SAMPLE_TYPE },
+ { "x2", RTBUF_SIGNAL_SAMPLE_TYPE },
+ { "y1", RTBUF_SIGNAL_SAMPLE_TYPE },
+ { "y2", RTBUF_SIGNAL_SAMPLE_TYPE },
+ { 0, 0 } };
int rtbuf_signal_lowpass2_start (s_rtbuf *rtb)
{
@@ -64,3 +79,13 @@ int rtbuf_signal_lowpass2 (s_rtbuf *rtb)
}
return 0;
}
+
+s_rtbuf_lib_proc rtbuf_lib_proc =
+ { "lowpass2",
+ rtbuf_signal_lowpass2,
+ rtbuf_signal_lowpass2_start,
+ 0,
+ rtbuf_signal_lowpass2_in,
+ rtbuf_signal_lowpass2_out };
+
+unsigned long rtbuf_lib_ver = RTBUF_LIB_VER;
diff --git a/lib/signal/lowpass3.c b/lib/signal/lowpass3.c
index 1a37b21..6b32658 100644
--- a/lib/signal/lowpass3.c
+++ b/lib/signal/lowpass3.c
@@ -17,7 +17,24 @@
#include <math.h>
#include <rtbuf/rtbuf.h>
+#include <rtbuf/lib.h>
#include <rtbuf/signal.h>
+#include <rtbuf/signal_type.h>
+
+s_rtbuf_lib_proc_in rtbuf_signal_lowpass3_in[] = {
+ { "signal", RTBUF_SIGNAL_TYPE, 0.0, -1.0, 1.0 },
+ { "cutoff", RTBUF_SIGNAL_TYPE, 400.0, 0.0, RTBUF_SIGNAL_SAMPLERATE / 2.0 },
+ { 0, 0, 0.0, 0.0, 0.0 } };
+
+s_rtbuf_lib_proc_out rtbuf_signal_lowpass3_out[] = {
+ { "signal", RTBUF_SIGNAL_TYPE },
+ { "x1", RTBUF_SIGNAL_SAMPLE_TYPE },
+ { "x2", RTBUF_SIGNAL_SAMPLE_TYPE },
+ { "x3", RTBUF_SIGNAL_SAMPLE_TYPE },
+ { "y1", RTBUF_SIGNAL_SAMPLE_TYPE },
+ { "y2", RTBUF_SIGNAL_SAMPLE_TYPE },
+ { "y3", RTBUF_SIGNAL_SAMPLE_TYPE },
+ { 0, 0 } };
int rtbuf_signal_lowpass3_start (s_rtbuf *rtb)
{
@@ -77,3 +94,13 @@ int rtbuf_signal_lowpass3 (s_rtbuf *rtb)
}
return 0;
}
+
+s_rtbuf_lib_proc rtbuf_lib_proc =
+ { "lowpass3",
+ rtbuf_signal_lowpass3,
+ rtbuf_signal_lowpass3_start,
+ 0,
+ rtbuf_signal_lowpass3_in,
+ rtbuf_signal_lowpass3_out };
+
+unsigned long rtbuf_lib_ver = RTBUF_LIB_VER;
diff --git a/lib/signal/lowpass4.c b/lib/signal/lowpass4.c
index b98f362..0c43de7 100644
--- a/lib/signal/lowpass4.c
+++ b/lib/signal/lowpass4.c
@@ -51,7 +51,26 @@ y: (w4*(x4+4*x3+6*x2+4*x1+x)-(c*y4+d*y3+e*y2+f*y1))/g $
*/
#include <math.h>
#include <rtbuf/rtbuf.h>
+#include <rtbuf/lib.h>
#include <rtbuf/signal.h>
+#include <rtbuf/signal_type.h>
+
+s_rtbuf_lib_proc_in rtbuf_signal_lowpass4_in[] = {
+ { "signal", RTBUF_SIGNAL_TYPE, 0.0, -1.0, 1.0 },
+ { "cutoff", RTBUF_SIGNAL_TYPE, 400.0, 0.0, RTBUF_SIGNAL_SAMPLERATE / 2.0 },
+ { 0, 0, 0.0, 0.0, 0.0 } };
+
+s_rtbuf_lib_proc_out rtbuf_signal_lowpass4_out[] = {
+ { "signal", RTBUF_SIGNAL_TYPE },
+ { "x1", RTBUF_SIGNAL_SAMPLE_TYPE },
+ { "x2", RTBUF_SIGNAL_SAMPLE_TYPE },
+ { "x3", RTBUF_SIGNAL_SAMPLE_TYPE },
+ { "x4", RTBUF_SIGNAL_SAMPLE_TYPE },
+ { "y1", RTBUF_SIGNAL_SAMPLE_TYPE },
+ { "y2", RTBUF_SIGNAL_SAMPLE_TYPE },
+ { "y3", RTBUF_SIGNAL_SAMPLE_TYPE },
+ { "y4", RTBUF_SIGNAL_SAMPLE_TYPE },
+ { 0, 0 } };
int rtbuf_signal_lowpass4_start (s_rtbuf *rtb)
{
@@ -128,3 +147,13 @@ int rtbuf_signal_lowpass4 (s_rtbuf *rtb)
}
return 0;
}
+
+s_rtbuf_lib_proc rtbuf_lib_proc =
+ { "lowpass4",
+ rtbuf_signal_lowpass4,
+ rtbuf_signal_lowpass4_start,
+ 0,
+ rtbuf_signal_lowpass4_in,
+ rtbuf_signal_lowpass4_out };
+
+unsigned long rtbuf_lib_ver = RTBUF_LIB_VER;
diff --git a/lib/signal/lowpass5.c b/lib/signal/lowpass5.c
index 570c4aa..843ac6b 100644
--- a/lib/signal/lowpass5.c
+++ b/lib/signal/lowpass5.c
@@ -57,7 +57,28 @@ f: w5 + (r5 + 1)(-2)(f w4 - 8 f4 w) + (4 r5 + 12) (f2 w3 - 2 f3 w2) - 32
*/
#include <math.h>
#include <rtbuf/rtbuf.h>
+#include <rtbuf/lib.h>
#include <rtbuf/signal.h>
+#include <rtbuf/signal_type.h>
+
+s_rtbuf_lib_proc_in rtbuf_signal_lowpass5_in[] = {
+ { "signal", RTBUF_SIGNAL_TYPE, 0.0, -1.0, 1.0 },
+ { "cutoff", RTBUF_SIGNAL_TYPE, 400.0, 0.0, RTBUF_SIGNAL_SAMPLERATE / 2.0 },
+ { 0, 0, 0.0, 0.0, 0.0 } };
+
+s_rtbuf_lib_proc_out rtbuf_signal_lowpass5_out[] = {
+ { "signal", RTBUF_SIGNAL_TYPE },
+ { "x1", RTBUF_SIGNAL_SAMPLE_TYPE },
+ { "x2", RTBUF_SIGNAL_SAMPLE_TYPE },
+ { "x3", RTBUF_SIGNAL_SAMPLE_TYPE },
+ { "x4", RTBUF_SIGNAL_SAMPLE_TYPE },
+ { "x5", RTBUF_SIGNAL_SAMPLE_TYPE },
+ { "y1", RTBUF_SIGNAL_SAMPLE_TYPE },
+ { "y2", RTBUF_SIGNAL_SAMPLE_TYPE },
+ { "y3", RTBUF_SIGNAL_SAMPLE_TYPE },
+ { "y4", RTBUF_SIGNAL_SAMPLE_TYPE },
+ { "y5", RTBUF_SIGNAL_SAMPLE_TYPE },
+ { 0, 0 } };
int rtbuf_signal_lowpass5_start (s_rtbuf *rtb)
{
@@ -145,3 +166,13 @@ int rtbuf_signal_lowpass5 (s_rtbuf *rtb)
}
return 0;
}
+
+s_rtbuf_lib_proc rtbuf_lib_proc =
+ { "lowpass5",
+ rtbuf_signal_lowpass5,
+ rtbuf_signal_lowpass5_start,
+ 0,
+ rtbuf_signal_lowpass5_in,
+ rtbuf_signal_lowpass5_out };
+
+unsigned long rtbuf_lib_ver = RTBUF_LIB_VER;
diff --git a/lib/signal/sawtooth.c b/lib/signal/sawtooth.c
index ef1a064..3d29b98 100644
--- a/lib/signal/sawtooth.c
+++ b/lib/signal/sawtooth.c
@@ -18,7 +18,19 @@
#include <math.h>
#include <stdio.h>
#include <rtbuf/rtbuf.h>
+#include <rtbuf/lib.h>
#include <rtbuf/signal.h>
+#include <rtbuf/signal_type.h>
+
+s_rtbuf_lib_proc_in rtbuf_signal_sawtooth_in[] = {
+ { "frequency", RTBUF_SIGNAL_TYPE, 220.0, 0.0, RTBUF_SIGNAL_SAMPLERATE / 2.0 },
+ { "amplitude", RTBUF_SIGNAL_TYPE, 1.0, 0.0, 1.0 },
+ { 0, 0, 0.0, 0.0, 0.0 } };
+
+s_rtbuf_lib_proc_out rtbuf_signal_sawtooth_out[] = {
+ { "signal", RTBUF_SIGNAL_TYPE },
+ { "phase", "double" },
+ { 0, 0 } };
int rtbuf_signal_sawtooth_start (s_rtbuf *rtb)
{
@@ -50,3 +62,13 @@ int rtbuf_signal_sawtooth (s_rtbuf *rtb)
}
return 0;
}
+
+s_rtbuf_lib_proc rtbuf_lib_proc =
+ { "sawtooth",
+ rtbuf_signal_sawtooth,
+ rtbuf_signal_sawtooth_start,
+ 0,
+ rtbuf_signal_sawtooth_in,
+ rtbuf_signal_sawtooth_out };
+
+unsigned long rtbuf_lib_ver = RTBUF_LIB_VER;
diff --git a/lib/signal/square.c b/lib/signal/square.c
index b3b004a..39835f7 100644
--- a/lib/signal/square.c
+++ b/lib/signal/square.c
@@ -17,7 +17,20 @@
#include <math.h>
#include <stdio.h>
#include <rtbuf/rtbuf.h>
+#include <rtbuf/lib.h>
#include <rtbuf/signal.h>
+#include <rtbuf/signal_type.h>
+
+s_rtbuf_lib_proc_in rtbuf_signal_square_in[] = {
+ { "frequency", RTBUF_SIGNAL_TYPE, 220.0, 0.0, RTBUF_SIGNAL_SAMPLERATE / 2.0 },
+ { "amplitude", RTBUF_SIGNAL_TYPE, 1.0, 0.0, 1.0 },
+ { "pulse", RTBUF_SIGNAL_TYPE, 0.5, 0.0, 1.0 },
+ { 0, 0, 0.0, 0.0, 0.0 } };
+
+s_rtbuf_lib_proc_out rtbuf_signal_square_out[] = {
+ { "signal", RTBUF_SIGNAL_TYPE },
+ { "phase", "double" },
+ { 0, 0 } };
static
double square (double amp, double phase, double pulse)
@@ -61,3 +74,13 @@ int rtbuf_signal_square_start (s_rtbuf *rtb)
data->phase = 0;
return 0;
}
+
+s_rtbuf_lib_proc rtbuf_lib_proc =
+ { "square",
+ rtbuf_signal_square,
+ rtbuf_signal_square_start,
+ 0,
+ rtbuf_signal_square_in,
+ rtbuf_signal_square_out };
+
+unsigned long rtbuf_lib_ver = RTBUF_LIB_VER;
diff --git a/lib/synth/Makefile.am b/lib/synth/Makefile.am
new file mode 100644
index 0000000..73e81a7
--- /dev/null
+++ b/lib/synth/Makefile.am
@@ -0,0 +1,13 @@
+CLEANFILES =
+rtbuf_includedir = $(includedir)/rtbuf/synth
+rtbuf_include_HEADERS =
+rtbuf_libdir = $(libdir)/rtbuf/synth
+rtbuf_lib_LTLIBRARIES =
+
+rtbuf_lib_LTLIBRARIES += adsr.la
+adsr_la_LDFLAGS = -no-undefined -module -shared
+adsr_la_LIBADD = ../librtbuf_signal.la
+
+rtbuf_lib_LTLIBRARIES += synth.la
+synth_la_LDFLAGS = -no-undefined -module -shared
+synth_la_LIBADD = ../librtbuf_music.la ../librtbuf_signal.la
diff --git a/lib/synth/adsr.c b/lib/synth/adsr.c
new file mode 100644
index 0000000..3face6f
--- /dev/null
+++ b/lib/synth/adsr.c
@@ -0,0 +1,146 @@
+/*
+ * Copyright 2018 Thomas de Grivel <thoxdg@gmail.com> +33614550127
+ * Copyright 2018 Judy Najnudel <judy.najnudel@gmail.com>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <float.h>
+#include <stdio.h>
+#include <strings.h>
+#include <rtbuf/rtbuf.h>
+#include <rtbuf/lib.h>
+#include <rtbuf/signal.h>
+#include <rtbuf/signal_type.h>
+#include <rtbuf/music.h>
+#include <rtbuf/music_type.h>
+#include <rtbuf/synth.h>
+
+s_rtbuf_lib_proc_in rtbuf_synth_adsr_in[] = {
+ RTBUF_MUSIC_NOTE_IN(),
+ { "attack", RTBUF_SIGNAL_TYPE, 0.02, 0.0, 2.0 },
+ { "decay", RTBUF_SIGNAL_TYPE, 0.01, 0.0, 2.0 },
+ { "sustain", RTBUF_SIGNAL_TYPE, 0.4, 0.0, 1.0 },
+ { "release", RTBUF_SIGNAL_TYPE, 0.3, 0.0, 10.0 },
+ { 0, 0, 0.0, 0.0, 0.0 } };
+
+s_rtbuf_lib_proc_out rtbuf_synth_adsr_out[] = {
+ { "signal", RTBUF_SIGNAL_TYPE },
+ { "state", "int" },
+ { 0, 0 } };
+
+static
+double adsr (double attack, double decay, double sustain,
+ double release, double start, double stop)
+{
+ double t = start;
+ double x;
+ if (stop >= 0.0)
+ t = start - stop;
+ if (t < attack)
+ x = t / attack;
+ else if (t - attack < decay)
+ x = 1.0 + (sustain - 1.0) * (t - attack) / decay;
+ else
+ x = sustain;
+ if (stop < 0.0)
+ return x;
+ if (stop < release)
+ return x * (1.0 - stop / release);
+ return 0.0;
+}
+
+void rtbuf_synth_adsr_signal (s_rtbuf *rtb, double *signal,
+ double velocity, double start,
+ double stop, double r)
+{
+ double a =
+ rtbuf_signal_sample(rtb, RTBUF_SYNTH_ADSR_IN_ATTACK, 0.02);
+ double d =
+ rtbuf_signal_sample(rtb, RTBUF_SYNTH_ADSR_IN_DECAY, 0.01);
+ double s =
+ rtbuf_signal_sample(rtb, RTBUF_SYNTH_ADSR_IN_SUSTAIN, 0.4);
+ unsigned int i = 0;
+ (void) velocity;
+ (void) start;
+ (void) stop;
+ while (i < RTBUF_SIGNAL_SAMPLES) {
+ double dt = (double) i / RTBUF_SIGNAL_SAMPLERATE;
+ double start_i = start + dt;
+ double stop_i = stop < 0 ? stop : stop + dt;
+ a = max(0.0, a);
+ d = max(0.0, d);
+ s = max(0.0, s);
+ r = max(0.0, r);
+ *signal = velocity * adsr(a, d, s, r, start_i, stop_i);
+ signal++;
+ i++;
+ }
+}
+
+int rtbuf_synth_adsr (s_rtbuf *rtb)
+{
+ double vel;
+ double start;
+ s_rtbuf_synth_adsr_data *data;
+ assert(rtb);
+ assert(rtb->data);
+ vel = rtbuf_signal_sample(rtb, RTBUF_SYNTH_ADSR_IN_VELOCITY, 0.0);
+ start = rtbuf_signal_sample(rtb, RTBUF_SYNTH_ADSR_IN_START, -1.0);
+ data = (s_rtbuf_synth_adsr_data*) rtb->data;
+ if (data->state == RTBUF_SYNTH_ENVELOPE_STATE_NOT_STARTED) {
+ if (vel > 0.0 && start >= 0.0)
+ data->state = RTBUF_SYNTH_ENVELOPE_STATE_STARTED;
+ else
+ return 0;
+ }
+ if (data->state == RTBUF_SYNTH_ENVELOPE_STATE_ENDED)
+ return 0;
+ if (data->state == RTBUF_SYNTH_ENVELOPE_STATE_STARTED) {
+ double stop =
+ rtbuf_signal_sample(rtb, RTBUF_SYNTH_ADSR_IN_STOP, -1.0);
+ double rel =
+ rtbuf_signal_sample(rtb, RTBUF_SYNTH_ADSR_IN_RELEASE, 0.3);
+ if (stop > rel) {
+ rtbuf_signal_zero(data->signal);
+ data->state = RTBUF_SYNTH_ENVELOPE_STATE_ENDED;
+ return 0;
+ }
+ rtbuf_synth_adsr_signal(rtb, data->signal, vel, start, stop, rel);
+ return 0;
+ }
+ assert(data->state != data->state);
+ return 0;
+}
+
+int rtbuf_synth_adsr_start (s_rtbuf *rtb)
+{
+ s_rtbuf_synth_adsr_data *data;
+ assert(rtb->data);
+ assert(rtb->proc);
+ assert(rtb->proc->out_bytes == sizeof(*data));
+ data = (s_rtbuf_synth_adsr_data*) rtb->data;
+ data->state = RTBUF_SYNTH_ENVELOPE_STATE_NOT_STARTED;
+ bzero(data->signal, sizeof(t_rtbuf_signal));
+ return 0;
+}
+
+s_rtbuf_lib_proc rtbuf_lib_proc =
+ { "adsr",
+ rtbuf_synth_adsr,
+ rtbuf_synth_adsr_start,
+ 0,
+ rtbuf_synth_adsr_in,
+ rtbuf_synth_adsr_out };
+
+unsigned long rtbuf_lib_ver = RTBUF_LIB_VER;
diff --git a/lib/synth/rtbuf_synth.c b/lib/synth/rtbuf_synth.c
deleted file mode 100644
index 8fd9cef..0000000
--- a/lib/synth/rtbuf_synth.c
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * Copyright 2018 Thomas de Grivel <thoxdg@gmail.com> +33614550127
- *
- * Permission to use, copy, modify, and distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
- * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- */
-
-#include <float.h>
-#include <stdio.h>
-#include "rtbuf.h"
-#include "rtbuf_lib.h"
-#include "rtbuf_signal.h"
-#include "rtbuf_signal_type.h"
-#include "rtbuf_music.h"
-#include "rtbuf_music_type.h"
-#include "rtbuf_synth.h"
-
-s_rtbuf_lib_proc_in g_rtbuf_synth_adsr_in[] = {
- RTBUF_MUSIC_NOTE_IN(),
- { "attack", RTBUF_SIGNAL_TYPE, 0.02, 0.0, 2.0 },
- { "decay", RTBUF_SIGNAL_TYPE, 0.01, 0.0, 2.0 },
- { "sustain", RTBUF_SIGNAL_TYPE, 0.4, 0.0, 1.0 },
- { "release", RTBUF_SIGNAL_TYPE, 0.3, 0.0, 10.0 },
- { 0, 0, 0.0, 0.0, 0.0 } };
-
-s_rtbuf_lib_proc_out g_rtbuf_synth_adsr_out[] = {
- { "signal", RTBUF_SIGNAL_TYPE },
- { "state", "int" },
- { 0, 0 } };
-
-s_rtbuf_lib_proc_in g_rtbuf_synth_synth_in[] = {
- { "envelope", RTBUF_SIGNAL_TYPE, 1.0, 0.0, 1.0 },
- { "oscillator", RTBUF_SIGNAL_TYPE, 0.0, -1.0, 1.0 },
- RTBUF_MUSIC_NOTES_IN("note"),
- { 0, 0, 0.0, 0.0, 0.0 } };
-
-s_rtbuf_lib_proc_out g_rtbuf_synth_synth_out[] = {
- { "signal", RTBUF_SIGNAL_TYPE },
- { "note_n", "unsigned int" },
- { 0, 0 } };
-
-const char *rtbuf_lib_name = "synth";
-unsigned long rtbuf_lib_ver = RTBUF_LIB_VER;
-s_rtbuf_lib_proc rtbuf_lib_proc[] = {
- { "adsr", rtbuf_synth_adsr, rtbuf_synth_adsr_start, 0,
- g_rtbuf_synth_adsr_in, g_rtbuf_synth_adsr_out },
- { "synth", rtbuf_synth_synth, rtbuf_synth_synth_start, 0,
- g_rtbuf_synth_synth_in, g_rtbuf_synth_synth_out },
- { 0, 0, 0, 0, 0, 0 } };
-
-int rtbuf_lib_init (s_rtbuf_lib *lib)
-{
- (void) lib;
- rtbuf_music_init();
- return 0;
-}
diff --git a/lib/synth/rtbuf_synth.h b/lib/synth/rtbuf_synth.h
deleted file mode 100644
index a1124b1..0000000
--- a/lib/synth/rtbuf_synth.h
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * Copyright 2018 Thomas de Grivel <thoxdg@gmail.com> +33614550127
- *
- * Permission to use, copy, modify, and distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
- * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- */
-#ifndef RTBUF_SYNTH_H
-#define RTBUF_SYNTH_H
-
-#include "rtbuf.h"
-#include "rtbuf_music.h"
-#include "rtbuf_music_type.h"
-#include "rtbuf_signal.h"
-#include "rtbuf_synth_type.h"
-
-/* adsr */
-
-enum {
- RTBUF_MUSIC_NOTE_IN_ENUM(RTBUF_SYNTH_ADSR_IN),
- RTBUF_SYNTH_ADSR_IN_ATTACK,
- RTBUF_SYNTH_ADSR_IN_DECAY,
- RTBUF_SYNTH_ADSR_IN_SUSTAIN,
- RTBUF_SYNTH_ADSR_IN_RELEASE,
- RTBUF_SYNTH_ADSR_IN_N
-};
-
-enum {
- RTBUF_SYNTH_ENVELOPE_STATE_NOT_STARTED = 0,
- RTBUF_SYNTH_ENVELOPE_STATE_STARTED,
- RTBUF_SYNTH_ENVELOPE_STATE_ENDED
-};
-
-#pragma pack(push,1)
-typedef struct rtbuf_synth_adsr_data {
- t_rtbuf_signal signal;
- int state;
-} s_rtbuf_synth_adsr_data;
-#pragma pack(pop)
-
-int rtbuf_synth_adsr (s_rtbuf *rtb);
-int rtbuf_synth_adsr_start (s_rtbuf *rtb);
-
-/* synth */
-
-enum {
- RTBUF_SYNTH_SYNTH_IN_ENVELOPE = 0,
- RTBUF_SYNTH_SYNTH_IN_OSCILLATOR,
- RTBUF_SYNTH_SYNTH_IN_NOTES,
- RTBUF_SYNTH_NOTES_IN_ENUM(RTBUF_SYNTH_SYNTH_IN_NOTE),
- RTBUF_SYNTH_SYNTH_IN_N
-};
-
-#define RTBUF_SYNTH_SYNTH_IN_NOTE_ENVELOPE(i) \
- (RTBUF_SYNTH_SYNTH_IN_NOTE_0_ENVELOPE + 2 * i)
-
-#define RTBUF_SYNTH_SYNTH_IN_NOTE_OSCILLATOR(i) \
- (RTBUF_SYNTH_SYNTH_IN_NOTE_0_OSCILLATOR + 2 * i)
-
-#pragma pack(push,1)
-typedef struct rtbuf_synth_synth_data
-{
- t_rtbuf_signal signal;
- unsigned int note_n;
-} s_rtbuf_synth_synth_data;
-#pragma pack(pop)
-
-int rtbuf_synth_synth (s_rtbuf *rtb);
-int rtbuf_synth_synth_start (s_rtbuf *rtb);
-
-#endif /* RTBUF_SYNTH_H */
diff --git a/lib/synth/rtbuf_synth_adsr.c b/lib/synth/rtbuf_synth_adsr.c
deleted file mode 100644
index 3fbcf51..0000000
--- a/lib/synth/rtbuf_synth_adsr.c
+++ /dev/null
@@ -1,117 +0,0 @@
-/*
- * Copyright 2018 Thomas de Grivel <thoxdg@gmail.com> +33614550127
- * Copyright 2018 Judy Najnudel <judy.najnudel@gmail.com>
- *
- * Permission to use, copy, modify, and distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
- * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- */
-
-#include <stdio.h>
-#include <strings.h>
-#include "rtbuf.h"
-#include "rtbuf_synth.h"
-
-static
-double adsr (double attack, double decay, double sustain,
- double release, double start, double stop)
-{
- double t = start;
- double x;
- if (stop >= 0.0)
- t = start - stop;
- if (t < attack)
- x = t / attack;
- else if (t - attack < decay)
- x = 1.0 + (sustain - 1.0) * (t - attack) / decay;
- else
- x = sustain;
- if (stop < 0.0)
- return x;
- if (stop < release)
- return x * (1.0 - stop / release);
- return 0.0;
-}
-
-void rtbuf_synth_adsr_signal (s_rtbuf *rtb, double *signal,
- double velocity, double start,
- double stop, double r)
-{
- double a =
- rtbuf_signal_sample(rtb, RTBUF_SYNTH_ADSR_IN_ATTACK, 0.02);
- double d =
- rtbuf_signal_sample(rtb, RTBUF_SYNTH_ADSR_IN_DECAY, 0.01);
- double s =
- rtbuf_signal_sample(rtb, RTBUF_SYNTH_ADSR_IN_SUSTAIN, 0.4);
- unsigned int i = 0;
- (void) velocity;
- (void) start;
- (void) stop;
- while (i < RTBUF_SIGNAL_SAMPLES) {
- double dt = (double) i / RTBUF_SIGNAL_SAMPLERATE;
- double start_i = start + dt;
- double stop_i = stop < 0 ? stop : stop + dt;
- a = max(0.0, a);
- d = max(0.0, d);
- s = max(0.0, s);
- r = max(0.0, r);
- *signal = velocity * adsr(a, d, s, r, start_i, stop_i);
- signal++;
- i++;
- }
-}
-
-int rtbuf_synth_adsr (s_rtbuf *rtb)
-{
- double vel;
- double start;
- s_rtbuf_synth_adsr_data *data;
- assert(rtb);
- assert(rtb->data);
- vel = rtbuf_signal_sample(rtb, RTBUF_SYNTH_ADSR_IN_VELOCITY, 0.0);
- start = rtbuf_signal_sample(rtb, RTBUF_SYNTH_ADSR_IN_START, -1.0);
- data = (s_rtbuf_synth_adsr_data*) rtb->data;
- if (data->state == RTBUF_SYNTH_ENVELOPE_STATE_NOT_STARTED) {
- if (vel > 0.0 && start >= 0.0)
- data->state = RTBUF_SYNTH_ENVELOPE_STATE_STARTED;
- else
- return 0;
- }
- if (data->state == RTBUF_SYNTH_ENVELOPE_STATE_ENDED)
- return 0;
- if (data->state == RTBUF_SYNTH_ENVELOPE_STATE_STARTED) {
- double stop =
- rtbuf_signal_sample(rtb, RTBUF_SYNTH_ADSR_IN_STOP, -1.0);
- double rel =
- rtbuf_signal_sample(rtb, RTBUF_SYNTH_ADSR_IN_RELEASE, 0.3);
- if (stop > rel) {
- rtbuf_signal_zero(data->signal);
- data->state = RTBUF_SYNTH_ENVELOPE_STATE_ENDED;
- return 0;
- }
- rtbuf_synth_adsr_signal(rtb, data->signal, vel, start, stop, rel);
- return 0;
- }
- assert(data->state != data->state);
- return 0;
-}
-
-int rtbuf_synth_adsr_start (s_rtbuf *rtb)
-{
- s_rtbuf_synth_adsr_data *data;
- assert(rtb->data);
- assert(rtb->proc);
- assert(rtb->proc->out_bytes == sizeof(*data));
- data = (s_rtbuf_synth_adsr_data*) rtb->data;
- data->state = RTBUF_SYNTH_ENVELOPE_STATE_NOT_STARTED;
- bzero(data->signal, sizeof(t_rtbuf_signal));
- return 0;
-}
diff --git a/lib/synth/rtbuf_synth_synth.c b/lib/synth/rtbuf_synth_synth.c
deleted file mode 100644
index a165606..0000000
--- a/lib/synth/rtbuf_synth_synth.c
+++ /dev/null
@@ -1,244 +0,0 @@
-/*
- * Copyright 2018 Thomas de Grivel <thoxdg@gmail.com> +33614550127
- *
- * Permission to use, copy, modify, and distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
- * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- */
-
-#include <assert.h>
-#include <stdio.h>
-#include <strings.h>
-#include "rtbuf.h"
-#include "rtbuf_synth.h"
-#include "rtbuf_synth_type.h"
-
-s_rtbuf * rtbuf_in_rtbuf (s_rtbuf *rtb, unsigned int in)
-{
- int i;
- assert(in < rtb->proc->in_n);
- if ((i = rtb->in[in].rtb) < 0)
- return 0;
- return &g_rtbuf[i];
-}
-
-s_rtbuf * rtbuf_synth_synth_note_envelope (s_rtbuf *rtb, unsigned int i)
-{
- unsigned int j;
- assert(i < RTBUF_MUSIC_NOTE_MAX);
- j = RTBUF_SYNTH_SYNTH_IN_NOTE_ENVELOPE(i);
- return rtbuf_in_rtbuf(rtb, j);
-}
-
-s_rtbuf * rtbuf_synth_synth_note_oscillator (s_rtbuf *rtb,
- unsigned int i)
-{
- unsigned int j;
- assert(i < RTBUF_MUSIC_NOTE_MAX);
- j = RTBUF_SYNTH_SYNTH_IN_NOTE_OSCILLATOR(i);
- return rtbuf_in_rtbuf(rtb, j);
-}
-
-void rtbuf_synth_synth_delete_note (s_rtbuf *rtb,
- unsigned int i)
-{
- s_rtbuf *env = rtbuf_synth_synth_note_envelope(rtb, i);
- s_rtbuf *osc = rtbuf_synth_synth_note_oscillator(rtb, i);
- s_rtbuf_synth_synth_data *data;
- data = (s_rtbuf_synth_synth_data*) rtb->data;
- if (env || osc) {
- printf("synth_synth_delete_note %u\n", i);
- if (env)
- rtbuf_delete(env);
- if (osc)
- rtbuf_delete(osc);
- data->note_n--;
- }
-}
-
-void rtbuf_synth_synth_delete_notes (s_rtbuf *rtb)
-{
- s_rtbuf_synth_synth_data *data;
- unsigned int i = 0;
- data = (s_rtbuf_synth_synth_data*) rtb->data;
- while (i < RTBUF_MUSIC_NOTE_MAX && data->note_n > 0) {
- rtbuf_synth_synth_delete_note(rtb, i);
- i++;
- }
-}
-
-s_rtbuf * rtbuf_synth_synth_new_envelope (s_rtbuf *rtb,
- unsigned int i)
-{
- s_rtbuf *ref = rtbuf_in_rtbuf(rtb, RTBUF_SYNTH_SYNTH_IN_ENVELOPE);
- int env_i;
- s_rtbuf *env;
- unsigned int env_vel;
- unsigned int env_freq;
- unsigned int env_start;
- unsigned int env_stop;
- s_rtbuf_binding *v = &rtb->in[RTBUF_SYNTH_SYNTH_IN_NOTES];
- unsigned int kbd_i = v->rtb;
- unsigned int kbd_notes = v->out;
- unsigned int note_vel = RTBUF_MUSIC_NOTE_IN_VELOCITY(kbd_notes, i);
- unsigned int note_freq = RTBUF_MUSIC_NOTE_IN_FREQUENCY(kbd_notes, i);
- unsigned int note_start = RTBUF_MUSIC_NOTE_IN_START(kbd_notes, i);
- unsigned int note_stop = RTBUF_MUSIC_NOTE_IN_STOP(kbd_notes, i);
- assert(rtb > g_rtbuf);
- if (!ref)
- return 0;
- if((env_i = rtbuf_clone(ref)) < 0)
- return 0;
- env = &g_rtbuf[env_i];
- env_vel = rtbuf_in_find(env, "velocity");
- env_freq = rtbuf_in_find(env, "frequency");
- env_start = rtbuf_in_find(env, "start");
- env_stop = rtbuf_in_find(env, "stop");
- rtbuf_bind(kbd_i, note_vel , env, env_vel);
- rtbuf_bind(kbd_i, note_freq , env, env_freq);
- rtbuf_bind(kbd_i, note_start, env, env_start);
- rtbuf_bind(kbd_i, note_stop , env, env_stop);
- rtbuf_bind(env_i, 0, rtb, RTBUF_SYNTH_SYNTH_IN_NOTE_ENVELOPE(i));
- if (env->proc->start)
- env->proc->start(env);
- if (env->proc->f)
- env->proc->f(env);
- /* rtbuf_print_long(env_i); */
- printf("synth_synth_new_envelope %u\n", i);
- return env;
-}
-
-s_rtbuf * rtbuf_synth_synth_new_oscillator (s_rtbuf *rtb,
- unsigned int i)
-{
- s_rtbuf *ref =
- rtbuf_in_rtbuf(rtb, RTBUF_SYNTH_SYNTH_IN_OSCILLATOR);
- int osc_i;
- s_rtbuf *osc;
- unsigned int osc_freq;
- s_rtbuf_binding *v = &rtb->in[RTBUF_SYNTH_SYNTH_IN_NOTES];
- unsigned int kbd_i = v->rtb;
- unsigned int kbd_notes = v->out;
- unsigned int note_freq = RTBUF_MUSIC_NOTE_IN_FREQUENCY(kbd_notes, i);
- assert(rtb > g_rtbuf);
- if (!ref)
- return 0;
- if ((osc_i = rtbuf_clone(ref)) < 0)
- return 0;
- osc = &g_rtbuf[osc_i];
- osc_freq = rtbuf_in_find(osc, "frequency");
- rtbuf_bind(kbd_i, note_freq, osc, osc_freq);
- rtbuf_bind(osc_i, 0, rtb, RTBUF_SYNTH_SYNTH_IN_NOTE_OSCILLATOR(i));
- if (osc->proc->start)
- osc->proc->start(osc);
- if (osc->proc->f)
- osc->proc->f(osc);
- /* rtbuf_print_long(osc_i); */
- return osc;
-}
-
-void rtbuf_synth_synth_update_note_signal (s_rtbuf *rtb,
- unsigned int i)
-{
- s_rtbuf_synth_synth_data *data;
- s_rtbuf_signal_fun env;
- s_rtbuf_signal_fun osc;
- unsigned int j = 0;
- double *signal;
- assert(rtb);
- assert(rtb->data);
- assert(i < RTBUF_MUSIC_NOTE_MAX);
- rtbuf_signal_fun(rtb, RTBUF_SYNTH_SYNTH_IN_NOTE_ENVELOPE(i), &env);
- rtbuf_signal_fun(rtb, RTBUF_SYNTH_SYNTH_IN_NOTE_OSCILLATOR(i), &osc);
- data = (s_rtbuf_synth_synth_data *) rtb->data;
- signal = data->signal;
- while (j < RTBUF_SIGNAL_SAMPLES) {
- double e = env.sample_fun(env.signal, j);
- double o = osc.sample_fun(osc.signal, j);
- e = max(0.0, e);
- *signal += e * o;
- /* printf(" e=%f o=%f s=%f", e, o, *signal); */
- signal++;
- j++;
- }
-}
-
-void rtbuf_synth_synth_update_note (s_rtbuf *rtb,
- unsigned int i)
-{
- s_rtbuf_synth_synth_data *data;
- s_rtbuf_music_notes *notes =
- rtbuf_music_notes(rtb, RTBUF_SYNTH_SYNTH_IN_NOTES);
- s_rtbuf_music_note *note;
- assert(notes);
- assert(i < RTBUF_MUSIC_NOTE_MAX);
- assert(rtb->data);
- data = (s_rtbuf_synth_synth_data*) rtb->data;
- note = ¬es->note[i];
- if (note->velocity > 0.0 && note->start >= 0.0) {
- s_rtbuf *env = rtbuf_synth_synth_note_envelope(rtb, i);
- s_rtbuf *osc = rtbuf_synth_synth_note_oscillator(rtb, i);
- if (!env || !osc) {
- if (!env)
- env = rtbuf_synth_synth_new_envelope(rtb, i);
- if (!osc)
- osc = rtbuf_synth_synth_new_oscillator(rtb, i);
- data->note_n++;
- }
- if (env && osc) {
- unsigned int env_state_out = rtbuf_proc_out_find(env->proc,
- "state");
- int env_state = rtbuf_out_int(env, env_state_out,
- RTBUF_SYNTH_ENVELOPE_STATE_STARTED);
- if (env_state == RTBUF_SYNTH_ENVELOPE_STATE_STARTED)
- rtbuf_synth_synth_update_note_signal(rtb, i);
- }
- }
- else
- rtbuf_synth_synth_delete_note(rtb, i);
-}
-
-int rtbuf_synth_synth (s_rtbuf *rtb)
-{
- s_rtbuf_music_notes *notes =
- rtbuf_music_notes(rtb, RTBUF_SYNTH_SYNTH_IN_NOTES);
- s_rtbuf_synth_synth_data *data;
- unsigned int i = 0;
- unsigned int notes_n = notes ? notes->note_n : 0;
- unsigned int n;
- data = (s_rtbuf_synth_synth_data*) rtb->data;
- n = data->note_n;
- rtbuf_signal_zero(data->signal);
- while (i < RTBUF_MUSIC_NOTE_MAX && (n > 0 || notes_n > 0)) {
- s_rtbuf_music_note *note = notes ? ¬es->note[i] : 0;
- if (rtbuf_music_note_p(note))
- notes_n--;
- if (rtbuf_synth_synth_note_envelope(rtb, i))
- n--;
- rtbuf_synth_synth_update_note(rtb, i);
- i++;
- }
- return 0;
-}
-
-int rtbuf_synth_synth_start (s_rtbuf *rtb)
-{
- s_rtbuf_synth_synth_data *data;
- assert(rtb->proc->out_bytes == sizeof(*data));
- data = (s_rtbuf_synth_synth_data*) rtb->data;
- return 0;
-}
-
-int rtbuf_synth_synth_stop (s_rtbuf *rtb)
-{
- rtbuf_synth_synth_delete_notes(rtb);
- return 0;
-}
diff --git a/lib/synth/rtbuf_synth_type.c b/lib/synth/rtbuf_synth_type.c
deleted file mode 100644
index c127198..0000000
--- a/lib/synth/rtbuf_synth_type.c
+++ /dev/null
@@ -1,45 +0,0 @@
-
-#include <stdio.h>
-#include "rtbuf.h"
-#include "rtbuf_music.h"
-#include "rtbuf_music_type.h"
-
-void notes_in ()
-{
- unsigned int i = 0;
- const char *st = "RTBUF_SIGNAL_TYPE";
- printf("\n"
- "#define RTBUF_SYNTH_NOTES_IN(note) \\\n");
- while (i < RTBUF_MUSIC_NOTE_MAX) {
- printf(" { note \"[%u].envelope\" , %s }, \\\n", i, st);
- printf(" { note \"[%u].oscillator\", %s }", i, st);
- if (i < RTBUF_MUSIC_NOTE_MAX - 1)
- printf(", \\");
- printf("\n");
- i++;
- }
- i = 0;
- printf("\n"
- "#define RTBUF_SYNTH_NOTES_IN_ENUM(note) \\\n");
- while (i < RTBUF_MUSIC_NOTE_MAX) {
- printf(" note ## _%u_ENVELOPE , \\\n", i);
- printf(" note ## _%u_OSCILLATOR", i);
- if (i < RTBUF_MUSIC_NOTE_MAX - 1)
- printf(", \\");
- printf("\n");
- i++;
- }
-}
-
-int main ()
-{
- printf("/* file generated by rtbuf_synth_type */\n");
- printf("#ifndef RTBUF_SYNTH_TYPE_H\n"
- "#define RTBUF_SYNTH_TYPE_H\n"
- "\n"
- "#include \"rtbuf_signal_type.h\"\n");
- notes_in();
- printf("\n"
- "#endif\n");
- return 0;
-}
diff --git a/lib/synth/synth.c b/lib/synth/synth.c
new file mode 100644
index 0000000..2a39ea5
--- /dev/null
+++ b/lib/synth/synth.c
@@ -0,0 +1,278 @@
+/*
+ * Copyright 2018 Thomas de Grivel <thoxdg@gmail.com> +33614550127
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <assert.h>
+#include <float.h>
+#include <stdio.h>
+#include <strings.h>
+#include <rtbuf/rtbuf.h>
+#include <rtbuf/lib.h>
+#include <rtbuf/signal.h>
+#include <rtbuf/signal_type.h>
+#include <rtbuf/music.h>
+#include <rtbuf/music_type.h>
+#include <rtbuf/synth.h>
+#include <rtbuf/synth_type.h>
+
+s_rtbuf_lib_proc_in rtbuf_synth_synth_in[] = {
+ { "envelope", RTBUF_SIGNAL_TYPE, 1.0, 0.0, 1.0 },
+ { "oscillator", RTBUF_SIGNAL_TYPE, 0.0, -1.0, 1.0 },
+ RTBUF_MUSIC_NOTES_IN("note"),
+ { 0, 0, 0.0, 0.0, 0.0 } };
+
+s_rtbuf_lib_proc_out rtbuf_synth_synth_out[] = {
+ { "signal", RTBUF_SIGNAL_TYPE },
+ { "note_n", "unsigned int" },
+ { 0, 0 } };
+
+int rtbuf_lib_init (s_rtbuf_lib *lib)
+{
+ (void) lib;
+ rtbuf_music_init();
+ return 0;
+}
+
+s_rtbuf * rtbuf_in_rtbuf (s_rtbuf *rtb, unsigned int in)
+{
+ int i;
+ assert(in < rtb->proc->in_n);
+ if ((i = rtb->in[in].rtb) < 0)
+ return 0;
+ return &g_rtbuf[i];
+}
+
+s_rtbuf * rtbuf_synth_synth_note_envelope (s_rtbuf *rtb, unsigned int i)
+{
+ unsigned int j;
+ assert(i < RTBUF_MUSIC_NOTE_MAX);
+ j = RTBUF_SYNTH_SYNTH_IN_NOTE_ENVELOPE(i);
+ return rtbuf_in_rtbuf(rtb, j);
+}
+
+s_rtbuf * rtbuf_synth_synth_note_oscillator (s_rtbuf *rtb,
+ unsigned int i)
+{
+ unsigned int j;
+ assert(i < RTBUF_MUSIC_NOTE_MAX);
+ j = RTBUF_SYNTH_SYNTH_IN_NOTE_OSCILLATOR(i);
+ return rtbuf_in_rtbuf(rtb, j);
+}
+
+void rtbuf_synth_synth_delete_note (s_rtbuf *rtb,
+ unsigned int i)
+{
+ s_rtbuf *env = rtbuf_synth_synth_note_envelope(rtb, i);
+ s_rtbuf *osc = rtbuf_synth_synth_note_oscillator(rtb, i);
+ s_rtbuf_synth_synth_data *data;
+ data = (s_rtbuf_synth_synth_data*) rtb->data;
+ if (env || osc) {
+ printf("synth_synth_delete_note %u\n", i);
+ if (env)
+ rtbuf_delete(env);
+ if (osc)
+ rtbuf_delete(osc);
+ data->note_n--;
+ }
+}
+
+void rtbuf_synth_synth_delete_notes (s_rtbuf *rtb)
+{
+ s_rtbuf_synth_synth_data *data;
+ unsigned int i = 0;
+ data = (s_rtbuf_synth_synth_data*) rtb->data;
+ while (i < RTBUF_MUSIC_NOTE_MAX && data->note_n > 0) {
+ rtbuf_synth_synth_delete_note(rtb, i);
+ i++;
+ }
+}
+
+s_rtbuf * rtbuf_synth_synth_new_envelope (s_rtbuf *rtb,
+ unsigned int i)
+{
+ s_rtbuf *ref = rtbuf_in_rtbuf(rtb, RTBUF_SYNTH_SYNTH_IN_ENVELOPE);
+ int env_i;
+ s_rtbuf *env;
+ unsigned int env_vel;
+ unsigned int env_freq;
+ unsigned int env_start;
+ unsigned int env_stop;
+ s_rtbuf_binding *v = &rtb->in[RTBUF_SYNTH_SYNTH_IN_NOTES];
+ unsigned int kbd_i = v->rtb;
+ unsigned int kbd_notes = v->out;
+ unsigned int note_vel = RTBUF_MUSIC_NOTE_IN_VELOCITY(kbd_notes, i);
+ unsigned int note_freq = RTBUF_MUSIC_NOTE_IN_FREQUENCY(kbd_notes, i);
+ unsigned int note_start = RTBUF_MUSIC_NOTE_IN_START(kbd_notes, i);
+ unsigned int note_stop = RTBUF_MUSIC_NOTE_IN_STOP(kbd_notes, i);
+ assert(rtb > g_rtbuf);
+ if (!ref)
+ return 0;
+ if((env_i = rtbuf_clone(ref)) < 0)
+ return 0;
+ env = &g_rtbuf[env_i];
+ env_vel = rtbuf_in_find(env, "velocity");
+ env_freq = rtbuf_in_find(env, "frequency");
+ env_start = rtbuf_in_find(env, "start");
+ env_stop = rtbuf_in_find(env, "stop");
+ rtbuf_bind(kbd_i, note_vel , env, env_vel);
+ rtbuf_bind(kbd_i, note_freq , env, env_freq);
+ rtbuf_bind(kbd_i, note_start, env, env_start);
+ rtbuf_bind(kbd_i, note_stop , env, env_stop);
+ rtbuf_bind(env_i, 0, rtb, RTBUF_SYNTH_SYNTH_IN_NOTE_ENVELOPE(i));
+ if (env->proc->start)
+ env->proc->start(env);
+ if (env->proc->f)
+ env->proc->f(env);
+ /* rtbuf_print_long(env_i); */
+ printf("synth_synth_new_envelope %u\n", i);
+ return env;
+}
+
+s_rtbuf * rtbuf_synth_synth_new_oscillator (s_rtbuf *rtb,
+ unsigned int i)
+{
+ s_rtbuf *ref =
+ rtbuf_in_rtbuf(rtb, RTBUF_SYNTH_SYNTH_IN_OSCILLATOR);
+ int osc_i;
+ s_rtbuf *osc;
+ unsigned int osc_freq;
+ s_rtbuf_binding *v = &rtb->in[RTBUF_SYNTH_SYNTH_IN_NOTES];
+ unsigned int kbd_i = v->rtb;
+ unsigned int kbd_notes = v->out;
+ unsigned int note_freq = RTBUF_MUSIC_NOTE_IN_FREQUENCY(kbd_notes, i);
+ assert(rtb > g_rtbuf);
+ if (!ref)
+ return 0;
+ if ((osc_i = rtbuf_clone(ref)) < 0)
+ return 0;
+ osc = &g_rtbuf[osc_i];
+ osc_freq = rtbuf_in_find(osc, "frequency");
+ rtbuf_bind(kbd_i, note_freq, osc, osc_freq);
+ rtbuf_bind(osc_i, 0, rtb, RTBUF_SYNTH_SYNTH_IN_NOTE_OSCILLATOR(i));
+ if (osc->proc->start)
+ osc->proc->start(osc);
+ if (osc->proc->f)
+ osc->proc->f(osc);
+ /* rtbuf_print_long(osc_i); */
+ return osc;
+}
+
+void rtbuf_synth_synth_update_note_signal (s_rtbuf *rtb,
+ unsigned int i)
+{
+ s_rtbuf_synth_synth_data *data;
+ s_rtbuf_signal_fun env;
+ s_rtbuf_signal_fun osc;
+ unsigned int j = 0;
+ double *signal;
+ assert(rtb);
+ assert(rtb->data);
+ assert(i < RTBUF_MUSIC_NOTE_MAX);
+ rtbuf_signal_fun(rtb, RTBUF_SYNTH_SYNTH_IN_NOTE_ENVELOPE(i), &env);
+ rtbuf_signal_fun(rtb, RTBUF_SYNTH_SYNTH_IN_NOTE_OSCILLATOR(i), &osc);
+ data = (s_rtbuf_synth_synth_data *) rtb->data;
+ signal = data->signal;
+ while (j < RTBUF_SIGNAL_SAMPLES) {
+ double e = env.sample_fun(env.signal, j);
+ double o = osc.sample_fun(osc.signal, j);
+ e = max(0.0, e);
+ *signal += e * o;
+ /* printf(" e=%f o=%f s=%f", e, o, *signal); */
+ signal++;
+ j++;
+ }
+}
+
+void rtbuf_synth_synth_update_note (s_rtbuf *rtb,
+ unsigned int i)
+{
+ s_rtbuf_synth_synth_data *data;
+ s_rtbuf_music_notes *notes =
+ rtbuf_music_notes(rtb, RTBUF_SYNTH_SYNTH_IN_NOTES);
+ s_rtbuf_music_note *note;
+ assert(notes);
+ assert(i < RTBUF_MUSIC_NOTE_MAX);
+ assert(rtb->data);
+ data = (s_rtbuf_synth_synth_data*) rtb->data;
+ note = ¬es->note[i];
+ if (note->velocity > 0.0 && note->start >= 0.0) {
+ s_rtbuf *env = rtbuf_synth_synth_note_envelope(rtb, i);
+ s_rtbuf *osc = rtbuf_synth_synth_note_oscillator(rtb, i);
+ if (!env || !osc) {
+ if (!env)
+ env = rtbuf_synth_synth_new_envelope(rtb, i);
+ if (!osc)
+ osc = rtbuf_synth_synth_new_oscillator(rtb, i);
+ data->note_n++;
+ }
+ if (env && osc) {
+ unsigned int env_state_out = rtbuf_proc_out_find(env->proc,
+ "state");
+ int env_state = rtbuf_out_int(env, env_state_out,
+ RTBUF_SYNTH_ENVELOPE_STATE_STARTED);
+ if (env_state == RTBUF_SYNTH_ENVELOPE_STATE_STARTED)
+ rtbuf_synth_synth_update_note_signal(rtb, i);
+ }
+ }
+ else
+ rtbuf_synth_synth_delete_note(rtb, i);
+}
+
+int rtbuf_synth_synth (s_rtbuf *rtb)
+{
+ s_rtbuf_music_notes *notes =
+ rtbuf_music_notes(rtb, RTBUF_SYNTH_SYNTH_IN_NOTES);
+ s_rtbuf_synth_synth_data *data;
+ unsigned int i = 0;
+ unsigned int notes_n = notes ? notes->note_n : 0;
+ unsigned int n;
+ data = (s_rtbuf_synth_synth_data*) rtb->data;
+ n = data->note_n;
+ rtbuf_signal_zero(data->signal);
+ while (i < RTBUF_MUSIC_NOTE_MAX && (n > 0 || notes_n > 0)) {
+ s_rtbuf_music_note *note = notes ? ¬es->note[i] : 0;
+ if (rtbuf_music_note_p(note))
+ notes_n--;
+ if (rtbuf_synth_synth_note_envelope(rtb, i))
+ n--;
+ rtbuf_synth_synth_update_note(rtb, i);
+ i++;
+ }
+ return 0;
+}
+
+int rtbuf_synth_synth_start (s_rtbuf *rtb)
+{
+ s_rtbuf_synth_synth_data *data;
+ assert(rtb->proc->out_bytes == sizeof(*data));
+ data = (s_rtbuf_synth_synth_data*) rtb->data;
+ return 0;
+}
+
+int rtbuf_synth_synth_stop (s_rtbuf *rtb)
+{
+ rtbuf_synth_synth_delete_notes(rtb);
+ return 0;
+}
+
+s_rtbuf_lib_proc rtbuf_lib_proc =
+ { "synth",
+ rtbuf_synth_synth,
+ rtbuf_synth_synth_start,
+ 0,
+ rtbuf_synth_synth_in,
+ rtbuf_synth_synth_out };
+
+unsigned long rtbuf_lib_ver = RTBUF_LIB_VER;
diff --git a/lib/synth_type.c b/lib/synth_type.c
new file mode 100644
index 0000000..39b1b23
--- /dev/null
+++ b/lib/synth_type.c
@@ -0,0 +1,45 @@
+
+#include <stdio.h>
+#include <rtbuf/rtbuf.h>
+#include <rtbuf/music.h>
+#include <rtbuf/music_type.h>
+
+void notes_in ()
+{
+ unsigned int i = 0;
+ const char *st = "RTBUF_SIGNAL_TYPE";
+ printf("\n"
+ "#define RTBUF_SYNTH_NOTES_IN(note) \\\n");
+ while (i < RTBUF_MUSIC_NOTE_MAX) {
+ printf(" { note \"[%u].envelope\" , %s }, \\\n", i, st);
+ printf(" { note \"[%u].oscillator\", %s }", i, st);
+ if (i < RTBUF_MUSIC_NOTE_MAX - 1)
+ printf(", \\");
+ printf("\n");
+ i++;
+ }
+ i = 0;
+ printf("\n"
+ "#define RTBUF_SYNTH_NOTES_IN_ENUM(note) \\\n");
+ while (i < RTBUF_MUSIC_NOTE_MAX) {
+ printf(" note ## _%u_ENVELOPE , \\\n", i);
+ printf(" note ## _%u_OSCILLATOR", i);
+ if (i < RTBUF_MUSIC_NOTE_MAX - 1)
+ printf(", \\");
+ printf("\n");
+ i++;
+ }
+}
+
+int main ()
+{
+ printf("/* file generated by rtbuf_synth_type */\n");
+ printf("#ifndef RTBUF_SYNTH_TYPE_H\n"
+ "#define RTBUF_SYNTH_TYPE_H\n"
+ "\n"
+ "#include <rtbuf/signal_type.h>\n");
+ notes_in();
+ printf("\n"
+ "#endif\n");
+ return 0;
+}
diff --git a/test_glfw3_oscilloscope b/test_glfw3_oscilloscope
index 794706e..2b1e950 100644
--- a/test_glfw3_oscilloscope
+++ b/test_glfw3_oscilloscope
@@ -1,8 +1,9 @@
-load signal
-load glfw3
-new signal sinus
-new signal square
-new glfw3 oscilloscope
-bind 0 0 2 0
-bind 1 0 2 1
+load signal/sinus
+load signal/square
+load glfw3/oscilloscope
+let sin00 = new signal/sinus
+let sq00 = new signal/square
+let osc00 = new glfw3/oscilloscope
+bind sin00 signal osc00 black
+bind sq00 signal osc00 red
start
diff --git a/test_sinus b/test_sinus
index 79db059..1c3f238 100644
--- a/test_sinus
+++ b/test_sinus
@@ -1,6 +1,6 @@
-load signal
-load portaudio
-set sinus00 = new signal sinus
-set output00 = new portaudio output
+load signal/sinus
+let sinus00 = new signal/sinus
+load portaudio/output
+let output00 = new portaudio/output
bind sinus00 signal output00 left
bind sinus00 signal output00 right
diff --git a/test_synth b/test_synth
index d0d8e68..9ea16a5 100644
--- a/test_synth
+++ b/test_synth
@@ -1,39 +1,44 @@
-load signal
-load glfw3
-load synth
-load dynamic
-load portaudio
-
-set Keyboard00 = new glfw3 keyboard
-set ADSR00 = new synth adsr
-set Square00 = new signal square
-set Synth00 = new synth synth
+
+load glfw3/keyboard
+let Keyboard00 = new glfw3/keyboard
+load synth/adsr
+let ADSR00 = new synth/adsr
+load signal/square
+let Square00 = new signal/square
+load synth/synth
+let Synth00 = new synth/synth
bind Keyboard00 notes Synth00 notes
bind ADSR00 signal Synth00 envelope
bind Square00 signal Synth00 oscillator
-set Delay00 = new signal delay
+load signal/delay
+let Delay00 = new signal/delay
bind Synth00 signal Delay00 signal
-set Flanger00 = new signal flanger
+load signal/flanger
+let Flanger00 = new signal/flanger
bind Delay00 signal Flanger00 signal
-set LP00 = new signal lowpass5
+load signal/lowpass5
+let LP00 = new signal/lowpass5
bind Flanger00 signal LP00 signal
-set Limiter00 = new dynamic limiter
+load dynamic/limiter
+let Limiter00 = new dynamic/limiter
bind LP00 signal Limiter00 signal
-set Flanger01 = new signal flanger
+let Flanger01 = new signal/flanger
bind Synth00 signal Flanger01 signal
-set HP01 = new signal bandpass2
+load signal/bandpass2
+let HP01 = new signal/bandpass2
bind Flanger01 signal HP01 signal
-set Limiter01 = new dynamic limiter
+let Limiter01 = new dynamic/limiter
bind HP01 signal Limiter01 signal
-set Output = new portaudio output
+load portaudio/output
+let Output = new portaudio/output
bind Limiter01 signal Output left
bind Limiter00 signal Output right
start