18 #define M_PI 3.14159265358979323846 /* pi */
19 #define M_PI_2 1.57079632679489661923 /* pi/2 */
22 #define F_PI ((float)M_PI)
23 #define F_PI_2 ((float)M_PI_2)
26 #define aluPow(x,y) (powf((x),(y)))
28 #define aluPow(x,y) ((ALfloat)pow((double)(x),(double)(y)))
32 #define aluSqrt(x) (sqrtf((x)))
34 #define aluSqrt(x) ((ALfloat)sqrt((double)(x)))
38 #define aluCos(x) (cosf((x)))
40 #define aluCos(x) ((ALfloat)cos((double)(x)))
44 #define aluSin(x) (sinf((x)))
46 #define aluSin(x) ((ALfloat)sin((double)(x)))
50 #define aluAcos(x) (acosf((x)))
52 #define aluAcos(x) ((ALfloat)acos((double)(x)))
56 #define aluAtan(x) (atanf((x)))
58 #define aluAtan(x) ((ALfloat)atan((double)(x)))
62 #define aluFabs(x) (fabsf((x)))
64 #define aluFabs(x) ((ALfloat)fabs((double)(x)))
67 #define QUADRANT_NUM 128
68 #define LUT_NUM (4 * QUADRANT_NUM)
77 typedef ALvoid (*MixerFunc
)(struct ALsource
*self
, ALCdevice
*Device
,
78 const ALvoid
*RESTRICT data
,
79 ALuint
*DataPosInt
, ALuint
*DataPosFrac
,
80 ALuint OutPos
, ALuint SamplesToDo
,
90 RESAMPLER_DEFAULT
= LINEAR_RESAMPLER
108 InverseDistanceClamped
= AL_INVERSE_DISTANCE_CLAMPED
,
109 LinearDistanceClamped
= AL_LINEAR_DISTANCE_CLAMPED
,
110 ExponentDistanceClamped
= AL_EXPONENT_DISTANCE_CLAMPED
,
111 InverseDistance
= AL_INVERSE_DISTANCE
,
112 LinearDistance
= AL_LINEAR_DISTANCE
,
113 ExponentDistance
= AL_EXPONENT_DISTANCE
,
114 DisableDistance
= AL_NONE
117 #define BUFFERSIZE 4096
119 #define FRACTIONBITS (14)
120 #define FRACTIONONE (1<<FRACTIONBITS)
121 #define FRACTIONMASK (FRACTIONONE-1)
123 /* Size for temporary stack storage of buffer data. Larger values need more
124 * stack, while smaller values may need more iterations. The value needs to be
125 * a sensible size, however, as it constrains the max stepping value used for
127 * The mixer requires being able to do two samplings per mixing loop. A 16KB
128 * buffer can hold 512 sample frames for a 7.1 float buffer. With the cubic
129 * resampler (which requires 3 padding sample frames), this limits the maximum
130 * step to about 508. This means that buffer_freq*source_pitch cannot exceed
131 * device_freq*508 for an 8-channel 32-bit buffer. */
132 #ifndef STACK_DATA_SIZE
133 #define STACK_DATA_SIZE 16384
137 static __inline ALfloat
minf(ALfloat a
, ALfloat b
)
138 { return ((a
> b
) ? b
: a
); }
139 static __inline ALfloat
maxf(ALfloat a
, ALfloat b
)
140 { return ((a
> b
) ? a
: b
); }
141 static __inline ALfloat
clampf(ALfloat val
, ALfloat min
, ALfloat max
)
142 { return minf(max
, maxf(min
, val
)); }
144 static __inline ALuint
minu(ALuint a
, ALuint b
)
145 { return ((a
> b
) ? b
: a
); }
146 static __inline ALuint
maxu(ALuint a
, ALuint b
)
147 { return ((a
> b
) ? a
: b
); }
148 static __inline ALuint
clampu(ALuint val
, ALuint min
, ALuint max
)
149 { return minu(max
, maxu(min
, val
)); }
151 static __inline ALint
mini(ALint a
, ALint b
)
152 { return ((a
> b
) ? b
: a
); }
153 static __inline ALint
maxi(ALint a
, ALint b
)
154 { return ((a
> b
) ? a
: b
); }
155 static __inline ALint
clampi(ALint val
, ALint min
, ALint max
)
156 { return mini(max
, maxi(min
, val
)); }
159 static __inline ALdouble
lerp(ALdouble val1
, ALdouble val2
, ALdouble mu
)
161 return val1
+ (val2
-val1
)*mu
;
163 static __inline ALdouble
cubic(ALdouble val0
, ALdouble val1
, ALdouble val2
, ALdouble val3
, ALdouble mu
)
165 ALdouble mu2
= mu
*mu
;
166 ALdouble a0
= -0.5*val0
+ 1.5*val1
+ -1.5*val2
+ 0.5*val3
;
167 ALdouble a1
= val0
+ -2.5*val1
+ 2.0*val2
+ -0.5*val3
;
168 ALdouble a2
= -0.5*val0
+ 0.5*val2
;
171 return a0
*mu
*mu2
+ a1
*mu2
+ a2
*mu
+ a3
;
174 ALvoid
aluInitPanning(ALCdevice
*Device
);
175 ALint
aluCart2LUTpos(ALfloat re
, ALfloat im
);
177 ALvoid
CalcSourceParams(struct ALsource
*ALSource
, const ALCcontext
*ALContext
);
178 ALvoid
CalcNonAttnSourceParams(struct ALsource
*ALSource
, const ALCcontext
*ALContext
);
180 MixerFunc
SelectMixer(struct ALbuffer
*Buffer
, enum Resampler Resampler
);
181 MixerFunc
SelectHrtfMixer(struct ALbuffer
*Buffer
, enum Resampler Resampler
);
183 ALvoid
MixSource(struct ALsource
*Source
, ALCdevice
*Device
, ALuint SamplesToDo
);
185 ALvoid
aluMixData(ALCdevice
*device
, ALvoid
*buffer
, ALsizei size
);
186 ALvoid
aluHandleDisconnect(ALCdevice
*device
);
188 extern ALfloat ConeScale
;
189 extern ALfloat ZScale
;