diff --git a/build/rtbuf_sndio/Makefile b/build/rtbuf_sndio/Makefile
index 76e9218..55f76bc 100644
--- a/build/rtbuf_sndio/Makefile
+++ b/build/rtbuf_sndio/Makefile
@@ -8,7 +8,7 @@ CFLAGS = -O0 -ggdb -W -Wall -Werror -fpic
LDFLAGS = -fPIC -shared
LIBS = -lsndio
HEADERS = rtbuf.h rtbuf_lib.h rtbuf_signal.h rtbuf_sndio.h
-OBJECTS = rtbuf_sndio.o
+OBJECTS = rtbuf_sndio.o rtbuf_sndio_input.o rtbuf_sndio_output.o
SRC = ${HEADERS} ${OBJECTS:%.o=%.c}
diff --git a/rtbuf_sndio.c b/rtbuf_sndio.c
index 2a18289..dd8f5b5 100644
--- a/rtbuf_sndio.c
+++ b/rtbuf_sndio.c
@@ -27,120 +27,3 @@ void print_sio_par (struct sio_par *par)
printf("#<sio_par bits=%i sig=%i rchan=%i pchan=%i rate=%i>",
par->bits, par->sig, par->rchan, par->pchan, par->rate);
}
-
-int rtbuf_sndio_input (s_rtbuf *rtb)
-{
- /*
- s_sndio_input_data *data = (s_sndio_input_data*) rtb->data;
- */
- (void) rtb;
- return 0;
-}
-
-int rtbuf_sndio_input_start (s_rtbuf *rtb)
-{
- (void) rtb;
- return 0;
-}
-
-int rtbuf_sndio_input_stop (s_rtbuf *rtb)
-{
- (void) rtb;
- return 0;
-}
-
-void rtbuf_sndio_output_parameters (struct sio_par *want)
-{
- bzero(want, sizeof(struct sio_par));
- sio_initpar(want);
- want->bits = 16;
- want->sig = 1;
- want->rchan = 0;
- want->pchan = RTBUF_SNDIO_CHANNELS;
- want->rate = RTBUF_SIGNAL_SAMPLERATE;
- want->appbufsz = RTBUF_SIGNAL_SAMPLES;
- want->xrun = SIO_SYNC;
- print_sio_par(want); printf("\n");
-}
-
-int rtbuf_sndio_output_check_parameters (struct sio_par *have)
-{
- print_sio_par(have); printf("\n");
- int ok = (have->bits == 16 &&
- have->sig == 1 &&
- have->rchan == 0 &&
- have->pchan == RTBUF_SNDIO_CHANNELS &&
- have->rate == RTBUF_SIGNAL_SAMPLERATE);
- return ok;
-}
-
-int rtbuf_sndio_output_start (s_rtbuf *rtb)
-{
- s_rtbuf_sndio_output_data *data;
- int err = 0;
- data = (s_rtbuf_sndio_output_data*) rtb->data;
- if (!data->sio_hdl) {
- data->sio_hdl = sio_open(SIO_DEVANY, SIO_PLAY, 0);
- if (!data->sio_hdl)
- err = rtbuf_err("sndio_output_start: sio_open failed");
- else {
- rtbuf_sndio_output_parameters(&data->want);
- if (sio_setpar(data->sio_hdl, &data->want) != 1)
- err = rtbuf_err("sndio_output_start: sio_setpar failed");
- else if (sio_getpar(data->sio_hdl, &data->have) != 1)
- err = rtbuf_err("sndio_output_start: sio_getpar failed");
- else if (!rtbuf_sndio_output_check_parameters(&data->have))
- err = rtbuf_err("sndio_output_start: check_parameters failed");
- else if (sio_start(data->sio_hdl) != 1)
- err = rtbuf_err("sndio_output_start: sio_start failed");
- }
- }
- return err;
-}
-
-int rtbuf_sndio_output_stop (s_rtbuf *rtb)
-{
- s_rtbuf_sndio_output_data *data;
- data = (s_rtbuf_sndio_output_data*) rtb->data;
- if (data->sio_hdl) {
- sio_close(data->sio_hdl);
- data->sio_hdl = 0;
- }
- return 0;
-}
-
-int rtbuf_sndio_output (s_rtbuf *rtb)
-{
- s_rtbuf_sndio_output_data *data;
- double *in[RTBUF_SNDIO_CHANNELS];
- short *sample;
- unsigned int i = 0;
- unsigned int j = 0;
- data = (s_rtbuf_sndio_output_data*) rtb->data;
- sample = data->samples;
- //printf("sndio_output");
- while (j < RTBUF_SNDIO_CHANNELS) {
- in[j] = rtb->var[j] < 0 ? 0 : (double*) g_rtbuf[rtb->var[j]].data;
- j++;
- }
- while (i < RTBUF_SIGNAL_SAMPLES) {
- j = 0;
- while (j < RTBUF_SNDIO_CHANNELS) {
- if (in[j]) {
- double limit = max(-1.0, min(*in[j], 1.0));
- in[j]++;
- *sample = (short) (((1 << 15) - 1) * limit);
- //printf(" %i", *sample);
- }
- else
- *sample = 0;
- sample++;
- j++;
- }
- i++;
- }
- sio_write(data->sio_hdl, data->samples,
- sizeof(data->samples));
- //printf("\n");
- return 0;
-}
diff --git a/rtbuf_sndio.h b/rtbuf_sndio.h
index 224f584..314b8bb 100644
--- a/rtbuf_sndio.h
+++ b/rtbuf_sndio.h
@@ -1,6 +1,8 @@
#ifndef RTBUF_SNDIO_H
#define RTBUF_SNDIO_H
+void print_sio_par (struct sio_par *par);
+
enum {
RTBUF_SNDIO_LEFT = 0,
RTBUF_SNDIO_RIGHT,
diff --git a/rtbuf_sndio_input.c b/rtbuf_sndio_input.c
new file mode 100644
index 0000000..d0321e9
--- /dev/null
+++ b/rtbuf_sndio_input.c
@@ -0,0 +1,28 @@
+
+#include <sndio.h>
+#include <stdio.h>
+#include <strings.h>
+#include "rtbuf.h"
+#include "rtbuf_signal.h"
+#include "rtbuf_sndio.h"
+
+int rtbuf_sndio_input (s_rtbuf *rtb)
+{
+ /*
+ s_sndio_input_data *data = (s_sndio_input_data*) rtb->data;
+ */
+ (void) rtb;
+ return 0;
+}
+
+int rtbuf_sndio_input_start (s_rtbuf *rtb)
+{
+ (void) rtb;
+ return 0;
+}
+
+int rtbuf_sndio_input_stop (s_rtbuf *rtb)
+{
+ (void) rtb;
+ return 0;
+}
diff --git a/rtbuf_sndio_output.c b/rtbuf_sndio_output.c
new file mode 100644
index 0000000..3a434d7
--- /dev/null
+++ b/rtbuf_sndio_output.c
@@ -0,0 +1,103 @@
+
+#include <sndio.h>
+#include <stdio.h>
+#include <strings.h>
+#include "rtbuf.h"
+#include "rtbuf_signal.h"
+#include "rtbuf_sndio.h"
+
+void rtbuf_sndio_output_parameters (struct sio_par *want)
+{
+ bzero(want, sizeof(struct sio_par));
+ sio_initpar(want);
+ want->bits = 16;
+ want->sig = 1;
+ want->rchan = 0;
+ want->pchan = RTBUF_SNDIO_CHANNELS;
+ want->rate = RTBUF_SIGNAL_SAMPLERATE;
+ want->appbufsz = RTBUF_SIGNAL_SAMPLES;
+ want->xrun = SIO_SYNC;
+ print_sio_par(want); printf("\n");
+}
+
+int rtbuf_sndio_output_check_parameters (struct sio_par *have)
+{
+ print_sio_par(have); printf("\n");
+ int ok = (have->bits == 16 &&
+ have->sig == 1 &&
+ have->rchan == 0 &&
+ have->pchan == RTBUF_SNDIO_CHANNELS &&
+ have->rate == RTBUF_SIGNAL_SAMPLERATE);
+ return ok;
+}
+
+int rtbuf_sndio_output_start (s_rtbuf *rtb)
+{
+ s_rtbuf_sndio_output_data *data;
+ int err = 0;
+ data = (s_rtbuf_sndio_output_data*) rtb->data;
+ if (!data->sio_hdl) {
+ data->sio_hdl = sio_open(SIO_DEVANY, SIO_PLAY, 0);
+ if (!data->sio_hdl)
+ err = rtbuf_err("sndio_output_start: sio_open failed");
+ else {
+ rtbuf_sndio_output_parameters(&data->want);
+ if (sio_setpar(data->sio_hdl, &data->want) != 1)
+ err = rtbuf_err("sndio_output_start: sio_setpar failed");
+ else if (sio_getpar(data->sio_hdl, &data->have) != 1)
+ err = rtbuf_err("sndio_output_start: sio_getpar failed");
+ else if (!rtbuf_sndio_output_check_parameters(&data->have))
+ err = rtbuf_err("sndio_output_start: check_parameters failed");
+ else if (sio_start(data->sio_hdl) != 1)
+ err = rtbuf_err("sndio_output_start: sio_start failed");
+ }
+ }
+ return err;
+}
+
+int rtbuf_sndio_output_stop (s_rtbuf *rtb)
+{
+ s_rtbuf_sndio_output_data *data;
+ data = (s_rtbuf_sndio_output_data*) rtb->data;
+ if (data->sio_hdl) {
+ sio_close(data->sio_hdl);
+ data->sio_hdl = 0;
+ }
+ return 0;
+}
+
+int rtbuf_sndio_output (s_rtbuf *rtb)
+{
+ s_rtbuf_sndio_output_data *data;
+ double *in[RTBUF_SNDIO_CHANNELS];
+ short *sample;
+ unsigned int i = 0;
+ unsigned int j = 0;
+ data = (s_rtbuf_sndio_output_data*) rtb->data;
+ sample = data->samples;
+ //printf("sndio_output");
+ while (j < RTBUF_SNDIO_CHANNELS) {
+ in[j] = rtb->var[j] < 0 ? 0 : (double*) g_rtbuf[rtb->var[j]].data;
+ j++;
+ }
+ while (i < RTBUF_SIGNAL_SAMPLES) {
+ j = 0;
+ while (j < RTBUF_SNDIO_CHANNELS) {
+ if (in[j]) {
+ double limit = max(-1.0, min(*in[j], 1.0));
+ in[j]++;
+ *sample = (short) (((1 << 15) - 1) * limit);
+ //printf(" %i", *sample);
+ }
+ else
+ *sample = 0;
+ sample++;
+ j++;
+ }
+ i++;
+ }
+ sio_write(data->sio_hdl, data->samples,
+ sizeof(data->samples));
+ //printf("\n");
+ return 0;
+}