X-Git-Url: https://git.distorted.org.uk/~mdw/disorder/blobdiff_plain/8023f60b5faf0e0f48c71d13c2f1319daff7871b..6e2c9f5f8b0b75d89c750dd1a2d8a4fb9d1d3952:/server/speaker.c diff --git a/server/speaker.c b/server/speaker.c index 1eb3a24..be783af 100644 --- a/server/speaker.c +++ b/server/speaker.c @@ -57,6 +57,12 @@ #include #endif +#ifdef WORDS_BIGENDIAN +# define MACHINE_AO_FMT AO_FMT_BIG +#else +# define MACHINE_AO_FMT AO_FMT_LITTLE +#endif + #define BUFFER_SECONDS 5 /* How many seconds of input to * buffer. */ @@ -241,7 +247,7 @@ static int formats_equal(const ao_sample_format *a, static void idle(void) { D(("idle")); #if API_ALSA - if(pcm) { + if(!config->speaker_command && pcm) { int err; if((err = snd_pcm_nonblock(pcm, 0)) < 0) @@ -300,20 +306,39 @@ static void log_params(snd_pcm_hw_params_t *hwparams, } #endif -static void soxargs(const char ***pp, char **qq, ao_sample_format *ao) -{ +static void soxargs(const char ***pp, char **qq, ao_sample_format *ao) { int n; *(*pp)++ = "-t.raw"; *(*pp)++ = "-s"; *(*pp)++ = *qq; n = sprintf(*qq, "-r%d", ao->rate); *qq += n + 1; - switch(ao->byte_format) { + *(*pp)++ = *qq; n = sprintf(*qq, "-c%d", ao->channels); *qq += n + 1; + /* sox 12.17.9 insists on -b etc; CVS sox insists on - etc; both are + * deployed! */ + switch(config->sox_generation) { + case 0: + if(ao->bits != 8 + && ao->byte_format != AO_FMT_NATIVE + && ao->byte_format != MACHINE_AO_FMT) { + *(*pp)++ = "-x"; + } + switch(ao->bits) { + case 8: *(*pp)++ = "-b"; break; + case 16: *(*pp)++ = "-w"; break; + case 32: *(*pp)++ = "-l"; break; + case 64: *(*pp)++ = "-d"; break; + default: fatal(0, "cannot handle sample size %d", (int)ao->bits); + } + break; + case 1: + switch(ao->byte_format) { case AO_FMT_NATIVE: break; - case AO_FMT_BIG: *(*pp)++ = "-B"; - case AO_FMT_LITTLE: *(*pp)++ = "-L"; + case AO_FMT_BIG: *(*pp)++ = "-B"; break; + case AO_FMT_LITTLE: *(*pp)++ = "-L"; break; + } + *(*pp)++ = *qq; n = sprintf(*qq, "-%d", ao->bits/8); *qq += n + 1; + break; } - *(*pp)++ = *qq; n = sprintf(*qq, "-%d", ao->bits/8); *qq += n + 1; - *(*pp)++ = *qq; n = sprintf(*qq, "-c%d", ao->channels); *qq += n + 1; } /* Make sure the sound device is open and has the right sample format. Return @@ -369,6 +394,8 @@ static int activate(void) { } return 0; } + if(config->speaker_command) + return -1; #if API_ALSA /* If we need to change format then close the current device. */ if(pcm && !formats_equal(&playing->format, &pcm_format)) @@ -530,7 +557,7 @@ static void play(size_t frames) { else avail_bytes = playing->used; - if(kidfd == -1) { + if(!config->speaker_command) { #if API_ALSA snd_pcm_sframes_t pcm_written_frames; size_t avail_frames; @@ -636,7 +663,6 @@ int main(int argc, char **argv) { #endif set_progname(argv); - mem_init(0); if(!setlocale(LC_CTYPE, "")) fatal(errno, "error calling setlocale"); while((n = getopt_long(argc, argv, "hVc:dD", options, 0)) >= 0) { switch(n) { @@ -690,9 +716,10 @@ int main(int argc, char **argv) { alsa_slots = -1; kid_slot = -1; if(ready && !forceplay) { - if(kidfd >= 0) - kid_slot = addfd(kidfd, POLLOUT); - else { + if(config->speaker_command) { + if(kidfd >= 0) + kid_slot = addfd(kidfd, POLLOUT); + } else { #if API_ALSA int retry = 3;