Skip to content

Commit

Permalink
Merge branch 'master' of git://repo.or.cz/openal-soft
Browse files Browse the repository at this point in the history
  • Loading branch information
AerialX committed Oct 4, 2011
2 parents 55d7fa9 + a5c74e3 commit 5e77ab7
Show file tree
Hide file tree
Showing 28 changed files with 900 additions and 463 deletions.
19 changes: 8 additions & 11 deletions Alc/ALc.c
Expand Up @@ -376,8 +376,8 @@ static volatile ALCenum g_eLastNullDeviceError = ALC_NO_ERROR;

// Default context extensions
static const ALchar alExtList[] =
"AL_EXT_DOUBLE AL_EXT_EXPONENT_DISTANCE AL_EXT_FLOAT32 AL_EXT_IMA4 "
"AL_EXT_LINEAR_DISTANCE AL_EXT_MCFORMATS AL_EXT_MULAW "
"AL_EXT_ALAW AL_EXT_DOUBLE AL_EXT_EXPONENT_DISTANCE AL_EXT_FLOAT32 "
"AL_EXT_IMA4 AL_EXT_LINEAR_DISTANCE AL_EXT_MCFORMATS AL_EXT_MULAW "
"AL_EXT_MULAW_MCFORMATS AL_EXT_OFFSET AL_EXT_source_distance_model "
"AL_LOKI_quadriphonic AL_SOFTX_buffer_samples AL_SOFT_buffer_sub_data "
"AL_SOFTX_deferred_updates AL_SOFT_loop_points "
Expand All @@ -396,12 +396,6 @@ enum LogLevel LogLevel = LogWarning;
enum LogLevel LogLevel = LogError;
#endif

// Cone scalar
ALdouble ConeScale = 0.5;

// Localized Z scalar for mono sources
ALdouble ZScale = 1.0;

/* Flag to trap ALC device errors */
static ALCboolean TrapALCError = ALC_FALSE;

Expand Down Expand Up @@ -499,11 +493,11 @@ static void alc_init(void)

str = getenv("__ALSOFT_HALF_ANGLE_CONES");
if(str && (strcasecmp(str, "true") == 0 || strtol(str, NULL, 0) == 1))
ConeScale = 1.0;
ConeScale = 1.0f;

str = getenv("__ALSOFT_REVERSE_Z");
if(str && (strcasecmp(str, "true") == 0 || strtol(str, NULL, 0) == 1))
ZScale = -1.0;
ZScale = -1.0f;

str = getenv("__ALSOFT_TRAP_ERROR");
if(str && (strcasecmp(str, "true") == 0 || strtol(str, NULL, 0) == 1))
Expand Down Expand Up @@ -1010,7 +1004,7 @@ static void alcSetError(ALCdevice *device, ALCenum errorCode)
if(IsDebuggerPresent())
DebugBreak();
#elif defined(SIGTRAP)
kill(getpid(), SIGTRAP);
raise(SIGTRAP);
#endif
}

Expand All @@ -1029,6 +1023,7 @@ static void alcSetError(ALCdevice *device, ALCenum errorCode)
static ALCboolean UpdateDeviceParams(ALCdevice *device, const ALCint *attrList)
{
ALCcontext *context;
int oldMode;
ALuint i;

// Check for attributes
Expand Down Expand Up @@ -1205,6 +1200,7 @@ static ALCboolean UpdateDeviceParams(ALCdevice *device, const ALCint *attrList)
}
TRACE("Stereo duplication %s\n", (device->Flags&DEVICE_DUPLICATE_STEREO)?"enabled":"disabled");

oldMode = SetMixerFPUMode();
context = device->ContextList;
while(context)
{
Expand Down Expand Up @@ -1250,6 +1246,7 @@ static ALCboolean UpdateDeviceParams(ALCdevice *device, const ALCint *attrList)

context = context->next;
}
RestoreFPUMode(oldMode);
UnlockDevice(device);

return ALC_TRUE;
Expand Down
99 changes: 47 additions & 52 deletions Alc/ALu.c
Expand Up @@ -37,6 +37,13 @@
#include "bs2b.h"


