Mercurial > audio-send
comparison OpenAL32/Include/alu.h @ 0:f9476ff7637e
initial forking of open-al to create multiple listeners
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Tue, 25 Oct 2011 13:02:31 -0700 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:f9476ff7637e |
---|---|
1 #ifndef _ALU_H_ | |
2 #define _ALU_H_ | |
3 | |
4 #include "AL/al.h" | |
5 #include "AL/alc.h" | |
6 #include "AL/alext.h" | |
7 | |
8 #include <limits.h> | |
9 #include <math.h> | |
10 #ifdef HAVE_FLOAT_H | |
11 #include <float.h> | |
12 #endif | |
13 #ifdef HAVE_IEEEFP_H | |
14 #include <ieeefp.h> | |
15 #endif | |
16 | |
17 #ifndef M_PI | |
18 #define M_PI 3.14159265358979323846 /* pi */ | |
19 #define M_PI_2 1.57079632679489661923 /* pi/2 */ | |
20 #endif | |
21 | |
22 #ifdef HAVE_POWF | |
23 #define aluPow(x,y) (powf((x),(y))) | |
24 #else | |
25 #define aluPow(x,y) ((ALfloat)pow((double)(x),(double)(y))) | |
26 #endif | |
27 | |
28 #ifdef HAVE_SQRTF | |
29 #define aluSqrt(x) (sqrtf((x))) | |
30 #else | |
31 #define aluSqrt(x) ((ALfloat)sqrt((double)(x))) | |
32 #endif | |
33 | |
34 #ifdef HAVE_ACOSF | |
35 #define aluAcos(x) (acosf((x))) | |
36 #else | |
37 #define aluAcos(x) ((ALfloat)acos((double)(x))) | |
38 #endif | |
39 | |
40 #ifdef HAVE_ATANF | |
41 #define aluAtan(x) (atanf((x))) | |
42 #else | |
43 #define aluAtan(x) ((ALfloat)atan((double)(x))) | |
44 #endif | |
45 | |
46 #ifdef HAVE_FABSF | |
47 #define aluFabs(x) (fabsf((x))) | |
48 #else | |
49 #define aluFabs(x) ((ALfloat)fabs((double)(x))) | |
50 #endif | |
51 | |
52 #define QUADRANT_NUM 128 | |
53 #define LUT_NUM (4 * QUADRANT_NUM) | |
54 | |
55 #ifdef __cplusplus | |
56 extern "C" { | |
57 #endif | |
58 | |
59 struct ALsource; | |
60 struct ALbuffer; | |
61 | |
62 typedef ALvoid (*MixerFunc)(struct ALsource *self, ALCdevice *Device, | |
63 const ALvoid *RESTRICT data, | |
64 ALuint *DataPosInt, ALuint *DataPosFrac, | |
65 ALuint OutPos, ALuint SamplesToDo, | |
66 ALuint BufferSize); | |
67 | |
68 enum Resampler { | |
69 POINT_RESAMPLER = 0, | |
70 LINEAR_RESAMPLER, | |
71 CUBIC_RESAMPLER, | |
72 | |
73 RESAMPLER_MAX, | |
74 RESAMPLER_MIN = -1, | |
75 RESAMPLER_DEFAULT = LINEAR_RESAMPLER | |
76 }; | |
77 | |
78 enum Channel { | |
79 FRONT_LEFT = 0, | |
80 FRONT_RIGHT, | |
81 FRONT_CENTER, | |
82 LFE, | |
83 BACK_LEFT, | |
84 BACK_RIGHT, | |
85 BACK_CENTER, | |
86 SIDE_LEFT, | |
87 SIDE_RIGHT, | |
88 | |
89 MAXCHANNELS | |
90 }; | |
91 | |
92 enum DistanceModel { | |
93 InverseDistanceClamped = AL_INVERSE_DISTANCE_CLAMPED, | |
94 LinearDistanceClamped = AL_LINEAR_DISTANCE_CLAMPED, | |
95 ExponentDistanceClamped = AL_EXPONENT_DISTANCE_CLAMPED, | |
96 InverseDistance = AL_INVERSE_DISTANCE, | |
97 LinearDistance = AL_LINEAR_DISTANCE, | |
98 ExponentDistance = AL_EXPONENT_DISTANCE, | |
99 DisableDistance = AL_NONE | |
100 }; | |
101 | |
102 #define BUFFERSIZE 4096 | |
103 | |
104 #define FRACTIONBITS (14) | |
105 #define FRACTIONONE (1<<FRACTIONBITS) | |
106 #define FRACTIONMASK (FRACTIONONE-1) | |
107 | |
108 /* Size for temporary stack storage of buffer data. Larger values need more | |
109 * stack, while smaller values may need more iterations. The value needs to be | |
110 * a sensible size, however, as it constrains the max stepping value used for | |
111 * mixing. | |
112 * The mixer requires being able to do two samplings per mixing loop. A 16KB | |
113 * buffer can hold 512 sample frames for a 7.1 float buffer. With the cubic | |
114 * resampler (which requires 3 padding sample frames), this limits the maximum | |
115 * step to about 508. This means that buffer_freq*source_pitch cannot exceed | |
116 * device_freq*508 for an 8-channel 32-bit buffer. */ | |
117 #ifndef STACK_DATA_SIZE | |
118 #define STACK_DATA_SIZE 16384 | |
119 #endif | |
120 | |
121 | |
122 static __inline ALfloat minf(ALfloat a, ALfloat b) | |
123 { return ((a > b) ? b : a); } | |
124 static __inline ALfloat maxf(ALfloat a, ALfloat b) | |
125 { return ((a > b) ? a : b); } | |
126 static __inline ALfloat clampf(ALfloat val, ALfloat min, ALfloat max) | |
127 { return minf(max, maxf(min, val)); } | |
128 | |
129 static __inline ALuint minu(ALuint a, ALuint b) | |
130 { return ((a > b) ? b : a); } | |
131 static __inline ALuint maxu(ALuint a, ALuint b) | |
132 { return ((a > b) ? a : b); } | |
133 static __inline ALuint clampu(ALuint val, ALuint min, ALuint max) | |
134 { return minu(max, maxu(min, val)); } | |
135 | |
136 static __inline ALint mini(ALint a, ALint b) | |
137 { return ((a > b) ? b : a); } | |
138 static __inline ALint maxi(ALint a, ALint b) | |
139 { return ((a > b) ? a : b); } | |
140 static __inline ALint clampi(ALint val, ALint min, ALint max) | |
141 { return mini(max, maxi(min, val)); } | |
142 | |
143 | |
144 static __inline ALdouble lerp(ALdouble val1, ALdouble val2, ALdouble mu) | |
145 { | |
146 return val1 + (val2-val1)*mu; | |
147 } | |
148 static __inline ALdouble cubic(ALdouble val0, ALdouble val1, ALdouble val2, ALdouble val3, ALdouble mu) | |
149 { | |
150 ALdouble mu2 = mu*mu; | |
151 ALdouble a0 = -0.5*val0 + 1.5*val1 + -1.5*val2 + 0.5*val3; | |
152 ALdouble a1 = val0 + -2.5*val1 + 2.0*val2 + -0.5*val3; | |
153 ALdouble a2 = -0.5*val0 + 0.5*val2; | |
154 ALdouble a3 = val1; | |
155 | |
156 return a0*mu*mu2 + a1*mu2 + a2*mu + a3; | |
157 } | |
158 | |
159 ALvoid aluInitPanning(ALCdevice *Device); | |
160 ALint aluCart2LUTpos(ALfloat re, ALfloat im); | |
161 | |
162 ALvoid CalcSourceParams(struct ALsource *ALSource, const ALCcontext *ALContext); | |
163 ALvoid CalcNonAttnSourceParams(struct ALsource *ALSource, const ALCcontext *ALContext); | |
164 | |
165 MixerFunc SelectMixer(struct ALbuffer *Buffer, enum Resampler Resampler); | |
166 MixerFunc SelectHrtfMixer(struct ALbuffer *Buffer, enum Resampler Resampler); | |
167 | |
168 ALvoid MixSource(struct ALsource *Source, ALCdevice *Device, ALuint SamplesToDo); | |
169 | |
170 ALvoid aluMixData(ALCdevice *device, ALvoid *buffer, ALsizei size); | |
171 ALvoid aluHandleDisconnect(ALCdevice *device); | |
172 | |
173 #ifdef __cplusplus | |
174 } | |
175 #endif | |
176 | |
177 #endif | |
178 |