Mercurial > sdl-ios-xcode
comparison src/audio/dmedia/SDL_irixaudio.c @ 1668:4da1ee79c9af SDL-1.3
more tweaking indent options
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Mon, 29 May 2006 04:04:35 +0000 |
parents | 782fd950bd46 |
children |
comparison
equal
deleted
inserted
replaced
1667:1fddae038bc8 | 1668:4da1ee79c9af |
---|---|
43 #define alSetSampFmt(x,y) ALsetsampfmt(x,y) | 43 #define alSetSampFmt(x,y) ALsetsampfmt(x,y) |
44 #define alSetWidth(x,y) ALsetwidth(x,y) | 44 #define alSetWidth(x,y) ALsetwidth(x,y) |
45 #endif | 45 #endif |
46 | 46 |
47 /* Audio driver functions */ | 47 /* Audio driver functions */ |
48 static int AL_OpenAudio (_THIS, SDL_AudioSpec * spec); | 48 static int AL_OpenAudio(_THIS, SDL_AudioSpec * spec); |
49 static void AL_WaitAudio (_THIS); | 49 static void AL_WaitAudio(_THIS); |
50 static void AL_PlayAudio (_THIS); | 50 static void AL_PlayAudio(_THIS); |
51 static Uint8 *AL_GetAudioBuf (_THIS); | 51 static Uint8 *AL_GetAudioBuf(_THIS); |
52 static void AL_CloseAudio (_THIS); | 52 static void AL_CloseAudio(_THIS); |
53 | 53 |
54 /* Audio driver bootstrap functions */ | 54 /* Audio driver bootstrap functions */ |
55 | 55 |
56 static int | 56 static int |
57 Audio_Available (void) | 57 Audio_Available(void) |
58 { | 58 { |
59 return 1; | 59 return 1; |
60 } | 60 } |
61 | 61 |
62 static void | 62 static void |
63 Audio_DeleteDevice (SDL_AudioDevice * device) | 63 Audio_DeleteDevice(SDL_AudioDevice * device) |
64 { | 64 { |
65 SDL_free (device->hidden); | 65 SDL_free(device->hidden); |
66 SDL_free (device); | 66 SDL_free(device); |
67 } | 67 } |
68 | 68 |
69 static SDL_AudioDevice * | 69 static SDL_AudioDevice * |
70 Audio_CreateDevice (int devindex) | 70 Audio_CreateDevice(int devindex) |
71 { | 71 { |
72 SDL_AudioDevice *this; | 72 SDL_AudioDevice *this; |
73 | 73 |
74 /* Initialize all variables that we clean on shutdown */ | 74 /* Initialize all variables that we clean on shutdown */ |
75 this = (SDL_AudioDevice *) SDL_malloc (sizeof (SDL_AudioDevice)); | 75 this = (SDL_AudioDevice *) SDL_malloc(sizeof(SDL_AudioDevice)); |
76 if (this) { | 76 if (this) { |
77 SDL_memset (this, 0, (sizeof *this)); | 77 SDL_memset(this, 0, (sizeof *this)); |
78 this->hidden = (struct SDL_PrivateAudioData *) | 78 this->hidden = (struct SDL_PrivateAudioData *) |
79 SDL_malloc ((sizeof *this->hidden)); | 79 SDL_malloc((sizeof *this->hidden)); |
80 } | 80 } |
81 if ((this == NULL) || (this->hidden == NULL)) { | 81 if ((this == NULL) || (this->hidden == NULL)) { |
82 SDL_OutOfMemory (); | 82 SDL_OutOfMemory(); |
83 if (this) { | 83 if (this) { |
84 SDL_free (this); | 84 SDL_free(this); |
85 } | 85 } |
86 return (0); | 86 return (0); |
87 } | 87 } |
88 SDL_memset (this->hidden, 0, (sizeof *this->hidden)); | 88 SDL_memset(this->hidden, 0, (sizeof *this->hidden)); |
89 | 89 |
90 /* Set the function pointers */ | 90 /* Set the function pointers */ |
91 this->OpenAudio = AL_OpenAudio; | 91 this->OpenAudio = AL_OpenAudio; |
92 this->WaitAudio = AL_WaitAudio; | 92 this->WaitAudio = AL_WaitAudio; |
93 this->PlayAudio = AL_PlayAudio; | 93 this->PlayAudio = AL_PlayAudio; |
104 Audio_Available, Audio_CreateDevice | 104 Audio_Available, Audio_CreateDevice |
105 }; | 105 }; |
106 | 106 |
107 | 107 |
108 void static | 108 void static |
109 AL_WaitAudio (_THIS) | 109 AL_WaitAudio(_THIS) |
110 { | 110 { |
111 Sint32 timeleft; | 111 Sint32 timeleft; |
112 | 112 |
113 timeleft = this->spec.samples - alGetFillable (audio_port); | 113 timeleft = this->spec.samples - alGetFillable(audio_port); |
114 if (timeleft > 0) { | 114 if (timeleft > 0) { |
115 timeleft /= (this->spec.freq / 1000); | 115 timeleft /= (this->spec.freq / 1000); |
116 SDL_Delay ((Uint32) timeleft); | 116 SDL_Delay((Uint32) timeleft); |
117 } | 117 } |
118 } | 118 } |
119 | 119 |
120 static void | 120 static void |
121 AL_PlayAudio (_THIS) | 121 AL_PlayAudio(_THIS) |
122 { | 122 { |
123 /* Write the audio data out */ | 123 /* Write the audio data out */ |
124 if (alWriteFrames (audio_port, mixbuf, this->spec.samples) < 0) { | 124 if (alWriteFrames(audio_port, mixbuf, this->spec.samples) < 0) { |
125 /* Assume fatal error, for now */ | 125 /* Assume fatal error, for now */ |
126 this->enabled = 0; | 126 this->enabled = 0; |
127 } | 127 } |
128 } | 128 } |
129 | 129 |
130 static Uint8 * | 130 static Uint8 * |
131 AL_GetAudioBuf (_THIS) | 131 AL_GetAudioBuf(_THIS) |
132 { | 132 { |
133 return (mixbuf); | 133 return (mixbuf); |
134 } | 134 } |
135 | 135 |
136 static void | 136 static void |
137 AL_CloseAudio (_THIS) | 137 AL_CloseAudio(_THIS) |
138 { | 138 { |
139 if (mixbuf != NULL) { | 139 if (mixbuf != NULL) { |
140 SDL_FreeAudioMem (mixbuf); | 140 SDL_FreeAudioMem(mixbuf); |
141 mixbuf = NULL; | 141 mixbuf = NULL; |
142 } | 142 } |
143 if (audio_port != NULL) { | 143 if (audio_port != NULL) { |
144 alClosePort (audio_port); | 144 alClosePort(audio_port); |
145 audio_port = NULL; | 145 audio_port = NULL; |
146 } | 146 } |
147 } | 147 } |
148 | 148 |
149 static int | 149 static int |
150 AL_OpenAudio (_THIS, SDL_AudioSpec * spec) | 150 AL_OpenAudio(_THIS, SDL_AudioSpec * spec) |
151 { | 151 { |
152 ALconfig audio_config; | 152 ALconfig audio_config; |
153 #ifdef OLD_IRIX_AUDIO | 153 #ifdef OLD_IRIX_AUDIO |
154 long audio_param[2]; | 154 long audio_param[2]; |
155 #else | 155 #else |
174 } | 174 } |
175 break; | 175 break; |
176 | 176 |
177 default: | 177 default: |
178 { | 178 { |
179 SDL_SetError ("Unsupported audio format"); | 179 SDL_SetError("Unsupported audio format"); |
180 return (-1); | 180 return (-1); |
181 } | 181 } |
182 } | 182 } |
183 | 183 |
184 /* Update the fragment size as size in bytes */ | 184 /* Update the fragment size as size in bytes */ |
185 SDL_CalculateAudioSpec (spec); | 185 SDL_CalculateAudioSpec(spec); |
186 | 186 |
187 /* Set output frequency */ | 187 /* Set output frequency */ |
188 #ifdef OLD_IRIX_AUDIO | 188 #ifdef OLD_IRIX_AUDIO |
189 audio_param[0] = AL_OUTPUT_RATE; | 189 audio_param[0] = AL_OUTPUT_RATE; |
190 audio_param[1] = spec->freq; | 190 audio_param[1] = spec->freq; |
191 if (ALsetparams (AL_DEFAULT_DEVICE, audio_param, 2) < 0) { | 191 if (ALsetparams(AL_DEFAULT_DEVICE, audio_param, 2) < 0) { |
192 #else | 192 #else |
193 audio_param.param = AL_RATE; | 193 audio_param.param = AL_RATE; |
194 audio_param.value.i = spec->freq; | 194 audio_param.value.i = spec->freq; |
195 if (alSetParams (AL_DEFAULT_OUTPUT, &audio_param, 1) < 0) { | 195 if (alSetParams(AL_DEFAULT_OUTPUT, &audio_param, 1) < 0) { |
196 #endif | 196 #endif |
197 SDL_SetError ("alSetParams failed"); | 197 SDL_SetError("alSetParams failed"); |
198 return (-1); | 198 return (-1); |
199 } | 199 } |
200 | 200 |
201 /* Open the audio port with the requested frequency */ | 201 /* Open the audio port with the requested frequency */ |
202 audio_port = NULL; | 202 audio_port = NULL; |
203 audio_config = alNewConfig (); | 203 audio_config = alNewConfig(); |
204 if (audio_config && | 204 if (audio_config && |
205 (alSetSampFmt (audio_config, AL_SAMPFMT_TWOSCOMP) >= 0) && | 205 (alSetSampFmt(audio_config, AL_SAMPFMT_TWOSCOMP) >= 0) && |
206 (alSetWidth (audio_config, width) >= 0) && | 206 (alSetWidth(audio_config, width) >= 0) && |
207 (alSetQueueSize (audio_config, spec->samples * 2) >= 0) && | 207 (alSetQueueSize(audio_config, spec->samples * 2) >= 0) && |
208 (alSetChannels (audio_config, spec->channels) >= 0)) { | 208 (alSetChannels(audio_config, spec->channels) >= 0)) { |
209 audio_port = alOpenPort ("SDL audio", "w", audio_config); | 209 audio_port = alOpenPort("SDL audio", "w", audio_config); |
210 } | 210 } |
211 alFreeConfig (audio_config); | 211 alFreeConfig(audio_config); |
212 if (audio_port == NULL) { | 212 if (audio_port == NULL) { |
213 SDL_SetError ("Unable to open audio port"); | 213 SDL_SetError("Unable to open audio port"); |
214 return (-1); | 214 return (-1); |
215 } | 215 } |
216 | 216 |
217 /* Allocate mixing buffer */ | 217 /* Allocate mixing buffer */ |
218 mixbuf = (Uint8 *) SDL_AllocAudioMem (spec->size); | 218 mixbuf = (Uint8 *) SDL_AllocAudioMem(spec->size); |
219 if (mixbuf == NULL) { | 219 if (mixbuf == NULL) { |
220 SDL_OutOfMemory (); | 220 SDL_OutOfMemory(); |
221 return (-1); | 221 return (-1); |
222 } | 222 } |
223 SDL_memset (mixbuf, spec->silence, spec->size); | 223 SDL_memset(mixbuf, spec->silence, spec->size); |
224 | 224 |
225 /* We're ready to rock and roll. :-) */ | 225 /* We're ready to rock and roll. :-) */ |
226 return (0); | 226 return (0); |
227 } | 227 } |
228 | 228 |