/* Cone scalar */
ALfloat ConeScale = 0.5f;

/* Localized Z scalar for mono sources */
ALfloat ZScale = 1.0f;


static __inline ALvoid aluCrossproduct(const ALfloat *inVector1, const ALfloat *inVector2, ALfloat *outVector)
{
outVector[0] = inVector1[1]*inVector2[2] - inVector1[2]*inVector2[1];
Expand Down Expand Up @@ -161,7 +168,7 @@ ALvoid CalcNonAttnSourceParams(ALsource *ALSource, const ALCcontext *ALContext)
ALSource->Params.Step = maxstep<<FRACTIONBITS;
else
{
ALSource->Params.Step = Pitch*FRACTIONONE;
ALSource->Params.Step = fastf2i(Pitch*FRACTIONONE);
if(ALSource->Params.Step == 0)
ALSource->Params.Step = 1;
}
Expand Down Expand Up @@ -211,8 +218,8 @@ ALvoid CalcNonAttnSourceParams(ALsource *ALSource, const ALCcontext *ALContext)
DryGain *= aluSqrt(2.0f/4.0f);
for(c = 0;c < 2;c++)
{
pos = aluCart2LUTpos(cos(angles_Rear[c] * (M_PI/180.0)),
sin(angles_Rear[c] * (M_PI/180.0)));
pos = aluCart2LUTpos(aluCos(F_PI/180.0f * angles_Rear[c]),
aluSin(F_PI/180.0f * angles_Rear[c]));
SpeakerGain = Device->PanningLUT[pos];

for(i = 0;i < (ALint)Device->NumChan;i++)
Expand Down Expand Up @@ -284,7 +291,7 @@ ALvoid CalcNonAttnSourceParams(ALsource *ALSource, const ALCcontext *ALContext)
/* Get the static HRIR coefficients and delays for this
* channel. */
GetLerpedHrtfCoeffs(ALContext->Device->Hrtf,
0.0, angles[c] * (M_PI/180.0),
0.0f, F_PI/180.0f * angles[c],
DryGain*ListenerGain,
ALSource->Params.HrtfCoeffs[c],
ALSource->Params.HrtfDelay[c]);
Expand All @@ -301,8 +308,8 @@ ALvoid CalcNonAttnSourceParams(ALsource *ALSource, const ALCcontext *ALContext)
SrcMatrix[c][LFE] += DryGain * ListenerGain;
continue;
}
pos = aluCart2LUTpos(cos(angles[c] * (M_PI/180.0)),
sin(angles[c] * (M_PI/180.0)));
pos = aluCart2LUTpos(aluCos(F_PI/180.0f * angles[c]),
aluSin(F_PI/180.0f * angles[c]));
SpeakerGain = Device->PanningLUT[pos];

for(i = 0;i < (ALint)Device->NumChan;i++)
Expand All @@ -321,7 +328,7 @@ ALvoid CalcNonAttnSourceParams(ALsource *ALSource, const ALCcontext *ALContext)

/* Update filter coefficients. Calculations based on the I3DL2
* spec. */
cw = cos(2.0*M_PI * LOWPASSFREQCUTOFF / Frequency);
cw = aluCos(F_PI*2.0f * LOWPASSFREQREF / Frequency);

/* 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
Expand Down Expand Up @@ -572,13 +579,30 @@ ALvoid CalcSourceParams(ALsource *ALSource, const ALCcontext *ALContext)
AirAbsorptionFactor*EffectiveDist);
}

//3. Apply directional soundcones
Angle = aluAcos(aluDotproduct(Direction,SourceToListener)) * (180.0/M_PI);
if(WetGainAuto)
{
/* Apply a decay-time transformation to the wet path, based on the
* attenuation of the dry path.
*
* Using the approximate (effective) source to listener distance, the
* initial decay of the reverb effect is calculated and applied to the
* wet path.
*/
for(i = 0;i < NumSends;i++)
{
if(DecayDistance[i] > 0.0f)
WetGain[i] *= aluPow(0.001f /* -60dB */,
EffectiveDist / DecayDistance[i]);
}
}

