Mercurial > sdl-ios-xcode
comparison src/audio/SDL_mixer.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 |
---|---|
88 /* The volume ranges from 0 - 128 */ | 88 /* The volume ranges from 0 - 128 */ |
89 #define ADJUST_VOLUME(s, v) (s = (s*v)/SDL_MIX_MAXVOLUME) | 89 #define ADJUST_VOLUME(s, v) (s = (s*v)/SDL_MIX_MAXVOLUME) |
90 #define ADJUST_VOLUME_U8(s, v) (s = (((s-128)*v)/SDL_MIX_MAXVOLUME)+128) | 90 #define ADJUST_VOLUME_U8(s, v) (s = (((s-128)*v)/SDL_MIX_MAXVOLUME)+128) |
91 | 91 |
92 void | 92 void |
93 SDL_MixAudio (Uint8 * dst, const Uint8 * src, Uint32 len, int volume) | 93 SDL_MixAudio(Uint8 * dst, const Uint8 * src, Uint32 len, int volume) |
94 { | 94 { |
95 Uint16 format; | 95 Uint16 format; |
96 | 96 |
97 if (volume == 0) { | 97 if (volume == 0) { |
98 return; | 98 return; |
111 switch (format) { | 111 switch (format) { |
112 | 112 |
113 case AUDIO_U8: | 113 case AUDIO_U8: |
114 { | 114 { |
115 #if defined(__GNUC__) && defined(__M68000__) && defined(SDL_ASSEMBLY_ROUTINES) | 115 #if defined(__GNUC__) && defined(__M68000__) && defined(SDL_ASSEMBLY_ROUTINES) |
116 SDL_MixAudio_m68k_U8 ((char *) dst, (char *) src, | 116 SDL_MixAudio_m68k_U8((char *) dst, (char *) src, |
117 (unsigned long) len, (long) volume, | 117 (unsigned long) len, (long) volume, |
118 (char *) mix8); | 118 (char *) mix8); |
119 #else | 119 #else |
120 Uint8 src_sample; | 120 Uint8 src_sample; |
121 | 121 |
122 while (len--) { | 122 while (len--) { |
123 src_sample = *src; | 123 src_sample = *src; |
124 ADJUST_VOLUME_U8 (src_sample, volume); | 124 ADJUST_VOLUME_U8(src_sample, volume); |
125 *dst = mix8[*dst + src_sample]; | 125 *dst = mix8[*dst + src_sample]; |
126 ++dst; | 126 ++dst; |
127 ++src; | 127 ++src; |
128 } | 128 } |
129 #endif | 129 #endif |
131 break; | 131 break; |
132 | 132 |
133 case AUDIO_S8: | 133 case AUDIO_S8: |
134 { | 134 { |
135 #if defined(__GNUC__) && defined(__i386__) && defined(SDL_ASSEMBLY_ROUTINES) | 135 #if defined(__GNUC__) && defined(__i386__) && defined(SDL_ASSEMBLY_ROUTINES) |
136 if (SDL_HasMMX ()) { | 136 if (SDL_HasMMX()) { |
137 SDL_MixAudio_MMX_S8 ((char *) dst, (char *) src, | 137 SDL_MixAudio_MMX_S8((char *) dst, (char *) src, |
138 (unsigned int) len, (int) volume); | 138 (unsigned int) len, (int) volume); |
139 } else | 139 } else |
140 #elif ((defined(_MSC_VER) && defined(_M_IX86)) || defined(__WATCOMC__)) && defined(SDL_ASSEMBLY_ROUTINES) | 140 #elif ((defined(_MSC_VER) && defined(_M_IX86)) || defined(__WATCOMC__)) && defined(SDL_ASSEMBLY_ROUTINES) |
141 if (SDL_HasMMX ()) { | 141 if (SDL_HasMMX()) { |
142 SDL_MixAudio_MMX_S8_VC ((char *) dst, (char *) src, | 142 SDL_MixAudio_MMX_S8_VC((char *) dst, (char *) src, |
143 (unsigned int) len, (int) volume); | 143 (unsigned int) len, (int) volume); |
144 } else | 144 } else |
145 #endif | 145 #endif |
146 #if defined(__GNUC__) && defined(__M68000__) && defined(SDL_ASSEMBLY_ROUTINES) | 146 #if defined(__GNUC__) && defined(__M68000__) && defined(SDL_ASSEMBLY_ROUTINES) |
147 SDL_MixAudio_m68k_S8 ((char *) dst, (char *) src, | 147 SDL_MixAudio_m68k_S8((char *) dst, (char *) src, |
148 (unsigned long) len, (long) volume); | 148 (unsigned long) len, (long) volume); |
149 #else | 149 #else |
150 { | 150 { |
151 Sint8 *dst8, *src8; | 151 Sint8 *dst8, *src8; |
152 Sint8 src_sample; | 152 Sint8 src_sample; |
153 int dst_sample; | 153 int dst_sample; |
156 | 156 |
157 src8 = (Sint8 *) src; | 157 src8 = (Sint8 *) src; |
158 dst8 = (Sint8 *) dst; | 158 dst8 = (Sint8 *) dst; |
159 while (len--) { | 159 while (len--) { |
160 src_sample = *src8; | 160 src_sample = *src8; |
161 ADJUST_VOLUME (src_sample, volume); | 161 ADJUST_VOLUME(src_sample, volume); |
162 dst_sample = *dst8 + src_sample; | 162 dst_sample = *dst8 + src_sample; |
163 if (dst_sample > max_audioval) { | 163 if (dst_sample > max_audioval) { |
164 *dst8 = max_audioval; | 164 *dst8 = max_audioval; |
165 } else if (dst_sample < min_audioval) { | 165 } else if (dst_sample < min_audioval) { |
166 *dst8 = min_audioval; | 166 *dst8 = min_audioval; |
176 break; | 176 break; |
177 | 177 |
178 case AUDIO_S16LSB: | 178 case AUDIO_S16LSB: |
179 { | 179 { |
180 #if defined(__GNUC__) && defined(__i386__) && defined(SDL_ASSEMBLY_ROUTINES) | 180 #if defined(__GNUC__) && defined(__i386__) && defined(SDL_ASSEMBLY_ROUTINES) |
181 if (SDL_HasMMX ()) { | 181 if (SDL_HasMMX()) { |
182 SDL_MixAudio_MMX_S16 ((char *) dst, (char *) src, | 182 SDL_MixAudio_MMX_S16((char *) dst, (char *) src, |
183 (unsigned int) len, (int) volume); | 183 (unsigned int) len, (int) volume); |
184 } else | 184 } else |
185 #elif ((defined(_MSC_VER) && defined(_M_IX86)) || defined(__WATCOMC__)) && defined(SDL_ASSEMBLY_ROUTINES) | 185 #elif ((defined(_MSC_VER) && defined(_M_IX86)) || defined(__WATCOMC__)) && defined(SDL_ASSEMBLY_ROUTINES) |
186 if (SDL_HasMMX ()) { | 186 if (SDL_HasMMX()) { |
187 SDL_MixAudio_MMX_S16_VC ((char *) dst, (char *) src, | 187 SDL_MixAudio_MMX_S16_VC((char *) dst, (char *) src, |
188 (unsigned int) len, (int) volume); | 188 (unsigned int) len, (int) volume); |
189 } else | 189 } else |
190 #endif | 190 #endif |
191 #if defined(__GNUC__) && defined(__M68000__) && defined(SDL_ASSEMBLY_ROUTINES) | 191 #if defined(__GNUC__) && defined(__M68000__) && defined(SDL_ASSEMBLY_ROUTINES) |
192 SDL_MixAudio_m68k_S16LSB ((short *) dst, (short *) src, | 192 SDL_MixAudio_m68k_S16LSB((short *) dst, (short *) src, |
193 (unsigned long) len, (long) volume); | 193 (unsigned long) len, (long) volume); |
194 #else | 194 #else |
195 { | 195 { |
196 Sint16 src1, src2; | 196 Sint16 src1, src2; |
197 int dst_sample; | 197 int dst_sample; |
198 const int max_audioval = ((1 << (16 - 1)) - 1); | 198 const int max_audioval = ((1 << (16 - 1)) - 1); |
199 const int min_audioval = -(1 << (16 - 1)); | 199 const int min_audioval = -(1 << (16 - 1)); |
200 | 200 |
201 len /= 2; | 201 len /= 2; |
202 while (len--) { | 202 while (len--) { |
203 src1 = ((src[1]) << 8 | src[0]); | 203 src1 = ((src[1]) << 8 | src[0]); |
204 ADJUST_VOLUME (src1, volume); | 204 ADJUST_VOLUME(src1, volume); |
205 src2 = ((dst[1]) << 8 | dst[0]); | 205 src2 = ((dst[1]) << 8 | dst[0]); |
206 src += 2; | 206 src += 2; |
207 dst_sample = src1 + src2; | 207 dst_sample = src1 + src2; |
208 if (dst_sample > max_audioval) { | 208 if (dst_sample > max_audioval) { |
209 dst_sample = max_audioval; | 209 dst_sample = max_audioval; |
221 break; | 221 break; |
222 | 222 |
223 case AUDIO_S16MSB: | 223 case AUDIO_S16MSB: |
224 { | 224 { |
225 #if defined(__GNUC__) && defined(__M68000__) && defined(SDL_ASSEMBLY_ROUTINES) | 225 #if defined(__GNUC__) && defined(__M68000__) && defined(SDL_ASSEMBLY_ROUTINES) |
226 SDL_MixAudio_m68k_S16MSB ((short *) dst, (short *) src, | 226 SDL_MixAudio_m68k_S16MSB((short *) dst, (short *) src, |
227 (unsigned long) len, (long) volume); | 227 (unsigned long) len, (long) volume); |
228 #else | 228 #else |
229 Sint16 src1, src2; | 229 Sint16 src1, src2; |
230 int dst_sample; | 230 int dst_sample; |
231 const int max_audioval = ((1 << (16 - 1)) - 1); | 231 const int max_audioval = ((1 << (16 - 1)) - 1); |
232 const int min_audioval = -(1 << (16 - 1)); | 232 const int min_audioval = -(1 << (16 - 1)); |
233 | 233 |
234 len /= 2; | 234 len /= 2; |
235 while (len--) { | 235 while (len--) { |
236 src1 = ((src[0]) << 8 | src[1]); | 236 src1 = ((src[0]) << 8 | src[1]); |
237 ADJUST_VOLUME (src1, volume); | 237 ADJUST_VOLUME(src1, volume); |
238 src2 = ((dst[0]) << 8 | dst[1]); | 238 src2 = ((dst[0]) << 8 | dst[1]); |
239 src += 2; | 239 src += 2; |
240 dst_sample = src1 + src2; | 240 dst_sample = src1 + src2; |
241 if (dst_sample > max_audioval) { | 241 if (dst_sample > max_audioval) { |
242 dst_sample = max_audioval; | 242 dst_sample = max_audioval; |
251 #endif | 251 #endif |
252 } | 252 } |
253 break; | 253 break; |
254 | 254 |
255 default: /* If this happens... FIXME! */ | 255 default: /* If this happens... FIXME! */ |
256 SDL_SetError ("SDL_MixAudio(): unknown audio format"); | 256 SDL_SetError("SDL_MixAudio(): unknown audio format"); |
257 return; | 257 return; |
258 } | 258 } |
259 } | 259 } |
260 | 260 |
261 /* vi: set ts=4 sw=4 expandtab: */ | 261 /* vi: set ts=4 sw=4 expandtab: */ |