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