1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate  * Copyright 1989-2003 Sun Microsystems, Inc.  All rights reserved.
24*7c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
25*7c478bd9Sstevel@tonic-gate  */
26*7c478bd9Sstevel@tonic-gate 
27*7c478bd9Sstevel@tonic-gate /*
28*7c478bd9Sstevel@tonic-gate  * This file contains routines to read and write the audio device state.
29*7c478bd9Sstevel@tonic-gate  */
30*7c478bd9Sstevel@tonic-gate 
31*7c478bd9Sstevel@tonic-gate #include <errno.h>
32*7c478bd9Sstevel@tonic-gate #include <stropts.h>
33*7c478bd9Sstevel@tonic-gate #include <sys/types.h>
34*7c478bd9Sstevel@tonic-gate #include <sys/file.h>
35*7c478bd9Sstevel@tonic-gate #include <sys/stat.h>
36*7c478bd9Sstevel@tonic-gate #include <sys/ioctl.h>
37*7c478bd9Sstevel@tonic-gate 
38*7c478bd9Sstevel@tonic-gate #include <libaudio_impl.h>
39*7c478bd9Sstevel@tonic-gate #include <audio_errno.h>
40*7c478bd9Sstevel@tonic-gate #include <audio_hdr.h>
41*7c478bd9Sstevel@tonic-gate #include <audio_device.h>
42*7c478bd9Sstevel@tonic-gate 
43*7c478bd9Sstevel@tonic-gate 
44*7c478bd9Sstevel@tonic-gate /*
45*7c478bd9Sstevel@tonic-gate  * Get device information structure.
46*7c478bd9Sstevel@tonic-gate  */
47*7c478bd9Sstevel@tonic-gate int
audio_getinfo(int fd,Audio_info * ip)48*7c478bd9Sstevel@tonic-gate audio_getinfo(int fd, Audio_info *ip)
49*7c478bd9Sstevel@tonic-gate {
50*7c478bd9Sstevel@tonic-gate 	if (ioctl(fd, AUDIO_GETINFO, (char *)ip) < 0) {
51*7c478bd9Sstevel@tonic-gate 		return (AUDIO_UNIXERROR);
52*7c478bd9Sstevel@tonic-gate 	} else {
53*7c478bd9Sstevel@tonic-gate 		return (AUDIO_SUCCESS);
54*7c478bd9Sstevel@tonic-gate 	}
55*7c478bd9Sstevel@tonic-gate }
56*7c478bd9Sstevel@tonic-gate 
57*7c478bd9Sstevel@tonic-gate /*
58*7c478bd9Sstevel@tonic-gate  * Set device information structure.
59*7c478bd9Sstevel@tonic-gate  * The calling routine should use AUDIO_INITINFO prior to setting new values.
60*7c478bd9Sstevel@tonic-gate  */
61*7c478bd9Sstevel@tonic-gate int
audio_setinfo(int fd,Audio_info * ip)62*7c478bd9Sstevel@tonic-gate audio_setinfo(int fd, Audio_info *ip)
63*7c478bd9Sstevel@tonic-gate {
64*7c478bd9Sstevel@tonic-gate 	if (ioctl(fd, AUDIO_SETINFO, (char *)ip) < 0) {
65*7c478bd9Sstevel@tonic-gate 		return (AUDIO_UNIXERROR);
66*7c478bd9Sstevel@tonic-gate 	} else {
67*7c478bd9Sstevel@tonic-gate 		return (AUDIO_SUCCESS);
68*7c478bd9Sstevel@tonic-gate 	}
69*7c478bd9Sstevel@tonic-gate }
70*7c478bd9Sstevel@tonic-gate 
71*7c478bd9Sstevel@tonic-gate /*
72*7c478bd9Sstevel@tonic-gate  * Return an Audio_hdr corresponding to the encoding configuration
73*7c478bd9Sstevel@tonic-gate  * of the audio device on 'fd'.
74*7c478bd9Sstevel@tonic-gate  */
75*7c478bd9Sstevel@tonic-gate int
audio__setplayhdr(int fd,Audio_hdr * hdrp,unsigned int which)76*7c478bd9Sstevel@tonic-gate audio__setplayhdr(int fd, Audio_hdr *hdrp, unsigned int which)
77*7c478bd9Sstevel@tonic-gate {
78*7c478bd9Sstevel@tonic-gate 	Audio_hdr		thdr;
79*7c478bd9Sstevel@tonic-gate 	Audio_info		info;
80*7c478bd9Sstevel@tonic-gate 	struct audio_prinfo	*prinfo;
81*7c478bd9Sstevel@tonic-gate 	int			err;
82*7c478bd9Sstevel@tonic-gate 
83*7c478bd9Sstevel@tonic-gate 	if (which & AUDIO__PLAY)
84*7c478bd9Sstevel@tonic-gate 		prinfo = &info.play;
85*7c478bd9Sstevel@tonic-gate 	else if (which & AUDIO__RECORD)
86*7c478bd9Sstevel@tonic-gate 		prinfo = &info.record;
87*7c478bd9Sstevel@tonic-gate 	else
88*7c478bd9Sstevel@tonic-gate 		return (AUDIO_ERR_BADARG);
89*7c478bd9Sstevel@tonic-gate 
90*7c478bd9Sstevel@tonic-gate 	if (which & AUDIO__SET) {
91*7c478bd9Sstevel@tonic-gate 		thdr = *hdrp;			/* save original hdr */
92*7c478bd9Sstevel@tonic-gate 		AUDIO_INITINFO(&info);
93*7c478bd9Sstevel@tonic-gate 		prinfo->sample_rate = hdrp->sample_rate;
94*7c478bd9Sstevel@tonic-gate 		prinfo->channels = hdrp->channels;
95*7c478bd9Sstevel@tonic-gate 		prinfo->encoding = hdrp->encoding;
96*7c478bd9Sstevel@tonic-gate 		prinfo->precision = hdrp->bytes_per_unit * 8;
97*7c478bd9Sstevel@tonic-gate 		err = audio_setinfo(fd, &info);
98*7c478bd9Sstevel@tonic-gate 	} else {
99*7c478bd9Sstevel@tonic-gate 		err = audio_getinfo(fd, &info);
100*7c478bd9Sstevel@tonic-gate 	}
101*7c478bd9Sstevel@tonic-gate 
102*7c478bd9Sstevel@tonic-gate 	/* Decode back into the header structure */
103*7c478bd9Sstevel@tonic-gate 	/* since the I_SMSG is set, upon completion of updating 	*/
104*7c478bd9Sstevel@tonic-gate 	/* the format, the driver sends the msg  so the 		*/
105*7c478bd9Sstevel@tonic-gate 	/* system call is interrupted.  For now, just ignore this 	*/
106*7c478bd9Sstevel@tonic-gate 	if ((err == AUDIO_SUCCESS) || (errno == EINTR)) {
107*7c478bd9Sstevel@tonic-gate 		hdrp->sample_rate = prinfo->sample_rate;
108*7c478bd9Sstevel@tonic-gate 		hdrp->channels = prinfo->channels;
109*7c478bd9Sstevel@tonic-gate 		hdrp->data_size = AUDIO_UNKNOWN_SIZE;
110*7c478bd9Sstevel@tonic-gate 		hdrp->encoding = prinfo->encoding;
111*7c478bd9Sstevel@tonic-gate 		switch (hdrp->encoding) {
112*7c478bd9Sstevel@tonic-gate 		case AUDIO_ENCODING_ULAW:
113*7c478bd9Sstevel@tonic-gate 		case AUDIO_ENCODING_ALAW:
114*7c478bd9Sstevel@tonic-gate 		case AUDIO_ENCODING_LINEAR:
115*7c478bd9Sstevel@tonic-gate 		case AUDIO_ENCODING_LINEAR8:
116*7c478bd9Sstevel@tonic-gate 		case AUDIO_ENCODING_FLOAT:
117*7c478bd9Sstevel@tonic-gate 			hdrp->bytes_per_unit = prinfo->precision / 8;
118*7c478bd9Sstevel@tonic-gate 			hdrp->samples_per_unit = 1;
119*7c478bd9Sstevel@tonic-gate 			break;
120*7c478bd9Sstevel@tonic-gate 		default:
121*7c478bd9Sstevel@tonic-gate 			return (AUDIO_ERR_ENCODING);
122*7c478bd9Sstevel@tonic-gate 		}
123*7c478bd9Sstevel@tonic-gate 		if (which & AUDIO__SET) {
124*7c478bd9Sstevel@tonic-gate 			/* Check to see if *all* changes took effect */
125*7c478bd9Sstevel@tonic-gate 			if (audio_cmp_hdr(hdrp, &thdr) != 0)
126*7c478bd9Sstevel@tonic-gate 				return (AUDIO_ERR_NOEFFECT);
127*7c478bd9Sstevel@tonic-gate 		}
128*7c478bd9Sstevel@tonic-gate 	}
129*7c478bd9Sstevel@tonic-gate 	return (err);
130*7c478bd9Sstevel@tonic-gate }
131*7c478bd9Sstevel@tonic-gate 
132*7c478bd9Sstevel@tonic-gate 
133*7c478bd9Sstevel@tonic-gate /*
134*7c478bd9Sstevel@tonic-gate  * Attempt to configure the audio device to match a particular encoding.
135*7c478bd9Sstevel@tonic-gate  */
136*7c478bd9Sstevel@tonic-gate 
137*7c478bd9Sstevel@tonic-gate /*
138*7c478bd9Sstevel@tonic-gate  * Set and/or set individual state values.
139*7c478bd9Sstevel@tonic-gate  * This routine is generally invoked by using the audio_set_*()
140*7c478bd9Sstevel@tonic-gate  * and audio_get_*() macros.
141*7c478bd9Sstevel@tonic-gate  * The 'valp' argument is always a pointer to an unsigned int.
142*7c478bd9Sstevel@tonic-gate  * Conversions to/from (unsigned char) flags are taken care of.
143*7c478bd9Sstevel@tonic-gate  */
144*7c478bd9Sstevel@tonic-gate int
audio__setval(int fd,unsigned int * valp,unsigned int which)145*7c478bd9Sstevel@tonic-gate audio__setval(int fd, unsigned int *valp, unsigned int which)
146*7c478bd9Sstevel@tonic-gate {
147*7c478bd9Sstevel@tonic-gate 	Audio_info		info;
148*7c478bd9Sstevel@tonic-gate 	struct audio_prinfo	*prinfo;
149*7c478bd9Sstevel@tonic-gate 	int			err;
150*7c478bd9Sstevel@tonic-gate 	unsigned		*up;
151*7c478bd9Sstevel@tonic-gate 	unsigned char		*cp;
152*7c478bd9Sstevel@tonic-gate 
153*7c478bd9Sstevel@tonic-gate 	/* Set a pointer to the value of interest */
154*7c478bd9Sstevel@tonic-gate 	if (which & AUDIO__PLAY)
155*7c478bd9Sstevel@tonic-gate 		prinfo = &info.play;
156*7c478bd9Sstevel@tonic-gate 	else if (which & AUDIO__RECORD)
157*7c478bd9Sstevel@tonic-gate 		prinfo = &info.record;
158*7c478bd9Sstevel@tonic-gate 	else if ((which & AUDIO__SETVAL_MASK) != AUDIO__MONGAIN)
159*7c478bd9Sstevel@tonic-gate 		return (AUDIO_ERR_BADARG);
160*7c478bd9Sstevel@tonic-gate 
161*7c478bd9Sstevel@tonic-gate 	up = NULL;
162*7c478bd9Sstevel@tonic-gate 	switch (which & AUDIO__SETVAL_MASK) {
163*7c478bd9Sstevel@tonic-gate 	case AUDIO__PORT:
164*7c478bd9Sstevel@tonic-gate 		up = &prinfo->port; break;
165*7c478bd9Sstevel@tonic-gate 	case AUDIO__SAMPLES:
166*7c478bd9Sstevel@tonic-gate 		up = &prinfo->samples; break;
167*7c478bd9Sstevel@tonic-gate 	case AUDIO__ERROR:
168*7c478bd9Sstevel@tonic-gate 		cp = &prinfo->error; break;
169*7c478bd9Sstevel@tonic-gate 	case AUDIO__EOF:
170*7c478bd9Sstevel@tonic-gate 		up = &prinfo->eof; break;
171*7c478bd9Sstevel@tonic-gate 	case AUDIO__OPEN:
172*7c478bd9Sstevel@tonic-gate 		cp = &prinfo->open; break;
173*7c478bd9Sstevel@tonic-gate 	case AUDIO__ACTIVE:
174*7c478bd9Sstevel@tonic-gate 		cp = &prinfo->active; break;
175*7c478bd9Sstevel@tonic-gate 	case AUDIO__WAITING:
176*7c478bd9Sstevel@tonic-gate 		cp = &prinfo->waiting; break;
177*7c478bd9Sstevel@tonic-gate 	case AUDIO__GAIN:
178*7c478bd9Sstevel@tonic-gate 		up = &prinfo->gain; break;
179*7c478bd9Sstevel@tonic-gate 	case AUDIO__MONGAIN:
180*7c478bd9Sstevel@tonic-gate 		up = &info.monitor_gain; break;
181*7c478bd9Sstevel@tonic-gate 	case AUDIO__BALANCE:
182*7c478bd9Sstevel@tonic-gate 		cp = &prinfo->balance; break;
183*7c478bd9Sstevel@tonic-gate 	default:
184*7c478bd9Sstevel@tonic-gate 		return (AUDIO_ERR_BADARG);
185*7c478bd9Sstevel@tonic-gate 	}
186*7c478bd9Sstevel@tonic-gate 
187*7c478bd9Sstevel@tonic-gate 	if (which & AUDIO__SET) {
188*7c478bd9Sstevel@tonic-gate 		/* Init so that only the value of interest is changed */
189*7c478bd9Sstevel@tonic-gate 		AUDIO_INITINFO(&info);
190*7c478bd9Sstevel@tonic-gate 		if (up != NULL) {
191*7c478bd9Sstevel@tonic-gate 			*up = *valp;
192*7c478bd9Sstevel@tonic-gate 		} else {
193*7c478bd9Sstevel@tonic-gate 			*cp = (unsigned char) *valp;
194*7c478bd9Sstevel@tonic-gate 		}
195*7c478bd9Sstevel@tonic-gate 		err = audio_setinfo(fd, &info);
196*7c478bd9Sstevel@tonic-gate 	} else {
197*7c478bd9Sstevel@tonic-gate 		err = audio_getinfo(fd, &info);
198*7c478bd9Sstevel@tonic-gate 	}
199*7c478bd9Sstevel@tonic-gate 	if (err == AUDIO_SUCCESS) {
200*7c478bd9Sstevel@tonic-gate 		if (up != NULL)
201*7c478bd9Sstevel@tonic-gate 			*valp = *up;
202*7c478bd9Sstevel@tonic-gate 		else
203*7c478bd9Sstevel@tonic-gate 			*valp = (unsigned)*cp;
204*7c478bd9Sstevel@tonic-gate 	}
205*7c478bd9Sstevel@tonic-gate 	return (err);
206*7c478bd9Sstevel@tonic-gate }
207*7c478bd9Sstevel@tonic-gate 
208*7c478bd9Sstevel@tonic-gate /*
209*7c478bd9Sstevel@tonic-gate  * Get/set gain value.
210*7c478bd9Sstevel@tonic-gate  * NOTE: legal values are floating-point double 0. - 1.
211*7c478bd9Sstevel@tonic-gate  */
212*7c478bd9Sstevel@tonic-gate int
audio__setgain(int fd,double * valp,unsigned int which)213*7c478bd9Sstevel@tonic-gate audio__setgain(int fd, double *valp, unsigned int which)
214*7c478bd9Sstevel@tonic-gate {
215*7c478bd9Sstevel@tonic-gate 	int		err;
216*7c478bd9Sstevel@tonic-gate 	unsigned	x;
217*7c478bd9Sstevel@tonic-gate 
218*7c478bd9Sstevel@tonic-gate 	if (which & AUDIO__SET) {
219*7c478bd9Sstevel@tonic-gate 		if ((*valp < 0.) || (*valp > 1.))
220*7c478bd9Sstevel@tonic-gate 			return (AUDIO_ERR_BADARG);
221*7c478bd9Sstevel@tonic-gate 
222*7c478bd9Sstevel@tonic-gate 		/* Map value into legal range */
223*7c478bd9Sstevel@tonic-gate 		x = ((unsigned)(*valp * (AUDIO_MAX_GAIN - AUDIO_MIN_GAIN))) +
224*7c478bd9Sstevel@tonic-gate 		    AUDIO_MIN_GAIN;
225*7c478bd9Sstevel@tonic-gate 	}
226*7c478bd9Sstevel@tonic-gate 
227*7c478bd9Sstevel@tonic-gate 	/* Get or set the new value */
228*7c478bd9Sstevel@tonic-gate 	err = audio__setval(fd, &x, which);
229*7c478bd9Sstevel@tonic-gate 	if (err == AUDIO_SUCCESS) {
230*7c478bd9Sstevel@tonic-gate 		/* Map value back to double */
231*7c478bd9Sstevel@tonic-gate 		*valp = ((double)(x - AUDIO_MIN_GAIN) /
232*7c478bd9Sstevel@tonic-gate 		    (AUDIO_MAX_GAIN - AUDIO_MIN_GAIN));
233*7c478bd9Sstevel@tonic-gate 	}
234*7c478bd9Sstevel@tonic-gate 	return (err);
235*7c478bd9Sstevel@tonic-gate }
236*7c478bd9Sstevel@tonic-gate 
237*7c478bd9Sstevel@tonic-gate /*
238*7c478bd9Sstevel@tonic-gate  * Set Pause/resume flags.
239*7c478bd9Sstevel@tonic-gate  * Can set play and record individually or together.
240*7c478bd9Sstevel@tonic-gate  */
241*7c478bd9Sstevel@tonic-gate int
audio__setpause(int fd,unsigned int which)242*7c478bd9Sstevel@tonic-gate audio__setpause(int fd, unsigned int which)
243*7c478bd9Sstevel@tonic-gate {
244*7c478bd9Sstevel@tonic-gate 	Audio_info	info;
245*7c478bd9Sstevel@tonic-gate 	int		err;
246*7c478bd9Sstevel@tonic-gate 	unsigned char	x;
247*7c478bd9Sstevel@tonic-gate 
248*7c478bd9Sstevel@tonic-gate 	AUDIO_INITINFO(&info);
249*7c478bd9Sstevel@tonic-gate 
250*7c478bd9Sstevel@tonic-gate 	if ((which & AUDIO__SETVAL_MASK) == AUDIO__PAUSE) {
251*7c478bd9Sstevel@tonic-gate 		x = TRUE;
252*7c478bd9Sstevel@tonic-gate 	} else if ((which & AUDIO__SETVAL_MASK) == AUDIO__RESUME) {
253*7c478bd9Sstevel@tonic-gate 		x = FALSE;
254*7c478bd9Sstevel@tonic-gate 	} else {
255*7c478bd9Sstevel@tonic-gate 		return (AUDIO_ERR_BADARG);
256*7c478bd9Sstevel@tonic-gate 	}
257*7c478bd9Sstevel@tonic-gate 
258*7c478bd9Sstevel@tonic-gate 	if (which & AUDIO__PLAY) {
259*7c478bd9Sstevel@tonic-gate 		info.play.pause = x;
260*7c478bd9Sstevel@tonic-gate 	}
261*7c478bd9Sstevel@tonic-gate 	if (which & AUDIO__RECORD) {
262*7c478bd9Sstevel@tonic-gate 		info.record.pause = x;
263*7c478bd9Sstevel@tonic-gate 	}
264*7c478bd9Sstevel@tonic-gate 
265*7c478bd9Sstevel@tonic-gate 	/* Set the new value */
266*7c478bd9Sstevel@tonic-gate 	err = audio_setinfo(fd, &info);
267*7c478bd9Sstevel@tonic-gate 
268*7c478bd9Sstevel@tonic-gate 	/* Check to see if this took effect */
269*7c478bd9Sstevel@tonic-gate 	if (err == AUDIO_SUCCESS) {
270*7c478bd9Sstevel@tonic-gate 		if (((which & AUDIO__PLAY) && (info.play.pause != x)) ||
271*7c478bd9Sstevel@tonic-gate 		    ((which & AUDIO__RECORD) && (info.record.pause != x)))
272*7c478bd9Sstevel@tonic-gate 			return (AUDIO_ERR_NOEFFECT);
273*7c478bd9Sstevel@tonic-gate 	}
274*7c478bd9Sstevel@tonic-gate 	return (err);
275*7c478bd9Sstevel@tonic-gate }
276*7c478bd9Sstevel@tonic-gate 
277*7c478bd9Sstevel@tonic-gate 
278*7c478bd9Sstevel@tonic-gate /*
279*7c478bd9Sstevel@tonic-gate  * Flush play and/or record buffers.
280*7c478bd9Sstevel@tonic-gate  */
281*7c478bd9Sstevel@tonic-gate int
audio__flush(int fd,unsigned int which)282*7c478bd9Sstevel@tonic-gate audio__flush(int fd, unsigned int which)
283*7c478bd9Sstevel@tonic-gate {
284*7c478bd9Sstevel@tonic-gate 	int		flag;
285*7c478bd9Sstevel@tonic-gate 
286*7c478bd9Sstevel@tonic-gate 	flag = (which & AUDIO__PLAY) ? FLUSHW : 0;
287*7c478bd9Sstevel@tonic-gate 	flag |= (which & AUDIO__RECORD) ? FLUSHR : 0;
288*7c478bd9Sstevel@tonic-gate 
289*7c478bd9Sstevel@tonic-gate 	return ((ioctl(fd, I_FLUSH, flag) < 0) ?
290*7c478bd9Sstevel@tonic-gate 	    AUDIO_UNIXERROR : AUDIO_SUCCESS);
291*7c478bd9Sstevel@tonic-gate }
292*7c478bd9Sstevel@tonic-gate 
293*7c478bd9Sstevel@tonic-gate 
294*7c478bd9Sstevel@tonic-gate /*
295*7c478bd9Sstevel@tonic-gate  * Wait synchronously for output buffers to finish playing.
296*7c478bd9Sstevel@tonic-gate  * If 'sig' is TRUE, signals may interrupt the drain.
297*7c478bd9Sstevel@tonic-gate  */
298*7c478bd9Sstevel@tonic-gate int
audio_drain(int fd,int sig)299*7c478bd9Sstevel@tonic-gate audio_drain(int fd, int sig)
300*7c478bd9Sstevel@tonic-gate {
301*7c478bd9Sstevel@tonic-gate 	while (ioctl(fd, AUDIO_DRAIN, 0) < 0) {
302*7c478bd9Sstevel@tonic-gate 		if (errno != EINTR) {
303*7c478bd9Sstevel@tonic-gate 			return (AUDIO_UNIXERROR);
304*7c478bd9Sstevel@tonic-gate 		}
305*7c478bd9Sstevel@tonic-gate 
306*7c478bd9Sstevel@tonic-gate 		if (sig) {
307*7c478bd9Sstevel@tonic-gate 			return (AUDIO_ERR_INTERRUPTED);
308*7c478bd9Sstevel@tonic-gate 		}
309*7c478bd9Sstevel@tonic-gate 	}
310*7c478bd9Sstevel@tonic-gate 	return (AUDIO_SUCCESS);
311*7c478bd9Sstevel@tonic-gate }
312*7c478bd9Sstevel@tonic-gate 
313*7c478bd9Sstevel@tonic-gate /*
314*7c478bd9Sstevel@tonic-gate  * Write an EOF marker to the output audio stream.
315*7c478bd9Sstevel@tonic-gate  */
316*7c478bd9Sstevel@tonic-gate int
audio_play_eof(int fd)317*7c478bd9Sstevel@tonic-gate audio_play_eof(int fd)
318*7c478bd9Sstevel@tonic-gate {
319*7c478bd9Sstevel@tonic-gate 	return (write(fd, (char *)NULL, 0) < 0 ?
320*7c478bd9Sstevel@tonic-gate 	    AUDIO_UNIXERROR : AUDIO_SUCCESS);
321*7c478bd9Sstevel@tonic-gate }
322