/* Calculate directional soundcones */
Angle = aluAcos(aluDotproduct(Direction,SourceToListener)) * (180.0f/F_PI);
if(Angle >= InnerAngle && Angle <= OuterAngle)
{
ALfloat scale = (Angle-InnerAngle) / (OuterAngle-InnerAngle);
ConeVolume = lerp(1.0, ALSource->flOuterGain, scale);
ConeHF = lerp(1.0, ALSource->OuterGainHF, scale);
ConeVolume = lerp(1.0f, ALSource->flOuterGain, scale);
ConeHF = lerp(1.0f, ALSource->OuterGainHF, scale);
}
else if(Angle > OuterAngle)
{
Expand Down Expand Up @@ -619,23 +643,6 @@ ALvoid CalcSourceParams(ALsource *ALSource, const ALCcontext *ALContext)
WetGainHF[i] *= ALSource->Send[i].WetGainHF;
}

if(WetGainAuto)
{
/* Apply a decay-time transformation to the wet path, based on the
* attenuation of the dry path.
*
* Using the approximate (effective) source to listener distance, the
* initial decay of the reverb effect is calculated and applied to the
* wet path.
*/
for(i = 0;i < NumSends;i++)
{
if(DecayDistance[i] > 0.0f)
WetGain[i] *= aluPow(0.001f /* -60dB */,
EffectiveDist / DecayDistance[i]);
}
}

// Calculate Velocity
if(DopplerFactor != 0.0f)
{
Expand Down Expand Up @@ -676,7 +683,7 @@ ALvoid CalcSourceParams(ALsource *ALSource, const ALCcontext *ALContext)
ALSource->Params.Step = maxstep<<FRACTIONBITS;
else
{
ALSource->Params.Step = Pitch*FRACTIONONE;
ALSource->Params.Step = fastf2i(Pitch*FRACTIONONE);
if(ALSource->Params.Step == 0)
ALSource->Params.Step = 1;
}
Expand Down Expand Up @@ -709,8 +716,8 @@ ALvoid CalcSourceParams(ALsource *ALSource, const ALCcontext *ALContext)
// Calculate elevation and azimuth only when the source is not at
// the listener. This prevents +0 and -0 Z from producing
// inconsistent panning.
ev = asin(Position[1]);
az = atan2(Position[0], -Position[2]*ZScale);
ev = aluAsin(Position[1]);
az = aluAtan2(Position[0], -Position[2]*ZScale);
}

