1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
|
/* this file is a part of amp software, (C) tomislav uzelac 1996,1997
Origional code by: Karl Anders Oygard
Modified by:
* Andrew Richards - moved code from audio.c
*/
#include <assert.h>
#include <unistd.h>
#include <stdio.h>
#include <dmedia/audio.h>
#include "audioIO.h"
/* declare these static to effectively isolate the audio device */
static ALport audioport;
static ALconfig audioconfig;
/* audioOpen() */
/* should open the audio device, perform any special initialization */
/* Set the frequency, no of channels and volume. Volume is only set if */
/* it is not -1 */
void audioOpen() {
printf("sorry. The audio part for irix must be fixed. \n");
}
void
audioInit(int sampleSize,int frequency, int stereo)
{
ALconfig audioconfig;
audioconfig = ALnewconfig();
if (!audioconfig)
die("out of memory\n");
else {
long pvbuf[] = { AL_OUTPUT_COUNT, 0, AL_MONITOR_CTL, 0, AL_OUTPUT_RATE, 0};
if (ALgetparams(AL_DEFAULT_DEVICE, pvbuf, 6) < 0)
if (oserror() == AL_BAD_DEVICE_ACCESS)
die("couldn't access audio device\n");
if (pvbuf[1] == 0 && pvbuf[3] == AL_MONITOR_OFF) {
long al_params[] = { AL_OUTPUT_RATE, 0};
al_params[1] = frequency;
ALsetparams(AL_DEFAULT_DEVICE, al_params, 2);
} else
if (pvbuf[5] != frequency)
die("audio device is already in use with wrong sample output rate\n");
/* ALsetsampfmt(audioconfig, AL_SAMPFMT_TWOSCOMP); this is the default */
/* ALsetwidth(audioconfig, AL_SAMPLE_16); this is the default */
if (!stereo) ALsetchannels(audioconfig, AL_MONO);
/* else ALsetchannels(audioconfig, AL_STEREO); this is the default */
ALsetqueuesize(audioconfig, AUSIZ * 2);
audioport = ALopenport("amp", "w", audioconfig);
if (audioport == (ALport) 0) {
switch (oserror()) {
case AL_BAD_NO_PORTS:
die("system is out of ports\n");
case AL_BAD_DEVICE_ACCESS:
die("couldn't access audio device\n");
case AL_BAD_OUT_OF_MEM:
die("out of memory\n");
}
exit(-1);
}
ALsetfillpoint(audioport, AUSIZ);
}
}
/* audioSetVolume - only code this if your system can change the volume while */
/* playing. sets the output volume 0-100 */
void
audioSetVolume(int volume)
{
long al_params[] = { AL_LEFT_SPEAKER_GAIN, 0, AL_RIGHT_SPEAKER_GAIN, 0};
al_params[1] = al_params[3] = volume * 100 / 255;
ALsetparams(AL_DEFAULT_DEVICE, al_params, 4);
}
/* audioFlush() */
/* should flush the audio device */
void
audioFlush()
{
DB(audio, msg("audio: flush %d\n",audio_fd) );
}
/* audioClose() */
/* should close the audio device and perform any special shutdown */
void
audioClose()
{
int write_fd;
/* wait for all samples to be played */
write_fd = ALgetfd(audioport);
if (write_fd >= 0) {
fd_set write_fds;
FD_ZERO(&write_fds);
FD_SET(write_fd, &write_fds);
ALsetfillpoint(audioport, AUSIZ * 2);
select(write_fd + 1, NULL, &write_fds, NULL, NULL);
}
/* now close it */
ALcloseport(audioport);
DB(audio, msg("audio: closed %d\n",audio_fd) );
}
/* audioWrite */
/* writes count bytes from buffer to the audio device */
/* returns the number of bytes actually written */
int audioWrite(char *buffer, int count)
{
if (ALwritesamps(audioport, buffer, count / 2) == 0) {
ALsetfillpoint(audioport, AUSIZ);
return(count);
} else
return 0;
}
/* Let buffer.c have the audio descriptor so it can select on it. This
means that the program is dependent on an file descriptor to
work. Should really move the select's etc (with inlines of course) in
here so that this is the ONLY file which has hardware dependent audio
stuff in it. */
int
getAudioFd()
{
return ALgetfd(audioport);
}
|