zenilib: zenilib/jni/external/openal-soft/Alc/mixer_inc.c Source File

zenilib 0.5.3.0

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
mixer_inc.c
Go to the documentation of this file.
1 #include "config.h"
2
3 #include "alMain.h"
4 #include "alSource.h"
5 #include "mixer_defs.h"
6
7 #ifdef __GNUC__
8 #define LIKELY(x) __builtin_expect(!!(x), 1)
9 #define UNLIKELY(x) __builtin_expect(!!(x), 0)
10 #else
11 #define LIKELY(x) (x)
12 #define UNLIKELY(x) (x)
13 #endif
14
15 #define REAL_MERGE2(a,b) a##b
16 #define MERGE2(a,b) REAL_MERGE2(a,b)
17
18 #define MixDirect_Hrtf MERGE2(MixDirect_Hrtf_,SUFFIX)
19
20
21 static __inline void ApplyCoeffsStep(ALuint Offset, ALfloat (*RESTRICT Values)[2],
22 const ALuint irSize,
23 ALfloat (*RESTRICT Coeffs)[2],
24 const ALfloat (*RESTRICT CoeffStep)[2],
25 ALfloat left, ALfloat right);
26 static __inline void ApplyCoeffs(ALuint Offset, ALfloat (*RESTRICT Values)[2],
27 const ALuint irSize,
28 ALfloat (*RESTRICT Coeffs)[2],
29 ALfloat left, ALfloat right);
30
31
32 void MixDirect_Hrtf(const DirectParams *params, const ALfloat *RESTRICT data, ALuint srcchan,
33 ALuint OutPos, ALuint SamplesToDo, ALuint BufferSize)
34 {
35 ALfloat (*RESTRICT DryBuffer)[BUFFERSIZE] = params->OutBuffer;
36 ALfloat *RESTRICT ClickRemoval = params->ClickRemoval;
37 ALfloat *RESTRICT PendingClicks = params->PendingClicks;
38 const ALuint IrSize = params->Hrtf.Params.IrSize;
39 const ALint *RESTRICT DelayStep = params->Hrtf.Params.DelayStep;
40 const ALfloat (*RESTRICT CoeffStep)[2] = params->Hrtf.Params.CoeffStep;
41 const ALfloat (*RESTRICT TargetCoeffs)[2] = params->Hrtf.Params.Coeffs[srcchan];
42 const ALuint *RESTRICT TargetDelay = params->Hrtf.Params.Delay[srcchan];
43 ALfloat *RESTRICT History = params->Hrtf.State->History[srcchan];
44 ALfloat (*RESTRICT Values)[2] = params->Hrtf.State->Values[srcchan];
45 ALint Counter = maxu(params->Hrtf.State->Counter, OutPos) - OutPos;
46 ALuint Offset = params->Hrtf.State->Offset + OutPos;
47 ALIGN(16) ALfloat Coeffs[HRIR_LENGTH][2];
48 ALuint Delay[2];
49 ALfloat left, right;
50 ALuint pos;
51 ALuint c;
52
53 pos = 0;
54 for(c = 0;c < IrSize;c++)
55 {
56 Coeffs[c][0] = TargetCoeffs[c][0] - (CoeffStep[c][0]*Counter);
57 Coeffs[c][1] = TargetCoeffs[c][1] - (CoeffStep[c][1]*Counter);
58 }
59
60 Delay[0] = TargetDelay[0] - (DelayStep[0]*Counter);
61 Delay[1] = TargetDelay[1] - (DelayStep[1]*Counter);
62
63 if(LIKELY(OutPos == 0))
64 {
65 History[Offset&SRC_HISTORY_MASK] = data[pos];
66 left = lerp(History[(Offset-(Delay[0]>>HRTFDELAY_BITS))&SRC_HISTORY_MASK],
67 History[(Offset-(Delay[0]>>HRTFDELAY_BITS)-1)&SRC_HISTORY_MASK],
68 (Delay[0]&HRTFDELAY_MASK)*(1.0f/HRTFDELAY_FRACONE));
69 right = lerp(History[(Offset-(Delay[1]>>HRTFDELAY_BITS))&SRC_HISTORY_MASK],
70 History[(Offset-(Delay[1]>>HRTFDELAY_BITS)-1)&SRC_HISTORY_MASK],
71 (Delay[1]&HRTFDELAY_MASK)*(1.0f/HRTFDELAY_FRACONE));
72
73 ClickRemoval[FrontLeft] -= Values[(Offset+1)&HRIR_MASK][0] +
74 Coeffs[0][0] * left;
75 ClickRemoval[FrontRight] -= Values[(Offset+1)&HRIR_MASK][1] +
76 Coeffs[0][1] * right;
77 }
78 for(pos = 0;pos < BufferSize && Counter > 0;pos++)
79 {
80 History[Offset&SRC_HISTORY_MASK] = data[pos];
81 left = lerp(History[(Offset-(Delay[0]>>HRTFDELAY_BITS))&SRC_HISTORY_MASK],
82 History[(Offset-(Delay[0]>>HRTFDELAY_BITS)-1)&SRC_HISTORY_MASK],
83 (Delay[0]&HRTFDELAY_MASK)*(1.0f/HRTFDELAY_FRACONE));
84 right = lerp(History[(Offset-(Delay[1]>>HRTFDELAY_BITS))&SRC_HISTORY_MASK],
85 History[(Offset-(Delay[1]>>HRTFDELAY_BITS)-1)&SRC_HISTORY_MASK],
86 (Delay[1]&HRTFDELAY_MASK)*(1.0f/HRTFDELAY_FRACONE));
87
88 Delay[0] += DelayStep[0];
89 Delay[1] += DelayStep[1];
90
91 Values[(Offset+IrSize)&HRIR_MASK][0] = 0.0f;
92 Values[(Offset+IrSize)&HRIR_MASK][1] = 0.0f;
93 Offset++;
94
95 ApplyCoeffsStep(Offset, Values, IrSize, Coeffs, CoeffStep, left, right);
96 DryBuffer[FrontLeft][OutPos] += Values[Offset&HRIR_MASK][0];
97 DryBuffer[FrontRight][OutPos] += Values[Offset&HRIR_MASK][1];
98
99 OutPos++;
100 Counter--;
101 }
102
103 Delay[0] >>= HRTFDELAY_BITS;
104 Delay[1] >>= HRTFDELAY_BITS;
105 for(;pos < BufferSize;pos++)
106 {
107 History[Offset&SRC_HISTORY_MASK] = data[pos];
108 left = History[(Offset-Delay[0])&SRC_HISTORY_MASK];
109 right = History[(Offset-Delay[1])&SRC_HISTORY_MASK];
110
111 Values[(Offset+IrSize)&HRIR_MASK][0] = 0.0f;
112 Values[(Offset+IrSize)&HRIR_MASK][1] = 0.0f;
113 Offset++;
114
115 ApplyCoeffs(Offset, Values, IrSize, Coeffs, left, right);
116 DryBuffer[FrontLeft][OutPos] += Values[Offset&HRIR_MASK][0];
117 DryBuffer[FrontRight][OutPos] += Values[Offset&HRIR_MASK][1];
118
119 OutPos++;
120 }
121 if(LIKELY(OutPos == SamplesToDo))
122 {
123 History[Offset&SRC_HISTORY_MASK] = data[pos];
124 left = History[(Offset-Delay[0])&SRC_HISTORY_MASK];
125 right = History[(Offset-Delay[1])&SRC_HISTORY_MASK];
126
127 PendingClicks[FrontLeft] += Values[(Offset+1)&HRIR_MASK][0] +
128 Coeffs[0][0] * left;
129 PendingClicks[FrontRight] += Values[(Offset+1)&HRIR_MASK][1] +
130 Coeffs[0][1] * right;
131 }
132 }
133
134
135 #undef MixDirect_Hrtf
136
137 #undef MERGE2
138 #undef REAL_MERGE2
139
140 #undef UNLIKELY
141 #undef LIKELY
DirectParams::OutBuffer
ALfloat(* OutBuffer)[BUFFERSIZE]
Definition: alSource.h:50
HrtfParams::IrSize
ALuint IrSize
Definition: alSource.h:46
DirectParams
Definition: alSource.h:49
left
GLint left
Definition: glew.h:7291
f
GLclampf f
Definition: glew.h:3390
lerp
static __inline ALfloat lerp(ALfloat val1, ALfloat val2, ALfloat mu)
Definition: alu.h:90
HRTFDELAY_BITS
#define HRTFDELAY_BITS
Definition: alMain.h:778
ALint
int ALint
Definition: al.h:56
HrtfParams::DelayStep
ALint DelayStep[2]
Definition: alSource.h:45
alSource.h
HrtfParams::Delay
ALuint Delay[MaxChannels][2]
Definition: alSource.h:44
HRIR_LENGTH
#define HRIR_LENGTH
Definition: alMain.h:776
ALfloat
float ALfloat
Definition: al.h:68
ApplyCoeffs
static __inline void ApplyCoeffs(ALuint Offset, ALfloat(*RESTRICT Values)[2], const ALuint irSize, ALfloat(*RESTRICT Coeffs)[2], ALfloat left, ALfloat right)
SRC_HISTORY_MASK
#define SRC_HISTORY_MASK
Definition: alSource.h:16
HRTFDELAY_FRACONE
#define HRTFDELAY_FRACONE
Definition: alMain.h:779
params
GLenum GLvoid ** params
Definition: gl2ext.h:806
FrontLeft
Definition: alMain.h:481
MixDirect_Hrtf
#define MixDirect_Hrtf
Definition: mixer_inc.c:18
alMain.h
HRTFDELAY_MASK
#define HRTFDELAY_MASK
Definition: alMain.h:780
data
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl2ext.h:848
c
const GLfloat * c
Definition: glew.h:14913
mixer_defs.h
DirectParams::Params
HrtfParams Params
Definition: alSource.h:55
LIKELY
#define LIKELY(x)
Definition: mixer_inc.c:11
ALuint
unsigned int ALuint
Definition: al.h:59
ApplyCoeffsStep
static __inline void ApplyCoeffsStep(ALuint Offset, ALfloat(*RESTRICT Values)[2], const ALuint irSize, ALfloat(*RESTRICT Coeffs)[2], const ALfloat(*RESTRICT CoeffStep)[2], ALfloat left, ALfloat right)
DirectParams::PendingClicks
ALfloat * PendingClicks
Definition: alSource.h:52
DirectParams::Hrtf
struct DirectParams::@60 Hrtf
HrtfState::Counter
ALuint Counter
Definition: alSource.h:33
DirectParams::State
HrtfState * State
Definition: alSource.h:56
FrontRight
Definition: alMain.h:482
HRIR_MASK
#define HRIR_MASK
Definition: alMain.h:777
right
GLfloat right
Definition: glew.h:13816
BUFFERSIZE
#define BUFFERSIZE
Definition: alMain.h:556
maxu
static __inline ALuint maxu(ALuint a, ALuint b)
Definition: alu.h:63
DirectParams::ClickRemoval
ALfloat * ClickRemoval
Definition: alSource.h:51
HrtfState::Offset
ALuint Offset
Definition: alSource.h:36