Ryan C. Gordon - Tue Sep 11 12:05:54 PDT 2001
* Reworked playwave.c to make it more useful as a mixer testbed
* Added a realtime sound effect API to SDL_mixer.h
* Added the following standard sound effects:
panning, distance attenuation, basic positional audio, stereo reversal
* Added API for mixer versioning: Mix_Linked_Version() and MIX_VERSION()
2 MIXERLIB: An audio mixer library based on the SDL library
3 Copyright (C) 1997-1999 Sam Lantinga
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.
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.
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
19 This file by Ryan C. Gordon (icculus@linuxgames.com)
21 These are some internally supported special effects that use SDL_mixer's
22 effect callback API. They are meant for speed over quality. :)
32 #include "SDL_mixer.h"
34 #define __MIX_INTERNAL_EFFECT__
35 #include "effects_internal.h"
43 gettimeofday(&tv1, NULL);
45 ... do your thing here ...
47 gettimeofday(&tv2, NULL);
48 printf("%ld\n", tv2.tv_usec - tv1.tv_usec);
54 * Stereo reversal effect...this one's pretty straightforward...
57 static void _Eff_reversestereo16(int chan, void *stream, int len, void *udata)
59 /* 16 bits * 2 channels. */
60 Uint32 *ptr = (Uint32 *) stream;
63 for (i = 0; i < len; i += sizeof (Uint32), ptr++) {
64 *ptr = (((*ptr) & 0xFFFF0000) >> 16) | (((*ptr) & 0x0000FFFF) << 16);
69 static void _Eff_reversestereo8(int chan, void *stream, int len, void *udata)
71 /* 8 bits * 2 channels. */
72 Uint32 *ptr = (Uint32 *) stream;
75 /* get the last two bytes if len is not divisible by four... */
76 if (len % sizeof (Uint32) != 0) {
77 Uint16 *p = (Uint16 *) (((Uint8 *) stream) + (len - 2));
78 *p = (((*p) & 0xFF00) >> 8) | (((*ptr) & 0x00FF) << 8);
82 for (i = 0; i < len; i += sizeof (Uint32), ptr++) {
83 *ptr = (((*ptr) & 0x0000FF00) >> 8) | (((*ptr) & 0x000000FF) << 8) |
84 (((*ptr) & 0xFF000000) >> 8) | (((*ptr) & 0x00FF0000) << 8);
89 int Mix_SetReverseStereo(int channel, int flip)
91 Mix_EffectFunc_t f = NULL;
95 Mix_QuerySpec(NULL, &format, &channels);
98 if ((format & 0xFF) == 16)
99 f = _Eff_reversestereo16;
100 else if ((format & 0xFF) == 8)
101 f = _Eff_reversestereo8;
103 Mix_SetError("Unsupported audio format");
108 return(Mix_UnregisterEffect(channel, f));
110 return(Mix_RegisterEffect(channel, f, NULL, NULL));
118 /* end of effect_stereoreverse.c ... */