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

Latest commit

 

History

History
229 lines (194 loc) · 5.82 KB

SDL_irixaudio.c

File metadata and controls

229 lines (194 loc) · 5.82 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
*/
Feb 21, 2006
Feb 21, 2006
22
#include "SDL_config.h"
Apr 26, 2001
Apr 26, 2001
23
24
/* Allow access to a raw mixing buffer (For IRIX 6.5 and higher) */
Jul 18, 2004
Jul 18, 2004
25
/* patch for IRIX 5 by Georg Schwarz 18/07/2004 */
Apr 26, 2001
Apr 26, 2001
26
27
28
#include "SDL_timer.h"
#include "SDL_audio.h"
Feb 16, 2006
Feb 16, 2006
29
30
#include "../SDL_audiomem.h"
#include "../SDL_audio_c.h"
Apr 26, 2001
Apr 26, 2001
31
32
33
#include "SDL_irixaudio.h"
May 28, 2006
May 28, 2006
34
#ifndef AL_RESOURCE /* as a test whether we use the old IRIX audio libraries */
Jul 18, 2004
Jul 18, 2004
35
36
37
38
39
40
41
42
43
44
45
46
#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
Apr 26, 2001
Apr 26, 2001
47
/* Audio driver functions */
May 29, 2006
May 29, 2006
48
49
50
51
52
static int AL_OpenAudio(_THIS, SDL_AudioSpec * spec);
static void AL_WaitAudio(_THIS);
static void AL_PlayAudio(_THIS);
static Uint8 *AL_GetAudioBuf(_THIS);
static void AL_CloseAudio(_THIS);
Apr 26, 2001
Apr 26, 2001
53
54
55
/* Audio driver bootstrap functions */
May 28, 2006
May 28, 2006
56
static int
May 29, 2006
May 29, 2006
57
Audio_Available(void)
Apr 26, 2001
Apr 26, 2001
58
{
May 28, 2006
May 28, 2006
59
return 1;
Apr 26, 2001
Apr 26, 2001
60
61
}
May 28, 2006
May 28, 2006
62
static void
May 29, 2006
May 29, 2006
63
Audio_DeleteDevice(SDL_AudioDevice * device)
Apr 26, 2001
Apr 26, 2001
64
{
May 29, 2006
May 29, 2006
65
66
SDL_free(device->hidden);
SDL_free(device);
Apr 26, 2001
Apr 26, 2001
67
68
}
May 28, 2006
May 28, 2006
69
static SDL_AudioDevice *
May 29, 2006
May 29, 2006
70
Audio_CreateDevice(int devindex)
Apr 26, 2001
Apr 26, 2001
71
{
May 28, 2006
May 28, 2006
72
73
74
SDL_AudioDevice *this;
/* Initialize all variables that we clean on shutdown */
May 29, 2006
May 29, 2006
75
this = (SDL_AudioDevice *) SDL_malloc(sizeof(SDL_AudioDevice));
May 28, 2006
May 28, 2006
76
if (this) {
May 29, 2006
May 29, 2006
77
SDL_memset(this, 0, (sizeof *this));
May 28, 2006
May 28, 2006
78
this->hidden = (struct SDL_PrivateAudioData *)
May 29, 2006
May 29, 2006
79
SDL_malloc((sizeof *this->hidden));
May 28, 2006
May 28, 2006
80
81
}
if ((this == NULL) || (this->hidden == NULL)) {
May 29, 2006
May 29, 2006
82
SDL_OutOfMemory();
May 28, 2006
May 28, 2006
83
if (this) {
May 29, 2006
May 29, 2006
84
SDL_free(this);
May 28, 2006
May 28, 2006
85
86
87
}
return (0);
}
May 29, 2006
May 29, 2006
88
SDL_memset(this->hidden, 0, (sizeof *this->hidden));
May 28, 2006
May 28, 2006
89
90
91
92
93
94
95
96
97
98
99
/* Set the function pointers */
this->OpenAudio = AL_OpenAudio;
this->WaitAudio = AL_WaitAudio;
this->PlayAudio = AL_PlayAudio;
this->GetAudioBuf = AL_GetAudioBuf;
this->CloseAudio = AL_CloseAudio;
this->free = Audio_DeleteDevice;
return this;
Apr 26, 2001
Apr 26, 2001
100
101
}
Aug 9, 2001
Aug 9, 2001
102
AudioBootStrap DMEDIA_bootstrap = {
May 28, 2006
May 28, 2006
103
104
"AL", "IRIX DMedia audio",
Audio_Available, Audio_CreateDevice
Apr 26, 2001
Apr 26, 2001
105
106
107
};
May 28, 2006
May 28, 2006
108
void static
May 29, 2006
May 29, 2006
109
AL_WaitAudio(_THIS)
Apr 26, 2001
Apr 26, 2001
110
{
May 28, 2006
May 28, 2006
111
Sint32 timeleft;
Apr 26, 2001
Apr 26, 2001
112
May 29, 2006
May 29, 2006
113
timeleft = this->spec.samples - alGetFillable(audio_port);
May 28, 2006
May 28, 2006
114
115
if (timeleft > 0) {
timeleft /= (this->spec.freq / 1000);
May 29, 2006
May 29, 2006
116
SDL_Delay((Uint32) timeleft);
May 28, 2006
May 28, 2006
117
}
Apr 26, 2001
Apr 26, 2001
118
119
}
May 28, 2006
May 28, 2006
120
static void
May 29, 2006
May 29, 2006
121
AL_PlayAudio(_THIS)
Apr 26, 2001
Apr 26, 2001
122
{
May 28, 2006
May 28, 2006
123
/* Write the audio data out */
May 29, 2006
May 29, 2006
124
if (alWriteFrames(audio_port, mixbuf, this->spec.samples) < 0) {
May 28, 2006
May 28, 2006
125
126
127
/* Assume fatal error, for now */
this->enabled = 0;
}
Apr 26, 2001
Apr 26, 2001
128
129
}
May 28, 2006
May 28, 2006
130
static Uint8 *
May 29, 2006
May 29, 2006
131
AL_GetAudioBuf(_THIS)
Apr 26, 2001
Apr 26, 2001
132
{
May 28, 2006
May 28, 2006
133
return (mixbuf);
Apr 26, 2001
Apr 26, 2001
134
135
}
May 28, 2006
May 28, 2006
136
static void
May 29, 2006
May 29, 2006
137
AL_CloseAudio(_THIS)
Apr 26, 2001
Apr 26, 2001
138
{
May 28, 2006
May 28, 2006
139
if (mixbuf != NULL) {
May 29, 2006
May 29, 2006
140
SDL_FreeAudioMem(mixbuf);
May 28, 2006
May 28, 2006
141
142
143
mixbuf = NULL;
}
if (audio_port != NULL) {
May 29, 2006
May 29, 2006
144
alClosePort(audio_port);
May 28, 2006
May 28, 2006
145
146
audio_port = NULL;
}
Apr 26, 2001
Apr 26, 2001
147
148
}
May 28, 2006
May 28, 2006
149
static int
May 29, 2006
May 29, 2006
150
AL_OpenAudio(_THIS, SDL_AudioSpec * spec)
Apr 26, 2001
Apr 26, 2001
151
{
May 28, 2006
May 28, 2006
152
ALconfig audio_config;
Jul 18, 2004
Jul 18, 2004
153
#ifdef OLD_IRIX_AUDIO
May 28, 2006
May 28, 2006
154
long audio_param[2];
Jul 18, 2004
Jul 18, 2004
155
#else
May 28, 2006
May 28, 2006
156
ALpv audio_param;
Jul 18, 2004
Jul 18, 2004
157
#endif
May 28, 2006
May 28, 2006
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
int width;
/* Determine the audio parameters from the AudioSpec */
switch (spec->format & 0xFF) {
case 8:
{ /* Signed 8 bit audio data */
spec->format = AUDIO_S8;
width = AL_SAMPLE_8;
}
break;
case 16:
{ /* Signed 16 bit audio data */
spec->format = AUDIO_S16MSB;
width = AL_SAMPLE_16;
}
break;
default:
{
May 29, 2006
May 29, 2006
179
SDL_SetError("Unsupported audio format");
May 28, 2006
May 28, 2006
180
181
182
183
184
return (-1);
}
}
/* Update the fragment size as size in bytes */
May 29, 2006
May 29, 2006
185
SDL_CalculateAudioSpec(spec);
May 28, 2006
May 28, 2006
186
187
/* Set output frequency */
Jul 18, 2004
Jul 18, 2004
188
#ifdef OLD_IRIX_AUDIO
May 28, 2006
May 28, 2006
189
190
audio_param[0] = AL_OUTPUT_RATE;
audio_param[1] = spec->freq;
May 29, 2006
May 29, 2006
191
if (ALsetparams(AL_DEFAULT_DEVICE, audio_param, 2) < 0) {
Jul 18, 2004
Jul 18, 2004
192
#else
May 28, 2006
May 28, 2006
193
194
audio_param.param = AL_RATE;
audio_param.value.i = spec->freq;
May 29, 2006
May 29, 2006
195
if (alSetParams(AL_DEFAULT_OUTPUT, &audio_param, 1) < 0) {
Jul 18, 2004
Jul 18, 2004
196
#endif
May 29, 2006
May 29, 2006
197
SDL_SetError("alSetParams failed");
May 28, 2006
May 28, 2006
198
199
200
201
202
return (-1);
}
/* Open the audio port with the requested frequency */
audio_port = NULL;
May 29, 2006
May 29, 2006
203
audio_config = alNewConfig();
May 28, 2006
May 28, 2006
204
if (audio_config &&
May 29, 2006
May 29, 2006
205
206
207
208
209
(alSetSampFmt(audio_config, AL_SAMPFMT_TWOSCOMP) >= 0) &&
(alSetWidth(audio_config, width) >= 0) &&
(alSetQueueSize(audio_config, spec->samples * 2) >= 0) &&
(alSetChannels(audio_config, spec->channels) >= 0)) {
audio_port = alOpenPort("SDL audio", "w", audio_config);
May 28, 2006
May 28, 2006
210
}
May 29, 2006
May 29, 2006
211
alFreeConfig(audio_config);
May 28, 2006
May 28, 2006
212
if (audio_port == NULL) {
May 29, 2006
May 29, 2006
213
SDL_SetError("Unable to open audio port");
May 28, 2006
May 28, 2006
214
215
216
217
return (-1);
}
/* Allocate mixing buffer */
May 29, 2006
May 29, 2006
218
mixbuf = (Uint8 *) SDL_AllocAudioMem(spec->size);
May 28, 2006
May 28, 2006
219
if (mixbuf == NULL) {
May 29, 2006
May 29, 2006
220
SDL_OutOfMemory();
May 28, 2006
May 28, 2006
221
222
return (-1);
}
May 29, 2006
May 29, 2006
223
SDL_memset(mixbuf, spec->silence, spec->size);
May 28, 2006
May 28, 2006
224
225
226
/* We're ready to rock and roll. :-) */
return (0);
Apr 26, 2001
Apr 26, 2001
227
}
May 28, 2006
May 28, 2006
228
229
/* vi: set ts=4 sw=4 expandtab: */