Make sure the muLaw sample encoder is inlined
[openal-soft.git] / OpenAL32 / Include / alu.h
blob7f1cad0fe9c9675f32775ad2dec0f78b9fd27bc3
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
14 #ifndef M_PI
15 #define M_PI 3.14159265358979323846 /* pi */
16 #define M_PI_2 1.57079632679489661923 /* pi/2 */
17 #endif
19 #ifdef HAVE_POWF
20 #define aluPow(x,y) ((ALfloat)powf((float)(x),(float)(y)))
21 #else
22 #define aluPow(x,y) ((ALfloat)pow((double)(x),(double)(y)))
23 #endif
25 #ifdef HAVE_SQRTF
26 #define aluSqrt(x) ((ALfloat)sqrtf((float)(x)))
27 #else
28 #define aluSqrt(x) ((ALfloat)sqrt((double)(x)))
29 #endif
31 #ifdef HAVE_ACOSF
32 #define aluAcos(x) ((ALfloat)acosf((float)(x)))
33 #else
34 #define aluAcos(x) ((ALfloat)acos((double)(x)))
35 #endif
37 #ifdef HAVE_ATANF
38 #define aluAtan(x) ((ALfloat)atanf((float)(x)))
39 #else
40 #define aluAtan(x) ((ALfloat)atan((double)(x)))
41 #endif
43 #ifdef HAVE_FABSF
44 #define aluFabs(x) ((ALfloat)fabsf((float)(x)))
45 #else
46 #define aluFabs(x) ((ALfloat)fabs((double)(x)))
47 #endif
49 // fixes for mingw32.
50 #if defined(max) && !defined(__max)
51 #define __max max
52 #endif
53 #if defined(min) && !defined(__min)
54 #define __min min
55 #endif
57 #define QUADRANT_NUM 128
58 #define LUT_NUM (4 * QUADRANT_NUM)
60 #ifdef __cplusplus
61 extern "C" {
62 #endif
64 typedef enum {
65 FRONT_LEFT = 0,
66 FRONT_RIGHT,
67 FRONT_CENTER,
68 LFE,
69 BACK_LEFT,
70 BACK_RIGHT,
71 BACK_CENTER,
72 SIDE_LEFT,
73 SIDE_RIGHT,
75 OUTPUTCHANNELS
76 } Channel;
78 #define BUFFERSIZE 4096
80 #define FRACTIONBITS (14)
81 #define FRACTIONONE (1<<FRACTIONBITS)
82 #define FRACTIONMASK (FRACTIONONE-1)
84 /* Size for temporary stack storage of buffer data. Larger values need more
85 * stack, while smaller values may need more iterations. The value needs to be
86 * a sensible size, however, as it constrains the max stepping value used for
87 * mixing.
88 * The mixer requires being able to do two samplings per mixing loop. A 16KB
89 * buffer can hold 512 sample frames for a 7.1 float buffer. With the cubic
90 * resampler (which requires 3 padding sample frames), this limits the maximum
91 * step to about 508. This means that buffer_freq*source_pitch cannot exceed
92 * device_freq*508 for an 8-channel 32-bit buffer. */
93 #ifndef STACK_DATA_SIZE
94 #define STACK_DATA_SIZE 16384
95 #endif
98 ALuint aluBytesFromFormat(ALenum format);
99 ALuint aluChannelsFromFormat(ALenum format);
100 static __inline ALuint aluFrameSizeFromFormat(ALenum format)
102 return aluBytesFromFormat(format) * aluChannelsFromFormat(format);
105 static __inline ALdouble lerp(ALdouble val1, ALdouble val2, ALdouble mu)
107 return val1 + (val2-val1)*mu;
109 static __inline ALdouble cubic(ALdouble val0, ALdouble val1, ALdouble val2, ALdouble val3, ALdouble mu)
111 ALdouble mu2 = mu*mu;
112 ALdouble a0 = -0.5*val0 + 1.5*val1 + -1.5*val2 + 0.5*val3;
113 ALdouble a1 = val0 + -2.5*val1 + 2.0*val2 + -0.5*val3;
114 ALdouble a2 = -0.5*val0 + 0.5*val2;
115 ALdouble a3 = val1;
117 return a0*mu*mu2 + a1*mu2 + a2*mu + a3;
120 struct ALsource;
122 ALvoid aluInitPanning(ALCdevice *Device);
123 ALint aluCart2LUTpos(ALfloat re, ALfloat im);
125 ALvoid CalcSourceParams(struct ALsource *ALSource, const ALCcontext *ALContext);
126 ALvoid CalcNonAttnSourceParams(struct ALsource *ALSource, const ALCcontext *ALContext);
128 ALvoid MixSource(struct ALsource *Source, ALCdevice *Device, ALuint SamplesToDo);
130 ALvoid aluMixData(ALCdevice *device, ALvoid *buffer, ALsizei size);
131 ALvoid aluHandleDisconnect(ALCdevice *device);
133 #ifdef __cplusplus
135 #endif
137 #endif