2010-08-03 23:19:36 -07:00
|
|
|
/**
|
|
|
|
* OpenAL cross platform audio library
|
|
|
|
* Copyright (C) 1999-2007 by authors.
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
2014-08-18 14:11:03 +02:00
|
|
|
* Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2010-08-03 23:19:36 -07:00
|
|
|
* Or go to http://www.gnu.org/copyleft/lgpl.html
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <math.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
#include "alMain.h"
|
|
|
|
#include "AL/al.h"
|
|
|
|
#include "AL/alc.h"
|
|
|
|
#include "alSource.h"
|
|
|
|
#include "alBuffer.h"
|
|
|
|
#include "alListener.h"
|
|
|
|
#include "alAuxEffectSlot.h"
|
|
|
|
#include "alu.h"
|
2014-06-13 16:07:25 -07:00
|
|
|
|
|
|
|
#include "mixer_defs.h"
|
2010-08-03 23:19:36 -07:00
|
|
|
|
2011-05-06 00:20:40 -07:00
|
|
|
|
2014-06-06 01:52:53 -07:00
|
|
|
extern inline void InitiatePositionArrays(ALuint frac, ALuint increment, ALuint *frac_arr, ALuint *pos_arr, ALuint size);
|
|
|
|
|
2014-12-15 12:23:28 -08:00
|
|
|
alignas(16) ALfloat CubicLUT[FRACTIONONE][4];
|
|
|
|
|
|
|
|
|
|
|
|
void aluInitResamplers(void)
|
|
|
|
{
|
|
|
|
ALuint i;
|
|
|
|
for(i = 0;i < FRACTIONONE;i++)
|
|
|
|
{
|
|
|
|
ALfloat mu = (ALfloat)i / FRACTIONONE;
|
|
|
|
ALfloat mu2 = mu*mu, mu3 = mu*mu*mu;
|
|
|
|
CubicLUT[i][0] = -0.5f*mu3 + mu2 + -0.5f*mu;
|
|
|
|
CubicLUT[i][1] = 1.5f*mu3 + -2.5f*mu2 + 1.0f;
|
|
|
|
CubicLUT[i][2] = -1.5f*mu3 + 2.0f*mu2 + 0.5f*mu;
|
|
|
|
CubicLUT[i][3] = 0.5f*mu3 + -0.5f*mu2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-06 01:52:53 -07:00
|
|
|
|
2014-11-23 10:49:54 -08:00
|
|
|
static inline HrtfMixerFunc SelectHrtfMixer(void)
|
|
|
|
{
|
|
|
|
#ifdef HAVE_SSE
|
|
|
|
if((CPUCapFlags&CPU_CAP_SSE))
|
|
|
|
return MixHrtf_SSE;
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_NEON
|
|
|
|
if((CPUCapFlags&CPU_CAP_NEON))
|
|
|
|
return MixHrtf_Neon;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return MixHrtf_C;
|
|
|
|
}
|
|
|
|
|
2014-06-13 16:07:25 -07:00
|
|
|
static inline MixerFunc SelectMixer(void)
|
|
|
|
{
|
|
|
|
#ifdef HAVE_SSE
|
|
|
|
if((CPUCapFlags&CPU_CAP_SSE))
|
|
|
|
return Mix_SSE;
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_NEON
|
|
|
|
if((CPUCapFlags&CPU_CAP_NEON))
|
|
|
|
return Mix_Neon;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return Mix_C;
|
|
|
|
}
|
|
|
|
|
2014-11-02 00:27:26 -07:00
|
|
|
static inline ResamplerFunc SelectResampler(enum Resampler resampler)
|
2014-06-13 16:07:25 -07:00
|
|
|
{
|
2014-11-02 00:27:26 -07:00
|
|
|
switch(resampler)
|
2014-06-13 16:07:25 -07:00
|
|
|
{
|
|
|
|
case PointResampler:
|
|
|
|
return Resample_point32_C;
|
|
|
|
case LinearResampler:
|
|
|
|
#ifdef HAVE_SSE4_1
|
|
|
|
if((CPUCapFlags&CPU_CAP_SSE4_1))
|
|
|
|
return Resample_lerp32_SSE41;
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_SSE2
|
|
|
|
if((CPUCapFlags&CPU_CAP_SSE2))
|
|
|
|
return Resample_lerp32_SSE2;
|
|
|
|
#endif
|
|
|
|
return Resample_lerp32_C;
|
|
|
|
case CubicResampler:
|
2014-12-15 13:58:41 -08:00
|
|
|
#ifdef HAVE_SSE4_1
|
|
|
|
if((CPUCapFlags&CPU_CAP_SSE4_1))
|
|
|
|
return Resample_cubic32_SSE41;
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_SSE2
|
|
|
|
if((CPUCapFlags&CPU_CAP_SSE2))
|
|
|
|
return Resample_cubic32_SSE2;
|
|
|
|
#endif
|
2014-06-13 16:07:25 -07:00
|
|
|
return Resample_cubic32_C;
|
|
|
|
case ResamplerMax:
|
|
|
|
/* Shouldn't happen */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Resample_point32_C;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-05-28 22:27:07 -07:00
|
|
|
static inline ALfloat Sample_ALbyte(ALbyte val)
|
2011-10-04 09:47:08 -07:00
|
|
|
{ return val * (1.0f/127.0f); }
|
|
|
|
|
2013-05-28 22:27:07 -07:00
|
|
|
static inline ALfloat Sample_ALshort(ALshort val)
|
2011-10-04 09:47:08 -07:00
|
|
|
{ return val * (1.0f/32767.0f); }
|
|
|
|
|
2013-05-28 22:27:07 -07:00
|
|
|
static inline ALfloat Sample_ALfloat(ALfloat val)
|
2011-10-04 09:47:08 -07:00
|
|
|
{ return val; }
|
|
|
|
|
|
|
|
#define DECL_TEMPLATE(T) \
|
2014-12-18 08:52:04 -08:00
|
|
|
static inline void Load_##T(ALfloat *dst, const T *src, ALuint srcstep, ALuint samples)\
|
2011-10-04 09:47:08 -07:00
|
|
|
{ \
|
|
|
|
ALuint i; \
|
|
|
|
for(i = 0;i < samples;i++) \
|
2012-09-26 17:16:25 -07:00
|
|
|
dst[i] = Sample_##T(src[i*srcstep]); \
|
2011-10-04 09:47:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
DECL_TEMPLATE(ALbyte)
|
|
|
|
DECL_TEMPLATE(ALshort)
|
|
|
|
DECL_TEMPLATE(ALfloat)
|
|
|
|
|
|
|
|
#undef DECL_TEMPLATE
|
|
|
|
|
2014-06-29 02:04:05 -07:00
|
|
|
static void LoadSamples(ALfloat *dst, const ALvoid *src, ALuint srcstep, enum FmtType srctype, ALuint samples)
|
2011-10-04 09:47:08 -07:00
|
|
|
{
|
|
|
|
switch(srctype)
|
|
|
|
{
|
|
|
|
case FmtByte:
|
2012-09-26 17:16:25 -07:00
|
|
|
Load_ALbyte(dst, src, srcstep, samples);
|
2011-10-04 09:47:08 -07:00
|
|
|
break;
|
|
|
|
case FmtShort:
|
2012-09-26 17:16:25 -07:00
|
|
|
Load_ALshort(dst, src, srcstep, samples);
|
2011-10-04 09:47:08 -07:00
|
|
|
break;
|
|
|
|
case FmtFloat:
|
2012-09-26 17:16:25 -07:00
|
|
|
Load_ALfloat(dst, src, srcstep, samples);
|
2011-10-04 09:47:08 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-18 08:52:04 -08:00
|
|
|
static inline void SilenceSamples(ALfloat *dst, ALuint samples)
|
2011-10-04 09:47:08 -07:00
|
|
|
{
|
|
|
|
ALuint i;
|
|
|
|
for(i = 0;i < samples;i++)
|
|
|
|
dst[i] = 0.0f;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-05-19 01:54:52 -07:00
|
|
|
static const ALfloat *DoFilters(ALfilterState *lpfilter, ALfilterState *hpfilter,
|
|
|
|
ALfloat *restrict dst, const ALfloat *restrict src,
|
|
|
|
ALuint numsamples, enum ActiveFilters type)
|
2012-09-11 05:24:19 -07:00
|
|
|
{
|
|
|
|
ALuint i;
|
2014-05-17 07:17:48 -07:00
|
|
|
switch(type)
|
|
|
|
{
|
|
|
|
case AF_None:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case AF_LowPass:
|
2014-05-18 05:02:34 -07:00
|
|
|
ALfilterState_process(lpfilter, dst, src, numsamples);
|
2014-05-19 01:54:52 -07:00
|
|
|
return dst;
|
2014-05-17 07:54:25 -07:00
|
|
|
case AF_HighPass:
|
2014-05-18 05:02:34 -07:00
|
|
|
ALfilterState_process(hpfilter, dst, src, numsamples);
|
2014-05-19 01:54:52 -07:00
|
|
|
return dst;
|
2014-05-17 07:54:25 -07:00
|
|
|
|
|
|
|
case AF_BandPass:
|
2014-05-18 05:02:34 -07:00
|
|
|
for(i = 0;i < numsamples;)
|
|
|
|
{
|
|
|
|
ALfloat temp[64];
|
|
|
|
ALuint todo = minu(64, numsamples-i);
|
|
|
|
|
2014-05-21 14:59:21 -07:00
|
|
|
ALfilterState_process(lpfilter, temp, src+i, todo);
|
|
|
|
ALfilterState_process(hpfilter, dst+i, temp, todo);
|
2014-05-18 05:02:34 -07:00
|
|
|
i += todo;
|
|
|
|
}
|
2014-05-19 01:54:52 -07:00
|
|
|
return dst;
|
2014-05-17 07:17:48 -07:00
|
|
|
}
|
2014-05-19 01:54:52 -07:00
|
|
|
return src;
|
2012-09-11 05:24:19 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-08-21 03:24:48 -07:00
|
|
|
ALvoid MixSource(ALvoice *voice, ALsource *Source, ALCdevice *Device, ALuint SamplesToDo)
|
2010-09-22 09:38:24 -07:00
|
|
|
{
|
2014-06-13 16:07:25 -07:00
|
|
|
MixerFunc Mix;
|
2014-11-23 10:49:54 -08:00
|
|
|
HrtfMixerFunc HrtfMix;
|
2014-06-13 16:07:25 -07:00
|
|
|
ResamplerFunc Resample;
|
2010-09-22 09:38:24 -07:00
|
|
|
ALbufferlistitem *BufferListItem;
|
|
|
|
ALuint DataPosInt, DataPosFrac;
|
2014-10-31 17:18:45 -07:00
|
|
|
ALboolean isbformat = AL_FALSE;
|
2010-09-22 09:38:24 -07:00
|
|
|
ALboolean Looping;
|
2010-11-25 13:17:51 -08:00
|
|
|
ALuint increment;
|
2011-07-02 21:33:53 -07:00
|
|
|
enum Resampler Resampler;
|
2010-09-22 09:38:24 -07:00
|
|
|
ALenum State;
|
2010-11-26 12:59:45 -08:00
|
|
|
ALuint OutPos;
|
2011-10-04 09:47:08 -07:00
|
|
|
ALuint NumChannels;
|
2012-09-26 17:16:25 -07:00
|
|
|
ALuint SampleSize;
|
2010-11-25 13:17:51 -08:00
|
|
|
ALint64 DataSize64;
|
2014-11-29 03:32:25 -08:00
|
|
|
ALuint IrSize;
|
2012-09-26 17:16:25 -07:00
|
|
|
ALuint chan, j;
|
2010-09-22 09:38:24 -07:00
|
|
|
|
|
|
|
/* Get source info */
|
2014-05-10 03:21:40 -07:00
|
|
|
State = Source->state;
|
2014-07-31 07:20:36 -07:00
|
|
|
BufferListItem = ATOMIC_LOAD(&Source->current_buffer);
|
2014-05-10 03:21:40 -07:00
|
|
|
DataPosInt = Source->position;
|
|
|
|
DataPosFrac = Source->position_fraction;
|
|
|
|
Looping = Source->Looping;
|
2014-11-02 00:27:26 -07:00
|
|
|
Resampler = Source->Resampler;
|
2014-05-10 03:21:40 -07:00
|
|
|
NumChannels = Source->NumChannels;
|
|
|
|
SampleSize = Source->SampleSize;
|
2014-11-02 00:27:26 -07:00
|
|
|
increment = voice->Step;
|
2010-09-22 09:38:24 -07:00
|
|
|
|
2014-10-31 17:18:45 -07:00
|
|
|
while(BufferListItem)
|
|
|
|
{
|
|
|
|
ALbuffer *buffer;
|
|
|
|
if((buffer=BufferListItem->buffer) != NULL)
|
|
|
|
{
|
|
|
|
isbformat = (buffer->FmtChannels == FmtBFormat2D ||
|
|
|
|
buffer->FmtChannels == FmtBFormat3D);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
BufferListItem = BufferListItem->next;
|
|
|
|
}
|
2014-12-17 10:57:35 -08:00
|
|
|
assert(BufferListItem != NULL);
|
2014-10-31 17:18:45 -07:00
|
|
|
|
2014-11-29 03:32:25 -08:00
|
|
|
IrSize = (Device->Hrtf ? GetHrtfIrSize(Device->Hrtf) : 0);
|
|
|
|
|
2014-06-13 16:07:25 -07:00
|
|
|
Mix = SelectMixer();
|
2014-11-23 10:49:54 -08:00
|
|
|
HrtfMix = SelectHrtfMixer();
|
2014-11-02 00:27:26 -07:00
|
|
|
Resample = ((increment == FRACTIONONE && DataPosFrac == 0) ?
|
|
|
|
Resample_copy32_C : SelectResampler(Resampler));
|
2010-09-22 09:38:24 -07:00
|
|
|
|
2010-11-26 12:59:45 -08:00
|
|
|
OutPos = 0;
|
2010-09-22 09:38:24 -07:00
|
|
|
do {
|
2010-11-26 02:53:15 -08:00
|
|
|
const ALuint BufferPrePadding = ResamplerPrePadding[Resampler];
|
|
|
|
const ALuint BufferPadding = ResamplerPadding[Resampler];
|
2012-09-26 17:16:25 -07:00
|
|
|
ALuint SrcBufferSize, DstBufferSize;
|
2010-09-22 09:38:24 -07:00
|
|
|
|
2013-10-26 08:49:37 -07:00
|
|
|
/* Figure out how many buffer samples will be needed */
|
2014-03-23 17:33:57 -07:00
|
|
|
DataSize64 = SamplesToDo-OutPos;
|
2010-11-25 11:16:19 -08:00
|
|
|
DataSize64 *= increment;
|
|
|
|
DataSize64 += DataPosFrac+FRACTIONMASK;
|
|
|
|
DataSize64 >>= FRACTIONBITS;
|
2010-11-26 02:53:15 -08:00
|
|
|
DataSize64 += BufferPadding+BufferPrePadding;
|
2010-11-25 11:16:19 -08:00
|
|
|
|
2012-09-26 17:16:25 -07:00
|
|
|
SrcBufferSize = (ALuint)mini64(DataSize64, BUFFERSIZE);
|
2010-11-25 11:16:19 -08:00
|
|
|
|
2012-09-26 17:16:25 -07:00
|
|
|
/* Figure out how many samples we can actually mix from this. */
|
|
|
|
DataSize64 = SrcBufferSize;
|
|
|
|
DataSize64 -= BufferPadding+BufferPrePadding;
|
|
|
|
DataSize64 <<= FRACTIONBITS;
|
|
|
|
DataSize64 -= DataPosFrac;
|
|
|
|
|
|
|
|
DstBufferSize = (ALuint)((DataSize64+(increment-1)) / increment);
|
|
|
|
DstBufferSize = minu(DstBufferSize, (SamplesToDo-OutPos));
|
|
|
|
|
|
|
|
/* Some mixers like having a multiple of 4, so try to give that unless
|
|
|
|
* this is the last update. */
|
|
|
|
if(OutPos+DstBufferSize < SamplesToDo)
|
|
|
|
DstBufferSize &= ~3;
|
|
|
|
|
|
|
|
for(chan = 0;chan < NumChannels;chan++)
|
2010-09-22 09:38:24 -07:00
|
|
|
{
|
2014-05-19 05:46:01 -07:00
|
|
|
const ALfloat *ResampledData;
|
|
|
|
ALfloat *SrcData = Device->SourceData;
|
2012-09-26 17:16:25 -07:00
|
|
|
ALuint SrcDataSize = 0;
|
2010-11-25 11:16:19 -08:00
|
|
|
|
2012-09-26 17:16:25 -07:00
|
|
|
if(Source->SourceType == AL_STATIC)
|
2010-09-22 09:38:24 -07:00
|
|
|
{
|
2014-05-21 15:37:22 -07:00
|
|
|
const ALbuffer *ALBuffer = BufferListItem->buffer;
|
2012-09-26 17:16:25 -07:00
|
|
|
const ALubyte *Data = ALBuffer->data;
|
|
|
|
ALuint DataSize;
|
|
|
|
ALuint pos;
|
2010-09-22 09:38:24 -07:00
|
|
|
|
2014-12-18 08:42:03 -08:00
|
|
|
/* Offset to current channel */
|
|
|
|
Data += chan*SampleSize;
|
|
|
|
|
2012-09-26 17:16:25 -07:00
|
|
|
/* If current pos is beyond the loop range, do not loop */
|
|
|
|
if(Looping == AL_FALSE || DataPosInt >= (ALuint)ALBuffer->LoopEnd)
|
2010-11-25 21:42:15 -08:00
|
|
|
{
|
2012-09-26 17:16:25 -07:00
|
|
|
Looping = AL_FALSE;
|
2010-11-25 21:42:15 -08:00
|
|
|
|
2012-09-26 17:16:25 -07:00
|
|
|
if(DataPosInt >= BufferPrePadding)
|
|
|
|
pos = DataPosInt - BufferPrePadding;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
DataSize = BufferPrePadding - DataPosInt;
|
|
|
|
DataSize = minu(SrcBufferSize - SrcDataSize, DataSize);
|
2010-11-25 21:42:15 -08:00
|
|
|
|
2014-06-29 02:04:05 -07:00
|
|
|
SilenceSamples(&SrcData[SrcDataSize], DataSize);
|
2012-09-26 17:16:25 -07:00
|
|
|
SrcDataSize += DataSize;
|
2010-11-25 21:42:15 -08:00
|
|
|
|
2012-09-26 17:16:25 -07:00
|
|
|
pos = 0;
|
|
|
|
}
|
2010-09-22 09:38:24 -07:00
|
|
|
|
2012-09-26 17:16:25 -07:00
|
|
|
/* Copy what's left to play in the source buffer, and clear the
|
|
|
|
* rest of the temp buffer */
|
|
|
|
DataSize = minu(SrcBufferSize - SrcDataSize, ALBuffer->SampleLen - pos);
|
2010-11-25 11:16:19 -08:00
|
|
|
|
2014-12-18 08:42:03 -08:00
|
|
|
LoadSamples(&SrcData[SrcDataSize], &Data[pos * NumChannels*SampleSize],
|
2014-06-29 02:04:05 -07:00
|
|
|
NumChannels, ALBuffer->FmtType, DataSize);
|
2012-09-26 17:16:25 -07:00
|
|
|
SrcDataSize += DataSize;
|
2010-11-25 11:16:19 -08:00
|
|
|
|
2014-06-29 02:04:05 -07:00
|
|
|
SilenceSamples(&SrcData[SrcDataSize], SrcBufferSize - SrcDataSize);
|
2012-09-26 17:16:25 -07:00
|
|
|
SrcDataSize += SrcBufferSize - SrcDataSize;
|
2010-11-25 21:42:15 -08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-09-26 17:16:25 -07:00
|
|
|
ALuint LoopStart = ALBuffer->LoopStart;
|
|
|
|
ALuint LoopEnd = ALBuffer->LoopEnd;
|
2010-11-25 21:42:15 -08:00
|
|
|
|
2012-09-26 17:16:25 -07:00
|
|
|
if(DataPosInt >= LoopStart)
|
|
|
|
{
|
|
|
|
pos = DataPosInt-LoopStart;
|
|
|
|
while(pos < BufferPrePadding)
|
|
|
|
pos += LoopEnd-LoopStart;
|
|
|
|
pos -= BufferPrePadding;
|
|
|
|
pos += LoopStart;
|
|
|
|
}
|
|
|
|
else if(DataPosInt >= BufferPrePadding)
|
|
|
|
pos = DataPosInt - BufferPrePadding;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
DataSize = BufferPrePadding - DataPosInt;
|
|
|
|
DataSize = minu(SrcBufferSize - SrcDataSize, DataSize);
|
2010-11-25 21:42:15 -08:00
|
|
|
|
2014-06-29 02:04:05 -07:00
|
|
|
SilenceSamples(&SrcData[SrcDataSize], DataSize);
|
2012-09-26 17:16:25 -07:00
|
|
|
SrcDataSize += DataSize;
|
2010-11-25 11:16:19 -08:00
|
|
|
|
2012-09-26 17:16:25 -07:00
|
|
|
pos = 0;
|
|
|
|
}
|
2010-11-25 11:16:19 -08:00
|
|
|
|
2012-09-26 17:16:25 -07:00
|
|
|
/* Copy what's left of this loop iteration, then copy repeats
|
|
|
|
* of the loop section */
|
|
|
|
DataSize = LoopEnd - pos;
|
|
|
|
DataSize = minu(SrcBufferSize - SrcDataSize, DataSize);
|
2010-11-25 11:16:19 -08:00
|
|
|
|
2014-12-18 08:42:03 -08:00
|
|
|
LoadSamples(&SrcData[SrcDataSize], &Data[pos * NumChannels*SampleSize],
|
2014-06-29 02:04:05 -07:00
|
|
|
NumChannels, ALBuffer->FmtType, DataSize);
|
2010-11-25 11:16:19 -08:00
|
|
|
SrcDataSize += DataSize;
|
2012-09-26 17:16:25 -07:00
|
|
|
|
|
|
|
DataSize = LoopEnd-LoopStart;
|
|
|
|
while(SrcBufferSize > SrcDataSize)
|
|
|
|
{
|
|
|
|
DataSize = minu(SrcBufferSize - SrcDataSize, DataSize);
|
|
|
|
|
2014-12-18 08:42:03 -08:00
|
|
|
LoadSamples(&SrcData[SrcDataSize], &Data[LoopStart * NumChannels*SampleSize],
|
2014-06-29 02:04:05 -07:00
|
|
|
NumChannels, ALBuffer->FmtType, DataSize);
|
2012-09-26 17:16:25 -07:00
|
|
|
SrcDataSize += DataSize;
|
|
|
|
}
|
2010-11-25 11:16:19 -08:00
|
|
|
}
|
2010-09-22 09:38:24 -07:00
|
|
|
}
|
2010-11-25 21:42:15 -08:00
|
|
|
else
|
|
|
|
{
|
2012-09-26 17:16:25 -07:00
|
|
|
/* Crawl the buffer queue to fill in the temp buffer */
|
|
|
|
ALbufferlistitem *tmpiter = BufferListItem;
|
|
|
|
ALuint pos;
|
|
|
|
|
|
|
|
if(DataPosInt >= BufferPrePadding)
|
|
|
|
pos = DataPosInt - BufferPrePadding;
|
|
|
|
else
|
2010-11-25 21:42:15 -08:00
|
|
|
{
|
2012-09-26 17:16:25 -07:00
|
|
|
pos = BufferPrePadding - DataPosInt;
|
|
|
|
while(pos > 0)
|
2010-11-25 21:42:15 -08:00
|
|
|
{
|
2014-05-10 02:01:38 -07:00
|
|
|
ALbufferlistitem *prev;
|
|
|
|
if((prev=tmpiter->prev) != NULL)
|
|
|
|
tmpiter = prev;
|
|
|
|
else if(Looping)
|
|
|
|
{
|
|
|
|
while(tmpiter->next)
|
|
|
|
tmpiter = tmpiter->next;
|
|
|
|
}
|
|
|
|
else
|
2012-09-26 17:16:25 -07:00
|
|
|
{
|
|
|
|
ALuint DataSize = minu(SrcBufferSize - SrcDataSize, pos);
|
2010-11-25 21:42:15 -08:00
|
|
|
|
2014-06-29 02:04:05 -07:00
|
|
|
SilenceSamples(&SrcData[SrcDataSize], DataSize);
|
2012-09-26 17:16:25 -07:00
|
|
|
SrcDataSize += DataSize;
|
2010-11-25 21:42:15 -08:00
|
|
|
|
2012-09-26 17:16:25 -07:00
|
|
|
pos = 0;
|
|
|
|
break;
|
|
|
|
}
|
2010-11-25 21:42:15 -08:00
|
|
|
|
2012-09-26 17:16:25 -07:00
|
|
|
if(tmpiter->buffer)
|
2010-11-25 21:42:15 -08:00
|
|
|
{
|
2012-09-26 17:16:25 -07:00
|
|
|
if((ALuint)tmpiter->buffer->SampleLen > pos)
|
|
|
|
{
|
|
|
|
pos = tmpiter->buffer->SampleLen - pos;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
pos -= tmpiter->buffer->SampleLen;
|
2010-11-25 21:42:15 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-11-25 11:16:19 -08:00
|
|
|
|
2012-09-26 17:16:25 -07:00
|
|
|
while(tmpiter && SrcBufferSize > SrcDataSize)
|
2010-11-25 11:16:19 -08:00
|
|
|
{
|
2012-09-26 17:16:25 -07:00
|
|
|
const ALbuffer *ALBuffer;
|
|
|
|
if((ALBuffer=tmpiter->buffer) != NULL)
|
2010-11-25 11:16:19 -08:00
|
|
|
{
|
2012-09-26 17:16:25 -07:00
|
|
|
const ALubyte *Data = ALBuffer->data;
|
|
|
|
ALuint DataSize = ALBuffer->SampleLen;
|
2010-11-25 11:16:19 -08:00
|
|
|
|
2012-09-26 17:16:25 -07:00
|
|
|
/* Skip the data already played */
|
|
|
|
if(DataSize <= pos)
|
|
|
|
pos -= DataSize;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Data += (pos*NumChannels + chan)*SampleSize;
|
|
|
|
DataSize -= pos;
|
|
|
|
pos -= pos;
|
|
|
|
|
|
|
|
DataSize = minu(SrcBufferSize - SrcDataSize, DataSize);
|
2014-06-29 02:04:05 -07:00
|
|
|
LoadSamples(&SrcData[SrcDataSize], Data, NumChannels,
|
|
|
|
ALBuffer->FmtType, DataSize);
|
2012-09-26 17:16:25 -07:00
|
|
|
SrcDataSize += DataSize;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
tmpiter = tmpiter->next;
|
|
|
|
if(!tmpiter && Looping)
|
2014-07-31 07:20:36 -07:00
|
|
|
tmpiter = ATOMIC_LOAD(&Source->queue);
|
2012-09-26 17:16:25 -07:00
|
|
|
else if(!tmpiter)
|
|
|
|
{
|
2014-06-29 02:04:05 -07:00
|
|
|
SilenceSamples(&SrcData[SrcDataSize], SrcBufferSize - SrcDataSize);
|
2012-09-26 17:16:25 -07:00
|
|
|
SrcDataSize += SrcBufferSize - SrcDataSize;
|
2010-11-25 11:16:19 -08:00
|
|
|
}
|
|
|
|
}
|
2010-09-22 09:38:24 -07:00
|
|
|
}
|
|
|
|
|
2012-09-26 17:16:25 -07:00
|
|
|
/* Now resample, then filter and mix to the appropriate outputs. */
|
2014-06-13 16:07:25 -07:00
|
|
|
ResampledData = Resample(
|
2014-05-19 05:46:01 -07:00
|
|
|
&SrcData[BufferPrePadding], DataPosFrac, increment,
|
|
|
|
Device->ResampledData, DstBufferSize
|
|
|
|
);
|
2012-09-26 17:16:25 -07:00
|
|
|
{
|
2014-08-21 03:24:48 -07:00
|
|
|
DirectParams *parms = &voice->Direct;
|
2014-05-19 01:54:52 -07:00
|
|
|
const ALfloat *samples;
|
2012-09-14 04:13:18 -07:00
|
|
|
|
2014-05-19 02:24:31 -07:00
|
|
|
samples = DoFilters(
|
|
|
|
&parms->Filters[chan].LowPass, &parms->Filters[chan].HighPass,
|
2014-05-19 05:46:01 -07:00
|
|
|
Device->FilteredData, ResampledData, DstBufferSize,
|
|
|
|
parms->Filters[chan].ActiveType
|
2014-05-19 02:24:31 -07:00
|
|
|
);
|
2014-11-23 10:49:54 -08:00
|
|
|
if(!voice->IsHrtf)
|
|
|
|
Mix(samples, parms->OutChannels, parms->OutBuffer, parms->Gains[chan],
|
|
|
|
parms->Counter, OutPos, DstBufferSize);
|
|
|
|
else
|
|
|
|
HrtfMix(parms->OutBuffer, samples, parms->Counter, voice->Offset,
|
2014-11-29 03:32:25 -08:00
|
|
|
OutPos, IrSize, &parms->Hrtf.Params[chan],
|
2014-11-23 10:49:54 -08:00
|
|
|
&parms->Hrtf.State[chan], DstBufferSize);
|
2012-09-26 17:16:25 -07:00
|
|
|
}
|
2012-09-11 05:24:19 -07:00
|
|
|
|
2014-10-31 17:18:45 -07:00
|
|
|
/* Only the first channel for B-Format buffers (W channel) goes to
|
|
|
|
* the send paths. */
|
|
|
|
if(chan > 0 && isbformat)
|
|
|
|
continue;
|
2012-09-08 21:34:36 -07:00
|
|
|
for(j = 0;j < Device->NumAuxSends;j++)
|
|
|
|
{
|
2014-08-21 03:24:48 -07:00
|
|
|
SendParams *parms = &voice->Send[j];
|
2014-05-19 01:54:52 -07:00
|
|
|
const ALfloat *samples;
|
|
|
|
|
2014-05-18 11:05:38 -07:00
|
|
|
if(!parms->OutBuffer)
|
2012-09-08 21:34:36 -07:00
|
|
|
continue;
|
2012-09-11 05:24:19 -07:00
|
|
|
|
2014-05-19 02:24:31 -07:00
|
|
|
samples = DoFilters(
|
|
|
|
&parms->Filters[chan].LowPass, &parms->Filters[chan].HighPass,
|
2014-05-19 05:46:01 -07:00
|
|
|
Device->FilteredData, ResampledData, DstBufferSize,
|
|
|
|
parms->Filters[chan].ActiveType
|
2014-05-19 02:24:31 -07:00
|
|
|
);
|
2014-06-13 16:07:25 -07:00
|
|
|
Mix(samples, 1, parms->OutBuffer, &parms->Gain,
|
|
|
|
parms->Counter, OutPos, DstBufferSize);
|
2012-09-08 21:34:36 -07:00
|
|
|
}
|
2012-04-27 23:46:51 -07:00
|
|
|
}
|
2012-09-26 17:16:25 -07:00
|
|
|
/* Update positions */
|
2014-06-02 19:19:22 -07:00
|
|
|
DataPosFrac += increment*DstBufferSize;
|
|
|
|
DataPosInt += DataPosFrac>>FRACTIONBITS;
|
|
|
|
DataPosFrac &= FRACTIONMASK;
|
|
|
|
|
2012-09-26 17:16:25 -07:00
|
|
|
OutPos += DstBufferSize;
|
2014-08-21 03:24:48 -07:00
|
|
|
voice->Offset += DstBufferSize;
|
|
|
|
voice->Direct.Counter = maxu(voice->Direct.Counter, DstBufferSize) - DstBufferSize;
|
2014-05-21 14:47:25 -07:00
|
|
|
for(j = 0;j < Device->NumAuxSends;j++)
|
2014-08-21 03:24:48 -07:00
|
|
|
voice->Send[j].Counter = maxu(voice->Send[j].Counter, DstBufferSize) - DstBufferSize;
|
2010-08-03 23:19:36 -07:00
|
|
|
|
|
|
|
/* Handle looping sources */
|
2010-11-25 11:16:19 -08:00
|
|
|
while(1)
|
2010-08-03 23:19:36 -07:00
|
|
|
{
|
2010-11-25 11:16:19 -08:00
|
|
|
const ALbuffer *ALBuffer;
|
|
|
|
ALuint DataSize = 0;
|
|
|
|
ALuint LoopStart = 0;
|
|
|
|
ALuint LoopEnd = 0;
|
|
|
|
|
|
|
|
if((ALBuffer=BufferListItem->buffer) != NULL)
|
|
|
|
{
|
2011-10-03 10:07:50 -07:00
|
|
|
DataSize = ALBuffer->SampleLen;
|
2010-11-25 11:16:19 -08:00
|
|
|
LoopStart = ALBuffer->LoopStart;
|
|
|
|
LoopEnd = ALBuffer->LoopEnd;
|
2011-02-06 01:07:37 -08:00
|
|
|
if(LoopEnd > DataPosInt)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-04-19 21:46:29 -07:00
|
|
|
if(Looping && Source->SourceType == AL_STATIC)
|
2011-02-06 01:07:37 -08:00
|
|
|
{
|
2014-05-15 01:44:29 -07:00
|
|
|
assert(LoopEnd > LoopStart);
|
2011-02-06 01:07:37 -08:00
|
|
|
DataPosInt = ((DataPosInt-LoopStart)%(LoopEnd-LoopStart)) + LoopStart;
|
|
|
|
break;
|
2010-11-25 11:16:19 -08:00
|
|
|
}
|
|
|
|
|
2011-02-06 01:07:37 -08:00
|
|
|
if(DataSize > DataPosInt)
|
|
|
|
break;
|
|
|
|
|
2014-07-31 07:20:36 -07:00
|
|
|
if(!(BufferListItem=BufferListItem->next))
|
2010-08-03 23:19:36 -07:00
|
|
|
{
|
2014-07-31 07:20:36 -07:00
|
|
|
if(Looping)
|
|
|
|
BufferListItem = ATOMIC_LOAD(&Source->queue);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
State = AL_STOPPED;
|
|
|
|
BufferListItem = NULL;
|
|
|
|
DataPosInt = 0;
|
|
|
|
DataPosFrac = 0;
|
|
|
|
break;
|
|
|
|
}
|
2010-08-03 23:19:36 -07:00
|
|
|
}
|
2010-11-25 11:16:19 -08:00
|
|
|
|
|
|
|
DataPosInt -= DataSize;
|
2010-08-03 23:19:36 -07:00
|
|
|
}
|
2010-11-26 12:59:45 -08:00
|
|
|
} while(State == AL_PLAYING && OutPos < SamplesToDo);
|
2010-08-03 23:19:36 -07:00
|
|
|
|
|
|
|
/* Update source info */
|
2010-09-23 16:49:33 -07:00
|
|
|
Source->state = State;
|
2014-07-31 07:20:36 -07:00
|
|
|
ATOMIC_STORE(&Source->current_buffer, BufferListItem);
|
2010-09-23 16:49:33 -07:00
|
|
|
Source->position = DataPosInt;
|
|
|
|
Source->position_fraction = DataPosFrac;
|
2010-08-03 23:19:36 -07:00
|
|
|
}
|