Skip to content

Latest commit

 

History

History
122 lines (92 loc) · 3.21 KB

effects_internal.c

File metadata and controls

122 lines (92 loc) · 3.21 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
These are some helper functions for the internal mixer special effects.
*/
Dec 14, 2001
Dec 14, 2001
24
/* $Id$ */
25
26
27
28
29
30
31
32
33
34
/* ------ These are used internally only. Don't touch. ------ */
#include <stdio.h>
#include <stdlib.h>
#include "SDL_mixer.h"
Jul 15, 2007
Jul 15, 2007
35
36
37
#define __MIX_INTERNAL_EFFECT__
#include "effects_internal.h"
38
39
40
41
42
43
44
45
46
/* Should we favor speed over memory usage and/or quality of output? */
int _Mix_effects_max_speed = 0;
void _Mix_InitEffects(void)
{
_Mix_effects_max_speed = (getenv(MIX_EFFECTSMAXSPEED) != NULL);
}
Jul 15, 2007
Jul 15, 2007
47
48
49
50
51
void _Mix_DeinitEffects(void)
{
_Eff_PositionDeinit();
}
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
77
void *_Eff_volume_table = NULL;
/* Build the volume table for Uint8-format samples.
*
* Each column of the table is a possible sample, while each row of the
* table is a volume. Volume is a Uint8, where 0 is silence and 255 is full
* volume. So _Eff_volume_table[128][mysample] would be the value of
* mysample, at half volume.
*/
void *_Eff_build_volume_table_u8(void)
{
int volume;
int sample;
Uint8 *rc;
if (!_Mix_effects_max_speed) {
return(NULL);
}
if (!_Eff_volume_table) {
rc = malloc(256 * 256);
if (rc) {
_Eff_volume_table = (void *) rc;
for (volume = 0; volume < 256; volume++) {
Dec 27, 2002
Dec 27, 2002
78
79
80
for (sample = -128; sample < 128; sample ++) {
*rc = (Uint8)(((float) sample) * ((float) volume / 255.0))
+ 128;
81
82
83
84
85
86
87
88
89
90
91
92
93
94
rc++;
}
}
}
}
return(_Eff_volume_table);
}
/* Build the volume table for Sint8-format samples.
*
* Each column of the table is a possible sample, while each row of the
* table is a volume. Volume is a Uint8, where 0 is silence and 255 is full
Dec 27, 2002
Dec 27, 2002
95
* volume. So _Eff_volume_table[128][mysample+128] would be the value of
96
97
98
99
100
101
102
103
104
105
106
107
108
* mysample, at half volume.
*/
void *_Eff_build_volume_table_s8(void)
{
int volume;
int sample;
Sint8 *rc;
if (!_Eff_volume_table) {
rc = malloc(256 * 256);
if (rc) {
_Eff_volume_table = (void *) rc;
for (volume = 0; volume < 256; volume++) {
Dec 27, 2002
Dec 27, 2002
109
for (sample = -128; sample < 128; sample ++) {
110
111
112
113
114
115
116
117
118
119
120
121
*rc = (Sint8)(((float) sample) * ((float) volume / 255.0));
rc++;
}
}
}
}
return(_Eff_volume_table);
}
/* end of effects.c ... */