// Check to see if the HRIR is already moving.
Expand Down Expand Up @@ -772,7 +779,7 @@ ALvoid CalcSourceParams(ALsource *ALSource, const ALCcontext *ALContext)
DirGain = aluSqrt(Position[0]*Position[0] + Position[2]*Position[2]);
// elevation adjustment for directional gain. this sucks, but
// has low complexity
AmbientGain = aluSqrt(1.0/Device->NumChan);
AmbientGain = aluSqrt(1.0f/Device->NumChan);
for(i = 0;i < MAXCHANNELS;i++)
{
ALuint i2;
Expand All @@ -790,7 +797,7 @@ ALvoid CalcSourceParams(ALsource *ALSource, const ALCcontext *ALContext)
ALSource->Params.Send[i].WetGain = WetGain[i];

/* Update filter coefficients. */
cw = cos(2.0*M_PI * LOWPASSFREQCUTOFF / Frequency);
cw = aluCos(F_PI*2.0f * LOWPASSFREQREF / Frequency);

ALSource->Params.iirFilter.coeff = lpCoeffCalc(DryGainHF, cw);
for(i = 0;i < NumSends;i++)
Expand All @@ -807,7 +814,7 @@ static __inline ALshort aluF2S(ALfloat val)
{
if(val > 1.0f) return 32767;
if(val < -1.0f) return -32768;
return (ALint)(val*32767.0f);
return fastf2i(val*32767.0f);
}
static __inline ALushort aluF2US(ALfloat val)
{ return aluF2S(val)+32768; }
Expand Down Expand Up @@ -945,15 +952,7 @@ ALvoid aluMixData(ALCdevice *device, ALvoid *buffer, ALsizei size)
int fpuState;
ALuint i, c;

#if defined(HAVE_FESETROUND)
fpuState = fegetround();
fesetround(FE_TOWARDZERO);
#elif defined(HAVE__CONTROLFP)
fpuState = _controlfp(0, 0);
(void)_controlfp(_RC_CHOP, _MCW_RC);
#else
(void)fpuState;
#endif
fpuState = SetMixerFPUMode();

while(size > 0)
{
Expand Down Expand Up @@ -1000,7 +999,7 @@ ALvoid aluMixData(ALCdevice *device, ALvoid *buffer, ALsizei size)
for(c = 0;c < SamplesToDo;c++)
{
(*slot)->WetBuffer[c] += (*slot)->ClickRemoval[0];
(*slot)->ClickRemoval[0] -= (*slot)->ClickRemoval[0] / 256.0f;
(*slot)->ClickRemoval[0] -= (*slot)->ClickRemoval[0] * (1.0f/256.0f);
}
(*slot)->ClickRemoval[0] += (*slot)->PendingClicks[0];
(*slot)->PendingClicks[0] = 0.0f;
Expand All @@ -1027,7 +1026,7 @@ ALvoid aluMixData(ALCdevice *device, ALvoid *buffer, ALsizei size)
for(i = 0;i < SamplesToDo;i++)
{
device->DryBuffer[i][FRONT_CENTER] += device->ClickRemoval[FRONT_CENTER];
device->ClickRemoval[FRONT_CENTER] -= device->ClickRemoval[FRONT_CENTER] / 256.0f;
device->ClickRemoval[FRONT_CENTER] -= device->ClickRemoval[FRONT_CENTER] * (1.0f/256.0f);
}
device->ClickRemoval[FRONT_CENTER] += device->PendingClicks[FRONT_CENTER];
device->PendingClicks[FRONT_CENTER] = 0.0f;
Expand All @@ -1040,7 +1039,7 @@ ALvoid aluMixData(ALCdevice *device, ALvoid *buffer, ALsizei size)
for(c = 0;c < 2;c++)
{
device->DryBuffer[i][c] += device->ClickRemoval[c];
device->ClickRemoval[c] -= device->ClickRemoval[c] / 256.0f;
device->ClickRemoval[c] -= device->ClickRemoval[c] * (1.0f/256.0f);
}
}
for(c = 0;c < 2;c++)
Expand All @@ -1056,7 +1055,7 @@ ALvoid aluMixData(ALCdevice *device, ALvoid *buffer, ALsizei size)
for(c = 0;c < MAXCHANNELS;c++)
{
device->DryBuffer[i][c] += device->ClickRemoval[c];
device->ClickRemoval[c] -= device->ClickRemoval[c] / 256.0f;
device->ClickRemoval[c] -= device->ClickRemoval[c] * (1.0f/256.0f);
}
}
for(c = 0;c < MAXCHANNELS;c++)
Expand Down Expand Up @@ -1091,11 +1090,7 @@ ALvoid aluMixData(ALCdevice *device, ALvoid *buffer, ALsizei size)
size -= SamplesToDo;
}

#if defined(HAVE_FESETROUND)
fesetround(fpuState);
#elif defined(HAVE__CONTROLFP)
_controlfp(fpuState, _MCW_RC);
#endif
RestoreFPUMode(fpuState);
}


Expand Down
10 changes: 5 additions & 5 deletions Alc/alcEcho.c
Expand Up @@ -73,8 +73,8 @@ static ALboolean EchoDeviceUpdate(ALeffectState *effect, ALCdevice *Device)

// Use the next power of 2 for the buffer length, so the tap offsets can be
// wrapped using a mask instead of a modulo
maxlen = (ALuint)(AL_ECHO_MAX_DELAY * Device->Frequency) + 1;
maxlen += (ALuint)(AL_ECHO_MAX_LRDELAY * Device->Frequency) + 1;
maxlen = fastf2u(AL_ECHO_MAX_DELAY * Device->Frequency) + 1;
maxlen += fastf2u(AL_ECHO_MAX_LRDELAY * Device->Frequency) + 1;
maxlen = NextPowerOf2(maxlen);

