2010-08-04 06:19:36 +00: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
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
* 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"
|
|
|
|
#include "bs2b.h"
|
|
|
|
|
2012-08-15 08:01:55 +00:00
|
|
|
#include "mixer_defs.h"
|
2010-08-04 06:19:36 +00:00
|
|
|
|
2011-05-01 20:59:44 +00:00
|
|
|
|
2012-09-09 04:34:36 +00:00
|
|
|
DryMixerFunc SelectDirectMixer(void)
|
2011-08-12 02:02:45 +00:00
|
|
|
{
|
2012-08-15 08:24:50 +00:00
|
|
|
#ifdef HAVE_SSE
|
2012-08-15 08:01:55 +00:00
|
|
|
if((CPUCapFlags&CPU_CAP_SSE))
|
2012-09-09 04:34:36 +00:00
|
|
|
return MixDirect_SSE;
|
2012-08-14 10:53:07 +00:00
|
|
|
#endif
|
2012-08-15 08:24:50 +00:00
|
|
|
#ifdef HAVE_NEON
|
2012-08-15 08:01:55 +00:00
|
|
|
if((CPUCapFlags&CPU_CAP_NEON))
|
2012-09-09 04:34:36 +00:00
|
|
|
return MixDirect_Neon;
|
2012-08-13 16:18:46 +00:00
|
|
|
#endif
|
2011-05-02 09:22:30 +00:00
|
|
|
|
2012-09-09 04:34:36 +00:00
|
|
|
return MixDirect_C;
|
2011-06-25 07:08:05 +00:00
|
|
|
}
|
|
|
|
|
2012-09-09 04:34:36 +00:00
|
|
|
DryMixerFunc SelectHrtfMixer(void)
|
2011-06-25 07:08:05 +00:00
|
|
|
{
|
2012-08-15 08:24:50 +00:00
|
|
|
#ifdef HAVE_SSE
|
2012-08-15 08:01:55 +00:00
|
|
|
if((CPUCapFlags&CPU_CAP_SSE))
|
2012-09-09 04:34:36 +00:00
|
|
|
return MixDirect_Hrtf_SSE;
|
2012-08-14 10:53:07 +00:00
|
|
|
#endif
|
2012-08-15 08:24:50 +00:00
|
|
|
#ifdef HAVE_NEON
|
2012-08-15 08:01:55 +00:00
|
|
|
if((CPUCapFlags&CPU_CAP_NEON))
|
2012-09-09 04:34:36 +00:00
|
|
|
return MixDirect_Hrtf_Neon;
|
2012-08-13 16:18:46 +00:00
|
|
|
#endif
|
2012-08-15 08:01:55 +00:00
|
|
|
|
2012-09-09 04:34:36 +00:00
|
|
|
return MixDirect_Hrtf_C;
|
2012-04-28 06:46:51 +00:00
|
|
|
}
|
|
|
|
|
2012-09-09 04:34:36 +00:00
|
|
|
WetMixerFunc SelectSendMixer(void)
|
2012-04-28 06:46:51 +00:00
|
|
|
{
|
2012-08-15 08:24:50 +00:00
|
|
|
#ifdef HAVE_SSE
|
2012-08-15 08:01:55 +00:00
|
|
|
if((CPUCapFlags&CPU_CAP_SSE))
|
2012-09-09 04:34:36 +00:00
|
|
|
return MixSend_SSE;
|
2012-08-15 08:01:55 +00:00
|
|
|
#endif
|
2012-08-15 08:24:50 +00:00
|
|
|
#ifdef HAVE_NEON
|
2012-08-15 08:01:55 +00:00
|
|
|
if((CPUCapFlags&CPU_CAP_NEON))
|
2012-09-09 04:34:36 +00:00
|
|
|
return MixSend_Neon;
|
2012-08-15 08:01:55 +00:00
|
|
|
#endif
|
|
|
|
|
2012-09-09 04:34:36 +00:00
|
|
|
return MixSend_C;
|
2011-05-06 07:20:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-04 16:47:08 +00:00
|
|
|
static __inline ALfloat Sample_ALbyte(ALbyte val)
|
|
|
|
{ return val * (1.0f/127.0f); }
|
|
|
|
|
|
|
|
static __inline ALfloat Sample_ALshort(ALshort val)
|
|
|
|
{ return val * (1.0f/32767.0f); }
|
|
|
|
|
|
|
|
static __inline ALfloat Sample_ALfloat(ALfloat val)
|
|
|
|
{ return val; }
|
|
|
|
|
|
|
|
#define DECL_TEMPLATE(T) \
|
|
|
|
static void Load_##T(ALfloat *dst, const T *src, ALuint samples) \
|
|
|
|
{ \
|
|
|
|
ALuint i; \
|
|
|
|
for(i = 0;i < samples;i++) \
|
|
|
|
dst[i] = Sample_##T(src[i]); \
|
|
|
|
}
|
|
|
|
|
|
|
|
DECL_TEMPLATE(ALbyte)
|
|
|
|
DECL_TEMPLATE(ALshort)
|
|
|
|
DECL_TEMPLATE(ALfloat)
|
|
|
|
|
|
|
|
#undef DECL_TEMPLATE
|
|
|
|
|
|
|
|
static void LoadStack(ALfloat *dst, const ALvoid *src, enum FmtType srctype, ALuint samples)
|
|
|
|
{
|
|
|
|
switch(srctype)
|
|
|
|
{
|
|
|
|
case FmtByte:
|
|
|
|
Load_ALbyte(dst, src, samples);
|
|
|
|
break;
|
|
|
|
case FmtShort:
|
|
|
|
Load_ALshort(dst, src, samples);
|
|
|
|
break;
|
|
|
|
case FmtFloat:
|
|
|
|
Load_ALfloat(dst, src, samples);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void SilenceStack(ALfloat *dst, ALuint samples)
|
|
|
|
{
|
|
|
|
ALuint i;
|
|
|
|
for(i = 0;i < samples;i++)
|
|
|
|
dst[i] = 0.0f;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-09-09 04:34:36 +00:00
|
|
|
static __inline ALfloat point32(const ALfloat *vals, ALint step, ALint frac)
|
|
|
|
{ return vals[0]; (void)step; (void)frac; }
|
|
|
|
static __inline ALfloat lerp32(const ALfloat *vals, ALint step, ALint frac)
|
|
|
|
{ return lerp(vals[0], vals[step], frac * (1.0f/FRACTIONONE)); }
|
|
|
|
static __inline ALfloat cubic32(const ALfloat *vals, ALint step, ALint frac)
|
|
|
|
{ return cubic(vals[-step], vals[0], vals[step], vals[step+step],
|
|
|
|
frac * (1.0f/FRACTIONONE)); }
|
|
|
|
|
|
|
|
#define DECL_TEMPLATE(Sampler) \
|
|
|
|
static void Resample_##Sampler(const ALfloat *data, ALuint frac, \
|
|
|
|
ALuint increment, ALuint NumChannels, ALfloat *RESTRICT OutBuffer, \
|
|
|
|
ALuint BufferSize) \
|
|
|
|
{ \
|
|
|
|
ALuint pos = 0; \
|
|
|
|
ALfloat value; \
|
|
|
|
ALuint i; \
|
|
|
|
\
|
|
|
|
for(i = 0;i < BufferSize+1;i++) \
|
|
|
|
{ \
|
|
|
|
value = Sampler(data + pos*NumChannels, NumChannels, frac); \
|
|
|
|
OutBuffer[i] = value; \
|
|
|
|
\
|
|
|
|
frac += increment; \
|
|
|
|
pos += frac>>FRACTIONBITS; \
|
|
|
|
frac &= FRACTIONMASK; \
|
|
|
|
} \
|
|
|
|
}
|
|
|
|
|
|
|
|
DECL_TEMPLATE(point32)
|
|
|
|
DECL_TEMPLATE(lerp32)
|
|
|
|
DECL_TEMPLATE(cubic32)
|
|
|
|
|
|
|
|
#undef DECL_TEMPLATE
|
|
|
|
|
|
|
|
static void Resample(enum Resampler Resampler, const ALfloat *data, ALuint frac,
|
|
|
|
ALuint increment, ALuint NumChannels,
|
|
|
|
ALfloat *RESTRICT OutBuffer, ALuint BufferSize)
|
|
|
|
{
|
|
|
|
if(increment == FRACTIONONE)
|
|
|
|
goto do_point;
|
|
|
|
switch(Resampler)
|
|
|
|
{
|
|
|
|
case PointResampler:
|
|
|
|
do_point:
|
|
|
|
Resample_point32(data, frac, increment, NumChannels,
|
|
|
|
OutBuffer, BufferSize);
|
|
|
|
break;
|
|
|
|
case LinearResampler:
|
|
|
|
Resample_lerp32(data, frac, increment, NumChannels,
|
|
|
|
OutBuffer, BufferSize);
|
|
|
|
break;
|
|
|
|
case CubicResampler:
|
|
|
|
Resample_cubic32(data, frac, increment, NumChannels,
|
|
|
|
OutBuffer, BufferSize);
|
|
|
|
break;
|
|
|
|
case ResamplerMax:
|
|
|
|
/* Shouldn't happen */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-09-26 19:23:22 +00:00
|
|
|
ALvoid MixSource(ALsource *Source, ALCdevice *Device, ALuint SamplesToDo)
|
2010-09-22 16:38:24 +00:00
|
|
|
{
|
|
|
|
ALbufferlistitem *BufferListItem;
|
|
|
|
ALuint DataPosInt, DataPosFrac;
|
|
|
|
ALuint BuffersPlayed;
|
|
|
|
ALboolean Looping;
|
2010-11-25 21:17:51 +00:00
|
|
|
ALuint increment;
|
2011-07-03 04:33:53 +00:00
|
|
|
enum Resampler Resampler;
|
2010-09-22 16:38:24 +00:00
|
|
|
ALenum State;
|
2010-11-26 20:59:45 +00:00
|
|
|
ALuint OutPos;
|
2011-10-04 16:47:08 +00:00
|
|
|
ALuint NumChannels;
|
2010-11-27 07:42:30 +00:00
|
|
|
ALuint FrameSize;
|
2010-11-25 21:17:51 +00:00
|
|
|
ALint64 DataSize64;
|
2012-09-09 04:34:36 +00:00
|
|
|
ALuint i, j;
|
2010-09-22 16:38:24 +00:00
|
|
|
|
|
|
|
/* Get source info */
|
2010-09-23 23:49:33 +00:00
|
|
|
State = Source->state;
|
|
|
|
BuffersPlayed = Source->BuffersPlayed;
|
|
|
|
DataPosInt = Source->position;
|
|
|
|
DataPosFrac = Source->position_fraction;
|
2012-04-20 04:46:29 +00:00
|
|
|
Looping = Source->Looping;
|
2010-11-25 19:16:19 +00:00
|
|
|
increment = Source->Params.Step;
|
2011-05-06 07:20:40 +00:00
|
|
|
Resampler = Source->Resampler;
|
2011-10-04 16:47:08 +00:00
|
|
|
NumChannels = Source->NumChannels;
|
|
|
|
FrameSize = NumChannels * Source->SampleSize;
|
2010-09-22 16:38:24 +00:00
|
|
|
|
|
|
|
/* Get current buffer queue item */
|
2010-09-23 23:49:33 +00:00
|
|
|
BufferListItem = Source->queue;
|
2010-09-22 16:38:24 +00:00
|
|
|
for(i = 0;i < BuffersPlayed;i++)
|
|
|
|
BufferListItem = BufferListItem->next;
|
|
|
|
|
2010-11-26 20:59:45 +00:00
|
|
|
OutPos = 0;
|
2010-09-22 16:38:24 +00:00
|
|
|
do {
|
2010-11-26 10:53:15 +00:00
|
|
|
const ALuint BufferPrePadding = ResamplerPrePadding[Resampler];
|
|
|
|
const ALuint BufferPadding = ResamplerPadding[Resampler];
|
2012-09-09 05:09:34 +00:00
|
|
|
ALfloat StackData[BUFFERSIZE];
|
2011-10-04 16:47:08 +00:00
|
|
|
ALfloat *SrcData = StackData;
|
2010-11-25 19:16:19 +00:00
|
|
|
ALuint SrcDataSize = 0;
|
2010-09-22 16:38:24 +00:00
|
|
|
ALuint BufferSize;
|
|
|
|
|
2010-11-25 19:16:19 +00:00
|
|
|
/* Figure out how many buffer bytes will be needed */
|
2010-11-26 20:59:45 +00:00
|
|
|
DataSize64 = SamplesToDo-OutPos+1;
|
2010-11-25 19:16:19 +00:00
|
|
|
DataSize64 *= increment;
|
|
|
|
DataSize64 += DataPosFrac+FRACTIONMASK;
|
|
|
|
DataSize64 >>= FRACTIONBITS;
|
2010-11-26 10:53:15 +00:00
|
|
|
DataSize64 += BufferPadding+BufferPrePadding;
|
2011-10-05 05:35:01 +00:00
|
|
|
DataSize64 *= NumChannels;
|
2010-11-25 19:16:19 +00:00
|
|
|
|
2012-09-09 05:09:34 +00:00
|
|
|
BufferSize = (ALuint)mini64(DataSize64, BUFFERSIZE);
|
2011-10-05 05:35:01 +00:00
|
|
|
BufferSize /= NumChannels;
|
2010-11-25 19:16:19 +00:00
|
|
|
|
2012-04-20 04:46:29 +00:00
|
|
|
if(Source->SourceType == AL_STATIC)
|
2010-09-22 16:38:24 +00:00
|
|
|
{
|
2011-08-23 16:52:01 +00:00
|
|
|
const ALbuffer *ALBuffer = Source->queue->buffer;
|
2010-11-25 19:16:19 +00:00
|
|
|
const ALubyte *Data = ALBuffer->data;
|
|
|
|
ALuint DataSize;
|
2010-11-26 05:42:15 +00:00
|
|
|
ALuint pos;
|
2010-11-25 19:16:19 +00:00
|
|
|
|
|
|
|
/* If current pos is beyond the loop range, do not loop */
|
|
|
|
if(Looping == AL_FALSE || DataPosInt >= (ALuint)ALBuffer->LoopEnd)
|
2010-09-22 16:38:24 +00:00
|
|
|
{
|
2010-11-25 19:16:19 +00:00
|
|
|
Looping = AL_FALSE;
|
2010-09-22 16:38:24 +00:00
|
|
|
|
2010-11-26 10:53:15 +00:00
|
|
|
if(DataPosInt >= BufferPrePadding)
|
2011-10-03 12:58:04 +00:00
|
|
|
pos = DataPosInt - BufferPrePadding;
|
2010-11-26 05:42:15 +00:00
|
|
|
else
|
|
|
|
{
|
2011-10-03 12:58:04 +00:00
|
|
|
DataSize = BufferPrePadding - DataPosInt;
|
2011-08-17 01:33:10 +00:00
|
|
|
DataSize = minu(BufferSize, DataSize);
|
2010-11-26 05:42:15 +00:00
|
|
|
|
2011-10-04 16:47:08 +00:00
|
|
|
SilenceStack(&SrcData[SrcDataSize*NumChannels],
|
|
|
|
DataSize*NumChannels);
|
2010-11-26 05:42:15 +00:00
|
|
|
SrcDataSize += DataSize;
|
|
|
|
BufferSize -= DataSize;
|
|
|
|
|
|
|
|
pos = 0;
|
|
|
|
}
|
|
|
|
|
2010-11-25 19:16:19 +00:00
|
|
|
/* Copy what's left to play in the source buffer, and clear the
|
|
|
|
* rest of the temp buffer */
|
2011-10-03 17:07:50 +00:00
|
|
|
DataSize = ALBuffer->SampleLen - pos;
|
2011-08-17 01:33:10 +00:00
|
|
|
DataSize = minu(BufferSize, DataSize);
|
2010-09-22 16:38:24 +00:00
|
|
|
|
2011-10-04 16:47:08 +00:00
|
|
|
LoadStack(&SrcData[SrcDataSize*NumChannels], &Data[pos*FrameSize],
|
|
|
|
ALBuffer->FmtType, DataSize*NumChannels);
|
2010-11-25 19:16:19 +00:00
|
|
|
SrcDataSize += DataSize;
|
|
|
|
BufferSize -= DataSize;
|
|
|
|
|
2011-10-04 16:47:08 +00:00
|
|
|
SilenceStack(&SrcData[SrcDataSize*NumChannels],
|
|
|
|
BufferSize*NumChannels);
|
2010-11-25 19:16:19 +00:00
|
|
|
SrcDataSize += BufferSize;
|
|
|
|
BufferSize -= BufferSize;
|
|
|
|
}
|
|
|
|
else
|
2010-09-22 16:38:24 +00:00
|
|
|
{
|
2010-11-25 19:16:19 +00:00
|
|
|
ALuint LoopStart = ALBuffer->LoopStart;
|
|
|
|
ALuint LoopEnd = ALBuffer->LoopEnd;
|
|
|
|
|
2010-11-26 05:42:15 +00:00
|
|
|
if(DataPosInt >= LoopStart)
|
|
|
|
{
|
|
|
|
pos = DataPosInt-LoopStart;
|
2010-11-26 10:53:15 +00:00
|
|
|
while(pos < BufferPrePadding)
|
2010-11-26 05:42:15 +00:00
|
|
|
pos += LoopEnd-LoopStart;
|
2010-11-26 10:53:15 +00:00
|
|
|
pos -= BufferPrePadding;
|
2010-11-26 05:42:15 +00:00
|
|
|
pos += LoopStart;
|
|
|
|
}
|
2010-11-26 10:53:15 +00:00
|
|
|
else if(DataPosInt >= BufferPrePadding)
|
2011-10-03 12:58:04 +00:00
|
|
|
pos = DataPosInt - BufferPrePadding;
|
2010-11-26 05:42:15 +00:00
|
|
|
else
|
|
|
|
{
|
2011-10-03 12:58:04 +00:00
|
|
|
DataSize = BufferPrePadding - DataPosInt;
|
2011-08-17 01:33:10 +00:00
|
|
|
DataSize = minu(BufferSize, DataSize);
|
2010-11-26 05:42:15 +00:00
|
|
|
|
2011-10-04 16:47:08 +00:00
|
|
|
SilenceStack(&SrcData[SrcDataSize*NumChannels], DataSize*NumChannels);
|
2010-11-26 05:42:15 +00:00
|
|
|
SrcDataSize += DataSize;
|
|
|
|
BufferSize -= DataSize;
|
|
|
|
|
|
|
|
pos = 0;
|
|
|
|
}
|
|
|
|
|
2010-11-25 19:16:19 +00:00
|
|
|
/* Copy what's left of this loop iteration, then copy repeats
|
|
|
|
* of the loop section */
|
2011-10-03 12:58:04 +00:00
|
|
|
DataSize = LoopEnd - pos;
|
2011-08-17 01:33:10 +00:00
|
|
|
DataSize = minu(BufferSize, DataSize);
|
2010-11-25 19:16:19 +00:00
|
|
|
|
2011-10-04 16:47:08 +00:00
|
|
|
LoadStack(&SrcData[SrcDataSize*NumChannels], &Data[pos*FrameSize],
|
|
|
|
ALBuffer->FmtType, DataSize*NumChannels);
|
2010-11-25 19:16:19 +00:00
|
|
|
SrcDataSize += DataSize;
|
|
|
|
BufferSize -= DataSize;
|
|
|
|
|
2011-10-03 12:58:04 +00:00
|
|
|
DataSize = LoopEnd-LoopStart;
|
2010-11-25 19:16:19 +00:00
|
|
|
while(BufferSize > 0)
|
|
|
|
{
|
2011-08-17 01:33:10 +00:00
|
|
|
DataSize = minu(BufferSize, DataSize);
|
2010-11-25 19:16:19 +00:00
|
|
|
|
2011-10-04 16:47:08 +00:00
|
|
|
LoadStack(&SrcData[SrcDataSize*NumChannels], &Data[LoopStart*FrameSize],
|
|
|
|
ALBuffer->FmtType, DataSize*NumChannels);
|
2010-11-25 19:16:19 +00:00
|
|
|
SrcDataSize += DataSize;
|
|
|
|
BufferSize -= DataSize;
|
|
|
|
}
|
2010-09-22 16:38:24 +00:00
|
|
|
}
|
|
|
|
}
|
2010-11-25 19:16:19 +00:00
|
|
|
else
|
2010-09-22 16:38:24 +00:00
|
|
|
{
|
2010-11-25 19:16:19 +00:00
|
|
|
/* Crawl the buffer queue to fill in the temp buffer */
|
2011-10-05 05:16:54 +00:00
|
|
|
ALbufferlistitem *tmpiter = BufferListItem;
|
2010-11-26 05:42:15 +00:00
|
|
|
ALuint pos;
|
|
|
|
|
2010-11-26 10:53:15 +00:00
|
|
|
if(DataPosInt >= BufferPrePadding)
|
2011-10-03 12:58:04 +00:00
|
|
|
pos = DataPosInt - BufferPrePadding;
|
2010-11-26 05:42:15 +00:00
|
|
|
else
|
|
|
|
{
|
2011-10-03 12:58:04 +00:00
|
|
|
pos = BufferPrePadding - DataPosInt;
|
2010-11-26 05:42:15 +00:00
|
|
|
while(pos > 0)
|
|
|
|
{
|
2011-10-05 05:16:54 +00:00
|
|
|
if(!tmpiter->prev && !Looping)
|
2010-11-26 05:42:15 +00:00
|
|
|
{
|
2011-08-17 01:33:10 +00:00
|
|
|
ALuint DataSize = minu(BufferSize, pos);
|
2010-11-26 05:42:15 +00:00
|
|
|
|
2011-10-04 16:47:08 +00:00
|
|
|
SilenceStack(&SrcData[SrcDataSize*NumChannels], DataSize*NumChannels);
|
2010-11-26 05:42:15 +00:00
|
|
|
SrcDataSize += DataSize;
|
|
|
|
BufferSize -= DataSize;
|
|
|
|
|
|
|
|
pos = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-10-05 05:16:54 +00:00
|
|
|
if(tmpiter->prev)
|
|
|
|
tmpiter = tmpiter->prev;
|
2011-01-23 23:04:42 +00:00
|
|
|
else
|
2010-11-26 05:42:15 +00:00
|
|
|
{
|
2011-10-05 05:16:54 +00:00
|
|
|
while(tmpiter->next)
|
|
|
|
tmpiter = tmpiter->next;
|
2010-11-26 05:42:15 +00:00
|
|
|
}
|
|
|
|
|
2011-10-05 05:16:54 +00:00
|
|
|
if(tmpiter->buffer)
|
2010-11-26 05:42:15 +00:00
|
|
|
{
|
2011-10-05 05:16:54 +00:00
|
|
|
if((ALuint)tmpiter->buffer->SampleLen > pos)
|
2010-11-26 05:42:15 +00:00
|
|
|
{
|
2011-10-05 05:16:54 +00:00
|
|
|
pos = tmpiter->buffer->SampleLen - pos;
|
2010-11-26 05:42:15 +00:00
|
|
|
break;
|
|
|
|
}
|
2011-10-05 05:16:54 +00:00
|
|
|
pos -= tmpiter->buffer->SampleLen;
|
2010-11-26 05:42:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-11-25 19:16:19 +00:00
|
|
|
|
2011-10-05 05:16:54 +00:00
|
|
|
while(tmpiter && BufferSize > 0)
|
2010-09-22 16:38:24 +00:00
|
|
|
{
|
2010-11-25 19:16:19 +00:00
|
|
|
const ALbuffer *ALBuffer;
|
2011-10-05 05:16:54 +00:00
|
|
|
if((ALBuffer=tmpiter->buffer) != NULL)
|
2010-11-25 19:16:19 +00:00
|
|
|
{
|
|
|
|
const ALubyte *Data = ALBuffer->data;
|
2011-10-03 17:07:50 +00:00
|
|
|
ALuint DataSize = ALBuffer->SampleLen;
|
2010-11-25 19:16:19 +00:00
|
|
|
|
|
|
|
/* Skip the data already played */
|
|
|
|
if(DataSize <= pos)
|
|
|
|
pos -= DataSize;
|
|
|
|
else
|
|
|
|
{
|
2011-10-03 12:58:04 +00:00
|
|
|
Data += pos*FrameSize;
|
2010-11-25 19:16:19 +00:00
|
|
|
DataSize -= pos;
|
|
|
|
pos -= pos;
|
|
|
|
|
2011-08-17 01:33:10 +00:00
|
|
|
DataSize = minu(BufferSize, DataSize);
|
2011-10-04 16:47:08 +00:00
|
|
|
LoadStack(&SrcData[SrcDataSize*NumChannels], Data,
|
|
|
|
ALBuffer->FmtType, DataSize*NumChannels);
|
2010-11-25 19:16:19 +00:00
|
|
|
SrcDataSize += DataSize;
|
|
|
|
BufferSize -= DataSize;
|
|
|
|
}
|
|
|
|
}
|
2011-10-05 05:16:54 +00:00
|
|
|
tmpiter = tmpiter->next;
|
|
|
|
if(!tmpiter && Looping)
|
|
|
|
tmpiter = Source->queue;
|
|
|
|
else if(!tmpiter)
|
2010-11-25 19:16:19 +00:00
|
|
|
{
|
2011-10-04 16:47:08 +00:00
|
|
|
SilenceStack(&SrcData[SrcDataSize*NumChannels], BufferSize*NumChannels);
|
2010-11-25 19:16:19 +00:00
|
|
|
SrcDataSize += BufferSize;
|
|
|
|
BufferSize -= BufferSize;
|
|
|
|
}
|
2010-09-22 16:38:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Figure out how many samples we can mix. */
|
2011-10-03 12:58:04 +00:00
|
|
|
DataSize64 = SrcDataSize;
|
2010-11-26 10:53:15 +00:00
|
|
|
DataSize64 -= BufferPadding+BufferPrePadding;
|
2010-09-22 16:38:24 +00:00
|
|
|
DataSize64 <<= FRACTIONBITS;
|
2010-11-25 21:17:51 +00:00
|
|
|
DataSize64 -= increment;
|
2010-11-26 23:51:13 +00:00
|
|
|
DataSize64 -= DataPosFrac;
|
2010-09-22 16:38:24 +00:00
|
|
|
|
2010-11-26 23:51:13 +00:00
|
|
|
BufferSize = (ALuint)((DataSize64+(increment-1)) / increment);
|
2011-08-17 01:33:10 +00:00
|
|
|
BufferSize = minu(BufferSize, (SamplesToDo-OutPos));
|
2010-09-22 16:38:24 +00:00
|
|
|
|
2012-09-09 11:27:47 +00:00
|
|
|
/* Some mixers like having a multiple of 4, so try to give that unless
|
|
|
|
* this is the last update. */
|
|
|
|
if(OutPos+BufferSize < SamplesToDo)
|
|
|
|
BufferSize &= ~3;
|
|
|
|
|
2011-10-04 16:47:08 +00:00
|
|
|
SrcData += BufferPrePadding*NumChannels;
|
2012-09-09 04:34:36 +00:00
|
|
|
for(i = 0;i < NumChannels;i++)
|
2012-04-28 06:46:51 +00:00
|
|
|
{
|
2012-09-09 04:34:36 +00:00
|
|
|
ALfloat ResampledData[BUFFERSIZE];
|
|
|
|
|
|
|
|
Resample(Resampler, SrcData+i, DataPosFrac, increment,
|
|
|
|
NumChannels, ResampledData, BufferSize);
|
|
|
|
|
|
|
|
Source->Params.DryMix(Source, Device, &Source->Params.Direct,
|
|
|
|
ResampledData, i, OutPos, SamplesToDo,
|
|
|
|
BufferSize);
|
|
|
|
for(j = 0;j < Device->NumAuxSends;j++)
|
|
|
|
{
|
2012-09-09 05:32:30 +00:00
|
|
|
if(!Source->Params.Send[j].Slot)
|
2012-09-09 04:34:36 +00:00
|
|
|
continue;
|
2012-09-09 05:32:30 +00:00
|
|
|
Source->Params.WetMix(&Source->Params.Send[j], ResampledData, i,
|
|
|
|
OutPos, SamplesToDo, BufferSize);
|
2012-09-09 04:34:36 +00:00
|
|
|
}
|
2012-04-28 06:46:51 +00:00
|
|
|
}
|
2012-04-26 13:44:37 +00:00
|
|
|
for(i = 0;i < BufferSize;i++)
|
|
|
|
{
|
|
|
|
DataPosFrac += increment;
|
|
|
|
DataPosInt += DataPosFrac>>FRACTIONBITS;
|
|
|
|
DataPosFrac &= FRACTIONMASK;
|
|
|
|
OutPos++;
|
|
|
|
}
|
2010-08-04 06:19:36 +00:00
|
|
|
|
|
|
|
/* Handle looping sources */
|
2010-11-25 19:16:19 +00:00
|
|
|
while(1)
|
2010-08-04 06:19:36 +00:00
|
|
|
{
|
2010-11-25 19:16:19 +00:00
|
|
|
const ALbuffer *ALBuffer;
|
|
|
|
ALuint DataSize = 0;
|
|
|
|
ALuint LoopStart = 0;
|
|
|
|
ALuint LoopEnd = 0;
|
|
|
|
|
|
|
|
if((ALBuffer=BufferListItem->buffer) != NULL)
|
|
|
|
{
|
2011-10-03 17:07:50 +00:00
|
|
|
DataSize = ALBuffer->SampleLen;
|
2010-11-25 19:16:19 +00:00
|
|
|
LoopStart = ALBuffer->LoopStart;
|
|
|
|
LoopEnd = ALBuffer->LoopEnd;
|
2011-02-06 09:07:37 +00:00
|
|
|
if(LoopEnd > DataPosInt)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-04-20 04:46:29 +00:00
|
|
|
if(Looping && Source->SourceType == AL_STATIC)
|
2011-02-06 09:07:37 +00:00
|
|
|
{
|
|
|
|
DataPosInt = ((DataPosInt-LoopStart)%(LoopEnd-LoopStart)) + LoopStart;
|
|
|
|
break;
|
2010-11-25 19:16:19 +00:00
|
|
|
}
|
|
|
|
|
2011-02-06 09:07:37 +00:00
|
|
|
if(DataSize > DataPosInt)
|
|
|
|
break;
|
|
|
|
|
2010-09-26 08:29:28 +00:00
|
|
|
if(BufferListItem->next)
|
2010-08-04 06:19:36 +00:00
|
|
|
{
|
|
|
|
BufferListItem = BufferListItem->next;
|
|
|
|
BuffersPlayed++;
|
|
|
|
}
|
|
|
|
else if(Looping)
|
|
|
|
{
|
2010-09-23 23:49:33 +00:00
|
|
|
BufferListItem = Source->queue;
|
2010-08-04 06:19:36 +00:00
|
|
|
BuffersPlayed = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
State = AL_STOPPED;
|
2010-09-23 23:49:33 +00:00
|
|
|
BufferListItem = Source->queue;
|
|
|
|
BuffersPlayed = Source->BuffersInQueue;
|
2010-08-04 06:19:36 +00:00
|
|
|
DataPosInt = 0;
|
|
|
|
DataPosFrac = 0;
|
2010-11-25 19:16:19 +00:00
|
|
|
break;
|
2010-08-04 06:19:36 +00:00
|
|
|
}
|
2010-11-25 19:16:19 +00:00
|
|
|
|
|
|
|
DataPosInt -= DataSize;
|
2010-08-04 06:19:36 +00:00
|
|
|
}
|
2010-11-26 20:59:45 +00:00
|
|
|
} while(State == AL_PLAYING && OutPos < SamplesToDo);
|
2010-08-04 06:19:36 +00:00
|
|
|
|
|
|
|
/* Update source info */
|
2010-09-23 23:49:33 +00:00
|
|
|
Source->state = State;
|
|
|
|
Source->BuffersPlayed = BuffersPlayed;
|
|
|
|
Source->position = DataPosInt;
|
|
|
|
Source->position_fraction = DataPosFrac;
|
2012-04-27 07:45:42 +00:00
|
|
|
Source->Hrtf.Offset += OutPos;
|
2011-07-16 23:24:01 +00:00
|
|
|
if(State == AL_PLAYING)
|
|
|
|
{
|
2012-04-27 07:45:42 +00:00
|
|
|
Source->Hrtf.Counter = maxu(Source->Hrtf.Counter, OutPos) - OutPos;
|
|
|
|
Source->Hrtf.Moving = AL_TRUE;
|
2011-07-16 23:24:01 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-04-27 07:45:42 +00:00
|
|
|
Source->Hrtf.Counter = 0;
|
|
|
|
Source->Hrtf.Moving = AL_FALSE;
|
2011-07-16 23:24:01 +00:00
|
|
|
}
|
2010-08-04 06:19:36 +00:00
|
|
|
}
|