Skip to content

Latest commit

 

History

History
118 lines (87 loc) · 3.1 KB

effect_stereoreverse.c

File metadata and controls

118 lines (87 loc) · 3.1 KB
 
Dec 14, 2001
Dec 14, 2001
2
SDL_mixer: An audio mixer library based on the SDL library
Dec 8, 2008
Dec 8, 2008
3
Copyright (C) 1997-2009 Sam Lantinga
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Jan 15, 2007
Jan 15, 2007
19
This file by Ryan C. Gordon (icculus@icculus.org)
20
21
22
23
24
25
26
27
28
These are some internally supported special effects that use SDL_mixer's
effect callback API. They are meant for speed over quality. :)
*/
/* $Id$ */
#include <stdio.h>
#include <stdlib.h>
Sep 11, 2001
Sep 11, 2001
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include "SDL.h"
#include "SDL_mixer.h"
#define __MIX_INTERNAL_EFFECT__
#include "effects_internal.h"
/* profile code:
#include <sys/time.h>
#include <unistd.h>
struct timeval tv1;
struct timeval tv2;
gettimeofday(&tv1, NULL);
... do your thing here ...
gettimeofday(&tv2, NULL);
printf("%ld\n", tv2.tv_usec - tv1.tv_usec);
*/
/*
* Stereo reversal effect...this one's pretty straightforward...
*/
static void _Eff_reversestereo16(int chan, void *stream, int len, void *udata)
{
/* 16 bits * 2 channels. */
Uint32 *ptr = (Uint32 *) stream;
int i;
for (i = 0; i < len; i += sizeof (Uint32), ptr++) {
*ptr = (((*ptr) & 0xFFFF0000) >> 16) | (((*ptr) & 0x0000FFFF) << 16);
}
}
static void _Eff_reversestereo8(int chan, void *stream, int len, void *udata)
{
/* 8 bits * 2 channels. */
Uint32 *ptr = (Uint32 *) stream;
int i;
/* get the last two bytes if len is not divisible by four... */
if (len % sizeof (Uint32) != 0) {
Uint16 *p = (Uint16 *) (((Uint8 *) stream) + (len - 2));
May 11, 2006
May 11, 2006
77
*p = (Uint16)((((*p) & 0xFF00) >> 8) | (((*ptr) & 0x00FF) << 8));
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
len -= 2;
}
for (i = 0; i < len; i += sizeof (Uint32), ptr++) {
*ptr = (((*ptr) & 0x0000FF00) >> 8) | (((*ptr) & 0x000000FF) << 8) |
(((*ptr) & 0xFF000000) >> 8) | (((*ptr) & 0x00FF0000) << 8);
}
}
int Mix_SetReverseStereo(int channel, int flip)
{
Mix_EffectFunc_t f = NULL;
int channels;
Uint16 format;
Mix_QuerySpec(NULL, &format, &channels);
if (channels == 2) {
if ((format & 0xFF) == 16)
f = _Eff_reversestereo16;
else if ((format & 0xFF) == 8)
f = _Eff_reversestereo8;
else {
Mix_SetError("Unsupported audio format");
return(0);
}
if (!flip) {
return(Mix_UnregisterEffect(channel, f));
} else {
return(Mix_RegisterEffect(channel, f, NULL, NULL));
}
}
return(1);
}
/* end of effect_stereoreverse.c ... */