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"
|
|
|
|
|
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) \
|
2012-09-27 00:16:25 +00:00
|
|
|
static void Load_##T(ALfloat *dst, const T *src, ALuint srcstep, ALuint samples)\
|
2011-10-04 16:47:08 +00:00
|
|
|
{ \
|
|
|
|
ALuint i; \
|
|
|
|
for(i = 0;i < samples;i++) \
|
2012-09-27 00:16:25 +00:00
|
|
|
dst[i] = Sample_##T(src[i*srcstep]); \
|
2011-10-04 16:47:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DECL_TEMPLATE(ALbyte)
|
|
|
|
DECL_TEMPLATE(ALshort)
|
|
|
|
DECL_TEMPLATE(ALfloat)
|
|
|
|
|
|
|
|
#undef DECL_TEMPLATE
|
|
|
|
|
2012-10-05 13:44:55 +00:00
|
|
|
static void LoadData(ALfloat *dst, const ALvoid *src, ALuint srcstep, enum FmtType srctype, ALuint samples)
|
2011-10-04 16:47:08 +00:00
|
|
|
{
|
|
|
|
switch(srctype)
|
|
|
|
{
|
|
|
|
case FmtByte:
|
2012-09-27 00:16:25 +00:00
|
|
|
Load_ALbyte(dst, src, srcstep, samples);
|
2011-10-04 16:47:08 +00:00
|
|
|
break;
|
|
|
|
case FmtShort:
|
2012-09-27 00:16:25 +00:00
|
|
|
Load_ALshort(dst, src, srcstep, samples);
|
2011-10-04 16:47:08 +00:00
|
|
|
break;
|
|
|
|
case FmtFloat:
|
2012-09-27 00:16:25 +00:00
|
|
|
Load_ALfloat(dst, src, srcstep, samples);
|
2011-10-04 16:47:08 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-05 13:44:55 +00:00
|
|
|
static void SilenceData(ALfloat *dst, ALuint samples)
|
2011-10-04 16:47:08 +00:00
|
|
|
{
|
|
|
|
ALuint i;
|
|
|
|
for(i = 0;i < samples;i++)
|
|
|
|
dst[i] = 0.0f;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-05-28 02:14:02 +00:00
|
|
|
static void DoFilter(ALfilterState *filter, ALfloat *restrict dst, const ALfloat *restrict src,
|
2013-05-21 14:10:24 +00:00
|
|
|
ALuint numsamples)
|
2012-09-11 12:24:19 +00:00
|
|
|
{
|
|
|
|
ALuint i;
|
|
|
|
for(i = 0;i < numsamples;i++)
|
2013-05-28 02:14:02 +00:00
|
|
|
dst[i] = ALfilterState_processSingle(filter, src[i]);
|
|
|
|
dst[i] = ALfilterState_processSingleC(filter, src[i]);
|
2012-09-11 12:24:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
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;
|
2012-09-27 00:16:25 +00:00
|
|
|
ALuint SampleSize;
|
2010-11-25 21:17:51 +00:00
|
|
|
ALint64 DataSize64;
|
2012-09-27 00:16:25 +00:00
|
|
|
ALuint chan, 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;
|
2012-10-05 13:03:19 +00:00
|
|
|
Resampler = (increment==FRACTIONONE) ? PointResampler : Source->Resampler;
|
2011-10-04 16:47:08 +00:00
|
|
|
NumChannels = Source->NumChannels;
|
2012-09-27 00:16:25 +00:00
|
|
|
SampleSize = 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;
|
2012-09-27 00:16:25 +00:00
|
|
|
for(j = 0;j < BuffersPlayed;j++)
|
2010-09-22 16:38:24 +00:00
|
|
|
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-27 00:16:25 +00:00
|
|
|
ALuint SrcBufferSize, DstBufferSize;
|
2010-09-22 16:38:24 +00:00
|
|
|
|
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;
|
2010-11-25 19:16:19 +00:00
|
|
|
|
2012-09-27 00:16:25 +00:00
|
|
|
SrcBufferSize = (ALuint)mini64(DataSize64, BUFFERSIZE);
|
2010-11-25 19:16:19 +00:00
|
|
|
|
2012-09-27 00:16:25 +00:00
|
|
|
/* Figure out how many samples we can actually mix from this. */
|
|
|
|
DataSize64 = SrcBufferSize;
|
|
|
|
DataSize64 -= BufferPadding+BufferPrePadding;
|
|
|
|
DataSize64 <<= FRACTIONBITS;
|
|
|
|
DataSize64 -= increment;
|
|
|
|
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 16:38:24 +00:00
|
|
|
{
|
2012-10-05 13:42:26 +00:00
|
|
|
ALfloat *SrcData = Device->SampleData1;
|
|
|
|
ALfloat *ResampledData = Device->SampleData2;
|
2012-09-27 00:16:25 +00:00
|
|
|
ALuint SrcDataSize = 0;
|
2010-11-25 19:16:19 +00:00
|
|
|
|
2012-09-27 00:16:25 +00:00
|
|
|
if(Source->SourceType == AL_STATIC)
|
2010-09-22 16:38:24 +00:00
|
|
|
{
|
2012-09-27 00:16:25 +00:00
|
|
|
const ALbuffer *ALBuffer = Source->queue->buffer;
|
|
|
|
const ALubyte *Data = ALBuffer->data;
|
|
|
|
ALuint DataSize;
|
|
|
|
ALuint pos;
|
2010-09-22 16:38:24 +00:00
|
|
|
|
2012-09-27 00:16:25 +00:00
|
|
|
/* If current pos is beyond the loop range, do not loop */
|
|
|
|
if(Looping == AL_FALSE || DataPosInt >= (ALuint)ALBuffer->LoopEnd)
|
2010-11-26 05:42:15 +00:00
|
|
|
{
|
2012-09-27 00:16:25 +00:00
|
|
|
Looping = AL_FALSE;
|
2010-11-26 05:42:15 +00:00
|
|
|
|
2012-09-27 00:16:25 +00:00
|
|
|
if(DataPosInt >= BufferPrePadding)
|
|
|
|
pos = DataPosInt - BufferPrePadding;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
DataSize = BufferPrePadding - DataPosInt;
|
|
|
|
DataSize = minu(SrcBufferSize - SrcDataSize, DataSize);
|
2010-11-26 05:42:15 +00:00
|
|
|
|
2012-10-05 13:44:55 +00:00
|
|
|
SilenceData(&SrcData[SrcDataSize], DataSize);
|
2012-09-27 00:16:25 +00:00
|
|
|
SrcDataSize += DataSize;
|
2010-11-26 05:42:15 +00:00
|
|
|
|
2012-09-27 00:16:25 +00:00
|
|
|
pos = 0;
|
|
|
|
}
|
2010-09-22 16:38:24 +00:00
|
|
|
|
2012-09-27 00:16:25 +00: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 19:16:19 +00:00
|
|
|
|
2012-10-05 13:44:55 +00:00
|
|
|
LoadData(&SrcData[SrcDataSize], &Data[(pos*NumChannels + chan)*SampleSize],
|
|
|
|
NumChannels, ALBuffer->FmtType, DataSize);
|
2012-09-27 00:16:25 +00:00
|
|
|
SrcDataSize += DataSize;
|
2010-11-25 19:16:19 +00:00
|
|
|
|
2012-10-05 13:44:55 +00:00
|
|
|
SilenceData(&SrcData[SrcDataSize], SrcBufferSize - SrcDataSize);
|
2012-09-27 00:16:25 +00:00
|
|
|
SrcDataSize += SrcBufferSize - SrcDataSize;
|
2010-11-26 05:42:15 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-09-27 00:16:25 +00:00
|
|
|
ALuint LoopStart = ALBuffer->LoopStart;
|
|
|
|
ALuint LoopEnd = ALBuffer->LoopEnd;
|
2010-11-26 05:42:15 +00:00
|
|
|
|
2012-09-27 00:16:25 +00: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-26 05:42:15 +00:00
|
|
|
|
2012-10-05 13:44:55 +00:00
|
|
|
SilenceData(&SrcData[SrcDataSize], DataSize);
|
2012-09-27 00:16:25 +00:00
|
|
|
SrcDataSize += DataSize;
|
2010-11-25 19:16:19 +00:00
|
|
|
|
2012-09-27 00:16:25 +00:00
|
|
|
pos = 0;
|
|
|
|
}
|
2010-11-25 19:16:19 +00:00
|
|
|
|
2012-09-27 00:16:25 +00: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 19:16:19 +00:00
|
|
|
|
2012-10-05 13:44:55 +00:00
|
|
|
LoadData(&SrcData[SrcDataSize], &Data[(pos*NumChannels + chan)*SampleSize],
|
|
|
|
NumChannels, ALBuffer->FmtType, DataSize);
|
2010-11-25 19:16:19 +00:00
|
|
|
SrcDataSize += DataSize;
|
2012-09-27 00:16:25 +00:00
|
|
|
|
|
|
|
DataSize = LoopEnd-LoopStart;
|
|
|
|
while(SrcBufferSize > SrcDataSize)
|
|
|
|
{
|
|
|
|
DataSize = minu(SrcBufferSize - SrcDataSize, DataSize);
|
|
|
|
|
2012-10-05 13:44:55 +00:00
|
|
|
LoadData(&SrcData[SrcDataSize], &Data[(LoopStart*NumChannels + chan)*SampleSize],
|
|
|
|
NumChannels, ALBuffer->FmtType, DataSize);
|
2012-09-27 00:16:25 +00:00
|
|
|
SrcDataSize += DataSize;
|
|
|
|
}
|
2010-11-25 19:16:19 +00:00
|
|
|
}
|
2010-09-22 16:38:24 +00:00
|
|
|
}
|
2010-11-26 05:42:15 +00:00
|
|
|
else
|
|
|
|
{
|
2012-09-27 00:16:25 +00: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-26 05:42:15 +00:00
|
|
|
{
|
2012-09-27 00:16:25 +00:00
|
|
|
pos = BufferPrePadding - DataPosInt;
|
|
|
|
while(pos > 0)
|
2010-11-26 05:42:15 +00:00
|
|
|
{
|
2012-09-27 00:16:25 +00:00
|
|
|
if(!tmpiter->prev && !Looping)
|
|
|
|
{
|
|
|
|
ALuint DataSize = minu(SrcBufferSize - SrcDataSize, pos);
|
2010-11-26 05:42:15 +00:00
|
|
|
|
2012-10-05 13:44:55 +00:00
|
|
|
SilenceData(&SrcData[SrcDataSize], DataSize);
|
2012-09-27 00:16:25 +00:00
|
|
|
SrcDataSize += DataSize;
|
2010-11-26 05:42:15 +00:00
|
|
|
|
2012-09-27 00:16:25 +00:00
|
|
|
pos = 0;
|
|
|
|
break;
|
|
|
|
}
|
2010-11-26 05:42:15 +00:00
|
|
|
|
2012-09-27 00:16:25 +00:00
|
|
|
if(tmpiter->prev)
|
|
|
|
tmpiter = tmpiter->prev;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
while(tmpiter->next)
|
|
|
|
tmpiter = tmpiter->next;
|
|
|
|
}
|
2010-11-26 05:42:15 +00:00
|
|
|
|
2012-09-27 00:16:25 +00:00
|
|
|
if(tmpiter->buffer)
|
2010-11-26 05:42:15 +00:00
|
|
|
{
|
2012-09-27 00:16:25 +00:00
|
|
|
if((ALuint)tmpiter->buffer->SampleLen > pos)
|
|
|
|
{
|
|
|
|
pos = tmpiter->buffer->SampleLen - pos;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
pos -= tmpiter->buffer->SampleLen;
|
2010-11-26 05:42:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-11-25 19:16:19 +00:00
|
|
|
|
2012-09-27 00:16:25 +00:00
|
|
|
while(tmpiter && SrcBufferSize > SrcDataSize)
|
2010-11-25 19:16:19 +00:00
|
|
|
{
|
2012-09-27 00:16:25 +00:00
|
|
|
const ALbuffer *ALBuffer;
|
|
|
|
if((ALBuffer=tmpiter->buffer) != NULL)
|
2010-11-25 19:16:19 +00:00
|
|
|
{
|
2012-09-27 00:16:25 +00:00
|
|
|
const ALubyte *Data = ALBuffer->data;
|
|
|
|
ALuint DataSize = ALBuffer->SampleLen;
|
2010-11-25 19:16:19 +00:00
|
|
|
|
2012-09-27 00:16:25 +00: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);
|
2012-10-05 13:44:55 +00:00
|
|
|
LoadData(&SrcData[SrcDataSize], Data, NumChannels,
|
|
|
|
ALBuffer->FmtType, DataSize);
|
2012-09-27 00:16:25 +00:00
|
|
|
SrcDataSize += DataSize;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
tmpiter = tmpiter->next;
|
|
|
|
if(!tmpiter && Looping)
|
|
|
|
tmpiter = Source->queue;
|
|
|
|
else if(!tmpiter)
|
|
|
|
{
|
2012-10-05 13:44:55 +00:00
|
|
|
SilenceData(&SrcData[SrcDataSize], SrcBufferSize - SrcDataSize);
|
2012-09-27 00:16:25 +00:00
|
|
|
SrcDataSize += SrcBufferSize - SrcDataSize;
|
2010-11-25 19:16:19 +00:00
|
|
|
}
|
|
|
|
}
|
2010-09-22 16:38:24 +00:00
|
|
|
}
|
|
|
|
|
2012-09-27 00:16:25 +00:00
|
|
|
/* Now resample, then filter and mix to the appropriate outputs. */
|
|
|
|
Source->Params.Resample(&SrcData[BufferPrePadding], DataPosFrac,
|
2012-09-27 09:46:15 +00:00
|
|
|
increment, ResampledData, DstBufferSize);
|
2012-09-09 11:27:47 +00:00
|
|
|
|
2012-09-27 00:16:25 +00:00
|
|
|
{
|
|
|
|
DirectParams *directparms = &Source->Params.Direct;
|
2012-09-14 11:13:18 +00:00
|
|
|
|
2013-05-28 02:14:02 +00:00
|
|
|
DoFilter(&directparms->Filter[chan], SrcData, ResampledData,
|
2012-09-27 00:16:25 +00:00
|
|
|
DstBufferSize);
|
2012-10-14 18:29:28 +00:00
|
|
|
Source->Params.DryMix(directparms, SrcData, chan, OutPos,
|
|
|
|
SamplesToDo, DstBufferSize);
|
2012-09-27 00:16:25 +00:00
|
|
|
}
|
2012-09-11 12:24:19 +00:00
|
|
|
|
2012-09-09 04:34:36 +00:00
|
|
|
for(j = 0;j < Device->NumAuxSends;j++)
|
|
|
|
{
|
2012-09-11 12:24:19 +00:00
|
|
|
SendParams *sendparms = &Source->Params.Send[j];
|
|
|
|
if(!sendparms->Slot)
|
2012-09-09 04:34:36 +00:00
|
|
|
continue;
|
2012-09-11 12:24:19 +00:00
|
|
|
|
2013-05-28 02:14:02 +00:00
|
|
|
DoFilter(&sendparms->Filter[chan], SrcData, ResampledData,
|
2012-09-27 00:16:25 +00:00
|
|
|
DstBufferSize);
|
|
|
|
Source->Params.WetMix(sendparms, SrcData, OutPos,
|
|
|
|
SamplesToDo, DstBufferSize);
|
2012-09-09 04:34:36 +00:00
|
|
|
}
|
2012-04-28 06:46:51 +00:00
|
|
|
}
|
2012-09-27 00:16:25 +00:00
|
|
|
/* Update positions */
|
|
|
|
for(j = 0;j < DstBufferSize;j++)
|
2012-04-26 13:44:37 +00:00
|
|
|
{
|
|
|
|
DataPosFrac += increment;
|
|
|
|
DataPosInt += DataPosFrac>>FRACTIONBITS;
|
|
|
|
DataPosFrac &= FRACTIONMASK;
|
|
|
|
}
|
2012-09-27 00:16:25 +00:00
|
|
|
OutPos += DstBufferSize;
|
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;
|
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
|
|
|
}
|