2
SDL - Simple DirectMedia Layer
3
Copyright (C) 1997, 1998 Sam Lantinga
5
This library is free software; you can redistribute it and/or
6
modify it under the terms of the GNU Library General Public
7
License as published by the Free Software Foundation; either
8
version 2 of the License, or (at your option) any later version.
10
This library is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
Library General Public License for more details.
15
You should have received a copy of the GNU Library General Public
16
License along with this library; if not, write to the Free
17
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20
5635-34 Springhouse Dr.
21
Pleasanton, CA 94588 (USA)
30
/* Allow access to a raw mixing buffer (For IRIX 6.5 and higher) */
31
/* patch for IRIX 5 by Georg Schwarz 18/07/2004 */
35
#include "Our_SDL_audio.h"
36
#include "SDL_audiomem.h"
37
#include "SDL_audio_c.h"
38
#include "SDL_irixaudio.h"
40
#ifndef AL_RESOURCE /* as a test whether we use the old IRIX audio libraries */
41
#define OLD_IRIX_AUDIO
42
#define alClosePort(x) ALcloseport(x)
43
#define alFreeConfig(x) ALfreeconfig(x)
44
#define alGetFillable(x) ALgetfillable(x)
45
#define alNewConfig() ALnewconfig()
46
#define alOpenPort(x,y,z) ALopenport(x,y,z)
47
#define alSetChannels(x,y) ALsetchannels(x,y)
48
#define alSetQueueSize(x,y) ALsetqueuesize(x,y)
49
#define alSetSampFmt(x,y) ALsetsampfmt(x,y)
50
#define alSetWidth(x,y) ALsetwidth(x,y)
53
/* Audio driver functions */
54
static int AL_OpenAudio(_THIS, SDL_AudioSpec *spec);
55
static void AL_WaitAudio(_THIS);
56
static void AL_PlayAudio(_THIS);
57
static Uint8 *AL_GetAudioBuf(_THIS);
58
static void AL_CloseAudio(_THIS);
60
/* Audio driver bootstrap functions */
62
static int Audio_Available(void)
67
static void Audio_DeleteDevice(SDL_AudioDevice *device)
73
static SDL_AudioDevice *Audio_CreateDevice(int devindex)
75
SDL_AudioDevice *this;
77
/* Initialize all variables that we clean on shutdown */
78
this = (SDL_AudioDevice *)malloc(sizeof(SDL_AudioDevice));
80
memset(this, 0, (sizeof *this));
81
this->hidden = (struct SDL_PrivateAudioData *)
82
malloc((sizeof *this->hidden));
84
if ( (this == NULL) || (this->hidden == NULL) ) {
91
memset(this->hidden, 0, (sizeof *this->hidden));
93
/* Set the function pointers */
94
this->OpenAudio = AL_OpenAudio;
95
this->WaitAudio = AL_WaitAudio;
96
this->PlayAudio = AL_PlayAudio;
97
this->GetAudioBuf = AL_GetAudioBuf;
98
this->CloseAudio = AL_CloseAudio;
100
this->free = Audio_DeleteDevice;
105
AudioBootStrap DMEDIA_bootstrap_ours = {
106
"AL", "IRIX DMedia audio",
107
Audio_Available, Audio_CreateDevice
111
void static AL_WaitAudio(_THIS)
115
timeleft = this->spec.samples - alGetFillable(audio_port);
116
if ( timeleft > 0 ) {
117
timeleft /= (this->spec.freq/1000);
118
SDL_Delay((Uint32)timeleft);
122
static void AL_PlayAudio(_THIS)
124
/* Write the audio data out */
125
if ( alWriteFrames(audio_port, mixbuf, this->spec.samples) < 0 ) {
126
/* Assume fatal error, for now */
131
static Uint8 *AL_GetAudioBuf(_THIS)
136
static void AL_CloseAudio(_THIS)
138
if ( mixbuf != NULL ) {
139
SDL_FreeAudioMem(mixbuf);
142
if ( audio_port != NULL ) {
143
alClosePort(audio_port);
148
static int AL_OpenAudio(_THIS, SDL_AudioSpec *spec)
150
ALconfig audio_config;
151
#ifdef OLD_IRIX_AUDIO
158
/* Determine the audio parameters from the AudioSpec */
159
switch ( spec->format & 0xFF ) {
161
case 8: { /* Signed 8 bit audio data */
162
spec->format = AUDIO_S8;
167
case 16: { /* Signed 16 bit audio data */
168
spec->format = AUDIO_S16MSB;
169
width = AL_SAMPLE_16;
174
SDL_SetError("Unsupported audio format");
179
/* Update the fragment size as size in bytes */
180
SDL_CalculateAudioSpec(spec);
182
/* Set output frequency */
183
#ifdef OLD_IRIX_AUDIO
184
audio_param[0] = AL_OUTPUT_RATE;
185
audio_param[1] = spec->freq;
186
if( ALsetparams(AL_DEFAULT_DEVICE, audio_param, 2) < 0 ) {
188
audio_param.param = AL_RATE;
189
audio_param.value.i = spec->freq;
190
if( alSetParams(AL_DEFAULT_OUTPUT, &audio_param, 1) < 0 ) {
192
SDL_SetError("alSetParams failed");
196
/* Open the audio port with the requested frequency */
198
audio_config = alNewConfig();
200
(alSetSampFmt(audio_config, AL_SAMPFMT_TWOSCOMP) >= 0) &&
201
(alSetWidth(audio_config, width) >= 0) &&
202
(alSetQueueSize(audio_config, spec->samples*2) >= 0) &&
203
(alSetChannels(audio_config, spec->channels) >= 0) ) {
204
audio_port = alOpenPort("SDL audio", "w", audio_config);
206
alFreeConfig(audio_config);
207
if( audio_port == NULL ) {
208
SDL_SetError("Unable to open audio port");
212
/* Allocate mixing buffer */
213
mixbuf = (Uint8 *)SDL_AllocAudioMem(spec->size);
214
if ( mixbuf == NULL ) {
218
memset(mixbuf, spec->silence, spec->size);
220
/* We're ready to rock and roll. :-) */