Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Latest commit

 

History

History
236 lines (200 loc) · 7.02 KB

SDL_irixaudio.c

File metadata and controls

236 lines (200 loc) · 7.02 KB
 
Apr 26, 2001
Apr 26, 2001
1
2
/*
SDL - Simple DirectMedia Layer
Feb 1, 2006
Feb 1, 2006
3
Copyright (C) 1997-2006 Sam Lantinga
Apr 26, 2001
Apr 26, 2001
4
5
This library is free software; you can redistribute it and/or
Feb 1, 2006
Feb 1, 2006
6
modify it under the terms of the GNU Lesser General Public
Apr 26, 2001
Apr 26, 2001
7
License as published by the Free Software Foundation; either
Feb 1, 2006
Feb 1, 2006
8
version 2.1 of the License, or (at your option) any later version.
Apr 26, 2001
Apr 26, 2001
9
10
11
12
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Feb 1, 2006
Feb 1, 2006
13
Lesser General Public License for more details.
Apr 26, 2001
Apr 26, 2001
14
Feb 1, 2006
Feb 1, 2006
15
16
17
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Apr 26, 2001
Apr 26, 2001
18
19
Sam Lantinga
Dec 14, 2001
Dec 14, 2001
20
slouken@libsdl.org
Apr 26, 2001
Apr 26, 2001
21
*/
Sep 1, 2006
Sep 1, 2006
22
#include <errno.h>
Feb 21, 2006
Feb 21, 2006
23
#include "SDL_config.h"
Apr 26, 2001
Apr 26, 2001
24
25
/* Allow access to a raw mixing buffer (For IRIX 6.5 and higher) */
Jul 18, 2004
Jul 18, 2004
26
/* patch for IRIX 5 by Georg Schwarz 18/07/2004 */
Apr 26, 2001
Apr 26, 2001
27
28
29
#include "SDL_timer.h"
#include "SDL_audio.h"
Feb 16, 2006
Feb 16, 2006
30
31
#include "../SDL_audiomem.h"
#include "../SDL_audio_c.h"
Apr 26, 2001
Apr 26, 2001
32
33
34
#include "SDL_irixaudio.h"
Jul 10, 2006
Jul 10, 2006
35
#ifndef AL_RESOURCE /* as a test whether we use the old IRIX audio libraries */
Jul 18, 2004
Jul 18, 2004
36
37
38
39
40
41
42
43
44
45
46
47
#define OLD_IRIX_AUDIO
#define alClosePort(x) ALcloseport(x)
#define alFreeConfig(x) ALfreeconfig(x)
#define alGetFillable(x) ALgetfillable(x)
#define alNewConfig() ALnewconfig()
#define alOpenPort(x,y,z) ALopenport(x,y,z)
#define alSetChannels(x,y) ALsetchannels(x,y)
#define alSetQueueSize(x,y) ALsetqueuesize(x,y)
#define alSetSampFmt(x,y) ALsetsampfmt(x,y)
#define alSetWidth(x,y) ALsetwidth(x,y)
#endif
Jul 10, 2006
Jul 10, 2006
48
void static
Oct 17, 2006
Oct 17, 2006
49
IRIXAUDIO_WaitDevice(_THIS)
Apr 26, 2001
Apr 26, 2001
50
{
Jul 10, 2006
Jul 10, 2006
51
Sint32 timeleft;
Apr 26, 2001
Apr 26, 2001
52
Oct 17, 2006
Oct 17, 2006
53
timeleft = this->spec.samples - alGetFillable(this->hidden->audio_port);
Jul 10, 2006
Jul 10, 2006
54
55
56
57
if (timeleft > 0) {
timeleft /= (this->spec.freq / 1000);
SDL_Delay((Uint32) timeleft);
}
Apr 26, 2001
Apr 26, 2001
58
59
}
Jul 10, 2006
Jul 10, 2006
60
static void
Oct 17, 2006
Oct 17, 2006
61
IRIXAUDIO_PlayDevice(_THIS)
Apr 26, 2001
Apr 26, 2001
62
{
Jul 10, 2006
Jul 10, 2006
63
/* Write the audio data out */
Oct 17, 2006
Oct 17, 2006
64
65
66
ALport port = this->hidden->audio_port;
Uint8 *mixbuf = this->hidden->mixbuf;
if (alWriteFrames(port, mixbuf, this->spec.samples) < 0) {
Jul 10, 2006
Jul 10, 2006
67
68
69
/* Assume fatal error, for now */
this->enabled = 0;
}
Apr 26, 2001
Apr 26, 2001
70
71
}
Jul 10, 2006
Jul 10, 2006
72
static Uint8 *
Oct 17, 2006
Oct 17, 2006
73
IRIXAUDIO_GetDeviceBuf(_THIS)
Apr 26, 2001
Apr 26, 2001
74
{
Oct 17, 2006
Oct 17, 2006
75
return (this->hidden->mixbuf);
Apr 26, 2001
Apr 26, 2001
76
77
}
Jul 10, 2006
Jul 10, 2006
78
static void
Oct 17, 2006
Oct 17, 2006
79
IRIXAUDIO_CloseDevice(_THIS)
Apr 26, 2001
Apr 26, 2001
80
{
Oct 17, 2006
Oct 17, 2006
81
82
83
84
85
86
87
88
89
90
91
if (this->hidden != NULL) {
if (this->hidden->mixbuf != NULL) {
SDL_FreeAudioMem(this->hidden->mixbuf);
this->hidden->mixbuf = NULL;
}
if (this->hidden->audio_port != NULL) {
alClosePort(this->hidden->audio_port);
this->hidden->audio_port = NULL;
}
SDL_free(this->hidden);
this->hidden = NULL;
Jul 10, 2006
Jul 10, 2006
92
}
Apr 26, 2001
Apr 26, 2001
93
94
}
Jul 10, 2006
Jul 10, 2006
95
static int
Oct 17, 2006
Oct 17, 2006
96
IRIXAUDIO_OpenDevice(_THIS, const char *devname, int iscapture)
Apr 26, 2001
Apr 26, 2001
97
{
Oct 17, 2006
Oct 17, 2006
98
SDL_AudioFormat test_format = SDL_FirstAudioFormat(this->spec.format);
Sep 1, 2006
Sep 1, 2006
99
100
101
102
long width = 0;
long fmt = 0;
int valid = 0;
Oct 17, 2006
Oct 17, 2006
103
104
105
106
107
108
109
110
111
112
113
/* !!! FIXME: Handle multiple devices and capture? */
/* Initialize all variables that we clean on shutdown */
this->hidden = (struct SDL_PrivateAudioData *)
SDL_malloc((sizeof *this->hidden));
if (this->hidden == NULL) {
SDL_OutOfMemory();
return 0;
}
SDL_memset(this->hidden, 0, (sizeof *this->hidden));
Jul 18, 2004
Jul 18, 2004
114
#ifdef OLD_IRIX_AUDIO
Sep 1, 2006
Sep 1, 2006
115
116
117
{
long audio_param[2];
audio_param[0] = AL_OUTPUT_RATE;
Oct 17, 2006
Oct 17, 2006
118
audio_param[1] = this->spec.freq;
Sep 1, 2006
Sep 1, 2006
119
120
valid = (ALsetparams(AL_DEFAULT_DEVICE, audio_param, 2) < 0);
}
Jul 18, 2004
Jul 18, 2004
121
#else
Sep 1, 2006
Sep 1, 2006
122
123
124
{
ALpv audio_param;
audio_param.param = AL_RATE;
Oct 17, 2006
Oct 17, 2006
125
audio_param.value.i = this->spec.freq;
Sep 1, 2006
Sep 1, 2006
126
127
valid = (alSetParams(AL_DEFAULT_OUTPUT, &audio_param, 1) < 0);
}
Jul 18, 2004
Jul 18, 2004
128
#endif
Jul 10, 2006
Jul 10, 2006
129
Sep 1, 2006
Sep 1, 2006
130
131
while ((!valid) && (test_format)) {
valid = 1;
Oct 17, 2006
Oct 17, 2006
132
this->spec.format = test_format;
Jul 10, 2006
Jul 10, 2006
133
Sep 1, 2006
Sep 1, 2006
134
switch (test_format) {
Sep 24, 2006
Sep 24, 2006
135
136
137
138
case AUDIO_S8:
width = AL_SAMPLE_8;
fmt = AL_SAMPFMT_TWOSCOMP;
break;
Sep 1, 2006
Sep 1, 2006
139
Sep 24, 2006
Sep 24, 2006
140
141
142
143
case AUDIO_S16SYS:
width = AL_SAMPLE_16;
fmt = AL_SAMPFMT_TWOSCOMP;
break;
Jul 10, 2006
Jul 10, 2006
144
Sep 24, 2006
Sep 24, 2006
145
146
147
148
case AUDIO_F32SYS:
width = 0; /* not used here... */
fmt = AL_SAMPFMT_FLOAT;
break;
Sep 1, 2006
Sep 1, 2006
149
150
151
/* Docs say there is int24, but not int32.... */
Sep 24, 2006
Sep 24, 2006
152
153
154
155
default:
valid = 0;
test_format = SDL_NextAudioFormat();
break;
Jul 10, 2006
Jul 10, 2006
156
157
}
Sep 1, 2006
Sep 1, 2006
158
159
160
161
if (valid) {
ALconfig audio_config = alNewConfig();
valid = 0;
if (audio_config) {
Oct 17, 2006
Oct 17, 2006
162
163
164
if (alSetChannels(audio_config, this->spec.channels) < 0) {
if (this->spec.channels > 2) { /* can't handle > stereo? */
this->spec.channels = 2; /* try again below. */
Sep 1, 2006
Sep 1, 2006
165
166
167
168
169
}
}
if ((alSetSampFmt(audio_config, fmt) >= 0) &&
((!width) || (alSetWidth(audio_config, width) >= 0)) &&
Oct 17, 2006
Oct 17, 2006
170
171
(alSetQueueSize(audio_config,this->spec.samples*2) >= 0) &&
(alSetChannels(audio_config, this->spec.channels) >= 0)) {
Sep 1, 2006
Sep 1, 2006
172
Oct 17, 2006
Oct 17, 2006
173
174
175
this->hidden->audio_port = alOpenPort("SDL audio", "w",
audio_config);
if (this->hidden->audio_port == NULL) {
Sep 1, 2006
Sep 1, 2006
176
177
178
/* docs say AL_BAD_CHANNELS happens here, too. */
int err = oserror();
if (err == AL_BAD_CHANNELS) {
Oct 17, 2006
Oct 17, 2006
179
180
181
182
this->spec.channels = 2;
alSetChannels(audio_config, this->spec.channels);
this->hidden->audio_port = alOpenPort("SDL audio", "w",
audio_config);
Sep 1, 2006
Sep 1, 2006
183
184
185
}
}
Oct 17, 2006
Oct 17, 2006
186
if (this->hidden->audio_port != NULL) {
Sep 1, 2006
Sep 1, 2006
187
188
189
190
191
192
valid = 1;
}
}
alFreeConfig(audio_config);
}
Jul 10, 2006
Jul 10, 2006
193
194
195
}
}
Sep 1, 2006
Sep 1, 2006
196
if (!valid) {
Oct 17, 2006
Oct 17, 2006
197
IRIXAUDIO_CloseDevice(this);
Sep 1, 2006
Sep 1, 2006
198
SDL_SetError("Unsupported audio format");
Oct 17, 2006
Oct 17, 2006
199
return 0;
Jul 10, 2006
Jul 10, 2006
200
201
}
Sep 1, 2006
Sep 1, 2006
202
/* Update the fragment size as size in bytes */
Oct 17, 2006
Oct 17, 2006
203
SDL_CalculateAudioSpec(&this->spec);
Jul 10, 2006
Jul 10, 2006
204
205
/* Allocate mixing buffer */
Oct 17, 2006
Oct 17, 2006
206
207
208
this->hidden->mixbuf = (Uint8 *) SDL_AllocAudioMem(this->spec.size);
if (this->hidden->mixbuf == NULL) {
IRIXAUDIO_CloseDevice(this);
Jul 10, 2006
Jul 10, 2006
209
SDL_OutOfMemory();
Oct 17, 2006
Oct 17, 2006
210
return 0;
Jul 10, 2006
Jul 10, 2006
211
}
Oct 17, 2006
Oct 17, 2006
212
SDL_memset(this->hidden->mixbuf, this->spec.silence, this->spec.size);
Jul 10, 2006
Jul 10, 2006
213
214
/* We're ready to rock and roll. :-) */
Oct 17, 2006
Oct 17, 2006
215
return 1;
Apr 26, 2001
Apr 26, 2001
216
}
Jul 10, 2006
Jul 10, 2006
217
Oct 17, 2006
Oct 17, 2006
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
static int
IRIXAUDIO_Init(SDL_AudioDriverImpl *impl)
{
/* Set the function pointers */
impl->OpenDevice = DSP_OpenDevice;
impl->PlayDevice = DSP_PlayDevice;
impl->WaitDevice = DSP_WaitDevice;
impl->GetDeviceBuf = DSP_GetDeviceBuf;
impl->CloseDevice = DSP_CloseDevice;
impl->OnlyHasDefaultOutputDevice = 1; /* !!! FIXME: not true, I think. */
return 1;
}
AudioBootStrap IRIXAUDIO_bootstrap = {
"AL", "IRIX DMedia audio", IRIXAUDIO_Init, 0
};
Jul 10, 2006
Jul 10, 2006
236
/* vi: set ts=4 sw=4 expandtab: */