41 {
return val * (1.0f/127.0f); }
44 {
return val * (1.0f/32767.0f); }
49 #define DECL_TEMPLATE(T) \
50 static void Load_##T(ALfloat *dst, const T *src, ALuint srcstep, ALuint samples)\
53 for(i = 0;i < samples;i++) \
54 dst[i] = Sample_##T(src[i*srcstep]); \
68 Load_ALbyte(dst, src, srcstep, samples);
71 Load_ALshort(dst, src, srcstep, samples);
74 Load_ALfloat(dst, src, srcstep, samples);
91 for(i = 0;i < numsamples;i++)
100 ALuint DataPosInt, DataPosFrac;
113 State = Source->
state;
124 BufferListItem = Source->
queue;
125 for(j = 0;j < BuffersPlayed;j++)
126 BufferListItem = BufferListItem->
next;
132 ALuint SrcBufferSize, DstBufferSize;
135 DataSize64 = SamplesToDo-OutPos+1;
136 DataSize64 *= increment;
139 DataSize64 += BufferPadding+BufferPrePadding;
144 DataSize64 = SrcBufferSize;
145 DataSize64 -= BufferPadding+BufferPrePadding;
147 DataSize64 -= increment;
148 DataSize64 -= DataPosFrac;
150 DstBufferSize = (
ALuint)((DataSize64+(increment-1)) / increment);
151 DstBufferSize =
minu(DstBufferSize, (SamplesToDo-OutPos));
155 if(OutPos+DstBufferSize < SamplesToDo)
158 for(chan = 0;chan < NumChannels;chan++)
160 ALfloat *SrcData = Device->SampleData1;
161 ALfloat *ResampledData = Device->SampleData2;
176 if(DataPosInt >= BufferPrePadding)
177 pos = DataPosInt - BufferPrePadding;
180 DataSize = BufferPrePadding - DataPosInt;
181 DataSize =
minu(SrcBufferSize - SrcDataSize, DataSize);
184 SrcDataSize += DataSize;
191 DataSize =
minu(SrcBufferSize - SrcDataSize, ALBuffer->
SampleLen - pos);
193 LoadData(&SrcData[SrcDataSize], &Data[(pos*NumChannels + chan)*SampleSize],
194 NumChannels, ALBuffer->
FmtType, DataSize);
195 SrcDataSize += DataSize;
197 SilenceData(&SrcData[SrcDataSize], SrcBufferSize - SrcDataSize);
198 SrcDataSize += SrcBufferSize - SrcDataSize;
205 if(DataPosInt >= LoopStart)
207 pos = DataPosInt-LoopStart;
208 while(pos < BufferPrePadding)
209 pos += LoopEnd-LoopStart;
210 pos -= BufferPrePadding;
213 else if(DataPosInt >= BufferPrePadding)
214 pos = DataPosInt - BufferPrePadding;
217 DataSize = BufferPrePadding - DataPosInt;
218 DataSize =
minu(SrcBufferSize - SrcDataSize, DataSize);
221 SrcDataSize += DataSize;
228 DataSize = LoopEnd - pos;
229 DataSize =
minu(SrcBufferSize - SrcDataSize, DataSize);
231 LoadData(&SrcData[SrcDataSize], &Data[(pos*NumChannels + chan)*SampleSize],
232 NumChannels, ALBuffer->
FmtType, DataSize);
233 SrcDataSize += DataSize;
235 DataSize = LoopEnd-LoopStart;
236 while(SrcBufferSize > SrcDataSize)
238 DataSize =
minu(SrcBufferSize - SrcDataSize, DataSize);
240 LoadData(&SrcData[SrcDataSize], &Data[(LoopStart*NumChannels + chan)*SampleSize],
241 NumChannels, ALBuffer->
FmtType, DataSize);
242 SrcDataSize += DataSize;
252 if(DataPosInt >= BufferPrePadding)
253 pos = DataPosInt - BufferPrePadding;
256 pos = BufferPrePadding - DataPosInt;
259 if(!tmpiter->
prev && !Looping)
261 ALuint DataSize =
minu(SrcBufferSize - SrcDataSize, pos);
264 SrcDataSize += DataSize;
271 tmpiter = tmpiter->
prev;
275 tmpiter = tmpiter->
next;
290 while(tmpiter && SrcBufferSize > SrcDataSize)
303 Data += (pos*NumChannels + chan)*SampleSize;
307 DataSize =
minu(SrcBufferSize - SrcDataSize, DataSize);
308 LoadData(&SrcData[SrcDataSize], Data, NumChannels,
310 SrcDataSize += DataSize;
313 tmpiter = tmpiter->
next;
314 if(!tmpiter && Looping)
315 tmpiter = Source->
queue;
318 SilenceData(&SrcData[SrcDataSize], SrcBufferSize - SrcDataSize);
319 SrcDataSize += SrcBufferSize - SrcDataSize;
326 increment, ResampledData, DstBufferSize);
333 Source->
Params.
DryMix(directparms, SrcData, chan, OutPos,
334 SamplesToDo, DstBufferSize);
346 SamplesToDo, DstBufferSize);
350 for(j = 0;j < DstBufferSize;j++)
352 DataPosFrac += increment;
356 OutPos += DstBufferSize;
371 if(LoopEnd > DataPosInt)
377 DataPosInt = ((DataPosInt-LoopStart)%(LoopEnd-LoopStart)) + LoopStart;
381 if(DataSize > DataPosInt)
384 if(BufferListItem->
next)
386 BufferListItem = BufferListItem->
next;
391 BufferListItem = Source->
queue;
397 BufferListItem = Source->
queue;
404 DataPosInt -= DataSize;
406 }
while(State ==
AL_PLAYING && OutPos < SamplesToDo);
GLuint const GLfloat * val
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter
const ALsizei ResamplerPadding[ResamplerMax]
static void Filter2P(FILTER *filter, ALuint chan, ALfloat *RESTRICT dst, const ALfloat *RESTRICT src, ALuint numsamples)
static __inline ALint64 mini64(ALint64 a, ALint64 b)
static __inline ALfloat lpFilter2P(FILTER *iir, ALuint offset, ALfloat input)
struct ALeffectslot * Slot
static __inline ALfloat Sample_ALfloat(ALfloat val)
static __inline ALfloat Sample_ALbyte(ALbyte val)
ALvoid MixSource(ALsource *Source, ALCdevice *Device, ALuint SamplesToDo)
const ALsizei ResamplerPrePadding[ResamplerMax]
static __inline ALfloat Sample_ALshort(ALshort val)
static void LoadData(ALfloat *dst, const ALvoid *src, ALuint srcstep, enum FmtType srctype, ALuint samples)
static __inline ALuint minu(ALuint a, ALuint b)
volatile ALboolean Looping
struct ALbufferlistitem * next
struct ALsource::@62 Params
static void SilenceData(ALfloat *dst, ALuint samples)
struct ALbufferlistitem * prev
volatile ALint SourceType
struct ALsource::@61 Send[MAX_SENDS]
static __inline ALfloat lpFilter2PC(const FILTER *iir, ALuint offset, ALfloat input)
static __inline ALuint maxu(ALuint a, ALuint b)