Mercurial > audio-send
view OpenAL32/Include/alu.h @ 33:3caceef436ea tip
formatting for web
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Sat, 11 Feb 2012 12:25:55 -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_H11 #include <float.h>12 #endif13 #ifdef HAVE_IEEEFP_H14 #include <ieeefp.h>15 #endif17 #ifndef M_PI18 #define M_PI 3.14159265358979323846 /* pi */19 #define M_PI_2 1.57079632679489661923 /* pi/2 */20 #endif22 #ifdef HAVE_POWF23 #define aluPow(x,y) (powf((x),(y)))24 #else25 #define aluPow(x,y) ((ALfloat)pow((double)(x),(double)(y)))26 #endif28 #ifdef HAVE_SQRTF29 #define aluSqrt(x) (sqrtf((x)))30 #else31 #define aluSqrt(x) ((ALfloat)sqrt((double)(x)))32 #endif34 #ifdef HAVE_ACOSF35 #define aluAcos(x) (acosf((x)))36 #else37 #define aluAcos(x) ((ALfloat)acos((double)(x)))38 #endif40 #ifdef HAVE_ATANF41 #define aluAtan(x) (atanf((x)))42 #else43 #define aluAtan(x) ((ALfloat)atan((double)(x)))44 #endif46 #ifdef HAVE_FABSF47 #define aluFabs(x) (fabsf((x)))48 #else49 #define aluFabs(x) ((ALfloat)fabs((double)(x)))50 #endif52 #define QUADRANT_NUM 12853 #define LUT_NUM (4 * QUADRANT_NUM)55 #ifdef __cplusplus56 extern "C" {57 #endif59 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_RESAMPLER76 };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 MAXCHANNELS90 };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_NONE100 };102 #define BUFFERSIZE 4096104 #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 more109 * stack, while smaller values may need more iterations. The value needs to be110 * a sensible size, however, as it constrains the max stepping value used for111 * mixing.112 * The mixer requires being able to do two samplings per mixing loop. A 16KB113 * buffer can hold 512 sample frames for a 7.1 float buffer. With the cubic114 * resampler (which requires 3 padding sample frames), this limits the maximum115 * step to about 508. This means that buffer_freq*source_pitch cannot exceed116 * device_freq*508 for an 8-channel 32-bit buffer. */117 #ifndef STACK_DATA_SIZE118 #define STACK_DATA_SIZE 16384119 #endif122 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 __cplusplus174 }175 #endif177 #endif