2007-11-13 18:02:18 -08: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>
|
2009-01-24 10:38:04 -08:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2009-01-25 19:20:47 -08:00
|
|
|
#include <ctype.h>
|
2009-02-02 11:18:33 -08:00
|
|
|
#include <assert.h>
|
2009-01-25 19:20:47 -08:00
|
|
|
|
2007-11-13 18:02:18 -08:00
|
|
|
#include "alMain.h"
|
|
|
|
#include "AL/al.h"
|
|
|
|
#include "AL/alc.h"
|
2007-12-31 01:09:57 -08:00
|
|
|
#include "alSource.h"
|
|
|
|
#include "alBuffer.h"
|
|
|
|
#include "alListener.h"
|
2008-01-16 14:01:24 -08:00
|
|
|
#include "alAuxEffectSlot.h"
|
2008-08-14 05:43:52 -07:00
|
|
|
#include "alu.h"
|
2008-01-03 05:36:51 -08:00
|
|
|
#include "bs2b.h"
|
2007-11-13 18:02:18 -08:00
|
|
|
|
2012-09-12 07:57:50 -07:00
|
|
|
#include "mixer_defs.h"
|
|
|
|
|
2009-08-15 11:33:38 -07:00
|
|
|
|
2011-12-20 01:17:11 -08:00
|
|
|
struct ChanMap {
|
|
|
|
enum Channel channel;
|
|
|
|
ALfloat angle;
|
|
|
|
};
|
|
|
|
|
2011-09-23 22:33:37 -07:00
|
|
|
/* Cone scalar */
|
2012-08-11 06:20:24 -07:00
|
|
|
ALfloat ConeScale = 1.0f;
|
2011-09-23 22:33:37 -07:00
|
|
|
|
|
|
|
/* Localized Z scalar for mono sources */
|
|
|
|
ALfloat ZScale = 1.0f;
|
|
|
|
|
|
|
|
|
2012-09-14 04:13:18 -07:00
|
|
|
static ResamplerFunc SelectResampler(enum Resampler Resampler, ALuint increment)
|
|
|
|
{
|
|
|
|
if(increment == FRACTIONONE)
|
|
|
|
return Resample_point32_C;
|
|
|
|
switch(Resampler)
|
|
|
|
{
|
|
|
|
case PointResampler:
|
|
|
|
return Resample_point32_C;
|
|
|
|
case LinearResampler:
|
|
|
|
return Resample_lerp32_C;
|
|
|
|
case CubicResampler:
|
|
|
|
return Resample_cubic32_C;
|
|
|
|
case ResamplerMax:
|
|
|
|
/* Shouldn't happen */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-09-14 07:01:58 -07:00
|
|
|
return Resample_point32_C;
|
2012-09-14 04:13:18 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-09-16 08:14:26 -07:00
|
|
|
static DryMixerFunc SelectHrtfMixer(void)
|
2012-09-12 07:57:50 -07:00
|
|
|
{
|
|
|
|
#ifdef HAVE_SSE
|
|
|
|
if((CPUCapFlags&CPU_CAP_SSE))
|
2012-09-16 08:14:26 -07:00
|
|
|
return MixDirect_Hrtf_SSE;
|
2012-09-12 07:57:50 -07:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_NEON
|
|
|
|
if((CPUCapFlags&CPU_CAP_NEON))
|
2012-09-16 08:14:26 -07:00
|
|
|
return MixDirect_Hrtf_Neon;
|
2012-09-12 07:57:50 -07:00
|
|
|
#endif
|
|
|
|
|
2012-09-16 08:14:26 -07:00
|
|
|
return MixDirect_Hrtf_C;
|
2012-09-12 07:57:50 -07:00
|
|
|
}
|
|
|
|
|
2012-09-16 08:14:26 -07:00
|
|
|
static DryMixerFunc SelectDirectMixer(void)
|
2012-09-12 07:57:50 -07:00
|
|
|
{
|
|
|
|
#ifdef HAVE_SSE
|
|
|
|
if((CPUCapFlags&CPU_CAP_SSE))
|
2012-09-16 08:14:26 -07:00
|
|
|
return MixDirect_SSE;
|
2012-09-12 07:57:50 -07:00
|
|
|
#endif
|
|
|
|
|
2012-09-16 08:14:26 -07:00
|
|
|
return MixDirect_C;
|
2012-09-12 07:57:50 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static WetMixerFunc SelectSendMixer(void)
|
|
|
|
{
|
|
|
|
#ifdef HAVE_SSE
|
|
|
|
if((CPUCapFlags&CPU_CAP_SSE))
|
|
|
|
return MixSend_SSE;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return MixSend_C;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-23 04:13:51 -08:00
|
|
|
static __inline ALvoid aluMatrixVector(ALfloat *vector,ALfloat w,ALfloat matrix[4][4])
|
2007-11-13 18:02:18 -08:00
|
|
|
{
|
2009-11-23 04:13:51 -08:00
|
|
|
ALfloat temp[4] = {
|
|
|
|
vector[0], vector[1], vector[2], w
|
|
|
|
};
|
2007-11-13 18:02:18 -08:00
|
|
|
|
2009-11-23 04:13:51 -08:00
|
|
|
vector[0] = temp[0]*matrix[0][0] + temp[1]*matrix[1][0] + temp[2]*matrix[2][0] + temp[3]*matrix[3][0];
|
|
|
|
vector[1] = temp[0]*matrix[0][1] + temp[1]*matrix[1][1] + temp[2]*matrix[2][1] + temp[3]*matrix[3][1];
|
|
|
|
vector[2] = temp[0]*matrix[0][2] + temp[1]*matrix[1][2] + temp[2]*matrix[2][2] + temp[3]*matrix[3][2];
|
2007-11-13 18:02:18 -08:00
|
|
|
}
|
|
|
|
|
2010-08-03 23:19:36 -07:00
|
|
|
|
2010-08-03 23:10:00 -07:00
|
|
|
ALvoid CalcNonAttnSourceParams(ALsource *ALSource, const ALCcontext *ALContext)
|
2010-08-05 01:07:20 -07:00
|
|
|
{
|
2012-06-28 18:49:49 -07:00
|
|
|
static const struct ChanMap MonoMap[1] = { { FrontCenter, 0.0f } };
|
2012-02-09 23:52:20 -08:00
|
|
|
static const struct ChanMap StereoMap[2] = {
|
2012-06-28 18:49:49 -07:00
|
|
|
{ FrontLeft, -30.0f * F_PI/180.0f },
|
|
|
|
{ FrontRight, 30.0f * F_PI/180.0f }
|
2012-02-09 23:52:20 -08:00
|
|
|
};
|
2012-08-09 05:38:07 -07:00
|
|
|
static const struct ChanMap StereoWideMap[2] = {
|
|
|
|
{ FrontLeft, -90.0f * F_PI/180.0f },
|
|
|
|
{ FrontRight, 90.0f * F_PI/180.0f }
|
|
|
|
};
|
2012-02-09 23:52:20 -08:00
|
|
|
static const struct ChanMap RearMap[2] = {
|
2012-06-28 18:49:49 -07:00
|
|
|
{ BackLeft, -150.0f * F_PI/180.0f },
|
|
|
|
{ BackRight, 150.0f * F_PI/180.0f }
|
2012-02-09 23:52:20 -08:00
|
|
|
};
|
|
|
|
static const struct ChanMap QuadMap[4] = {
|
2012-06-28 18:49:49 -07:00
|
|
|
{ FrontLeft, -45.0f * F_PI/180.0f },
|
|
|
|
{ FrontRight, 45.0f * F_PI/180.0f },
|
|
|
|
{ BackLeft, -135.0f * F_PI/180.0f },
|
|
|
|
{ BackRight, 135.0f * F_PI/180.0f }
|
2012-02-09 23:52:20 -08:00
|
|
|
};
|
|
|
|
static const struct ChanMap X51Map[6] = {
|
2012-06-28 18:49:49 -07:00
|
|
|
{ FrontLeft, -30.0f * F_PI/180.0f },
|
|
|
|
{ FrontRight, 30.0f * F_PI/180.0f },
|
|
|
|
{ FrontCenter, 0.0f * F_PI/180.0f },
|
2012-02-09 23:52:20 -08:00
|
|
|
{ LFE, 0.0f },
|
2012-06-28 18:49:49 -07:00
|
|
|
{ BackLeft, -110.0f * F_PI/180.0f },
|
|
|
|
{ BackRight, 110.0f * F_PI/180.0f }
|
2012-02-09 23:52:20 -08:00
|
|
|
};
|
|
|
|
static const struct ChanMap X61Map[7] = {
|
2012-06-28 18:49:49 -07:00
|
|
|
{ FrontLeft, -30.0f * F_PI/180.0f },
|
|
|
|
{ FrontRight, 30.0f * F_PI/180.0f },
|
|
|
|
{ FrontCenter, 0.0f * F_PI/180.0f },
|
2012-02-09 23:52:20 -08:00
|
|
|
{ LFE, 0.0f },
|
2012-06-28 18:49:49 -07:00
|
|
|
{ BackCenter, 180.0f * F_PI/180.0f },
|
|
|
|
{ SideLeft, -90.0f * F_PI/180.0f },
|
|
|
|
{ SideRight, 90.0f * F_PI/180.0f }
|
2012-02-09 23:52:20 -08:00
|
|
|
};
|
|
|
|
static const struct ChanMap X71Map[8] = {
|
2012-06-28 18:49:49 -07:00
|
|
|
{ FrontLeft, -30.0f * F_PI/180.0f },
|
|
|
|
{ FrontRight, 30.0f * F_PI/180.0f },
|
|
|
|
{ FrontCenter, 0.0f * F_PI/180.0f },
|
2012-02-09 23:52:20 -08:00
|
|
|
{ LFE, 0.0f },
|
2012-06-28 18:49:49 -07:00
|
|
|
{ BackLeft, -150.0f * F_PI/180.0f },
|
|
|
|
{ BackRight, 150.0f * F_PI/180.0f },
|
|
|
|
{ SideLeft, -90.0f * F_PI/180.0f },
|
|
|
|
{ SideRight, 90.0f * F_PI/180.0f }
|
2012-02-09 23:52:20 -08:00
|
|
|
};
|
2011-06-29 23:18:49 -07:00
|
|
|
|
2011-05-06 04:37:10 -07:00
|
|
|
ALCdevice *Device = ALContext->Device;
|
2010-08-05 01:07:20 -07:00
|
|
|
ALfloat SourceVolume,ListenerGain,MinVolume,MaxVolume;
|
2010-08-07 00:38:02 -07:00
|
|
|
ALbufferlistitem *BufferListItem;
|
2010-11-27 00:15:07 -08:00
|
|
|
enum FmtChannels Channels;
|
2012-06-28 18:49:49 -07:00
|
|
|
ALfloat (*SrcMatrix)[MaxChannels];
|
2010-08-05 01:07:20 -07:00
|
|
|
ALfloat DryGain, DryGainHF;
|
|
|
|
ALfloat WetGain[MAX_SENDS];
|
|
|
|
ALfloat WetGainHF[MAX_SENDS];
|
|
|
|
ALint NumSends, Frequency;
|
2011-12-20 01:17:11 -08:00
|
|
|
const struct ChanMap *chans = NULL;
|
2011-08-17 01:54:09 -07:00
|
|
|
enum Resampler Resampler;
|
2011-05-15 02:12:42 -07:00
|
|
|
ALint num_channels = 0;
|
2012-02-09 23:35:17 -08:00
|
|
|
ALboolean DirectChannels;
|
2012-08-09 05:38:07 -07:00
|
|
|
ALfloat hwidth = 0.0f;
|
2010-08-07 05:43:16 -07:00
|
|
|
ALfloat Pitch;
|
2010-08-05 01:07:20 -07:00
|
|
|
ALfloat cw;
|
2011-05-06 23:25:15 -07:00
|
|
|
ALint i, c;
|
2010-08-05 01:07:20 -07:00
|
|
|
|
2010-11-26 18:01:29 -08:00
|
|
|
/* Get device properties */
|
2011-10-11 22:30:58 -07:00
|
|
|
NumSends = Device->NumAuxSends;
|
|
|
|
Frequency = Device->Frequency;
|
2010-08-05 01:07:20 -07:00
|
|
|
|
2010-11-26 18:01:29 -08:00
|
|
|
/* Get listener properties */
|
2010-08-05 01:07:20 -07:00
|
|
|
ListenerGain = ALContext->Listener.Gain;
|
|
|
|
|
2010-11-26 18:01:29 -08:00
|
|
|
/* Get source properties */
|
2012-04-19 21:46:29 -07:00
|
|
|
SourceVolume = ALSource->Gain;
|
|
|
|
MinVolume = ALSource->MinGain;
|
|
|
|
MaxVolume = ALSource->MaxGain;
|
|
|
|
Pitch = ALSource->Pitch;
|
2011-08-17 01:54:09 -07:00
|
|
|
Resampler = ALSource->Resampler;
|
2012-02-09 23:35:17 -08:00
|
|
|
DirectChannels = ALSource->DirectChannels;
|
2010-08-05 01:07:20 -07:00
|
|
|
|
2010-11-26 18:01:29 -08:00
|
|
|
/* Calculate the stepping value */
|
2010-11-27 00:15:07 -08:00
|
|
|
Channels = FmtMono;
|
2010-08-07 00:38:02 -07:00
|
|
|
BufferListItem = ALSource->queue;
|
|
|
|
while(BufferListItem != NULL)
|
|
|
|
{
|
|
|
|
ALbuffer *ALBuffer;
|
|
|
|
if((ALBuffer=BufferListItem->buffer) != NULL)
|
|
|
|
{
|
2012-09-08 22:09:34 -07:00
|
|
|
ALsizei maxstep = BUFFERSIZE / ALSource->NumChannels;
|
2011-08-17 01:54:09 -07:00
|
|
|
maxstep -= ResamplerPadding[Resampler] +
|
|
|
|
ResamplerPrePadding[Resampler] + 1;
|
2011-08-16 18:33:10 -07:00
|
|
|
maxstep = mini(maxstep, INT_MAX>>FRACTIONBITS);
|
2010-11-26 17:47:43 -08:00
|
|
|
|
2010-11-28 13:08:51 -08:00
|
|
|
Pitch = Pitch * ALBuffer->Frequency / Frequency;
|
2010-11-26 17:47:43 -08:00
|
|
|
if(Pitch > (ALfloat)maxstep)
|
|
|
|
ALSource->Params.Step = maxstep<<FRACTIONBITS;
|
|
|
|
else
|
|
|
|
{
|
2011-09-29 03:51:46 -07:00
|
|
|
ALSource->Params.Step = fastf2i(Pitch*FRACTIONONE);
|
2010-11-26 17:47:43 -08:00
|
|
|
if(ALSource->Params.Step == 0)
|
|
|
|
ALSource->Params.Step = 1;
|
|
|
|
}
|
2012-09-14 04:13:18 -07:00
|
|
|
ALSource->Params.Resample = SelectResampler(Resampler, ALSource->Params.Step);
|
2010-11-26 17:47:43 -08:00
|
|
|
|
2010-11-27 00:15:07 -08:00
|
|
|
Channels = ALBuffer->FmtChannels;
|
2010-08-07 00:38:02 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
BufferListItem = BufferListItem->next;
|
|
|
|
}
|
2012-02-09 23:35:17 -08:00
|
|
|
if(!DirectChannels && Device->Hrtf)
|
2012-09-08 21:34:36 -07:00
|
|
|
ALSource->Params.DryMix = SelectHrtfMixer();
|
2011-10-04 09:55:36 -07:00
|
|
|
else
|
2012-09-08 21:34:36 -07:00
|
|
|
ALSource->Params.DryMix = SelectDirectMixer();
|
|
|
|
ALSource->Params.WetMix = SelectSendMixer();
|
2010-08-05 01:07:20 -07:00
|
|
|
|
2010-11-26 18:01:29 -08:00
|
|
|
/* Calculate gains */
|
2011-08-31 02:18:16 -07:00
|
|
|
DryGain = clampf(SourceVolume, MinVolume, MaxVolume);
|
2012-04-28 03:13:37 -07:00
|
|
|
DryGain *= ALSource->DirectGain * ListenerGain;
|
2011-08-31 02:18:16 -07:00
|
|
|
DryGainHF = ALSource->DirectGainHF;
|
2011-07-05 11:00:52 -07:00
|
|
|
for(i = 0;i < NumSends;i++)
|
|
|
|
{
|
2011-08-31 02:18:16 -07:00
|
|
|
WetGain[i] = clampf(SourceVolume, MinVolume, MaxVolume);
|
2012-04-28 03:13:37 -07:00
|
|
|
WetGain[i] *= ALSource->Send[i].Gain * ListenerGain;
|
2012-04-27 00:45:42 -07:00
|
|
|
WetGainHF[i] = ALSource->Send[i].GainHF;
|
2011-07-05 11:00:52 -07:00
|
|
|
}
|
2010-08-05 01:07:20 -07:00
|
|
|
|
2012-04-27 00:45:42 -07:00
|
|
|
SrcMatrix = ALSource->Params.Direct.Gains;
|
2012-06-28 18:49:49 -07:00
|
|
|
for(i = 0;i < MaxChannels;i++)
|
2010-08-05 01:07:20 -07:00
|
|
|
{
|
2012-06-28 18:49:49 -07:00
|
|
|
for(c = 0;c < MaxChannels;c++)
|
2011-05-06 23:25:15 -07:00
|
|
|
SrcMatrix[i][c] = 0.0f;
|
2010-12-09 16:37:23 -08:00
|
|
|
}
|
|
|
|
switch(Channels)
|
|
|
|
{
|
|
|
|
case FmtMono:
|
2011-12-20 01:17:11 -08:00
|
|
|
chans = MonoMap;
|
2011-05-15 02:12:42 -07:00
|
|
|
num_channels = 1;
|
2010-12-09 16:37:23 -08:00
|
|
|
break;
|
2011-05-15 00:18:28 -07:00
|
|
|
|
2012-04-29 04:44:53 -07:00
|
|
|
case FmtStereo:
|
2012-08-09 05:38:07 -07:00
|
|
|
if(!(Device->Flags&DEVICE_WIDE_STEREO))
|
|
|
|
chans = StereoMap;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
chans = StereoWideMap;
|
|
|
|
hwidth = 60.0f * F_PI/180.0f;
|
|
|
|
}
|
2011-06-17 16:20:18 -07:00
|
|
|
num_channels = 2;
|
2010-12-09 16:37:23 -08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case FmtRear:
|
2011-12-20 01:17:11 -08:00
|
|
|
chans = RearMap;
|
2011-05-15 02:12:42 -07:00
|
|
|
num_channels = 2;
|
2010-12-09 16:37:23 -08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case FmtQuad:
|
2011-12-20 01:17:11 -08:00
|
|
|
chans = QuadMap;
|
2011-05-15 02:12:42 -07:00
|
|
|
num_channels = 4;
|
2010-12-09 16:37:23 -08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case FmtX51:
|
2011-12-20 01:17:11 -08:00
|
|
|
chans = X51Map;
|
2011-05-15 02:12:42 -07:00
|
|
|
num_channels = 6;
|
2010-12-09 16:37:23 -08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case FmtX61:
|
2011-12-20 01:17:11 -08:00
|
|
|
chans = X61Map;
|
2011-05-15 02:12:42 -07:00
|
|
|
num_channels = 7;
|
2010-12-09 16:37:23 -08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case FmtX71:
|
2011-12-20 01:17:11 -08:00
|
|
|
chans = X71Map;
|
2011-05-15 02:12:42 -07:00
|
|
|
num_channels = 8;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-02-09 23:35:17 -08:00
|
|
|
if(DirectChannels != AL_FALSE)
|
2011-06-29 23:18:49 -07:00
|
|
|
{
|
|
|
|
for(c = 0;c < num_channels;c++)
|
2012-03-12 18:27:25 -07:00
|
|
|
{
|
|
|
|
for(i = 0;i < (ALint)Device->NumChan;i++)
|
|
|
|
{
|
|
|
|
enum Channel chan = Device->Speaker2Chan[i];
|
|
|
|
if(chan == chans[c].channel)
|
|
|
|
{
|
2012-04-28 03:13:37 -07:00
|
|
|
SrcMatrix[c][chan] += DryGain;
|
2012-03-12 18:27:25 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-06-29 23:18:49 -07:00
|
|
|
}
|
2011-10-06 01:16:07 -07:00
|
|
|
else if(Device->Hrtf)
|
2011-05-15 02:12:42 -07:00
|
|
|
{
|
2011-06-17 16:20:18 -07:00
|
|
|
for(c = 0;c < num_channels;c++)
|
2011-05-02 02:22:30 -07:00
|
|
|
{
|
2011-12-20 01:17:11 -08:00
|
|
|
if(chans[c].channel == LFE)
|
2011-06-17 16:20:18 -07:00
|
|
|
{
|
|
|
|
/* Skip LFE */
|
2012-04-28 02:23:53 -07:00
|
|
|
ALSource->Params.Direct.Hrtf.Delay[c][0] = 0;
|
|
|
|
ALSource->Params.Direct.Hrtf.Delay[c][1] = 0;
|
2011-06-17 16:20:18 -07:00
|
|
|
for(i = 0;i < HRIR_LENGTH;i++)
|
2011-05-25 19:04:19 -07:00
|
|
|
{
|
2012-04-28 02:23:53 -07:00
|
|
|
ALSource->Params.Direct.Hrtf.Coeffs[c][i][0] = 0.0f;
|
|
|
|
ALSource->Params.Direct.Hrtf.Coeffs[c][i][1] = 0.0f;
|
2011-05-25 19:04:19 -07:00
|
|
|
}
|
2011-06-17 16:20:18 -07:00
|
|
|
}
|
2011-07-16 16:24:01 -07:00
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Get the static HRIR coefficients and delays for this
|
|
|
|
* channel. */
|
2011-10-11 22:30:58 -07:00
|
|
|
GetLerpedHrtfCoeffs(Device->Hrtf,
|
2012-04-28 03:13:37 -07:00
|
|
|
0.0f, chans[c].angle, DryGain,
|
2012-04-28 02:23:53 -07:00
|
|
|
ALSource->Params.Direct.Hrtf.Coeffs[c],
|
|
|
|
ALSource->Params.Direct.Hrtf.Delay[c]);
|
2011-07-16 16:24:01 -07:00
|
|
|
}
|
2011-05-02 02:22:30 -07:00
|
|
|
}
|
2012-04-27 00:45:42 -07:00
|
|
|
ALSource->Hrtf.Counter = 0;
|
2011-06-17 16:20:18 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-08-09 05:38:07 -07:00
|
|
|
DryGain *= lerp(1.0f, 1.0f/sqrtf(Device->NumChan), hwidth/(F_PI*2.0f));
|
2011-06-17 16:20:18 -07:00
|
|
|
for(c = 0;c < num_channels;c++)
|
2011-05-02 02:22:30 -07:00
|
|
|
{
|
2012-04-26 00:59:17 -07:00
|
|
|
/* Special-case LFE */
|
|
|
|
if(chans[c].channel == LFE)
|
2011-04-14 21:03:37 -07:00
|
|
|
{
|
2012-04-29 05:04:46 -07:00
|
|
|
SrcMatrix[c][chans[c].channel] = DryGain;
|
2011-06-17 16:20:18 -07:00
|
|
|
continue;
|
|
|
|
}
|
2012-08-09 05:38:07 -07:00
|
|
|
ComputeAngleGains(Device, chans[c].angle, hwidth, DryGain,
|
2012-04-29 05:04:46 -07:00
|
|
|
SrcMatrix[c]);
|
2011-04-14 21:03:37 -07:00
|
|
|
}
|
|
|
|
}
|
2009-12-09 07:02:26 -08:00
|
|
|
for(i = 0;i < NumSends;i++)
|
2011-07-05 14:14:20 -07:00
|
|
|
{
|
2012-01-19 19:30:03 -08:00
|
|
|
ALeffectslot *Slot = ALSource->Send[i].Slot;
|
|
|
|
|
|
|
|
if(!Slot && i == 0)
|
|
|
|
Slot = Device->DefaultSlot;
|
2012-01-23 06:29:03 -08:00
|
|
|
if(Slot && Slot->effect.type == AL_EFFECT_NULL)
|
|
|
|
Slot = NULL;
|
2012-09-08 22:32:30 -07:00
|
|
|
ALSource->Params.Send[i].Slot = Slot;
|
2012-04-28 03:13:37 -07:00
|
|
|
ALSource->Params.Send[i].Gain = WetGain[i];
|
2011-07-05 14:14:20 -07:00
|
|
|
}
|
2009-12-09 07:02:26 -08:00
|
|
|
|
|
|
|
/* Update filter coefficients. Calculations based on the I3DL2
|
|
|
|
* spec. */
|
2012-06-29 02:12:36 -07:00
|
|
|
cw = cosf(F_PI*2.0f * LOWPASSFREQREF / Frequency);
|
2009-12-09 07:21:59 -08:00
|
|
|
|
2009-12-09 07:02:26 -08:00
|
|
|
/* We use two chained one-pole filters, so we need to take the
|
|
|
|
* square root of the squared gain, which is the same as the base
|
|
|
|
* gain. */
|
2012-04-27 00:45:42 -07:00
|
|
|
ALSource->Params.Direct.iirFilter.coeff = lpCoeffCalc(DryGainHF, cw);
|
2009-12-09 07:02:26 -08:00
|
|
|
for(i = 0;i < NumSends;i++)
|
|
|
|
{
|
2012-04-30 09:33:00 -07:00
|
|
|
ALfloat a = lpCoeffCalc(WetGainHF[i], cw);
|
2009-12-09 07:02:26 -08:00
|
|
|
ALSource->Params.Send[i].iirFilter.coeff = a;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-03 23:10:00 -07:00
|
|
|
ALvoid CalcSourceParams(ALsource *ALSource, const ALCcontext *ALContext)
|
2007-11-13 18:02:18 -08:00
|
|
|
{
|
2010-04-27 11:39:54 -07:00
|
|
|
const ALCdevice *Device = ALContext->Device;
|
2011-06-21 12:55:21 -07:00
|
|
|
ALfloat InnerAngle,OuterAngle,Angle,Distance,ClampedDist;
|
2008-01-15 21:57:50 -08:00
|
|
|
ALfloat Direction[3],Position[3],SourceToListener[3];
|
2009-11-22 22:36:20 -08:00
|
|
|
ALfloat Velocity[3],ListenerVel[3];
|
2011-05-06 02:53:22 -07:00
|
|
|
ALfloat MinVolume,MaxVolume,MinDist,MaxDist,Rolloff;
|
2009-04-13 02:50:40 -07:00
|
|
|
ALfloat ConeVolume,ConeHF,SourceVolume,ListenerGain;
|
2012-03-08 18:19:15 -08:00
|
|
|
ALfloat DopplerFactor, SpeedOfSound;
|
2010-09-12 00:10:33 -07:00
|
|
|
ALfloat AirAbsorptionFactor;
|
2011-07-05 11:00:52 -07:00
|
|
|
ALfloat RoomAirAbsorption[MAX_SENDS];
|
2010-08-07 00:38:02 -07:00
|
|
|
ALbufferlistitem *BufferListItem;
|
2012-03-14 22:45:52 -07:00
|
|
|
ALfloat Attenuation;
|
2009-04-11 20:04:46 -07:00
|
|
|
ALfloat RoomAttenuation[MAX_SENDS];
|
2007-12-17 19:40:43 -08:00
|
|
|
ALfloat MetersPerUnit;
|
2011-07-05 11:00:52 -07:00
|
|
|
ALfloat RoomRolloffBase;
|
2009-04-11 20:04:46 -07:00
|
|
|
ALfloat RoomRolloff[MAX_SENDS];
|
2011-07-05 11:00:52 -07:00
|
|
|
ALfloat DecayDistance[MAX_SENDS];
|
2010-10-10 03:47:57 -07:00
|
|
|
ALfloat DryGain;
|
|
|
|
ALfloat DryGainHF;
|
2011-07-05 11:00:52 -07:00
|
|
|
ALboolean DryGainHFAuto;
|
2009-10-21 15:31:21 -07:00
|
|
|
ALfloat WetGain[MAX_SENDS];
|
2009-10-21 13:08:50 -07:00
|
|
|
ALfloat WetGainHF[MAX_SENDS];
|
2011-07-01 01:46:56 -07:00
|
|
|
ALboolean WetGainAuto;
|
|
|
|
ALboolean WetGainHFAuto;
|
2011-08-17 01:54:09 -07:00
|
|
|
enum Resampler Resampler;
|
2012-03-09 23:53:45 -08:00
|
|
|
ALfloat Matrix[4][4];
|
2010-08-07 00:38:02 -07:00
|
|
|
ALfloat Pitch;
|
2009-10-21 13:08:50 -07:00
|
|
|
ALuint Frequency;
|
2009-04-13 20:33:41 -07:00
|
|
|
ALint NumSends;
|
2009-12-09 07:21:59 -08:00
|
|
|
ALfloat cw;
|
2012-03-09 23:53:45 -08:00
|
|
|
ALint i, j;
|
2007-11-13 18:02:18 -08:00
|
|
|
|
2010-10-10 03:47:57 -07:00
|
|
|
DryGainHF = 1.0f;
|
2009-12-01 03:32:04 -08:00
|
|
|
for(i = 0;i < MAX_SENDS;i++)
|
|
|
|
WetGainHF[i] = 1.0f;
|
|
|
|
|
2012-04-26 00:59:17 -07:00
|
|
|
/* Get context/device properties */
|
2012-03-08 18:19:15 -08:00
|
|
|
DopplerFactor = ALContext->DopplerFactor * ALSource->DopplerFactor;
|
2012-04-19 22:50:11 -07:00
|
|
|
SpeedOfSound = ALContext->SpeedOfSound * ALContext->DopplerVelocity;
|
2012-03-08 18:19:15 -08:00
|
|
|
NumSends = Device->NumAuxSends;
|
|
|
|
Frequency = Device->Frequency;
|
2007-11-13 18:02:18 -08:00
|
|
|
|
2012-04-26 00:59:17 -07:00
|
|
|
/* Get listener properties */
|
2011-09-11 01:26:09 -07:00
|
|
|
ListenerGain = ALContext->Listener.Gain;
|
|
|
|
MetersPerUnit = ALContext->Listener.MetersPerUnit;
|
|
|
|
ListenerVel[0] = ALContext->Listener.Velocity[0];
|
|
|
|
ListenerVel[1] = ALContext->Listener.Velocity[1];
|
|
|
|
ListenerVel[2] = ALContext->Listener.Velocity[2];
|
2012-04-26 00:59:17 -07:00
|
|
|
for(i = 0;i < 4;i++)
|
|
|
|
{
|
|
|
|
for(j = 0;j < 4;j++)
|
|
|
|
Matrix[i][j] = ALContext->Listener.Matrix[i][j];
|
|
|
|
}
|
2007-11-13 18:02:18 -08:00
|
|
|
|
2012-04-26 00:59:17 -07:00
|
|
|
/* Get source properties */
|
2012-04-19 21:46:29 -07:00
|
|
|
SourceVolume = ALSource->Gain;
|
|
|
|
MinVolume = ALSource->MinGain;
|
|
|
|
MaxVolume = ALSource->MaxGain;
|
|
|
|
Pitch = ALSource->Pitch;
|
2011-09-11 01:18:57 -07:00
|
|
|
Resampler = ALSource->Resampler;
|
2012-04-19 21:46:29 -07:00
|
|
|
Position[0] = ALSource->Position[0];
|
|
|
|
Position[1] = ALSource->Position[1];
|
|
|
|
Position[2] = ALSource->Position[2];
|
|
|
|
Direction[0] = ALSource->Orientation[0];
|
|
|
|
Direction[1] = ALSource->Orientation[1];
|
|
|
|
Direction[2] = ALSource->Orientation[2];
|
|
|
|
Velocity[0] = ALSource->Velocity[0];
|
|
|
|
Velocity[1] = ALSource->Velocity[1];
|
|
|
|
Velocity[2] = ALSource->Velocity[2];
|
|
|
|
MinDist = ALSource->RefDistance;
|
|
|
|
MaxDist = ALSource->MaxDistance;
|
|
|
|
Rolloff = ALSource->RollOffFactor;
|
2012-08-11 06:20:24 -07:00
|
|
|
InnerAngle = ALSource->InnerAngle;
|
|
|
|
OuterAngle = ALSource->OuterAngle;
|
2011-07-05 11:00:52 -07:00
|
|
|
AirAbsorptionFactor = ALSource->AirAbsorptionFactor;
|
2011-09-11 01:18:57 -07:00
|
|
|
DryGainHFAuto = ALSource->DryGainHFAuto;
|
|
|
|
WetGainAuto = ALSource->WetGainAuto;
|
|
|
|
WetGainHFAuto = ALSource->WetGainHFAuto;
|
2011-07-05 11:00:52 -07:00
|
|
|
RoomRolloffBase = ALSource->RoomRolloffFactor;
|
2011-07-03 03:34:40 -07:00
|
|
|
for(i = 0;i < NumSends;i++)
|
|
|
|
{
|
2011-07-05 11:00:52 -07:00
|
|
|
ALeffectslot *Slot = ALSource->Send[i].Slot;
|
|
|
|
|
2012-01-19 19:30:03 -08:00
|
|
|
if(!Slot && i == 0)
|
|
|
|
Slot = Device->DefaultSlot;
|
2011-07-05 11:00:52 -07:00
|
|
|
if(!Slot || Slot->effect.type == AL_EFFECT_NULL)
|
|
|
|
{
|
2012-01-23 06:29:03 -08:00
|
|
|
Slot = NULL;
|
2011-07-05 11:00:52 -07:00
|
|
|
RoomRolloff[i] = 0.0f;
|
|
|
|
DecayDistance[i] = 0.0f;
|
2011-07-11 22:07:37 -07:00
|
|
|
RoomAirAbsorption[i] = 1.0f;
|
2011-07-05 11:00:52 -07:00
|
|
|
}
|
|
|
|
else if(Slot->AuxSendAuto)
|
|
|
|
{
|
|
|
|
RoomRolloff[i] = RoomRolloffBase;
|
|
|
|
if(IsReverbEffect(Slot->effect.type))
|
|
|
|
{
|
2011-09-11 07:42:23 -07:00
|
|
|
RoomRolloff[i] += Slot->effect.Reverb.RoomRolloffFactor;
|
|
|
|
DecayDistance[i] = Slot->effect.Reverb.DecayTime *
|
2011-07-05 11:00:52 -07:00
|
|
|
SPEEDOFSOUNDMETRESPERSEC;
|
2011-09-11 07:42:23 -07:00
|
|
|
RoomAirAbsorption[i] = Slot->effect.Reverb.AirAbsorptionGainHF;
|
2011-07-05 11:00:52 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
DecayDistance[i] = 0.0f;
|
2011-07-11 22:07:37 -07:00
|
|
|
RoomAirAbsorption[i] = 1.0f;
|
2011-07-05 11:00:52 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* If the slot's auxiliary send auto is off, the data sent to the
|
|
|
|
* effect slot is the same as the dry path, sans filter effects */
|
|
|
|
RoomRolloff[i] = Rolloff;
|
|
|
|
DecayDistance[i] = 0.0f;
|
|
|
|
RoomAirAbsorption[i] = AIRABSORBGAINHF;
|
|
|
|
}
|
2011-07-05 14:14:20 -07:00
|
|
|
|
2012-09-08 22:32:30 -07:00
|
|
|
ALSource->Params.Send[i].Slot = Slot;
|
2011-07-03 03:34:40 -07:00
|
|
|
}
|
2007-11-13 18:02:18 -08:00
|
|
|
|
2012-04-26 00:59:17 -07:00
|
|
|
/* Transform source to listener space (convert to head relative) */
|
2012-04-19 21:46:29 -07:00
|
|
|
if(ALSource->HeadRelative == AL_FALSE)
|
2009-10-19 13:25:40 -07:00
|
|
|
{
|
2011-10-30 08:27:24 -07:00
|
|
|
/* Translate position */
|
2012-03-18 08:09:59 -07:00
|
|
|
Position[0] -= ALContext->Listener.Position[0];
|
|
|
|
Position[1] -= ALContext->Listener.Position[1];
|
|
|
|
Position[2] -= ALContext->Listener.Position[2];
|
2011-10-30 08:27:24 -07:00
|
|
|
|
2012-04-26 00:59:17 -07:00
|
|
|
/* Transform source vectors */
|
2011-10-30 08:27:24 -07:00
|
|
|
aluMatrixVector(Position, 1.0f, Matrix);
|
|
|
|
aluMatrixVector(Direction, 0.0f, Matrix);
|
|
|
|
aluMatrixVector(Velocity, 0.0f, Matrix);
|
2012-04-26 00:59:17 -07:00
|
|
|
/* Transform listener velocity */
|
2012-03-08 18:27:05 -08:00
|
|
|
aluMatrixVector(ListenerVel, 0.0f, Matrix);
|
2009-10-19 13:25:40 -07:00
|
|
|
}
|
|
|
|
else
|
2011-10-30 05:49:17 -07:00
|
|
|
{
|
2012-04-26 00:59:17 -07:00
|
|
|
/* Transform listener velocity from world space to listener space */
|
2012-03-09 23:53:45 -08:00
|
|
|
aluMatrixVector(ListenerVel, 0.0f, Matrix);
|
|
|
|
/* Offset the source velocity to be relative of the listener velocity */
|
|
|
|
Velocity[0] += ListenerVel[0];
|
|
|
|
Velocity[1] += ListenerVel[1];
|
|
|
|
Velocity[2] += ListenerVel[2];
|
2011-10-30 05:49:17 -07:00
|
|
|
}
|
2009-11-22 22:36:20 -08:00
|
|
|
|
|
|
|
SourceToListener[0] = -Position[0];
|
|
|
|
SourceToListener[1] = -Position[1];
|
|
|
|
SourceToListener[2] = -Position[2];
|
2009-10-19 13:25:40 -07:00
|
|
|
aluNormalize(SourceToListener);
|
|
|
|
aluNormalize(Direction);
|
2007-11-13 18:02:18 -08:00
|
|
|
|
2012-04-26 00:59:17 -07:00
|
|
|
/* Calculate distance attenuation */
|
2012-06-29 02:12:36 -07:00
|
|
|
Distance = sqrtf(aluDotproduct(Position, Position));
|
2011-06-21 12:55:21 -07:00
|
|
|
ClampedDist = Distance;
|
2009-10-19 13:25:40 -07:00
|
|
|
|
2010-10-10 04:00:50 -07:00
|
|
|
Attenuation = 1.0f;
|
2009-12-06 03:59:12 -08:00
|
|
|
for(i = 0;i < NumSends;i++)
|
2009-10-19 13:25:40 -07:00
|
|
|
RoomAttenuation[i] = 1.0f;
|
2009-11-27 20:05:21 -08:00
|
|
|
switch(ALContext->SourceDistanceModel ? ALSource->DistanceModel :
|
|
|
|
ALContext->DistanceModel)
|
2009-10-19 13:25:40 -07:00
|
|
|
{
|
2011-07-03 19:39:19 -07:00
|
|
|
case InverseDistanceClamped:
|
2011-08-16 18:40:21 -07:00
|
|
|
ClampedDist = clampf(ClampedDist, MinDist, MaxDist);
|
2009-10-19 13:25:40 -07:00
|
|
|
if(MaxDist < MinDist)
|
|
|
|
break;
|
2012-04-26 00:59:17 -07:00
|
|
|
/*fall-through*/
|
2011-07-03 19:39:19 -07:00
|
|
|
case InverseDistance:
|
2009-10-19 13:25:40 -07:00
|
|
|
if(MinDist > 0.0f)
|
|
|
|
{
|
2011-06-21 12:55:21 -07:00
|
|
|
if((MinDist + (Rolloff * (ClampedDist - MinDist))) > 0.0f)
|
|
|
|
Attenuation = MinDist / (MinDist + (Rolloff * (ClampedDist - MinDist)));
|
2009-10-19 13:25:40 -07:00
|
|
|
for(i = 0;i < NumSends;i++)
|
2007-12-18 19:03:40 -08:00
|
|
|
{
|
2011-06-21 12:55:21 -07:00
|
|
|
if((MinDist + (RoomRolloff[i] * (ClampedDist - MinDist))) > 0.0f)
|
|
|
|
RoomAttenuation[i] = MinDist / (MinDist + (RoomRolloff[i] * (ClampedDist - MinDist)));
|
2007-12-18 19:03:40 -08:00
|
|
|
}
|
2009-10-19 13:25:40 -07:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2011-07-03 19:39:19 -07:00
|
|
|
case LinearDistanceClamped:
|
2011-08-16 18:40:21 -07:00
|
|
|
ClampedDist = clampf(ClampedDist, MinDist, MaxDist);
|
2009-10-19 13:25:40 -07:00
|
|
|
if(MaxDist < MinDist)
|
2007-11-13 18:02:18 -08:00
|
|
|
break;
|
2012-04-26 00:59:17 -07:00
|
|
|
/*fall-through*/
|
2011-07-03 19:39:19 -07:00
|
|
|
case LinearDistance:
|
2009-10-19 13:25:40 -07:00
|
|
|
if(MaxDist != MinDist)
|
|
|
|
{
|
2011-06-21 12:55:21 -07:00
|
|
|
Attenuation = 1.0f - (Rolloff*(ClampedDist-MinDist)/(MaxDist - MinDist));
|
2011-08-16 18:40:21 -07:00
|
|
|
Attenuation = maxf(Attenuation, 0.0f);
|
2009-10-19 13:25:40 -07:00
|
|
|
for(i = 0;i < NumSends;i++)
|
2010-09-24 13:16:09 -07:00
|
|
|
{
|
2011-06-21 12:55:21 -07:00
|
|
|
RoomAttenuation[i] = 1.0f - (RoomRolloff[i]*(ClampedDist-MinDist)/(MaxDist - MinDist));
|
2011-08-16 18:40:21 -07:00
|
|
|
RoomAttenuation[i] = maxf(RoomAttenuation[i], 0.0f);
|
2010-09-24 13:16:09 -07:00
|
|
|
}
|
2009-10-19 13:25:40 -07:00
|
|
|
}
|
|
|
|
break;
|
2007-11-13 18:02:18 -08:00
|
|
|
|
2011-07-03 19:39:19 -07:00
|
|
|
case ExponentDistanceClamped:
|
2011-08-16 18:40:21 -07:00
|
|
|
ClampedDist = clampf(ClampedDist, MinDist, MaxDist);
|
2009-10-19 13:25:40 -07:00
|
|
|
if(MaxDist < MinDist)
|
2007-11-13 18:02:18 -08:00
|
|
|
break;
|
2012-04-26 00:59:17 -07:00
|
|
|
/*fall-through*/
|
2011-07-03 19:39:19 -07:00
|
|
|
case ExponentDistance:
|
2011-06-21 12:55:21 -07:00
|
|
|
if(ClampedDist > 0.0f && MinDist > 0.0f)
|
2009-10-19 13:25:40 -07:00
|
|
|
{
|
2012-06-29 02:12:36 -07:00
|
|
|
Attenuation = powf(ClampedDist/MinDist, -Rolloff);
|
2009-10-19 13:25:40 -07:00
|
|
|
for(i = 0;i < NumSends;i++)
|
2012-06-29 02:12:36 -07:00
|
|
|
RoomAttenuation[i] = powf(ClampedDist/MinDist, -RoomRolloff[i]);
|
2009-10-19 13:25:40 -07:00
|
|
|
}
|
|
|
|
break;
|
2007-11-13 18:02:18 -08:00
|
|
|
|
2011-07-03 19:39:19 -07:00
|
|
|
case DisableDistance:
|
2012-03-14 22:45:52 -07:00
|
|
|
ClampedDist = MinDist;
|
2009-10-19 13:25:40 -07:00
|
|
|
break;
|
|
|
|
}
|
2009-04-11 20:27:55 -07:00
|
|
|
|
2012-04-26 00:59:17 -07:00
|
|
|
/* Source Gain + Attenuation */
|
2011-06-18 16:45:26 -07:00
|
|
|
DryGain = SourceVolume * Attenuation;
|
2011-07-05 11:00:52 -07:00
|
|
|
for(i = 0;i < NumSends;i++)
|
|
|
|
WetGain[i] = SourceVolume * RoomAttenuation[i];
|
2011-06-18 16:45:26 -07:00
|
|
|
|
2012-04-26 00:59:17 -07:00
|
|
|
/* Distance-based air absorption */
|
2012-03-18 08:09:59 -07:00
|
|
|
if(AirAbsorptionFactor > 0.0f && ClampedDist > MinDist)
|
2011-07-05 11:00:52 -07:00
|
|
|
{
|
2012-03-18 08:09:59 -07:00
|
|
|
ALfloat meters = maxf(ClampedDist-MinDist, 0.0f) * MetersPerUnit;
|
2012-06-29 02:12:36 -07:00
|
|
|
DryGainHF *= powf(AIRABSORBGAINHF, AirAbsorptionFactor*meters);
|
2011-07-05 11:00:52 -07:00
|
|
|
for(i = 0;i < NumSends;i++)
|
2012-06-29 02:12:36 -07:00
|
|
|
WetGainHF[i] *= powf(RoomAirAbsorption[i], AirAbsorptionFactor*meters);
|
2011-07-05 11:00:52 -07:00
|
|
|
}
|
2007-11-13 18:02:18 -08:00
|
|
|
|
2012-03-18 08:06:21 -07:00
|
|
|
if(WetGainAuto)
|
2011-09-30 17:51:21 -07:00
|
|
|
{
|
2012-03-18 08:06:21 -07:00
|
|
|
ALfloat ApparentDist = 1.0f/maxf(Attenuation, 0.00001f) - 1.0f;
|
|
|
|
|
2011-09-30 17:51:21 -07:00
|
|
|
/* Apply a decay-time transformation to the wet path, based on the
|
|
|
|
* attenuation of the dry path.
|
|
|
|
*
|
2012-03-18 08:06:21 -07:00
|
|
|
* Using the apparent distance, based on the distance attenuation, the
|
|
|
|
* initial decay of the reverb effect is calculated and applied to the
|
|
|
|
* wet path.
|
2011-09-30 17:51:21 -07:00
|
|
|
*/
|
|
|
|
for(i = 0;i < NumSends;i++)
|
|
|
|
{
|
|
|
|
if(DecayDistance[i] > 0.0f)
|
2012-06-29 02:12:36 -07:00
|
|
|
WetGain[i] *= powf(0.001f/*-60dB*/, ApparentDist/DecayDistance[i]);
|
2011-09-30 17:51:21 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Calculate directional soundcones */
|
2012-08-11 06:20:24 -07:00
|
|
|
Angle = acosf(aluDotproduct(Direction,SourceToListener)) * ConeScale * (360.0f/F_PI);
|
2012-04-26 00:59:17 -07:00
|
|
|
if(Angle > InnerAngle && Angle <= OuterAngle)
|
2009-10-19 13:25:40 -07:00
|
|
|
{
|
|
|
|
ALfloat scale = (Angle-InnerAngle) / (OuterAngle-InnerAngle);
|
2012-04-19 21:46:29 -07:00
|
|
|
ConeVolume = lerp(1.0f, ALSource->OuterGain, scale);
|
2011-09-23 23:03:59 -07:00
|
|
|
ConeHF = lerp(1.0f, ALSource->OuterGainHF, scale);
|
2009-10-19 13:25:40 -07:00
|
|
|
}
|
|
|
|
else if(Angle > OuterAngle)
|
|
|
|
{
|
2012-04-19 21:46:29 -07:00
|
|
|
ConeVolume = ALSource->OuterGain;
|
2011-05-06 02:53:22 -07:00
|
|
|
ConeHF = ALSource->OuterGainHF;
|
2009-10-19 13:25:40 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ConeVolume = 1.0f;
|
|
|
|
ConeHF = 1.0f;
|
|
|
|
}
|
2008-01-15 21:57:50 -08:00
|
|
|
|
2010-10-10 03:47:57 -07:00
|
|
|
DryGain *= ConeVolume;
|
2011-07-05 11:00:52 -07:00
|
|
|
if(WetGainAuto)
|
|
|
|
{
|
|
|
|
for(i = 0;i < NumSends;i++)
|
|
|
|
WetGain[i] *= ConeVolume;
|
|
|
|
}
|
|
|
|
if(DryGainHFAuto)
|
2009-12-08 14:18:07 -08:00
|
|
|
DryGainHF *= ConeHF;
|
2011-07-05 11:00:52 -07:00
|
|
|
if(WetGainHFAuto)
|
|
|
|
{
|
|
|
|
for(i = 0;i < NumSends;i++)
|
2011-08-13 06:58:05 -07:00
|
|
|
WetGainHF[i] *= ConeHF;
|
2011-07-05 11:00:52 -07:00
|
|
|
}
|
2009-12-08 14:18:07 -08:00
|
|
|
|
2012-04-26 00:59:17 -07:00
|
|
|
/* Clamp to Min/Max Gain */
|
2011-08-16 18:40:21 -07:00
|
|
|
DryGain = clampf(DryGain, MinVolume, MaxVolume);
|
2009-10-19 13:25:40 -07:00
|
|
|
for(i = 0;i < NumSends;i++)
|
2011-08-16 18:40:21 -07:00
|
|
|
WetGain[i] = clampf(WetGain[i], MinVolume, MaxVolume);
|
2010-03-07 22:12:33 -08:00
|
|
|
|
2012-04-26 00:59:17 -07:00
|
|
|
/* Apply gain and frequency filters */
|
2011-08-31 02:18:16 -07:00
|
|
|
DryGain *= ALSource->DirectGain * ListenerGain;
|
|
|
|
DryGainHF *= ALSource->DirectGainHF;
|
2011-07-05 11:00:52 -07:00
|
|
|
for(i = 0;i < NumSends;i++)
|
|
|
|
{
|
2012-04-27 00:45:42 -07:00
|
|
|
WetGain[i] *= ALSource->Send[i].Gain * ListenerGain;
|
|
|
|
WetGainHF[i] *= ALSource->Send[i].GainHF;
|
2007-11-13 18:02:18 -08:00
|
|
|
}
|
2008-01-19 00:49:05 -08:00
|
|
|
|
2012-04-26 00:59:17 -07:00
|
|
|
/* Calculate velocity-based doppler effect */
|
2012-03-18 08:20:08 -07:00
|
|
|
if(DopplerFactor > 0.0f)
|
2009-12-01 03:32:04 -08:00
|
|
|
{
|
2010-10-10 04:00:50 -07:00
|
|
|
ALfloat VSS, VLS;
|
2012-03-08 18:19:15 -08:00
|
|
|
|
2012-03-18 08:20:08 -07:00
|
|
|
if(SpeedOfSound < 1.0f)
|
|
|
|
{
|
|
|
|
DopplerFactor *= 1.0f/SpeedOfSound;
|
|
|
|
SpeedOfSound = 1.0f;
|
|
|
|
}
|
|
|
|
|
2012-03-08 18:19:15 -08:00
|
|
|
VSS = aluDotproduct(Velocity, SourceToListener) * DopplerFactor;
|
|
|
|
VLS = aluDotproduct(ListenerVel, SourceToListener) * DopplerFactor;
|
|
|
|
|
2012-03-09 22:38:26 -08:00
|
|
|
Pitch *= clampf(SpeedOfSound-VLS, 1.0f, SpeedOfSound*2.0f - 1.0f) /
|
|
|
|
clampf(SpeedOfSound-VSS, 1.0f, SpeedOfSound*2.0f - 1.0f);
|
2009-12-01 03:32:04 -08:00
|
|
|
}
|
2010-08-07 00:38:02 -07:00
|
|
|
|
|
|
|
BufferListItem = ALSource->queue;
|
|
|
|
while(BufferListItem != NULL)
|
|
|
|
{
|
|
|
|
ALbuffer *ALBuffer;
|
|
|
|
if((ALBuffer=BufferListItem->buffer) != NULL)
|
|
|
|
{
|
2012-04-26 00:59:17 -07:00
|
|
|
/* Calculate fixed-point stepping value, based on the pitch, buffer
|
|
|
|
* frequency, and output frequency. */
|
2012-09-08 22:09:34 -07:00
|
|
|
ALsizei maxstep = BUFFERSIZE / ALSource->NumChannels;
|
2011-08-17 01:54:09 -07:00
|
|
|
maxstep -= ResamplerPadding[Resampler] +
|
|
|
|
ResamplerPrePadding[Resampler] + 1;
|
2011-08-16 18:33:10 -07:00
|
|
|
maxstep = mini(maxstep, INT_MAX>>FRACTIONBITS);
|
2010-11-26 17:47:43 -08:00
|
|
|
|
2010-11-28 13:08:51 -08:00
|
|
|
Pitch = Pitch * ALBuffer->Frequency / Frequency;
|
2010-11-26 17:47:43 -08:00
|
|
|
if(Pitch > (ALfloat)maxstep)
|
|
|
|
ALSource->Params.Step = maxstep<<FRACTIONBITS;
|
|
|
|
else
|
|
|
|
{
|
2011-09-29 03:51:46 -07:00
|
|
|
ALSource->Params.Step = fastf2i(Pitch*FRACTIONONE);
|
2010-11-26 17:47:43 -08:00
|
|
|
if(ALSource->Params.Step == 0)
|
|
|
|
ALSource->Params.Step = 1;
|
|
|
|
}
|
2012-09-14 04:13:18 -07:00
|
|
|
ALSource->Params.Resample = SelectResampler(Resampler, ALSource->Params.Step);
|
2011-06-25 00:08:05 -07:00
|
|
|
|
2010-08-07 00:38:02 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
BufferListItem = BufferListItem->next;
|
|
|
|
}
|
2011-10-06 01:16:07 -07:00
|
|
|
if(Device->Hrtf)
|
2012-09-08 21:34:36 -07:00
|
|
|
ALSource->Params.DryMix = SelectHrtfMixer();
|
2011-10-04 09:55:36 -07:00
|
|
|
else
|
2012-09-08 21:34:36 -07:00
|
|
|
ALSource->Params.DryMix = SelectDirectMixer();
|
|
|
|
ALSource->Params.WetMix = SelectSendMixer();
|
2009-12-01 03:32:04 -08:00
|
|
|
|
2011-10-06 01:16:07 -07:00
|
|
|
if(Device->Hrtf)
|
2010-12-09 16:37:23 -08:00
|
|
|
{
|
2012-04-26 00:59:17 -07:00
|
|
|
/* Use a binaural HRTF algorithm for stereo headphone playback */
|
2011-07-16 16:24:01 -07:00
|
|
|
ALfloat delta, ev = 0.0f, az = 0.0f;
|
|
|
|
|
2011-06-21 12:55:21 -07:00
|
|
|
if(Distance > 0.0f)
|
2011-05-20 07:58:05 -07:00
|
|
|
{
|
2011-06-21 12:55:21 -07:00
|
|
|
ALfloat invlen = 1.0f/Distance;
|
2011-05-20 07:58:05 -07:00
|
|
|
Position[0] *= invlen;
|
|
|
|
Position[1] *= invlen;
|
|
|
|
Position[2] *= invlen;
|
2011-07-16 16:24:01 -07:00
|
|
|
|
2012-04-26 00:59:17 -07:00
|
|
|
/* Calculate elevation and azimuth only when the source is not at
|
|
|
|
* the listener. This prevents +0 and -0 Z from producing
|
2012-06-28 17:26:00 -07:00
|
|
|
* inconsistent panning. Also, clamp Y in case FP precision errors
|
|
|
|
* cause it to land outside of -1..+1. */
|
2012-06-29 02:12:36 -07:00
|
|
|
ev = asinf(clampf(Position[1], -1.0f, 1.0f));
|
|
|
|
az = atan2f(Position[0], -Position[2]*ZScale);
|
2011-07-16 16:24:01 -07:00
|
|
|
}
|
|
|
|
|
2012-04-26 00:59:17 -07:00
|
|
|
/* Check to see if the HRIR is already moving. */
|
2012-04-27 00:45:42 -07:00
|
|
|
if(ALSource->Hrtf.Moving)
|
2011-07-16 16:24:01 -07:00
|
|
|
{
|
2012-04-26 00:59:17 -07:00
|
|
|
/* Calculate the normalized HRTF transition factor (delta). */
|
2012-04-28 02:23:53 -07:00
|
|
|
delta = CalcHrtfDelta(ALSource->Params.Direct.Hrtf.Gain, DryGain,
|
|
|
|
ALSource->Params.Direct.Hrtf.Dir, Position);
|
2012-04-26 00:59:17 -07:00
|
|
|
/* If the delta is large enough, get the moving HRIR target
|
|
|
|
* coefficients, target delays, steppping values, and counter. */
|
2011-07-16 16:24:01 -07:00
|
|
|
if(delta > 0.001f)
|
|
|
|
{
|
2012-04-27 00:45:42 -07:00
|
|
|
ALSource->Hrtf.Counter = GetMovingHrtfCoeffs(Device->Hrtf,
|
|
|
|
ev, az, DryGain, delta,
|
|
|
|
ALSource->Hrtf.Counter,
|
2012-04-28 02:23:53 -07:00
|
|
|
ALSource->Params.Direct.Hrtf.Coeffs[0],
|
|
|
|
ALSource->Params.Direct.Hrtf.Delay[0],
|
|
|
|
ALSource->Params.Direct.Hrtf.CoeffStep,
|
|
|
|
ALSource->Params.Direct.Hrtf.DelayStep);
|
|
|
|
ALSource->Params.Direct.Hrtf.Gain = DryGain;
|
|
|
|
ALSource->Params.Direct.Hrtf.Dir[0] = Position[0];
|
|
|
|
ALSource->Params.Direct.Hrtf.Dir[1] = Position[1];
|
|
|
|
ALSource->Params.Direct.Hrtf.Dir[2] = Position[2];
|
2011-07-16 16:24:01 -07:00
|
|
|
}
|
2011-07-05 03:36:14 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-04-26 00:59:17 -07:00
|
|
|
/* Get the initial (static) HRIR coefficients and delays. */
|
2011-09-18 09:52:40 -07:00
|
|
|
GetLerpedHrtfCoeffs(Device->Hrtf, ev, az, DryGain,
|
2012-04-28 02:23:53 -07:00
|
|
|
ALSource->Params.Direct.Hrtf.Coeffs[0],
|
|
|
|
ALSource->Params.Direct.Hrtf.Delay[0]);
|
2012-04-27 00:45:42 -07:00
|
|
|
ALSource->Hrtf.Counter = 0;
|
2012-04-28 02:23:53 -07:00
|
|
|
ALSource->Params.Direct.Hrtf.Gain = DryGain;
|
|
|
|
ALSource->Params.Direct.Hrtf.Dir[0] = Position[0];
|
|
|
|
ALSource->Params.Direct.Hrtf.Dir[1] = Position[1];
|
|
|
|
ALSource->Params.Direct.Hrtf.Dir[2] = Position[2];
|
2011-05-20 07:58:05 -07:00
|
|
|
}
|
2010-12-09 16:37:23 -08:00
|
|
|
}
|
2011-05-01 13:59:44 -07:00
|
|
|
else
|
2009-10-19 13:25:40 -07:00
|
|
|
{
|
2012-06-28 18:49:49 -07:00
|
|
|
ALfloat (*Matrix)[MaxChannels] = ALSource->Params.Direct.Gains;
|
2012-04-28 13:06:16 -07:00
|
|
|
ALfloat DirGain = 0.0f;
|
|
|
|
ALfloat AmbientGain;
|
|
|
|
|
2012-06-28 18:49:49 -07:00
|
|
|
for(i = 0;i < MaxChannels;i++)
|
2012-04-28 13:06:16 -07:00
|
|
|
{
|
2012-06-28 18:49:49 -07:00
|
|
|
for(j = 0;j < MaxChannels;j++)
|
2012-04-28 13:06:16 -07:00
|
|
|
Matrix[i][j] = 0.0f;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Normalize the length, and compute panned gains. */
|
|
|
|
if(Distance > 0.0f)
|
2011-05-20 07:58:05 -07:00
|
|
|
{
|
2012-04-28 13:06:16 -07:00
|
|
|
ALfloat invlen = 1.0f/Distance;
|
2011-05-20 07:58:05 -07:00
|
|
|
Position[0] *= invlen;
|
|
|
|
Position[1] *= invlen;
|
|
|
|
Position[2] *= invlen;
|
|
|
|
|
2012-06-29 02:12:36 -07:00
|
|
|
DirGain = sqrtf(Position[0]*Position[0] + Position[2]*Position[2]);
|
|
|
|
ComputeAngleGains(Device, atan2f(Position[0], -Position[2]*ZScale), 0.0f,
|
2012-04-28 13:06:16 -07:00
|
|
|
DryGain*DirGain, Matrix[0]);
|
|
|
|
}
|
2011-05-01 13:59:44 -07:00
|
|
|
|
2012-04-28 13:06:16 -07:00
|
|
|
/* Adjustment for vertical offsets. Not the greatest, but simple
|
2012-04-26 00:59:17 -07:00
|
|
|
* enough. */
|
2012-06-29 02:12:36 -07:00
|
|
|
AmbientGain = DryGain * sqrtf(1.0f/Device->NumChan) * (1.0f-DirGain);
|
2011-06-29 23:32:48 -07:00
|
|
|
for(i = 0;i < (ALint)Device->NumChan;i++)
|
2011-05-01 13:59:44 -07:00
|
|
|
{
|
2011-07-02 21:33:53 -07:00
|
|
|
enum Channel chan = Device->Speaker2Chan[i];
|
2012-04-28 13:06:16 -07:00
|
|
|
Matrix[0][chan] = maxf(Matrix[0][chan], AmbientGain);
|
2011-05-01 13:59:44 -07:00
|
|
|
}
|
2007-11-13 18:02:18 -08:00
|
|
|
}
|
2011-07-05 11:00:52 -07:00
|
|
|
for(i = 0;i < NumSends;i++)
|
2012-04-27 00:45:42 -07:00
|
|
|
ALSource->Params.Send[i].Gain = WetGain[i];
|
2009-10-21 13:08:50 -07:00
|
|
|
|
|
|
|
/* Update filter coefficients. */
|
2012-06-29 02:12:36 -07:00
|
|
|
cw = cosf(F_PI*2.0f * LOWPASSFREQREF / Frequency);
|
2009-12-09 07:21:59 -08:00
|
|
|
|
2012-04-27 00:45:42 -07:00
|
|
|
ALSource->Params.Direct.iirFilter.coeff = lpCoeffCalc(DryGainHF, cw);
|
2009-10-21 13:08:50 -07:00
|
|
|
for(i = 0;i < NumSends;i++)
|
|
|
|
{
|
2012-04-30 09:33:00 -07:00
|
|
|
ALfloat a = lpCoeffCalc(WetGainHF[i], cw);
|
2011-05-03 16:18:46 -07:00
|
|
|
ALSource->Params.Send[i].iirFilter.coeff = a;
|
2009-10-21 13:08:50 -07:00
|
|
|
}
|
2007-11-13 18:02:18 -08:00
|
|
|
}
|
|
|
|
|
2009-08-26 19:15:17 -07:00
|
|
|
|
2010-12-09 05:06:29 -08:00
|
|
|
static __inline ALfloat aluF2F(ALfloat val)
|
2011-08-17 02:33:25 -07:00
|
|
|
{ return val; }
|
2012-02-14 11:44:57 -08:00
|
|
|
static __inline ALint aluF2I(ALfloat val)
|
2010-11-21 02:51:18 -08:00
|
|
|
{
|
2012-02-14 11:44:57 -08:00
|
|
|
if(val > 1.0f) return 2147483647;
|
|
|
|
if(val < -1.0f) return -2147483647-1;
|
2012-02-17 01:29:23 -08:00
|
|
|
return fastf2i((ALfloat)(val*2147483647.0));
|
2010-11-21 02:51:18 -08:00
|
|
|
}
|
2012-02-14 11:44:57 -08:00
|
|
|
static __inline ALuint aluF2UI(ALfloat val)
|
|
|
|
{ return aluF2I(val)+2147483648u; }
|
|
|
|
static __inline ALshort aluF2S(ALfloat val)
|
|
|
|
{ return aluF2I(val)>>16; }
|
2011-08-17 02:33:25 -07:00
|
|
|
static __inline ALushort aluF2US(ALfloat val)
|
|
|
|
{ return aluF2S(val)+32768; }
|
2010-12-09 05:06:29 -08:00
|
|
|
static __inline ALbyte aluF2B(ALfloat val)
|
2012-02-14 11:44:57 -08:00
|
|
|
{ return aluF2I(val)>>24; }
|
2011-08-17 02:33:25 -07:00
|
|
|
static __inline ALubyte aluF2UB(ALfloat val)
|
2012-02-14 11:44:57 -08:00
|
|
|
{ return aluF2B(val)+128; }
|
2010-11-21 02:51:18 -08:00
|
|
|
|
2012-09-11 06:41:24 -07:00
|
|
|
#define DECL_TEMPLATE(T, func) \
|
2012-10-03 02:35:43 -07:00
|
|
|
static int Write_##T(ALCdevice *device, T *RESTRICT buffer, \
|
|
|
|
ALuint SamplesToDo) \
|
2010-12-01 21:50:49 -08:00
|
|
|
{ \
|
2012-09-11 06:32:42 -07:00
|
|
|
ALfloat (*RESTRICT DryBuffer)[BUFFERSIZE] = device->DryBuffer; \
|
2012-09-11 06:41:24 -07:00
|
|
|
ALuint numchans = ChannelsFromDevFmt(device->FmtChans); \
|
2011-07-17 01:55:25 -07:00
|
|
|
const enum Channel *ChanMap = device->DevChannels; \
|
2011-04-14 21:03:37 -07:00
|
|
|
ALuint i, j; \
|
2010-12-01 21:50:49 -08:00
|
|
|
\
|
2012-09-11 06:41:24 -07:00
|
|
|
for(j = 0;j < numchans;j++) \
|
2010-12-01 21:50:49 -08:00
|
|
|
{ \
|
2012-03-03 10:31:27 -08:00
|
|
|
T *RESTRICT out = buffer + j; \
|
|
|
|
enum Channel chan = ChanMap[j]; \
|
|
|
|
\
|
|
|
|
for(i = 0;i < SamplesToDo;i++) \
|
2012-09-11 06:41:24 -07:00
|
|
|
out[i*numchans] = func(DryBuffer[chan][i]); \
|
2010-12-01 21:50:49 -08:00
|
|
|
} \
|
2012-10-03 02:35:43 -07:00
|
|
|
return SamplesToDo*numchans*sizeof(T); \
|
2010-12-01 21:50:49 -08:00
|
|
|
}
|
|
|
|
|
2012-09-11 06:41:24 -07:00
|
|
|
DECL_TEMPLATE(ALfloat, aluF2F)
|
|
|
|
DECL_TEMPLATE(ALuint, aluF2UI)
|
|
|
|
DECL_TEMPLATE(ALint, aluF2I)
|
|
|
|
DECL_TEMPLATE(ALushort, aluF2US)
|
|
|
|
DECL_TEMPLATE(ALshort, aluF2S)
|
|
|
|
DECL_TEMPLATE(ALubyte, aluF2UB)
|
|
|
|
DECL_TEMPLATE(ALbyte, aluF2B)
|
2010-12-02 16:36:37 -08:00
|
|
|
|
2010-12-01 21:50:49 -08:00
|
|
|
#undef DECL_TEMPLATE
|
|
|
|
|
|
|
|
|
2010-11-21 02:51:18 -08:00
|
|
|
ALvoid aluMixData(ALCdevice *device, ALvoid *buffer, ALsizei size)
|
|
|
|
{
|
|
|
|
ALuint SamplesToDo;
|
2011-08-30 20:13:42 -07:00
|
|
|
ALeffectslot **slot, **slot_end;
|
2010-11-21 02:51:18 -08:00
|
|
|
ALsource **src, **src_end;
|
2011-08-28 19:28:41 -07:00
|
|
|
ALCcontext *ctx;
|
2012-09-16 01:35:16 -07:00
|
|
|
FPUCtl oldMode;
|
2010-12-01 21:50:49 -08:00
|
|
|
ALuint i, c;
|
2010-11-21 02:51:18 -08:00
|
|
|
|
2012-09-16 01:35:16 -07:00
|
|
|
SetMixerFPUMode(&oldMode);
|
2010-11-21 02:51:18 -08:00
|
|
|
|
|
|
|
while(size > 0)
|
|
|
|
{
|
2011-08-16 18:33:10 -07:00
|
|
|
SamplesToDo = minu(size, BUFFERSIZE);
|
2012-09-11 06:32:42 -07:00
|
|
|
for(c = 0;c < MaxChannels;c++)
|
|
|
|
memset(device->DryBuffer[c], 0, SamplesToDo*sizeof(ALfloat));
|
2010-11-21 02:51:18 -08:00
|
|
|
|
2012-08-18 15:58:04 -07:00
|
|
|
ALCdevice_Lock(device);
|
2011-08-28 19:28:41 -07:00
|
|
|
ctx = device->ContextList;
|
|
|
|
while(ctx)
|
2010-11-21 02:51:18 -08:00
|
|
|
{
|
2011-08-29 00:50:55 -07:00
|
|
|
ALenum DeferUpdates = ctx->DeferUpdates;
|
|
|
|
ALenum UpdateSources = AL_FALSE;
|
2011-07-11 01:05:42 -07:00
|
|
|
|
2011-08-22 17:13:03 -07:00
|
|
|
if(!DeferUpdates)
|
2011-08-29 21:30:12 -07:00
|
|
|
UpdateSources = ExchangeInt(&ctx->UpdateSources, AL_FALSE);
|
2011-07-11 01:05:42 -07:00
|
|
|
|
2012-04-26 00:59:17 -07:00
|
|
|
/* source processing */
|
2011-08-28 19:28:41 -07:00
|
|
|
src = ctx->ActiveSources;
|
|
|
|
src_end = src + ctx->ActiveSourceCount;
|
2010-11-21 02:51:18 -08:00
|
|
|
while(src != src_end)
|
|
|
|
{
|
|
|
|
if((*src)->state != AL_PLAYING)
|
|
|
|
{
|
2011-08-28 19:28:41 -07:00
|
|
|
--(ctx->ActiveSourceCount);
|
2010-11-21 02:51:18 -08:00
|
|
|
*src = *(--src_end);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2011-08-29 21:30:12 -07:00
|
|
|
if(!DeferUpdates && (ExchangeInt(&(*src)->NeedsUpdate, AL_FALSE) ||
|
2011-08-29 00:50:55 -07:00
|
|
|
UpdateSources))
|
2011-08-28 19:28:41 -07:00
|
|
|
ALsource_Update(*src, ctx);
|
2010-11-21 02:51:18 -08:00
|
|
|
|
2010-11-25 23:09:18 -08:00
|
|
|
MixSource(*src, device, SamplesToDo);
|
2010-11-21 02:51:18 -08:00
|
|
|
src++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* effect slot processing */
|
2011-08-30 20:13:42 -07:00
|
|
|
slot = ctx->ActiveEffectSlots;
|
|
|
|
slot_end = slot + ctx->ActiveEffectSlotCount;
|
|
|
|
while(slot != slot_end)
|
2010-11-21 02:51:18 -08:00
|
|
|
{
|
2012-09-16 09:04:37 -07:00
|
|
|
ALfloat offset = (*slot)->ClickRemoval[0];
|
|
|
|
if(offset < (1.0f/32768.0f))
|
|
|
|
offset = 0.0f;
|
|
|
|
else for(i = 0;i < SamplesToDo;i++)
|
2010-11-21 02:51:18 -08:00
|
|
|
{
|
2012-09-16 09:04:37 -07:00
|
|
|
(*slot)->WetBuffer[0][i] += offset;
|
|
|
|
offset -= offset * (1.0f/256.0f);
|
2010-11-21 02:51:18 -08:00
|
|
|
}
|
2012-09-16 09:04:37 -07:00
|
|
|
(*slot)->ClickRemoval[0] = offset + (*slot)->PendingClicks[0];
|
2011-09-12 01:09:01 -07:00
|
|
|
(*slot)->PendingClicks[0] = 0.0f;
|
2010-11-21 02:51:18 -08:00
|
|
|
|
2011-08-30 20:13:42 -07:00
|
|
|
if(!DeferUpdates && ExchangeInt(&(*slot)->NeedsUpdate, AL_FALSE))
|
2012-03-13 14:49:58 -07:00
|
|
|
ALeffectState_Update((*slot)->EffectState, device, *slot);
|
2011-07-16 02:41:02 -07:00
|
|
|
|
2011-09-12 05:59:23 -07:00
|
|
|
ALeffectState_Process((*slot)->EffectState, SamplesToDo,
|
2012-09-16 08:27:50 -07:00
|
|
|
(*slot)->WetBuffer[0], device->DryBuffer);
|
2010-11-21 02:51:18 -08:00
|
|
|
|
|
|
|
for(i = 0;i < SamplesToDo;i++)
|
2012-09-16 08:27:50 -07:00
|
|
|
(*slot)->WetBuffer[0][i] = 0.0f;
|
2011-08-30 20:13:42 -07:00
|
|
|
|
|
|
|
slot++;
|
2010-11-21 02:51:18 -08:00
|
|
|
}
|
|
|
|
|
2011-08-28 19:28:41 -07:00
|
|
|
ctx = ctx->next;
|
2010-11-21 02:51:18 -08:00
|
|
|
}
|
2012-01-19 19:30:03 -08:00
|
|
|
|
|
|
|
slot = &device->DefaultSlot;
|
2012-01-25 18:48:26 -08:00
|
|
|
if(*slot != NULL)
|
2012-01-19 19:30:03 -08:00
|
|
|
{
|
2012-09-16 09:04:37 -07:00
|
|
|
ALfloat offset = (*slot)->ClickRemoval[0];
|
|
|
|
if(offset < (1.0f/32768.0f))
|
|
|
|
offset = 0.0f;
|
|
|
|
else for(i = 0;i < SamplesToDo;i++)
|
2012-01-25 18:48:26 -08:00
|
|
|
{
|
2012-09-16 09:04:37 -07:00
|
|
|
(*slot)->WetBuffer[0][i] += offset;
|
|
|
|
offset -= offset * (1.0f/256.0f);
|
2012-01-25 18:48:26 -08:00
|
|
|
}
|
2012-09-16 09:04:37 -07:00
|
|
|
(*slot)->ClickRemoval[0] = offset + (*slot)->PendingClicks[0];
|
2012-01-25 18:48:26 -08:00
|
|
|
(*slot)->PendingClicks[0] = 0.0f;
|
2012-01-19 19:30:03 -08:00
|
|
|
|
2012-01-25 18:48:26 -08:00
|
|
|
if(ExchangeInt(&(*slot)->NeedsUpdate, AL_FALSE))
|
2012-03-13 14:49:58 -07:00
|
|
|
ALeffectState_Update((*slot)->EffectState, device, *slot);
|
2012-01-19 19:30:03 -08:00
|
|
|
|
2012-01-25 18:48:26 -08:00
|
|
|
ALeffectState_Process((*slot)->EffectState, SamplesToDo,
|
2012-09-16 08:27:50 -07:00
|
|
|
(*slot)->WetBuffer[0], device->DryBuffer);
|
2012-01-19 19:30:03 -08:00
|
|
|
|
2012-01-25 18:48:26 -08:00
|
|
|
for(i = 0;i < SamplesToDo;i++)
|
2012-09-16 08:27:50 -07:00
|
|
|
(*slot)->WetBuffer[0][i] = 0.0f;
|
2012-01-25 18:48:26 -08:00
|
|
|
}
|
2012-08-18 15:58:04 -07:00
|
|
|
ALCdevice_Unlock(device);
|
2010-11-21 02:51:18 -08:00
|
|
|
|
2012-04-26 00:59:17 -07:00
|
|
|
/* Click-removal. Could do better; this only really handles immediate
|
|
|
|
* changes between updates where a predictive sample could be
|
|
|
|
* generated. Delays caused by effects and HRTF aren't caught. */
|
2011-07-30 05:43:47 -07:00
|
|
|
if(device->FmtChans == DevFmtMono)
|
2010-11-21 02:51:18 -08:00
|
|
|
{
|
2012-09-16 08:42:36 -07:00
|
|
|
ALfloat offset = device->ClickRemoval[FrontCenter];
|
|
|
|
if(offset < (1.0f/32768.0f))
|
|
|
|
offset = 0.0f;
|
|
|
|
else for(i = 0;i < SamplesToDo;i++)
|
2010-11-21 02:51:18 -08:00
|
|
|
{
|
2012-09-16 08:42:36 -07:00
|
|
|
device->DryBuffer[FrontCenter][i] += offset;
|
|
|
|
offset -= offset * (1.0f/256.0f);
|
2010-11-21 02:51:18 -08:00
|
|
|
}
|
2012-09-16 08:42:36 -07:00
|
|
|
device->ClickRemoval[FrontCenter] = offset + device->PendingClicks[FrontCenter];
|
2012-06-28 18:49:49 -07:00
|
|
|
device->PendingClicks[FrontCenter] = 0.0f;
|
2010-11-21 02:51:18 -08:00
|
|
|
}
|
2011-07-30 05:43:47 -07:00
|
|
|
else if(device->FmtChans == DevFmtStereo)
|
2010-11-21 02:51:18 -08:00
|
|
|
{
|
2012-06-28 18:49:49 -07:00
|
|
|
/* Assumes the first two channels are FrontLeft and FrontRight */
|
2012-09-11 06:32:42 -07:00
|
|
|
for(c = 0;c < 2;c++)
|
2011-07-30 05:43:47 -07:00
|
|
|
{
|
2012-09-11 06:32:42 -07:00
|
|
|
ALfloat offset = device->ClickRemoval[c];
|
2012-09-16 08:42:36 -07:00
|
|
|
if(offset < (1.0f/32768.0f))
|
|
|
|
offset = 0.0f;
|
|
|
|
else for(i = 0;i < SamplesToDo;i++)
|
2011-07-30 05:43:47 -07:00
|
|
|
{
|
2012-09-11 06:32:42 -07:00
|
|
|
device->DryBuffer[c][i] += offset;
|
|
|
|
offset -= offset * (1.0f/256.0f);
|
2011-07-30 05:43:47 -07:00
|
|
|
}
|
2012-09-11 06:32:42 -07:00
|
|
|
device->ClickRemoval[c] = offset + device->PendingClicks[c];
|
2011-07-30 05:43:47 -07:00
|
|
|
device->PendingClicks[c] = 0.0f;
|
|
|
|
}
|
2012-03-03 09:41:16 -08:00
|
|
|
if(device->Bs2b)
|
|
|
|
{
|
2012-09-11 06:32:42 -07:00
|
|
|
float samples[2];
|
2012-03-03 09:41:16 -08:00
|
|
|
for(i = 0;i < SamplesToDo;i++)
|
2012-09-11 06:32:42 -07:00
|
|
|
{
|
|
|
|
samples[0] = device->DryBuffer[FrontLeft][i];
|
|
|
|
samples[1] = device->DryBuffer[FrontRight][i];
|
|
|
|
bs2b_cross_feed(device->Bs2b, samples);
|
|
|
|
device->DryBuffer[FrontLeft][i] = samples[0];
|
|
|
|
device->DryBuffer[FrontRight][i] = samples[1];
|
|
|
|
}
|
2012-03-03 09:41:16 -08:00
|
|
|
}
|
2011-07-30 05:43:47 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-09-11 06:32:42 -07:00
|
|
|
for(c = 0;c < MaxChannels;c++)
|
2011-07-30 05:43:47 -07:00
|
|
|
{
|
2012-09-11 06:32:42 -07:00
|
|
|
ALfloat offset = device->ClickRemoval[c];
|
2012-09-16 08:42:36 -07:00
|
|
|
if(offset < (1.0f/32768.0f))
|
|
|
|
offset = 0.0f;
|
|
|
|
else for(i = 0;i < SamplesToDo;i++)
|
2011-07-30 05:43:47 -07:00
|
|
|
{
|
2012-09-11 06:32:42 -07:00
|
|
|
device->DryBuffer[c][i] += offset;
|
|
|
|
offset -= offset * (1.0f/256.0f);
|
2011-07-30 05:43:47 -07:00
|
|
|
}
|
2012-09-11 06:32:42 -07:00
|
|
|
device->ClickRemoval[c] = offset + device->PendingClicks[c];
|
2011-07-30 05:43:47 -07:00
|
|
|
device->PendingClicks[c] = 0.0f;
|
|
|
|
}
|
2010-11-21 02:51:18 -08:00
|
|
|
}
|
|
|
|
|
2011-08-12 15:42:36 -07:00
|
|
|
if(buffer)
|
2010-11-21 02:51:18 -08:00
|
|
|
{
|
2012-10-03 02:35:43 -07:00
|
|
|
int bytes = 0;
|
2011-08-12 15:42:36 -07:00
|
|
|
switch(device->FmtType)
|
|
|
|
{
|
|
|
|
case DevFmtByte:
|
2012-10-03 02:35:43 -07:00
|
|
|
bytes = Write_ALbyte(device, buffer, SamplesToDo);
|
2011-08-12 15:42:36 -07:00
|
|
|
break;
|
|
|
|
case DevFmtUByte:
|
2012-10-03 02:35:43 -07:00
|
|
|
bytes = Write_ALubyte(device, buffer, SamplesToDo);
|
2011-08-12 15:42:36 -07:00
|
|
|
break;
|
|
|
|
case DevFmtShort:
|
2012-10-03 02:35:43 -07:00
|
|
|
bytes = Write_ALshort(device, buffer, SamplesToDo);
|
2011-08-12 15:42:36 -07:00
|
|
|
break;
|
|
|
|
case DevFmtUShort:
|
2012-10-03 02:35:43 -07:00
|
|
|
bytes = Write_ALushort(device, buffer, SamplesToDo);
|
2012-02-14 11:44:57 -08:00
|
|
|
break;
|
|
|
|
case DevFmtInt:
|
2012-10-03 02:35:43 -07:00
|
|
|
bytes = Write_ALint(device, buffer, SamplesToDo);
|
2012-02-14 11:44:57 -08:00
|
|
|
break;
|
|
|
|
case DevFmtUInt:
|
2012-10-03 02:35:43 -07:00
|
|
|
bytes = Write_ALuint(device, buffer, SamplesToDo);
|
2011-08-12 15:42:36 -07:00
|
|
|
break;
|
|
|
|
case DevFmtFloat:
|
2012-10-03 02:35:43 -07:00
|
|
|
bytes = Write_ALfloat(device, buffer, SamplesToDo);
|
2011-08-12 15:42:36 -07:00
|
|
|
break;
|
|
|
|
}
|
2012-10-03 02:35:43 -07:00
|
|
|
|
2012-10-04 06:16:16 -07:00
|
|
|
buffer = (ALubyte*)buffer + bytes;
|
2010-11-21 02:51:18 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
size -= SamplesToDo;
|
|
|
|
}
|
|
|
|
|
2012-09-16 01:35:16 -07:00
|
|
|
RestoreFPUMode(&oldMode);
|
2010-11-21 02:51:18 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-08-26 19:15:17 -07:00
|
|
|
ALvoid aluHandleDisconnect(ALCdevice *device)
|
|
|
|
{
|
2011-08-28 19:28:41 -07:00
|
|
|
ALCcontext *Context;
|
2009-10-20 11:54:04 -07:00
|
|
|
|
2012-08-18 15:58:04 -07:00
|
|
|
ALCdevice_Lock(device);
|
2011-09-10 19:22:46 -07:00
|
|
|
device->Connected = ALC_FALSE;
|
|
|
|
|
2011-08-28 19:28:41 -07:00
|
|
|
Context = device->ContextList;
|
|
|
|
while(Context)
|
2009-08-26 19:15:17 -07:00
|
|
|
{
|
2011-09-12 01:11:46 -07:00
|
|
|
ALsource **src, **src_end;
|
2009-08-26 19:15:17 -07:00
|
|
|
|
2011-09-12 01:11:46 -07:00
|
|
|
src = Context->ActiveSources;
|
|
|
|
src_end = src + Context->ActiveSourceCount;
|
|
|
|
while(src != src_end)
|
2009-08-26 19:15:17 -07:00
|
|
|
{
|
2011-09-12 01:11:46 -07:00
|
|
|
if((*src)->state == AL_PLAYING)
|
2009-08-26 19:15:17 -07:00
|
|
|
{
|
2011-09-12 01:11:46 -07:00
|
|
|
(*src)->state = AL_STOPPED;
|
|
|
|
(*src)->BuffersPlayed = (*src)->BuffersInQueue;
|
|
|
|
(*src)->position = 0;
|
|
|
|
(*src)->position_fraction = 0;
|
2009-08-26 19:15:17 -07:00
|
|
|
}
|
2011-09-12 01:11:46 -07:00
|
|
|
src++;
|
2009-08-26 19:15:17 -07:00
|
|
|
}
|
2011-09-12 01:11:46 -07:00
|
|
|
Context->ActiveSourceCount = 0;
|
2011-08-28 19:28:41 -07:00
|
|
|
|
|
|
|
Context = Context->next;
|
2009-08-26 19:15:17 -07:00
|
|
|
}
|
2012-08-18 15:58:04 -07:00
|
|
|
ALCdevice_Unlock(device);
|
2009-08-26 19:15:17 -07:00
|
|
|
}
|