2 * Copyright (c) 1999 Hellmuth Michaelis. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 *---------------------------------------------------------------------------
27 * isdnphone - audio operations
28 * ============================
30 * $Id: audio.c,v 1.5 1999/12/13 21:25:26 hm Exp $
32 * $FreeBSD: src/usr.sbin/i4b/isdnphone/audio.c,v 1.1.2.1 2001/08/01 17:45:06 obrien Exp $
33 * $DragonFly: src/usr.sbin/i4b/isdnphone/audio.c,v 1.2 2003/06/17 04:29:55 dillon Exp $
35 * last edit-date: [Mon Dec 13 21:52:39 1999]
37 *----------------------------------------------------------------------------*/
41 /*---------------------------------------------------------------------------*
43 *---------------------------------------------------------------------------*/
45 init_audio(char *audiodevice)
53 snd_capabilities soundcaps;
55 if((fd = open(audiodevice, O_RDWR)) < 0)
57 fprintf(stderr, "unable to open %s: %s\n", audiodevice, strerror(errno));
61 ret = ioctl(fd, AIOGCAP, &soundcaps);
65 fprintf(stderr, "ERROR: ioctl AIOGCAP %s: %s\n", audiodevice, strerror(errno));
69 fmt = soundcaps.formats;
71 if((fmt & AFMT_FULLDUPLEX) && (!(fmt & AFMT_WEIRD)))
76 play_fmt = rec_fmt = AFMT_A_LAW;
82 play_fmt = rec_fmt = AFMT_MU_LAW;
86 printf("sorry, A-law or u-law not supported!\n");
93 printf("no full-duplex available!\n");
98 pa.play_format = play_fmt;
99 pa.rec_format = rec_fmt;
100 pa.play_rate = pa.rec_rate = AUDIORATE;
102 ret = ioctl(fd, AIOSFMT, &pa);
106 fprintf(stderr, "ERROR: ioctl AIOSFMT %s: %s\n", audiodevice, strerror(errno));
110 sz.play_size = BCH_MAX_DATALEN;
111 sz.rec_size = BCH_MAX_DATALEN;
113 ret = ioctl(fd, AIOSSIZE, &sz);
117 fprintf(stderr, "ERROR: ioctl AIOSSIZE %s: %s\n", audiodevice, strerror(errno));
124 /*---------------------------------------------------------------------------*
125 * audio device has speech data from microphone
126 *---------------------------------------------------------------------------*/
130 unsigned char buffer[BCH_MAX_DATALEN];
133 ret = read(audiofd, buffer, BCH_MAX_DATALEN);
137 fatal("read audio failed: %s", strerror(errno));
140 debug("audio_hdlr: read %d bytes\n", ret);
144 telwrite(ret, buffer);
148 /*---------------------------------------------------------------------------*
149 * write audio data to loudspeaker
150 *---------------------------------------------------------------------------*/
152 audiowrite(int len, unsigned char *buf)
154 if((write(audiofd, buf, len)) < 0)
156 fatal("write audio failed: %s", strerror(errno));