Mercurial > sdl-ios-xcode
annotate src/audio/dmedia/SDL_irixaudio.c @ 1336:3692456e7b0f
Use SDL_ prefixed versions of C library functions.
FIXME:
Change #include <stdlib.h> to #include "SDL_stdlib.h"
Change #include <string.h> to #include "SDL_string.h"
Make sure nothing else broke because of this...
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Tue, 07 Feb 2006 06:59:48 +0000 |
parents | c9b51268668f |
children | 604d73db6802 |
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 <stdlib.h> | |
27 | |
28 #include "SDL_endian.h" | |
29 #include "SDL_timer.h" | |
30 #include "SDL_audio.h" | |
31 #include "SDL_audiomem.h" | |
32 #include "SDL_audio_c.h" | |
33 #include "SDL_irixaudio.h" | |
34 | |
35 | |
903
6e6248801043
Date: Sun, 18 Jul 2004 16:46:44 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
605
diff
changeset
|
36 #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
|
37 #define OLD_IRIX_AUDIO |
6e6248801043
Date: Sun, 18 Jul 2004 16:46:44 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
605
diff
changeset
|
38 #define alClosePort(x) ALcloseport(x) |
6e6248801043
Date: Sun, 18 Jul 2004 16:46:44 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
605
diff
changeset
|
39 #define alFreeConfig(x) ALfreeconfig(x) |
6e6248801043
Date: Sun, 18 Jul 2004 16:46:44 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
605
diff
changeset
|
40 #define alGetFillable(x) ALgetfillable(x) |
6e6248801043
Date: Sun, 18 Jul 2004 16:46:44 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
605
diff
changeset
|
41 #define alNewConfig() ALnewconfig() |
6e6248801043
Date: Sun, 18 Jul 2004 16:46:44 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
605
diff
changeset
|
42 #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
|
43 #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
|
44 #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
|
45 #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
|
46 #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
|
47 #endif |
6e6248801043
Date: Sun, 18 Jul 2004 16:46:44 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
605
diff
changeset
|
48 |
0 | 49 /* Audio driver functions */ |
50 static int AL_OpenAudio(_THIS, SDL_AudioSpec *spec); | |
51 static void AL_WaitAudio(_THIS); | |
52 static void AL_PlayAudio(_THIS); | |
53 static Uint8 *AL_GetAudioBuf(_THIS); | |
54 static void AL_CloseAudio(_THIS); | |
55 | |
56 /* Audio driver bootstrap functions */ | |
57 | |
58 static int Audio_Available(void) | |
59 { | |
60 return 1; | |
61 } | |
62 | |
63 static void Audio_DeleteDevice(SDL_AudioDevice *device) | |
64 { | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
65 SDL_free(device->hidden); |
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
66 SDL_free(device); |
0 | 67 } |
68 | |
69 static SDL_AudioDevice *Audio_CreateDevice(int devindex) | |
70 { | |
71 SDL_AudioDevice *this; | |
72 | |
73 /* 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
|
74 this = (SDL_AudioDevice *)SDL_malloc(sizeof(SDL_AudioDevice)); |
0 | 75 if ( this ) { |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
76 SDL_memset(this, 0, (sizeof *this)); |
0 | 77 this->hidden = (struct SDL_PrivateAudioData *) |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
78 SDL_malloc((sizeof *this->hidden)); |
0 | 79 } |
80 if ( (this == NULL) || (this->hidden == NULL) ) { | |
81 SDL_OutOfMemory(); | |
82 if ( this ) { | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
83 SDL_free(this); |
0 | 84 } |
85 return(0); | |
86 } | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
87 SDL_memset(this->hidden, 0, (sizeof *this->hidden)); |
0 | 88 |
89 /* Set the function pointers */ | |
90 this->OpenAudio = AL_OpenAudio; | |
91 this->WaitAudio = AL_WaitAudio; | |
92 this->PlayAudio = AL_PlayAudio; | |
93 this->GetAudioBuf = AL_GetAudioBuf; | |
94 this->CloseAudio = AL_CloseAudio; | |
95 | |
96 this->free = Audio_DeleteDevice; | |
97 | |
98 return this; | |
99 } | |
100 | |
148
8758b8d42cd9
Audio subsystem no longer assumes sun audio API on UNIX systems
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
101 AudioBootStrap DMEDIA_bootstrap = { |
0 | 102 "AL", "IRIX DMedia audio", |
103 Audio_Available, Audio_CreateDevice | |
104 }; | |
105 | |
106 | |
107 void static AL_WaitAudio(_THIS) | |
108 { | |
109 Sint32 timeleft; | |
110 | |
111 timeleft = this->spec.samples - alGetFillable(audio_port); | |
112 if ( timeleft > 0 ) { | |
113 timeleft /= (this->spec.freq/1000); | |
114 SDL_Delay((Uint32)timeleft); | |
115 } | |
116 } | |
117 | |
118 static void AL_PlayAudio(_THIS) | |
119 { | |
120 /* Write the audio data out */ | |
121 if ( alWriteFrames(audio_port, mixbuf, this->spec.samples) < 0 ) { | |
122 /* Assume fatal error, for now */ | |
123 this->enabled = 0; | |
124 } | |
125 } | |
126 | |
127 static Uint8 *AL_GetAudioBuf(_THIS) | |
128 { | |
129 return(mixbuf); | |
130 } | |
131 | |
132 static void AL_CloseAudio(_THIS) | |
133 { | |
134 if ( mixbuf != NULL ) { | |
135 SDL_FreeAudioMem(mixbuf); | |
136 mixbuf = NULL; | |
137 } | |
138 if ( audio_port != NULL ) { | |
605
6399f4e90211
IRIX patches from Andrea Suatoni
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
139 alClosePort(audio_port); |
0 | 140 audio_port = NULL; |
141 } | |
142 } | |
143 | |
144 static int AL_OpenAudio(_THIS, SDL_AudioSpec *spec) | |
145 { | |
146 ALconfig audio_config; | |
903
6e6248801043
Date: Sun, 18 Jul 2004 16:46:44 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
605
diff
changeset
|
147 #ifdef OLD_IRIX_AUDIO |
6e6248801043
Date: Sun, 18 Jul 2004 16:46:44 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
605
diff
changeset
|
148 long audio_param[2]; |
6e6248801043
Date: Sun, 18 Jul 2004 16:46:44 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
605
diff
changeset
|
149 #else |
0 | 150 ALpv audio_param; |
903
6e6248801043
Date: Sun, 18 Jul 2004 16:46:44 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
605
diff
changeset
|
151 #endif |
0 | 152 int width; |
153 | |
154 /* Determine the audio parameters from the AudioSpec */ | |
155 switch ( spec->format & 0xFF ) { | |
156 | |
157 case 8: { /* Signed 8 bit audio data */ | |
158 spec->format = AUDIO_S8; | |
159 width = AL_SAMPLE_8; | |
160 } | |
161 break; | |
162 | |
163 case 16: { /* Signed 16 bit audio data */ | |
164 spec->format = AUDIO_S16MSB; | |
165 width = AL_SAMPLE_16; | |
166 } | |
167 break; | |
168 | |
169 default: { | |
170 SDL_SetError("Unsupported audio format"); | |
171 return(-1); | |
172 } | |
173 } | |
174 | |
175 /* Update the fragment size as size in bytes */ | |
176 SDL_CalculateAudioSpec(spec); | |
177 | |
178 /* Set output frequency */ | |
903
6e6248801043
Date: Sun, 18 Jul 2004 16:46:44 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
605
diff
changeset
|
179 #ifdef OLD_IRIX_AUDIO |
6e6248801043
Date: Sun, 18 Jul 2004 16:46:44 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
605
diff
changeset
|
180 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
|
181 audio_param[1] = spec->freq; |
6e6248801043
Date: Sun, 18 Jul 2004 16:46:44 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
605
diff
changeset
|
182 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
|
183 #else |
0 | 184 audio_param.param = AL_RATE; |
185 audio_param.value.i = spec->freq; | |
186 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
|
187 #endif |
0 | 188 SDL_SetError("alSetParams failed"); |
189 return(-1); | |
190 } | |
191 | |
192 /* Open the audio port with the requested frequency */ | |
193 audio_port = NULL; | |
194 audio_config = alNewConfig(); | |
195 if ( audio_config && | |
196 (alSetSampFmt(audio_config, AL_SAMPFMT_TWOSCOMP) >= 0) && | |
197 (alSetWidth(audio_config, width) >= 0) && | |
198 (alSetQueueSize(audio_config, spec->samples*2) >= 0) && | |
199 (alSetChannels(audio_config, spec->channels) >= 0) ) { | |
605
6399f4e90211
IRIX patches from Andrea Suatoni
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
200 audio_port = alOpenPort("SDL audio", "w", audio_config); |
0 | 201 } |
202 alFreeConfig(audio_config); | |
203 if( audio_port == NULL ) { | |
204 SDL_SetError("Unable to open audio port"); | |
205 return(-1); | |
206 } | |
207 | |
208 /* Allocate mixing buffer */ | |
209 mixbuf = (Uint8 *)SDL_AllocAudioMem(spec->size); | |
210 if ( mixbuf == NULL ) { | |
211 SDL_OutOfMemory(); | |
212 return(-1); | |
213 } | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
214 SDL_memset(mixbuf, spec->silence, spec->size); |
0 | 215 |
216 /* We're ready to rock and roll. :-) */ | |
217 return(0); | |
218 } |