Skip to content

Latest commit

 

History

History
143 lines (112 loc) · 3.83 KB

effect_stereoreverse.c

File metadata and controls

143 lines (112 loc) · 3.83 KB
 
Dec 31, 2011
Dec 31, 2011
2
SDL_mixer: An audio mixer library based on the SDL library
Jan 5, 2019
Jan 5, 2019
3
Copyright (C) 1997-2019 Sam Lantinga <slouken@libsdl.org>
Dec 31, 2011
Dec 31, 2011
5
6
7
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Dec 31, 2011
Dec 31, 2011
9
10
11
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
Dec 31, 2011
Dec 31, 2011
13
14
15
16
17
18
19
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
Dec 31, 2011
Dec 31, 2011
21
This file by Ryan C. Gordon (icculus@icculus.org)
Dec 31, 2011
Dec 31, 2011
23
24
These are some internally supported special effects that use SDL_mixer's
effect callback API. They are meant for speed over quality. :)
25
26
27
28
*/
#include <stdio.h>
#include <stdlib.h>
Sep 11, 2001
Sep 11, 2001
29
30
31
32
#include "SDL.h"
#include "SDL_mixer.h"
Nov 26, 2019
Nov 26, 2019
33
#define MIX_INTERNAL_EFFECT__
34
35
36
37
38
39
40
#include "effects_internal.h"
/* profile code:
#include <sys/time.h>
#include <unistd.h>
struct timeval tv1;
struct timeval tv2;
May 22, 2013
May 22, 2013
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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...
*/
Oct 21, 2017
Oct 21, 2017
55
static void SDLCALL _Eff_reversestereo32(int chan, void *stream, int len, void *udata)
Sep 9, 2017
Sep 9, 2017
56
57
58
{
/* 16 bits * 2 channels. */
Uint32 *ptr = (Uint32 *) stream;
Oct 21, 2017
Oct 21, 2017
59
Uint32 tmp;
Sep 9, 2017
Sep 9, 2017
60
int i;
Nov 18, 2019
Nov 18, 2019
61
Nov 18, 2019
Nov 18, 2019
62
63
(void)chan;
(void)udata;
Sep 9, 2017
Sep 9, 2017
64
65
for (i = 0; i < len; i += 2 * sizeof (Uint32), ptr += 2) {
Oct 21, 2017
Oct 21, 2017
66
67
68
tmp = ptr[0];
ptr[0] = ptr[1];
ptr[1] = tmp;
Sep 9, 2017
Sep 9, 2017
69
70
71
}
}
Oct 21, 2017
Oct 21, 2017
72
static void SDLCALL _Eff_reversestereo16(int chan, void *stream, int len, void *udata)
73
74
75
76
{
/* 16 bits * 2 channels. */
Uint32 *ptr = (Uint32 *) stream;
int i;
Nov 18, 2019
Nov 18, 2019
77
Nov 18, 2019
Nov 18, 2019
78
79
(void)chan;
(void)udata;
80
81
82
83
84
85
for (i = 0; i < len; i += sizeof (Uint32), ptr++) {
*ptr = (((*ptr) & 0xFFFF0000) >> 16) | (((*ptr) & 0x0000FFFF) << 16);
}
}
Oct 21, 2017
Oct 21, 2017
86
static void SDLCALL _Eff_reversestereo8(int chan, void *stream, int len, void *udata)
87
88
89
90
{
/* 8 bits * 2 channels. */
Uint32 *ptr = (Uint32 *) stream;
int i;
Nov 18, 2019
Nov 18, 2019
91
Nov 18, 2019
Nov 18, 2019
92
93
(void)chan;
(void)udata;
94
95
/* get the last two bytes if len is not divisible by four... */
Nov 18, 2019
Nov 18, 2019
96
if (len % (int)sizeof(Uint32) != 0) {
97
Uint16 *p = (Uint16 *) (((Uint8 *) stream) + (len - 2));
May 11, 2006
May 11, 2006
98
*p = (Uint16)((((*p) & 0xFF00) >> 8) | (((*ptr) & 0x00FF) << 8));
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) {
Oct 21, 2017
Oct 21, 2017
118
119
120
int bits = (format & 0xFF);
switch (bits) {
case 8:
121
f = _Eff_reversestereo8;
Oct 21, 2017
Oct 21, 2017
122
123
break;
case 16:
Sep 9, 2017
Sep 9, 2017
124
f = _Eff_reversestereo16;
Oct 21, 2017
Oct 21, 2017
125
126
break;
case 32:
Sep 9, 2017
Sep 9, 2017
127
f = _Eff_reversestereo32;
Oct 21, 2017
Oct 21, 2017
128
129
break;
default:
130
131
132
Mix_SetError("Unsupported audio format");
return(0);
}
Nov 18, 2019
Nov 18, 2019
133
134
if (!flip) return Mix_UnregisterEffect(channel, f);
return(Mix_RegisterEffect(channel, f, NULL, NULL));
Oct 21, 2017
Oct 21, 2017
135
}
Nov 18, 2019
Nov 18, 2019
137
138
Mix_SetError("Trying to reverse stereo on a non-stereo stream");
return(0);
139
140
141
142
}
/* end of effect_stereoreverse.c ... */
Oct 17, 2017
Oct 17, 2017
143
/* vi: set ts=4 sw=4 expandtab: */