Commit dca29c5009efb37b4f2323fb56ae5d2707e2cfd5

Thomas de Grivel 2018-07-23T11:08:16

fix sndio

diff --git a/rtbuf_sndio.c b/rtbuf_sndio.c
index c47fb80..011fbbb 100644
--- a/rtbuf_sndio.c
+++ b/rtbuf_sndio.c
@@ -1,5 +1,6 @@
 
 #include <sndio.h>
+#include <stdio.h>
 #include <strings.h>
 #include "rtbuf.h"
 #include "rtbuf_lib.h"
@@ -62,9 +63,16 @@ int sndio_input_stop (s_rtbuf *rtb)
   return 0;
 }
 
+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);
+}
+
 void 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;
@@ -72,10 +80,12 @@ void sndio_output_parameters (struct sio_par *want)
   want->rate = RTBUF_SIGNAL_SAMPLERATE;
   want->appbufsz = RTBUF_SIGNAL_SAMPLES;
   want->xrun = SIO_SYNC;
+  print_sio_par(want); printf("\n");
 }
 
 int 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 &&
@@ -98,8 +108,10 @@ int sndio_output_start (s_rtbuf *rtb)
         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 (sndio_output_check_parameters(&data->have))
+      else if (!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;
@@ -132,14 +144,19 @@ int sndio_output (s_rtbuf *rtb)
   short *sample = data->samples;
   unsigned int i = 0;
   unsigned int j = 0;
-  while (j < RTBUF_SNDIO_CHANNELS)
+  //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;
@@ -150,5 +167,12 @@ int sndio_output (s_rtbuf *rtb)
   }
   sio_write(data->sio_hdl, data->samples,
             sizeof(data->samples));
+  //printf("\n");
   return 0;
 }
+
+int rtbuf_err (const char *msg)
+{
+  fprintf(stderr, "%s\n", msg);
+  return -1;
+}