Mercurial > sdl-ios-xcode
annotate src/audio/dmedia/SDL_irixaudio.c @ 1361:19418e4422cb
New configure-based build system. Still work in progress, but much improved
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Thu, 16 Feb 2006 10:11:48 +0000 |
parents | c71e05b4dc2e |
children | d910939febfa |
rev | line source |
---|---|
0 | 1 /* |
2 SDL - Simple DirectMedia Layer | |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
903
diff
changeset
|
3 Copyright (C) 1997-2006 Sam Lantinga |
0 | 4 |
5 This library is free software; you can redistribute it and/or | |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
903
diff
changeset
|
6 modify it under the terms of the GNU Lesser General Public |
0 | 7 License as published by the Free Software Foundation; either |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
903
diff
changeset
|
8 version 2.1 of the License, or (at your option) any later version. |
0 | 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 | |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
903
diff
changeset
|
13 Lesser General Public License for more details. |
0 | 14 |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
903
diff
changeset
|
15 You should have received a copy of the GNU Lesser General Public |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
903
diff
changeset
|
16 License along with this library; if not, write to the Free Software |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
903
diff
changeset
|
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
0 | 18 |
19 Sam Lantinga | |
252
e8157fcb3114
Updated the source with the correct e-mail address
Sam Lantinga <slouken@libsdl.org>
parents:
148
diff
changeset
|
20 slouken@libsdl.org |
0 | 21 */ |
22 | |
23 /* 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
|
24 /* patch for IRIX 5 by Georg Schwarz 18/07/2004 */ |
0 | 25 |
26 #include "SDL_timer.h" | |
27 #include "SDL_audio.h" | |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
28 #include "../SDL_audiomem.h" |
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
29 #include "../SDL_audio_c.h" |
0 | 30 #include "SDL_irixaudio.h" |
31 | |
32 | |
903
6e6248801043
Date: Sun, 18 Jul 2004 16:46:44 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
605
diff
changeset
|
33 #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
|
34 #define OLD_IRIX_AUDIO |
6e6248801043
Date: Sun, 18 Jul 2004 16:46:44 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
605
diff
changeset
|
35 #define alClosePort(x) ALcloseport(x) |
6e6248801043
Date: Sun, 18 Jul 2004 16:46:44 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
605
diff
changeset
|
36 #define alFreeConfig(x) ALfreeconfig(x) |
6e6248801043
Date: Sun, 18 Jul 2004 16:46:44 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
605
diff
changeset
|
37 #define alGetFillable(x) ALgetfillable(x) |
6e6248801043
Date: Sun, 18 Jul 2004 16:46:44 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
605
diff
changeset
|
38 #define alNewConfig() ALnewconfig() |
6e6248801043
Date: Sun, 18 Jul 2004 16:46:44 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
605
diff
changeset
|
39 #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
|
40 #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
|
41 #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
|
42 #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
|
43 #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
|
44 #endif |
6e6248801043
Date: Sun, 18 Jul 2004 16:46:44 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
605
diff
changeset
|
45 |
0 | 46 /* Audio driver functions */ |
47 static int AL_OpenAudio(_THIS, SDL_AudioSpec *spec); | |
48 static void AL_WaitAudio(_THIS); | |
49 static void AL_PlayAudio(_THIS); | |
50 static Uint8 *AL_GetAudioBuf(_THIS); | |
51 static void AL_CloseAudio(_THIS); | |
52 | |
53 /* Audio driver bootstrap functions */ | |
54 | |
55 static int Audio_Available(void) | |
56 { | |
57 return 1; | |
58 } | |
59 | |
60 static void Audio_DeleteDevice(SDL_AudioDevice *device) | |
61 { | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
62 SDL_free(device->hidden); |
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
63 SDL_free(device); |
0 | 64 } |
65 | |
66 static SDL_AudioDevice *Audio_CreateDevice(int devindex) | |
67 { | |
68 SDL_AudioDevice *this; | |
69 | |
70 /* Initialize all variables that we clean on shutdown */ | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
71 this = (SDL_AudioDevice *)SDL_malloc(sizeof(SDL_AudioDevice)); |
0 | 72 if ( this ) { |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
73 SDL_memset(this, 0, (sizeof *this)); |
0 | 74 this->hidden = (struct SDL_PrivateAudioData *) |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
75 SDL_malloc((sizeof *this->hidden)); |
0 | 76 } |
77 if ( (this == NULL) || (this->hidden == NULL) ) { | |
78 SDL_OutOfMemory(); | |
79 if ( this ) { | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
80 SDL_free(this); |
0 | 81 } |
82 return(0); | |
83 } | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
84 SDL_memset(this->hidden, 0, (sizeof *this->hidden)); |
0 | 85 |
86 /* Set the function pointers */ | |
87 this->OpenAudio = AL_OpenAudio; | |
88 this->WaitAudio = AL_WaitAudio; | |
89 this->PlayAudio = AL_PlayAudio; | |
90 this->GetAudioBuf = AL_GetAudioBuf; | |
91 this->CloseAudio = AL_CloseAudio; | |
92 | |
93 this->free = Audio_DeleteDevice; | |
94 | |
95 return this; | |
96 } | |
97 | |
148
8758b8d42cd9
Audio subsystem no longer assumes sun audio API on UNIX systems
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
98 AudioBootStrap DMEDIA_bootstrap = { |
0 | 99 "AL", "IRIX DMedia audio", |
100 Audio_Available, Audio_CreateDevice | |
101 }; | |
102 | |
103 | |
104 void static AL_WaitAudio(_THIS) | |
105 { | |
106 Sint32 timeleft; | |
107 | |
108 timeleft = this->spec.samples - alGetFillable(audio_port); | |
109 if ( timeleft > 0 ) { | |
110 timeleft /= (this->spec.freq/1000); | |
111 SDL_Delay((Uint32)timeleft); | |
112 } | |
113 } | |
114 | |
115 static void AL_PlayAudio(_THIS) | |
116 { | |
117 /* Write the audio data out */ | |
118 if ( alWriteFrames(audio_port, mixbuf, this->spec.samples) < 0 ) { | |
119 /* Assume fatal error, for now */ | |
120 this->enabled = 0; | |
121 } | |
122 } | |
123 | |
124 static Uint8 *AL_GetAudioBuf(_THIS) | |
125 { | |
126 return(mixbuf); | |
127 } | |
128 | |
129 static void AL_CloseAudio(_THIS) | |
130 { | |
131 if ( mixbuf != NULL ) { | |
132 SDL_FreeAudioMem(mixbuf); | |
133 mixbuf = NULL; | |
134 } | |
135 if ( audio_port != NULL ) { | |
605
6399f4e90211
IRIX patches from Andrea Suatoni
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
136 alClosePort(audio_port); |
0 | 137 audio_port = NULL; |
138 } | |
139 } | |
140 | |
141 static int AL_OpenAudio(_THIS, SDL_AudioSpec *spec) | |
142 { | |
143 ALconfig audio_config; | |
903
6e6248801043
Date: Sun, 18 Jul 2004 16:46:44 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
605
diff
changeset
|
144 #ifdef OLD_IRIX_AUDIO |
6e6248801043
Date: Sun, 18 Jul 2004 16:46:44 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
605
diff
changeset
|
145 long audio_param[2]; |
6e6248801043
Date: Sun, 18 Jul 2004 16:46:44 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
605
diff
changeset
|
146 #else |
0 | 147 ALpv audio_param; |
903
6e6248801043
Date: Sun, 18 Jul 2004 16:46:44 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
605
diff
changeset
|
148 #endif |
0 | 149 int width; |
150 | |
151 /* Determine the audio parameters from the AudioSpec */ | |
152 switch ( spec->format & 0xFF ) { | |
153 | |
154 case 8: { /* Signed 8 bit audio data */ | |
155 spec->format = AUDIO_S8; | |
156 width = AL_SAMPLE_8; | |
157 } | |
158 break; | |
159 | |
160 case 16: { /* Signed 16 bit audio data */ | |
161 spec->format = AUDIO_S16MSB; | |
162 width = AL_SAMPLE_16; | |
163 } | |
164 break; | |
165 | |
166 default: { | |
167 SDL_SetError("Unsupported audio format"); | |
168 return(-1); | |
169 } | |
170 } | |
171 | |
172 /* Update the fragment size as size in bytes */ | |
173 SDL_CalculateAudioSpec(spec); | |
174 | |
175 /* Set output frequency */ | |
903
6e6248801043
Date: Sun, 18 Jul 2004 16:46:44 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
605
diff
changeset
|
176 #ifdef OLD_IRIX_AUDIO |
6e6248801043
Date: Sun, 18 Jul 2004 16:46:44 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
605
diff
changeset
|
177 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
|
178 audio_param[1] = spec->freq; |
6e6248801043
Date: Sun, 18 Jul 2004 16:46:44 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
605
diff
changeset
|
179 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
|
180 #else |
0 | 181 audio_param.param = AL_RATE; |
182 audio_param.value.i = spec->freq; | |
183 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
|
184 #endif |
0 | 185 SDL_SetError("alSetParams failed"); |
186 return(-1); | |
187 } | |
188 | |
189 /* Open the audio port with the requested frequency */ | |
190 audio_port = NULL; | |
191 audio_config = alNewConfig(); | |
192 if ( audio_config && | |
193 (alSetSampFmt(audio_config, AL_SAMPFMT_TWOSCOMP) >= 0) && | |
194 (alSetWidth(audio_config, width) >= 0) && | |
195 (alSetQueueSize(audio_config, spec->samples*2) >= 0) && | |
196 (alSetChannels(audio_config, spec->channels) >= 0) ) { | |
605
6399f4e90211
IRIX patches from Andrea Suatoni
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
197 audio_port = alOpenPort("SDL audio", "w", audio_config); |
0 | 198 } |
199 alFreeConfig(audio_config); | |
200 if( audio_port == NULL ) { | |
201 SDL_SetError("Unable to open audio port"); | |
202 return(-1); | |
203 } | |
204 | |
205 /* Allocate mixing buffer */ | |
206 mixbuf = (Uint8 *)SDL_AllocAudioMem(spec->size); | |
207 if ( mixbuf == NULL ) { | |
208 SDL_OutOfMemory(); | |
209 return(-1); | |
210 } | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
211 SDL_memset(mixbuf, spec->silence, spec->size); |
0 | 212 |
213 /* We're ready to rock and roll. :-) */ | |
214 return(0); | |
215 } |