commit 5e0ef3147f9f69fb1679e52758236409d90d98e3
parent 0e8a8c2fdaafd53d147dc9bc74f11266033a77e8
Author: sin <sin@2f30.org>
Date: Fri, 3 Jun 2016 11:35:18 +0100
Open master output on demand
This also handles the case when we lose the output midway through.
Similar code should be written for the monitor output.
Diffstat:
1 file changed, 10 insertions(+), 5 deletions(-)
diff --git a/ncmixer.c b/ncmixer.c
@@ -21,6 +21,9 @@
#define SA struct sockaddr
#define CH0_NAME "/tmp/ch0"
#define CH1_NAME "/tmp/ch1"
+/* XXX: these two should be cmdline options */
+#define MASTER_DEV "rsnd/0" /* bypass sndiod for now */
+#define MONITOR_DEV "rsnd/1"
#define FPS 25
#define BITS 16
#define RATE 44100
@@ -390,7 +393,13 @@ loop(void)
attenuate();
mix();
- audio_play(sio_hdl_master, out_buf, out_nsamples * 2);
+ if (sio_hdl_master == NULL) {
+ sio_hdl_master = audio_open(MASTER_DEV);
+ if (sio_hdl_master != NULL &&
+ audio_play(sio_hdl_master, out_buf,
+ out_nsamples * 2) == -1)
+ audio_close(&sio_hdl_master);
+ }
draw();
}
}
@@ -424,13 +433,9 @@ curses_exit(void)
int
main(void)
{
- sio_hdl_master = audio_open(SIO_DEVANY);
- if (sio_hdl_master == NULL)
- return 1;
curses_init();
draw();
loop();
curses_exit();
- audio_close(&sio_hdl_master);
return 0;
}