diff options
author | IOhannes m zmölnig <zmoelnig@umlautQ.umlaeute.mur.at> | 2016-05-17 12:21:04 +0200 |
---|---|---|
committer | IOhannes m zmölnig <zmoelnig@umlautQ.umlaeute.mur.at> | 2016-05-17 12:21:04 +0200 |
commit | 248790aca5d5b6dc9a8edeea1abed0195ac1338e (patch) | |
tree | c473c68af2ab5d091d7035fa1b539cbaf2ac2e4f /audio.c | |
parent | 110d59c341b8c50c04f30d90e85e9b8f6f329a0e (diff) |
Imported Upstream version 16.5~dfsg
Diffstat (limited to 'audio.c')
-rw-r--r-- | audio.c | 44 |
1 files changed, 32 insertions, 12 deletions
@@ -83,7 +83,13 @@ /* these pull in stdbool.h apparently, so they have to precede sndlib.h */ #endif -#define HAVE_JACK_IN_LINUX (MUS_JACK && __linux__) +/* #define HAVE_JACK_IN_LINUX (MUS_JACK && __linux__) */ +/* using JACK on GNU/linux, GNU/kFreeBSD and GNU/Hurd is all the same */ +#if ((defined __linux__) || ((defined __FreeBSD_kernel__) && (defined __GLIBC__)) || (defined __GNU__)) + #define HAVE_JACK_IN_LINUX MUS_JACK +#else + #define HAVE_JACK_IN_LINUX 0 +#endif #include "_sndlib.h" #include "sndlib-strings.h" @@ -4799,7 +4805,7 @@ int mus_audio_read(int line, char *buf, int bytes) #include <fcntl.h> #include <sys/audioio.h> #include <sys/ioctl.h> - +#include <sys/param.h> #define return_error_exit(Error_Type, Audio_Line, Ur_Error_Message) \ do { char *Error_Message; Error_Message = Ur_Error_Message; \ @@ -4871,6 +4877,11 @@ static int cur_chans = 1, cur_srate = 22050; int mus_audio_write(int line, char *buf, int bytes) { +#if defined(__NetBSD__) && (__NetBSD_Version__ >= 700000000) + if (write(line, buf, bytes) != bytes) + return_error_exit(MUS_AUDIO_WRITE_ERROR, line, + mus_format("write error: %s", strerror(errno))); +#else /* trouble... AUDIO_WSEEK always returns 0, no way to tell that I'm about to * hit "hiwat", but when I do, it hangs. Can't use AUDIO_DRAIN -- * it introduces interruptions. Not sure what to do... @@ -4888,14 +4899,26 @@ int mus_audio_write(int line, char *buf, int bytes) else usleep(10000); mus_audio_write(line, (char *)(buf + b), bytes - b); } +#endif return(MUS_NO_ERROR); } +/* from Mike Scholz, 11-Feb-16 (edited): + * On Netbsd sound output with Snd and Sndplay stops before the sound is really at the end. + * [In audioplay] after the read-write loop they call ioctl(fd, AUDIO_DRAIN, NULL). + * Before closing sound output they call ioctl(fd, AUDIO_FLUSH, NULL) (like in audio.c), + * and in addition ioctl(fd, AUDIO_SETINFO, &info). The latter requires that + * audio_info_t a_info be a global variable. The AUDIO_DRAIN call has been in their + * sources since version 1.1 of /usr/src/usr.bin/audio/play/play.c from March 1999. + */ + +static audio_info_t a_info; int mus_audio_close(int line) { - usleep(100000); - ioctl(line, AUDIO_FLUSH, 0); + ioctl(line, AUDIO_DRAIN, NULL); + ioctl(line, AUDIO_FLUSH, NULL); + ioctl(line, AUDIO_SETINFO, &a_info); close(line); return(MUS_NO_ERROR); } @@ -4906,7 +4929,6 @@ static int netbsd_default_outputs = (AUDIO_HEADPHONE | AUDIO_LINE_OUT | AUDIO_SP int mus_audio_open_output(int dev, int srate, int chans, mus_sample_t samp_type, int size) { int line, encode; - audio_info_t a_info; line = open("/dev/sound", O_WRONLY); /* /dev/audio assumes mono 8-bit mulaw */ if (line == -1) @@ -5080,16 +5102,14 @@ static pa_simple *pa_out = NULL, *pa_in = NULL; int mus_audio_open_output(int dev, int srate, int chans, mus_sample_t samp_type, int size) { - pa_sample_spec *spec; + pa_sample_spec spec = {0}; int error; - spec = (pa_sample_spec *)malloc(sizeof(pa_sample_spec)); - spec->format = sndlib_to_pa_format(samp_type); - spec->rate = srate; - spec->channels = chans; + spec.format = sndlib_to_pa_format(samp_type); + spec.rate = srate; + spec.channels = chans; - pa_out = pa_simple_new(NULL, "snd", PA_STREAM_PLAYBACK, NULL, "playback", spec, NULL, NULL, &error); - free(spec); + pa_out = pa_simple_new(NULL, "snd", PA_STREAM_PLAYBACK, NULL, "playback", &spec, NULL, NULL, &error); if (!pa_out) { fprintf(stderr, "can't play: %s\n", pa_strerror(error)); |