if(maxlen != state->BufferLength)
Expand All @@ -101,8 +101,8 @@ static ALvoid EchoUpdate(ALeffectState *effect, ALCcontext *Context, const ALeff
ALfloat lrpan, cw, g, gain;
ALuint i;

state->Tap[0].delay = (ALuint)(Slot->effect.Echo.Delay * frequency) + 1;
state->Tap[1].delay = (ALuint)(Slot->effect.Echo.LRDelay * frequency);
state->Tap[0].delay = fastf2u(Slot->effect.Echo.Delay * frequency) + 1;
state->Tap[1].delay = fastf2u(Slot->effect.Echo.LRDelay * frequency);
state->Tap[1].delay += state->Tap[0].delay;

lrpan = Slot->effect.Echo.Spread*0.5f + 0.5f;
Expand All @@ -111,7 +111,7 @@ static ALvoid EchoUpdate(ALeffectState *effect, ALCcontext *Context, const ALeff

state->FeedGain = Slot->effect.Echo.Feedback;

cw = cos(2.0*M_PI * LOWPASSFREQCUTOFF / frequency);
cw = aluCos(F_PI*2.0f * LOWPASSFREQREF / frequency);
g = 1.0f - Slot->effect.Echo.Damping;
state->iirFilter.coeff = lpCoeffCalc(g, cw);

Expand Down
30 changes: 15 additions & 15 deletions Alc/alcModulator.c
Expand Up @@ -50,21 +50,22 @@ typedef struct ALmodulatorState {
} ALmodulatorState;

#define WAVEFORM_FRACBITS 16
#define WAVEFORM_FRACMASK ((1<<WAVEFORM_FRACBITS)-1)
#define WAVEFORM_FRACONE (1<<WAVEFORM_FRACBITS)
#define WAVEFORM_FRACMASK (WAVEFORM_FRACONE-1)

static __inline ALdouble Sin(ALuint index)
static __inline ALfloat Sin(ALuint index)
{
return sin(index * (M_PI*2.0 / (1<<WAVEFORM_FRACBITS)));
return aluSin(index * (F_PI*2.0f / WAVEFORM_FRACONE));
}

static __inline ALdouble Saw(ALuint index)
static __inline ALfloat Saw(ALuint index)
{
return index*(2.0/(1<<WAVEFORM_FRACBITS)) - 1.0;
return index*(2.0f/WAVEFORM_FRACONE) - 1.0f;
}

static __inline ALdouble Square(ALuint index)
static __inline ALfloat Square(ALuint index)
{
return (index&(1<<(WAVEFORM_FRACBITS-1))) ? -1.0 : 1.0;
return ((index>>(WAVEFORM_FRACBITS-1))&1)*2.0f - 1.0f;
}


Expand Down Expand Up @@ -146,13 +147,12 @@ static ALvoid ModulatorUpdate(ALeffectState *effect, ALCcontext *Context, const
else if(Slot->effect.Modulator.Waveform == AL_RING_MODULATOR_SQUARE)
state->Waveform = SQUARE;

state->step = Slot->effect.Modulator.Frequency*(1<<WAVEFORM_FRACBITS) /
Device->Frequency;
if(!state->step)
state->step = 1;
state->step = fastf2u(Slot->effect.Modulator.Frequency*WAVEFORM_FRACONE /
Device->Frequency);
if(state->step == 0) state->step = 1;

cw = cos(2.0*M_PI * Slot->effect.Modulator.HighPassCutoff /
Device->Frequency);
cw = aluCos(F_PI*2.0f * Slot->effect.Modulator.HighPassCutoff /
Device->Frequency);
a = (2.0f-cw) - aluSqrt(aluPow(2.0f-cw, 2.0f) - 1.0f);
state->iirFilter.coeff = a;

Expand Down Expand Up @@ -199,8 +199,8 @@ ALeffectState *ModulatorCreate(void)
state->state.Update = ModulatorUpdate;
state->state.Process = ModulatorProcess;

state->index = 0.0f;
state->step = 1.0f;
state->index = 0;
state->step = 1;

state->iirFilter.coeff = 0.0f;
state->iirFilter.history[0] = 0.0f;
Expand Down

0 comments on commit 5e77ab7

Please sign in to comment.