view OpenAL32/Include/alu.h @ 32:b8bc24918d63

moved ear.org into cortex
author Robert McIntyre <rlm@mit.edu>
date Sat, 04 Feb 2012 01:43:33 -0700
parents f9476ff7637e
children
line wrap: on
line source
1 #ifndef _ALU_H_
2 #define _ALU_H_
4 #include "AL/al.h"
5 #include "AL/alc.h"
6 #include "AL/alext.h"
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
17 #ifndef M_PI
18 #define M_PI 3.14159265358979323846 /* pi */
19 #define M_PI_2 1.57079632679489661923 /* pi/2 */
20 #endif
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
28 #ifdef HAVE_SQRTF
29 #define aluSqrt(x) (sqrtf((x)))
30 #else
31 #define aluSqrt(x) ((ALfloat)sqrt((double)(x)))
32 #endif
34 #ifdef HAVE_ACOSF
35 #define aluAcos(x) (acosf((x)))
36 #else
37 #define aluAcos(x) ((ALfloat)acos((double)(x)))
38 #endif
40 #ifdef HAVE_ATANF
41 #define aluAtan(x) (atanf((x)))
42 #else
43 #define aluAtan(x) ((ALfloat)atan((double)(x)))
44 #endif
46 #ifdef HAVE_FABSF
47 #define aluFabs(x) (fabsf((x)))
48 #else
49 #define aluFabs(x) ((ALfloat)fabs((double)(x)))
50 #endif
52 #define QUADRANT_NUM 128
53 #define LUT_NUM (4 * QUADRANT_NUM)
55 #ifdef __cplusplus
56 extern "C" {
57 #endif
59 struct ALsource;
60 struct ALbuffer;
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);
68 enum Resampler {
69 POINT_RESAMPLER = 0,
70 LINEAR_RESAMPLER,
71 CUBIC_RESAMPLER,
73 RESAMPLER_MAX,
74 RESAMPLER_MIN = -1,
75 RESAMPLER_DEFAULT = LINEAR_RESAMPLER
76 };
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,
89 MAXCHANNELS
90 };
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 };
102 #define BUFFERSIZE 4096
104 #define FRACTIONBITS (14)
105 #define FRACTIONONE (1<<FRACTIONBITS)
106 #define FRACTIONMASK (FRACTIONONE-1)
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
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)); }
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)); }
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)); }
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;
156 return a0*mu*mu2 + a1*mu2 + a2*mu + a3;
157 }
159 ALvoid aluInitPanning(ALCdevice *Device);
160 ALint aluCart2LUTpos(ALfloat re, ALfloat im);
162 ALvoid CalcSourceParams(struct ALsource *ALSource, const ALCcontext *ALContext);
163 ALvoid CalcNonAttnSourceParams(struct ALsource *ALSource, const ALCcontext *ALContext);
165 MixerFunc SelectMixer(struct ALbuffer *Buffer, enum Resampler Resampler);
166 MixerFunc SelectHrtfMixer(struct ALbuffer *Buffer, enum Resampler Resampler);
168 ALvoid MixSource(struct ALsource *Source, ALCdevice *Device, ALuint SamplesToDo);
170 ALvoid aluMixData(ALCdevice *device, ALvoid *buffer, ALsizei size);
171 ALvoid aluHandleDisconnect(ALCdevice *device);
173 #ifdef __cplusplus
174 }
175 #endif
177 #endif