zenilib  0.5.3.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
mixer_c.c
Go to the documentation of this file.
1 #include "config.h"
2 
3 #include <assert.h>
4 
5 #include "alMain.h"
6 #include "alu.h"
7 #include "alSource.h"
8 #include "alAuxEffectSlot.h"
9 
10 
11 static __inline ALfloat point32(const ALfloat *vals, ALuint frac)
12 { return vals[0]; (void)frac; }
13 static __inline ALfloat lerp32(const ALfloat *vals, ALuint frac)
14 { return lerp(vals[0], vals[1], frac * (1.0f/FRACTIONONE)); }
15 static __inline ALfloat cubic32(const ALfloat *vals, ALuint frac)
16 { return cubic(vals[-1], vals[0], vals[1], vals[2], frac * (1.0f/FRACTIONONE)); }
17 
19  ALuint increment, ALfloat *RESTRICT OutBuffer, ALuint BufferSize)
20 {
21  (void)frac;
22  assert(increment==FRACTIONONE);
23  memcpy(OutBuffer, data, (BufferSize+1)*sizeof(ALfloat));
24 }
25 
26 #define DECL_TEMPLATE(Sampler) \
27 void Resample_##Sampler##_C(const ALfloat *data, ALuint frac, \
28  ALuint increment, ALfloat *RESTRICT OutBuffer, ALuint BufferSize) \
29 { \
30  ALuint pos = 0; \
31  ALuint i; \
32  \
33  for(i = 0;i < BufferSize+1;i++) \
34  { \
35  OutBuffer[i] = Sampler(data + pos, frac); \
36  \
37  frac += increment; \
38  pos += frac>>FRACTIONBITS; \
39  frac &= FRACTIONMASK; \
40  } \
41 }
42 
46 
47 #undef DECL_TEMPLATE
48 
49 
50 static __inline void ApplyCoeffsStep(ALuint Offset, ALfloat (*RESTRICT Values)[2],
51  const ALuint IrSize,
52  ALfloat (*RESTRICT Coeffs)[2],
53  const ALfloat (*RESTRICT CoeffStep)[2],
55 {
56  ALuint c;
57  for(c = 0;c < IrSize;c++)
58  {
59  const ALuint off = (Offset+c)&HRIR_MASK;
60  Values[off][0] += Coeffs[c][0] * left;
61  Values[off][1] += Coeffs[c][1] * right;
62  Coeffs[c][0] += CoeffStep[c][0];
63  Coeffs[c][1] += CoeffStep[c][1];
64  }
65 }
66 
67 static __inline void ApplyCoeffs(ALuint Offset, ALfloat (*RESTRICT Values)[2],
68  const ALuint IrSize,
69  ALfloat (*RESTRICT Coeffs)[2],
71 {
72  ALuint c;
73  for(c = 0;c < IrSize;c++)
74  {
75  const ALuint off = (Offset+c)&HRIR_MASK;
76  Values[off][0] += Coeffs[c][0] * left;
77  Values[off][1] += Coeffs[c][1] * right;
78  }
79 }
80 
81 #define SUFFIX C
82 #include "mixer_inc.c"
83 #undef SUFFIX
84 
85 
86 void MixDirect_C(const DirectParams *params, const ALfloat *RESTRICT data, ALuint srcchan,
87  ALuint OutPos, ALuint SamplesToDo, ALuint BufferSize)
88 {
89  ALfloat (*RESTRICT DryBuffer)[BUFFERSIZE] = params->OutBuffer;
90  ALfloat *RESTRICT ClickRemoval = params->ClickRemoval;
91  ALfloat *RESTRICT PendingClicks = params->PendingClicks;
92  ALfloat DrySend;
93  ALuint pos;
94  ALuint c;
95 
96  for(c = 0;c < MaxChannels;c++)
97  {
98  DrySend = params->Gains[srcchan][c];
99  if(DrySend < 0.00001f)
100  continue;
101 
102  if(OutPos == 0)
103  ClickRemoval[c] -= data[0]*DrySend;
104  for(pos = 0;pos < BufferSize;pos++)
105  DryBuffer[c][OutPos+pos] += data[pos]*DrySend;
106  if(OutPos+pos == SamplesToDo)
107  PendingClicks[c] += data[pos]*DrySend;
108  }
109 }
110 
111 
112 void MixSend_C(const SendParams *params, const ALfloat *RESTRICT data,
113  ALuint OutPos, ALuint SamplesToDo, ALuint BufferSize)
114 {
115  ALeffectslot *Slot = params->Slot;
116  ALfloat (*RESTRICT WetBuffer)[BUFFERSIZE] = Slot->WetBuffer;
117  ALfloat *RESTRICT WetClickRemoval = Slot->ClickRemoval;
118  ALfloat *RESTRICT WetPendingClicks = Slot->PendingClicks;
119  ALfloat WetSend = params->Gain;
120  ALuint pos;
121 
122  if(WetSend < 0.00001f)
123  return;
124 
125  if(OutPos == 0)
126  WetClickRemoval[0] -= data[0] * WetSend;
127  for(pos = 0;pos < BufferSize;pos++)
128  WetBuffer[0][OutPos+pos] += data[pos] * WetSend;
129  if(OutPos+pos == SamplesToDo)
130  WetPendingClicks[0] += data[pos] * WetSend;
131 }
ALfloat(* OutBuffer)[BUFFERSIZE]
Definition: alSource.h:50
static __inline ALfloat point32(const ALfloat *vals, ALuint frac)
Definition: mixer_c.c:11
GLvoid **typedef void(GLAPIENTRY *PFNGLGETVERTEXATTRIBDVPROC)(GLuint
Definition: glew.h:1824
GLint left
Definition: glew.h:7291
GLclampf f
Definition: glew.h:3390
static __inline ALfloat lerp(ALfloat val1, ALfloat val2, ALfloat mu)
Definition: alu.h:90
#define DECL_TEMPLATE(Sampler)
Definition: mixer_c.c:26
static __inline ALfloat cubic(ALfloat val0, ALfloat val1, ALfloat val2, ALfloat val3, ALfloat mu)
Definition: alu.h:94
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)
Definition: mixer_c.c:50
#define FRACTIONONE
Definition: alu.h:50
#define assert(x)
Definition: SDL_malloc.c:1234
float ALfloat
Definition: al.h:68
GLenum GLvoid ** params
Definition: gl2ext.h:806
static __inline ALfloat lerp32(const ALfloat *vals, ALuint frac)
Definition: mixer_c.c:13
ALfloat PendingClicks[1]
struct ALeffectslot * Slot
Definition: alSource.h:70
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl2ext.h:848
static __inline void ApplyCoeffs(ALuint Offset, ALfloat(*RESTRICT Values)[2], const ALuint IrSize, ALfloat(*RESTRICT Coeffs)[2], ALfloat left, ALfloat right)
Definition: mixer_c.c:67
const GLfloat * c
Definition: glew.h:14913
ALfloat Gain
Definition: alSource.h:74
void MixSend_C(const SendParams *params, const ALfloat *RESTRICT data, ALuint OutPos, ALuint SamplesToDo, ALuint BufferSize)
Definition: mixer_c.c:112
ALfloat Gains[MaxChannels][MaxChannels]
Definition: alSource.h:62
unsigned int ALuint
Definition: al.h:59
void MixDirect_C(const DirectParams *params, const ALfloat *RESTRICT data, ALuint srcchan, ALuint OutPos, ALuint SamplesToDo, ALuint BufferSize)
Definition: mixer_c.c:86
ALfloat ClickRemoval[1]
#define memcpy
Definition: SDL_malloc.c:634
ALfloat * PendingClicks
Definition: alSource.h:52
#define HRIR_MASK
Definition: alMain.h:777
GLfloat right
Definition: glew.h:13816
#define BUFFERSIZE
Definition: alMain.h:556
static __inline ALfloat cubic32(const ALfloat *vals, ALuint frac)
Definition: mixer_c.c:15
ALfloat * ClickRemoval
Definition: alSource.h:51
void Resample_copy32_C(const ALfloat *data, ALuint frac, ALuint increment, ALfloat *RESTRICT OutBuffer, ALuint BufferSize)
Definition: mixer_c.c:18