4
** Copyright (c) 1993-2001 by Hans-Ulrich Kiel & Joerg Czeranski
5
** All rights reserved.
7
** Redistribution and use in source and binary forms, with or without
8
** modification, are permitted provided that the following conditions are
11
** 1. Redistributions of source code must retain the above copyright
12
** notice, this list of conditions and the following disclaimer.
13
** 2. Redistributions in binary form must reproduce the above copyright
14
** notice, this list of conditions and the following disclaimer in the
15
** documentation and/or other materials provided with the distribution.
16
** 3. The name of the authors may not be used to endorse or promote
17
** products derived from this software without specific prior written
19
** 4. The name ``iMaze'' may not be used for products derived from this
20
** software unless a prefix or a suffix is added to the name.
22
** THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
23
** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
24
** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25
** DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT,
26
** INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
27
** (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28
** SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29
** HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
30
** STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
31
** IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32
** POSSIBILITY OF SUCH DAMAGE.
35
** Datei: voxware_audio.c
38
** Plays sounds via Voxware kernel driver
48
#include <sys/ioctl.h>
51
#include <linux/soundcard.h>
53
#include <machine/soundcard.h>
57
#include "ereignisse.h"
63
static char sccsid[] = "@(#)voxware_audio.c 3.18 12/09/01";
66
struct arg_option audio_hw_opts[] =
72
#define DEV_AUDIO "/dev/dsp"
74
/* Daten pro Sekunde */
75
#define SAMPLING_RATE 8000
77
#define LOG2_PUFFER_GROESSE 10
78
#define PUFFER_GROESSE (1 << LOG2_PUFFER_GROESSE)
80
static int audio_deskriptor; /* Deskriptor fuer das Audio-Device */
82
/* tatsaechliche Puffer-Groesse */
83
static int puffer_groesse;
86
/* bis hier lokaler Teil */
87
/***********************************************/
88
/* ab hier globaler Teil */
94
/* 2 Fragmente der Groesse PUFFER_GROESSE */
95
int frag = 2 << 16 | LOG2_PUFFER_GROESSE;
97
if (ioctl(audio_deskriptor, SNDCTL_DSP_SETFRAGMENT, &frag))
99
static char *meldung[] = { "iMaze - Sound Error", "",
100
"Can't set fragment size:", NULL, NULL };
102
meldung[3] = fehler_text();
103
uebler_fehler(meldung, NULL);
107
/* Puffer-Groesse abfragen */
108
if (ioctl(audio_deskriptor, SNDCTL_DSP_GETBLKSIZE, &puffer_groesse))
110
static char *meldung[] = { "iMaze - Sound Error", "",
111
"Can't check audio buffer size:", NULL, NULL };
113
meldung[3] = fehler_text();
114
uebler_fehler(meldung, NULL);
117
/* Puffer zu gross? */
118
if (puffer_groesse > PUFFER_GROESSE)
119
puffer_groesse = PUFFER_GROESSE;
122
int speed = SAMPLING_RATE;
124
/* Abtastrate setzen */
125
if (ioctl(audio_deskriptor, SNDCTL_DSP_SPEED, &speed))
127
static char *meldung[] = { "iMaze - Sound Error", "",
128
"Can't set audio sample rate:", NULL, NULL };
130
meldung[3] = fehler_text();
131
uebler_fehler(meldung, NULL);
137
void audio_hw_start(void)
139
deskriptor_nicht_blockieren(audio_deskriptor);
143
void audio_hw_close(void)
145
close(audio_deskriptor);
149
int audio_hw_protect(void)
151
return 0; /* don't care about state information */
155
void audio_hw_unprotect(int state)
160
int audio_hw_is_busy(void)
162
return 0; /* always try to write */
166
int audio_hw_is_multiwrite_allowed(void)
168
return 0; /* never try to write more than once */
172
/* buffer[length], buffer[length + 1], ... might be modified! */
173
int audio_hw_write(unsigned char *buffer, int length)
177
if (length < puffer_groesse)
178
memset(buffer + length, 128, puffer_groesse - length);
180
written = write(audio_deskriptor, buffer, puffer_groesse);
182
if (written >= length)
189
void audio_hw_hint_waiting(void)
191
audio_select_descriptor(audio_deskriptor, audio_hw_ready_callback, 1);
195
void audio_hw_hint_not_waiting(void)
197
audio_select_descriptor(audio_deskriptor, (void (*)(void))NULL, 1);
201
int audio_open(char ***meldung)
203
static char *message[] = { "iMaze - Sound Error", "",
205
static char text[80];
207
if ((audio_deskriptor = open(DEV_AUDIO, O_WRONLY | O_NDELAY, 0)) >= 0)
210
sprintf(text, "Can't open %s:", DEV_AUDIO);
212
message[3] = fehler_text();
216
return errno == EBUSY ? 2 : 0;
220
int audio_hw_get_buffer_size(void)
222
return puffer_groesse;
226
int audio_hw_uses_ulaw(void)
228
return 0; /* no, linear encoding used */