Mercurial > audio-send
diff 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 |
line wrap: on
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/OpenAL32/Include/alu.h Tue Oct 25 13:02:31 2011 -0700 1.3 @@ -0,0 +1,178 @@ 1.4 +#ifndef _ALU_H_ 1.5 +#define _ALU_H_ 1.6 + 1.7 +#include "AL/al.h" 1.8 +#include "AL/alc.h" 1.9 +#include "AL/alext.h" 1.10 + 1.11 +#include <limits.h> 1.12 +#include <math.h> 1.13 +#ifdef HAVE_FLOAT_H 1.14 +#include <float.h> 1.15 +#endif 1.16 +#ifdef HAVE_IEEEFP_H 1.17 +#include <ieeefp.h> 1.18 +#endif 1.19 + 1.20 +#ifndef M_PI 1.21 +#define M_PI 3.14159265358979323846 /* pi */ 1.22 +#define M_PI_2 1.57079632679489661923 /* pi/2 */ 1.23 +#endif 1.24 + 1.25 +#ifdef HAVE_POWF 1.26 +#define aluPow(x,y) (powf((x),(y))) 1.27 +#else 1.28 +#define aluPow(x,y) ((ALfloat)pow((double)(x),(double)(y))) 1.29 +#endif 1.30 + 1.31 +#ifdef HAVE_SQRTF 1.32 +#define aluSqrt(x) (sqrtf((x))) 1.33 +#else 1.34 +#define aluSqrt(x) ((ALfloat)sqrt((double)(x))) 1.35 +#endif 1.36 + 1.37 +#ifdef HAVE_ACOSF 1.38 +#define aluAcos(x) (acosf((x))) 1.39 +#else 1.40 +#define aluAcos(x) ((ALfloat)acos((double)(x))) 1.41 +#endif 1.42 + 1.43 +#ifdef HAVE_ATANF 1.44 +#define aluAtan(x) (atanf((x))) 1.45 +#else 1.46 +#define aluAtan(x) ((ALfloat)atan((double)(x))) 1.47 +#endif 1.48 + 1.49 +#ifdef HAVE_FABSF 1.50 +#define aluFabs(x) (fabsf((x))) 1.51 +#else 1.52 +#define aluFabs(x) ((ALfloat)fabs((double)(x))) 1.53 +#endif 1.54 + 1.55 +#define QUADRANT_NUM 128 1.56 +#define LUT_NUM (4 * QUADRANT_NUM) 1.57 + 1.58 +#ifdef __cplusplus 1.59 +extern "C" { 1.60 +#endif 1.61 + 1.62 +struct ALsource; 1.63 +struct ALbuffer; 1.64 + 1.65 +typedef ALvoid (*MixerFunc)(struct ALsource *self, ALCdevice *Device, 1.66 + const ALvoid *RESTRICT data, 1.67 + ALuint *DataPosInt, ALuint *DataPosFrac, 1.68 + ALuint OutPos, ALuint SamplesToDo, 1.69 + ALuint BufferSize); 1.70 + 1.71 +enum Resampler { 1.72 + POINT_RESAMPLER = 0, 1.73 + LINEAR_RESAMPLER, 1.74 + CUBIC_RESAMPLER, 1.75 + 1.76 + RESAMPLER_MAX, 1.77 + RESAMPLER_MIN = -1, 1.78 + RESAMPLER_DEFAULT = LINEAR_RESAMPLER 1.79 +}; 1.80 + 1.81 +enum Channel { 1.82 + FRONT_LEFT = 0, 1.83 + FRONT_RIGHT, 1.84 + FRONT_CENTER, 1.85 + LFE, 1.86 + BACK_LEFT, 1.87 + BACK_RIGHT, 1.88 + BACK_CENTER, 1.89 + SIDE_LEFT, 1.90 + SIDE_RIGHT, 1.91 + 1.92 + MAXCHANNELS 1.93 +}; 1.94 + 1.95 +enum DistanceModel { 1.96 + InverseDistanceClamped = AL_INVERSE_DISTANCE_CLAMPED, 1.97 + LinearDistanceClamped = AL_LINEAR_DISTANCE_CLAMPED, 1.98 + ExponentDistanceClamped = AL_EXPONENT_DISTANCE_CLAMPED, 1.99 + InverseDistance = AL_INVERSE_DISTANCE, 1.100 + LinearDistance = AL_LINEAR_DISTANCE, 1.101 + ExponentDistance = AL_EXPONENT_DISTANCE, 1.102 + DisableDistance = AL_NONE 1.103 +}; 1.104 + 1.105 +#define BUFFERSIZE 4096 1.106 + 1.107 +#define FRACTIONBITS (14) 1.108 +#define FRACTIONONE (1<<FRACTIONBITS) 1.109 +#define FRACTIONMASK (FRACTIONONE-1) 1.110 + 1.111 +/* Size for temporary stack storage of buffer data. Larger values need more 1.112 + * stack, while smaller values may need more iterations. The value needs to be 1.113 + * a sensible size, however, as it constrains the max stepping value used for 1.114 + * mixing. 1.115 + * The mixer requires being able to do two samplings per mixing loop. A 16KB 1.116 + * buffer can hold 512 sample frames for a 7.1 float buffer. With the cubic 1.117 + * resampler (which requires 3 padding sample frames), this limits the maximum 1.118 + * step to about 508. This means that buffer_freq*source_pitch cannot exceed 1.119 + * device_freq*508 for an 8-channel 32-bit buffer. */ 1.120 +#ifndef STACK_DATA_SIZE 1.121 +#define STACK_DATA_SIZE 16384 1.122 +#endif 1.123 + 1.124 + 1.125 +static __inline ALfloat minf(ALfloat a, ALfloat b) 1.126 +{ return ((a > b) ? b : a); } 1.127 +static __inline ALfloat maxf(ALfloat a, ALfloat b) 1.128 +{ return ((a > b) ? a : b); } 1.129 +static __inline ALfloat clampf(ALfloat val, ALfloat min, ALfloat max) 1.130 +{ return minf(max, maxf(min, val)); } 1.131 + 1.132 +static __inline ALuint minu(ALuint a, ALuint b) 1.133 +{ return ((a > b) ? b : a); } 1.134 +static __inline ALuint maxu(ALuint a, ALuint b) 1.135 +{ return ((a > b) ? a : b); } 1.136 +static __inline ALuint clampu(ALuint val, ALuint min, ALuint max) 1.137 +{ return minu(max, maxu(min, val)); } 1.138 + 1.139 +static __inline ALint mini(ALint a, ALint b) 1.140 +{ return ((a > b) ? b : a); } 1.141 +static __inline ALint maxi(ALint a, ALint b) 1.142 +{ return ((a > b) ? a : b); } 1.143 +static __inline ALint clampi(ALint val, ALint min, ALint max) 1.144 +{ return mini(max, maxi(min, val)); } 1.145 + 1.146 + 1.147 +static __inline ALdouble lerp(ALdouble val1, ALdouble val2, ALdouble mu) 1.148 +{ 1.149 + return val1 + (val2-val1)*mu; 1.150 +} 1.151 +static __inline ALdouble cubic(ALdouble val0, ALdouble val1, ALdouble val2, ALdouble val3, ALdouble mu) 1.152 +{ 1.153 + ALdouble mu2 = mu*mu; 1.154 + ALdouble a0 = -0.5*val0 + 1.5*val1 + -1.5*val2 + 0.5*val3; 1.155 + ALdouble a1 = val0 + -2.5*val1 + 2.0*val2 + -0.5*val3; 1.156 + ALdouble a2 = -0.5*val0 + 0.5*val2; 1.157 + ALdouble a3 = val1; 1.158 + 1.159 + return a0*mu*mu2 + a1*mu2 + a2*mu + a3; 1.160 +} 1.161 + 1.162 +ALvoid aluInitPanning(ALCdevice *Device); 1.163 +ALint aluCart2LUTpos(ALfloat re, ALfloat im); 1.164 + 1.165 +ALvoid CalcSourceParams(struct ALsource *ALSource, const ALCcontext *ALContext); 1.166 +ALvoid CalcNonAttnSourceParams(struct ALsource *ALSource, const ALCcontext *ALContext); 1.167 + 1.168 +MixerFunc SelectMixer(struct ALbuffer *Buffer, enum Resampler Resampler); 1.169 +MixerFunc SelectHrtfMixer(struct ALbuffer *Buffer, enum Resampler Resampler); 1.170 + 1.171 +ALvoid MixSource(struct ALsource *Source, ALCdevice *Device, ALuint SamplesToDo); 1.172 + 1.173 +ALvoid aluMixData(ALCdevice *device, ALvoid *buffer, ALsizei size); 1.174 +ALvoid aluHandleDisconnect(ALCdevice *device); 1.175 + 1.176 +#ifdef __cplusplus 1.177 +} 1.178 +#endif 1.179 + 1.180 +#endif 1.181 +