Mercurial > sdl-ios-xcode
annotate src/audio/dmedia/SDL_irixaudio.c @ 1237:a8068adf156b
Disable XBIOS driver for mouse and joystick under MiNT. Will write a driver for /dev/mouse later.
author | Patrice Mandin <patmandin@gmail.com> |
---|---|
date | Fri, 06 Jan 2006 22:24:09 +0000 |
parents | 6e6248801043 |
children | c9b51268668f |
rev | line source |
---|---|
0 | 1 /* |
2 SDL - Simple DirectMedia Layer | |
3 Copyright (C) 1997, 1998 Sam Lantinga | |
4 | |
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. | |
9 | |
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. | |
14 | |
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 | |
18 | |
19 Sam Lantinga | |
20 5635-34 Springhouse Dr. | |
21 Pleasanton, CA 94588 (USA) | |
252
e8157fcb3114
Updated the source with the correct e-mail address
Sam Lantinga <slouken@libsdl.org>
parents:
148
diff
changeset
|
22 slouken@libsdl.org |
0 | 23 */ |
24 | |
25 #ifdef SAVE_RCSID | |
26 static char rcsid = | |
27 "@(#) $Id$"; | |
28 #endif | |
29 | |
30 /* Allow access to a raw mixing buffer (For IRIX 6.5 and higher) */ | |
903
6e6248801043
Date: Sun, 18 Jul 2004 16:46:44 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
605
diff
changeset
|
31 /* patch for IRIX 5 by Georg Schwarz 18/07/2004 */ |
0 | 32 |
33 #include <stdlib.h> | |
34 | |
35 #include "SDL_endian.h" | |
36 #include "SDL_timer.h" | |
37 #include "SDL_audio.h" | |
38 #include "SDL_audiomem.h" | |
39 #include "SDL_audio_c.h" | |
40 #include "SDL_irixaudio.h" | |
41 | |
42 | |
903
6e6248801043
Date: Sun, 18 Jul 2004 16:46:44 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
605
diff
changeset
|
43 #ifndef AL_RESOURCE /* as a test whether we use the old IRIX audio libraries */ |
6e6248801043
Date: Sun, 18 Jul 2004 16:46:44 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
605
diff
changeset
|
44 #define OLD_IRIX_AUDIO |
6e6248801043
Date: Sun, 18 Jul 2004 16:46:44 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
605
diff
changeset
|
45 #define alClosePort(x) ALcloseport(x) |
6e6248801043
Date: Sun, 18 Jul 2004 16:46:44 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
605
diff
changeset
|
46 #define alFreeConfig(x) ALfreeconfig(x) |
6e6248801043
Date: Sun, 18 Jul 2004 16:46:44 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
605
diff
changeset
|
47 #define alGetFillable(x) ALgetfillable(x) |
6e6248801043
Date: Sun, 18 Jul 2004 16:46:44 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
605
diff
changeset
|
48 #define alNewConfig() ALnewconfig() |
6e6248801043
Date: Sun, 18 Jul 2004 16:46:44 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
605
diff
changeset
|
49 #define alOpenPort(x,y,z) ALopenport(x,y,z) |
6e6248801043
Date: Sun, 18 Jul 2004 16:46:44 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
605
diff
changeset
|
50 #define alSetChannels(x,y) ALsetchannels(x,y) |
6e6248801043
Date: Sun, 18 Jul 2004 16:46:44 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
605
diff
changeset
|
51 #define alSetQueueSize(x,y) ALsetqueuesize(x,y) |
6e6248801043
Date: Sun, 18 Jul 2004 16:46:44 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
605
diff
changeset
|
52 #define alSetSampFmt(x,y) ALsetsampfmt(x,y) |
6e6248801043
Date: Sun, 18 Jul 2004 16:46:44 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
605
diff
changeset
|
53 #define alSetWidth(x,y) ALsetwidth(x,y) |
6e6248801043
Date: Sun, 18 Jul 2004 16:46:44 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
605
diff
changeset
|
54 #endif |
6e6248801043
Date: Sun, 18 Jul 2004 16:46:44 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
605
diff
changeset
|
55 |
0 | 56 /* Audio driver functions */ |
57 static int AL_OpenAudio(_THIS, SDL_AudioSpec *spec); | |
58 static void AL_WaitAudio(_THIS); | |
59 static void AL_PlayAudio(_THIS); | |
60 static Uint8 *AL_GetAudioBuf(_THIS); | |
61 static void AL_CloseAudio(_THIS); | |
62 | |
63 /* Audio driver bootstrap functions */ | |
64 | |
65 static int Audio_Available(void) | |
66 { | |
67 return 1; | |
68 } | |
69 | |
70 static void Audio_DeleteDevice(SDL_AudioDevice *device) | |
71 { | |
72 free(device->hidden); | |
73 free(device); | |
74 } | |
75 | |
76 static SDL_AudioDevice *Audio_CreateDevice(int devindex) | |
77 { | |
78 SDL_AudioDevice *this; | |
79 | |
80 /* Initialize all variables that we clean on shutdown */ | |
81 this = (SDL_AudioDevice *)malloc(sizeof(SDL_AudioDevice)); | |
82 if ( this ) { | |
83 memset(this, 0, (sizeof *this)); | |
84 this->hidden = (struct SDL_PrivateAudioData *) | |
85 malloc((sizeof *this->hidden)); | |
86 } | |
87 if ( (this == NULL) || (this->hidden == NULL) ) { | |
88 SDL_OutOfMemory(); | |
89 if ( this ) { | |
90 free(this); | |
91 } | |
92 return(0); | |
93 } | |
94 memset(this->hidden, 0, (sizeof *this->hidden)); | |
95 | |
96 /* Set the function pointers */ | |
97 this->OpenAudio = AL_OpenAudio; | |
98 this->WaitAudio = AL_WaitAudio; | |
99 this->PlayAudio = AL_PlayAudio; | |
100 this->GetAudioBuf = AL_GetAudioBuf; | |
101 this->CloseAudio = AL_CloseAudio; | |
102 | |
103 this->free = Audio_DeleteDevice; | |
104 | |
105 return this; | |
106 } | |
107 | |
148
8758b8d42cd9
Audio subsystem no longer assumes sun audio API on UNIX systems
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
108 AudioBootStrap DMEDIA_bootstrap = { |
0 | 109 "AL", "IRIX DMedia audio", |
110 Audio_Available, Audio_CreateDevice | |
111 }; | |
112 | |
113 | |
114 void static AL_WaitAudio(_THIS) | |
115 { | |
116 Sint32 timeleft; | |
117 | |
118 timeleft = this->spec.samples - alGetFillable(audio_port); | |
119 if ( timeleft > 0 ) { | |
120 timeleft /= (this->spec.freq/1000); | |
121 SDL_Delay((Uint32)timeleft); | |
122 } | |
123 } | |
124 | |
125 static void AL_PlayAudio(_THIS) | |
126 { | |
127 /* Write the audio data out */ | |
128 if ( alWriteFrames(audio_port, mixbuf, this->spec.samples) < 0 ) { | |
129 /* Assume fatal error, for now */ | |
130 this->enabled = 0; | |
131 } | |
132 } | |
133 | |
134 static Uint8 *AL_GetAudioBuf(_THIS) | |
135 { | |
136 return(mixbuf); | |
137 } | |
138 | |
139 static void AL_CloseAudio(_THIS) | |
140 { | |
141 if ( mixbuf != NULL ) { | |
142 SDL_FreeAudioMem(mixbuf); | |
143 mixbuf = NULL; | |
144 } | |
145 if ( audio_port != NULL ) { | |
605
6399f4e90211
IRIX patches from Andrea Suatoni
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
146 alClosePort(audio_port); |
0 | 147 audio_port = NULL; |
148 } | |
149 } | |
150 | |
151 static int AL_OpenAudio(_THIS, SDL_AudioSpec *spec) | |
152 { | |
153 ALconfig audio_config; | |
903
6e6248801043
Date: Sun, 18 Jul 2004 16:46:44 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
605
diff
changeset
|
154 #ifdef OLD_IRIX_AUDIO |
6e6248801043
Date: Sun, 18 Jul 2004 16:46:44 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
605
diff
changeset
|
155 long audio_param[2]; |
6e6248801043
Date: Sun, 18 Jul 2004 16:46:44 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
605
diff
changeset
|
156 #else |
0 | 157 ALpv audio_param; |
903
6e6248801043
Date: Sun, 18 Jul 2004 16:46:44 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
605
diff
changeset
|
158 #endif |
0 | 159 int width; |
160 | |
161 /* Determine the audio parameters from the AudioSpec */ | |
162 switch ( spec->format & 0xFF ) { | |
163 | |
164 case 8: { /* Signed 8 bit audio data */ | |
165 spec->format = AUDIO_S8; | |
166 width = AL_SAMPLE_8; | |
167 } | |
168 break; | |
169 | |
170 case 16: { /* Signed 16 bit audio data */ | |
171 spec->format = AUDIO_S16MSB; | |
172 width = AL_SAMPLE_16; | |
173 } | |
174 break; | |
175 | |
176 default: { | |
177 SDL_SetError("Unsupported audio format"); | |
178 return(-1); | |
179 } | |
180 } | |
181 | |
182 /* Update the fragment size as size in bytes */ | |
183 SDL_CalculateAudioSpec(spec); | |
184 | |
185 /* Set output frequency */ | |
903
6e6248801043
Date: Sun, 18 Jul 2004 16:46:44 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
605
diff
changeset
|
186 #ifdef OLD_IRIX_AUDIO |
6e6248801043
Date: Sun, 18 Jul 2004 16:46:44 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
605
diff
changeset
|
187 audio_param[0] = AL_OUTPUT_RATE; |
6e6248801043
Date: Sun, 18 Jul 2004 16:46:44 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
605
diff
changeset
|
188 audio_param[1] = spec->freq; |
6e6248801043
Date: Sun, 18 Jul 2004 16:46:44 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
605
diff
changeset
|
189 if( ALsetparams(AL_DEFAULT_DEVICE, audio_param, 2) < 0 ) { |
6e6248801043
Date: Sun, 18 Jul 2004 16:46:44 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
605
diff
changeset
|
190 #else |
0 | 191 audio_param.param = AL_RATE; |
192 audio_param.value.i = spec->freq; | |
193 if( alSetParams(AL_DEFAULT_OUTPUT, &audio_param, 1) < 0 ) { | |
903
6e6248801043
Date: Sun, 18 Jul 2004 16:46:44 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
605
diff
changeset
|
194 #endif |
0 | 195 SDL_SetError("alSetParams failed"); |
196 return(-1); | |
197 } | |
198 | |
199 /* Open the audio port with the requested frequency */ | |
200 audio_port = NULL; | |
201 audio_config = alNewConfig(); | |
202 if ( audio_config && | |
203 (alSetSampFmt(audio_config, AL_SAMPFMT_TWOSCOMP) >= 0) && | |
204 (alSetWidth(audio_config, width) >= 0) && | |
205 (alSetQueueSize(audio_config, spec->samples*2) >= 0) && | |
206 (alSetChannels(audio_config, spec->channels) >= 0) ) { | |
605
6399f4e90211
IRIX patches from Andrea Suatoni
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
207 audio_port = alOpenPort("SDL audio", "w", audio_config); |
0 | 208 } |
209 alFreeConfig(audio_config); | |
210 if( audio_port == NULL ) { | |
211 SDL_SetError("Unable to open audio port"); | |
212 return(-1); | |
213 } | |
214 | |
215 /* Allocate mixing buffer */ | |
216 mixbuf = (Uint8 *)SDL_AllocAudioMem(spec->size); | |
217 if ( mixbuf == NULL ) { | |
218 SDL_OutOfMemory(); | |
219 return(-1); | |
220 } | |
221 memset(mixbuf, spec->silence, spec->size); | |
222 | |
223 /* We're ready to rock and roll. :-) */ | |
224 return(0); | |
225 } |