Calculate the actual stepping value in the source update method

This commit is contained in:
Chris Robinson
2010-08-07 00:38:02 -07:00
parent 044662e4b7
commit f4304ca062
2 changed files with 61 additions and 36 deletions
+42 -4
View File
@@ -79,6 +79,7 @@ static __inline ALvoid aluMatrixVector(ALfloat *vector,ALfloat w,ALfloat matrix[
ALvoid CalcNonAttnSourceParams(ALsource *ALSource, const ALCcontext *ALContext)
{
ALfloat SourceVolume,ListenerGain,MinVolume,MaxVolume;
ALbufferlistitem *BufferListItem;
ALfloat DryGain, DryGainHF;
ALfloat WetGain[MAX_SENDS];
ALfloat WetGainHF[MAX_SENDS];
@@ -99,7 +100,18 @@ ALvoid CalcNonAttnSourceParams(ALsource *ALSource, const ALCcontext *ALContext)
MaxVolume = ALSource->flMaxGain;
//1. Multi-channel buffers always play "normal"
ALSource->Params.Pitch = ALSource->flPitch;
BufferListItem = ALSource->queue;
while(BufferListItem != NULL)
{
ALbuffer *ALBuffer;
if((ALBuffer=BufferListItem->buffer) != NULL)
{
ALSource->Params.Pitch = ALSource->flPitch*ALBuffer->frequency /
Frequency;
break;
}
BufferListItem = BufferListItem->next;
}
DryGain = SourceVolume;
DryGain = __min(DryGain,MaxVolume);
@@ -160,6 +172,7 @@ ALvoid CalcNonAttnSourceParams(ALsource *ALSource, const ALCcontext *ALContext)
ALvoid CalcNonAttnStereoSourceParams(ALsource *ALSource, const ALCcontext *ALContext)
{
ALfloat SourceVolume,ListenerGain,MinVolume,MaxVolume;
ALbufferlistitem *BufferListItem;
ALfloat DryGain, DryGainHF;
ALfloat WetGain[MAX_SENDS];
ALfloat WetGainHF[MAX_SENDS];
@@ -184,7 +197,18 @@ ALvoid CalcNonAttnStereoSourceParams(ALsource *ALSource, const ALCcontext *ALCon
MaxVolume = ALSource->flMaxGain;
//1. Multi-channel buffers always play "normal"
ALSource->Params.Pitch = ALSource->flPitch;
BufferListItem = ALSource->queue;
while(BufferListItem != NULL)
{
ALbuffer *ALBuffer;
if((ALBuffer=BufferListItem->buffer) != NULL)
{
ALSource->Params.Pitch = ALSource->flPitch*ALBuffer->frequency /
Frequency;
break;
}
BufferListItem = BufferListItem->next;
}
DryGain = SourceVolume;
DryGain = __min(DryGain,MaxVolume);
@@ -310,6 +334,7 @@ ALvoid CalcSourceParams(ALsource *ALSource, const ALCcontext *ALContext)
ALfloat MinVolume,MaxVolume,MinDist,MaxDist,Rolloff,OuterGainHF;
ALfloat ConeVolume,ConeHF,SourceVolume,ListenerGain;
ALfloat DopplerFactor, DopplerVelocity, flSpeedOfSound;
ALbufferlistitem *BufferListItem;
ALfloat Matrix[4][4];
ALfloat flAttenuation, effectiveDist;
ALfloat RoomAttenuation[MAX_SENDS];
@@ -320,6 +345,7 @@ ALvoid CalcSourceParams(ALsource *ALSource, const ALCcontext *ALContext)
ALfloat WetGainHF[MAX_SENDS];
ALfloat DirGain, AmbientGain;
const ALfloat *SpeakerGain;
ALfloat Pitch;
ALfloat length;
ALuint Frequency;
ALint NumSends;
@@ -624,12 +650,24 @@ ALvoid CalcSourceParams(ALsource *ALSource, const ALCcontext *ALContext)
else if(flVLS <= -flMaxVelocity)
flVLS = -flMaxVelocity + 1.0f;
ALSource->Params.Pitch = ALSource->flPitch *
Pitch = ALSource->flPitch *
((flSpeedOfSound * DopplerVelocity) - (DopplerFactor * flVLS)) /
((flSpeedOfSound * DopplerVelocity) - (DopplerFactor * flVSS));
}
else
ALSource->Params.Pitch = ALSource->flPitch;
Pitch = ALSource->flPitch;
BufferListItem = ALSource->queue;
while(BufferListItem != NULL)
{
ALbuffer *ALBuffer;
if((ALBuffer=BufferListItem->buffer) != NULL)
{
ALSource->Params.Pitch = Pitch*ALBuffer->frequency / Frequency;
break;
}
BufferListItem = BufferListItem->next;
}
// Use energy-preserving panning algorithm for multi-speaker playback
length = __max(OrigDist, MinDist);
+19 -32
View File
@@ -109,34 +109,11 @@ static void MixSource(ALsource *ALSource, ALCcontext *ALContext,
ALuint DeviceFreq;
ALint increment;
ALuint DataPosInt, DataPosFrac;
ALuint Channels, Bytes;
ALuint Frequency;
resampler_t Resampler;
ALuint BuffersPlayed;
ALboolean Looping;
ALfloat Pitch;
ALenum State;
DeviceFreq = ALContext->Device->Frequency;
/* Find buffer format */
Frequency = 0;
Channels = 0;
Bytes = 0;
BufferListItem = ALSource->queue;
while(BufferListItem != NULL)
{
ALbuffer *ALBuffer;
if((ALBuffer=BufferListItem->buffer) != NULL)
{
Channels = aluChannelsFromFormat(ALBuffer->format);
Bytes = aluBytesFromFormat(ALBuffer->format);
Frequency = ALBuffer->frequency;
break;
}
BufferListItem = BufferListItem->next;
}
if(ALSource->NeedsUpdate)
{
ALsource_Update(ALSource, ALContext);
@@ -151,12 +128,6 @@ static void MixSource(ALsource *ALSource, ALCcontext *ALContext,
DataPosFrac = ALSource->position_fraction;
Looping = ALSource->bLooping;
/* Compute 18.14 fixed point step */
Pitch = (ALSource->Params.Pitch*Frequency) / DeviceFreq;
if(Pitch > (float)MAX_PITCH) Pitch = (float)MAX_PITCH;
increment = (ALint)(Pitch*(ALfloat)(1L<<FRACTIONBITS));
if(increment <= 0) increment = (1<<FRACTIONBITS);
if(ALSource->FirstStart)
{
for(i = 0;i < OUTPUTCHANNELS;i++)
@@ -173,6 +144,8 @@ static void MixSource(ALsource *ALSource, ALCcontext *ALContext,
}
/* Compute the gain steps for each output channel */
DeviceFreq = ALContext->Device->Frequency;
rampLength = DeviceFreq * MIN_RAMP_LENGTH / 1000;
rampLength = max(rampLength, SamplesToDo);
@@ -199,11 +172,12 @@ static void MixSource(ALsource *ALSource, ALCcontext *ALContext,
j = 0;
do {
const ALbuffer *ALBuffer;
ALfloat *Data = NULL;
ALuint DataSize = 0;
ALuint LoopStart = 0;
ALuint LoopEnd = 0;
ALuint DataSize = 0;
ALbuffer *ALBuffer;
ALuint Channels, Bytes;
ALuint BufferSize;
/* Get buffer info */
@@ -211,9 +185,11 @@ static void MixSource(ALsource *ALSource, ALCcontext *ALContext,
{
Data = ALBuffer->data;
DataSize = ALBuffer->size;
DataSize /= Channels * Bytes;
DataSize /= aluFrameSizeFromFormat(ALBuffer->format);
LoopStart = ALBuffer->LoopStart;
LoopEnd = ALBuffer->LoopEnd;
Channels = aluChannelsFromFormat(ALBuffer->format);
Bytes = aluBytesFromFormat(ALBuffer->format);
}
if(Looping && ALSource->lSourceType == AL_STATIC)
@@ -255,6 +231,17 @@ static void MixSource(ALsource *ALSource, ALCcontext *ALContext,
else
memset(&Data[DataSize*Channels], 0, (BUFFER_PADDING*Channels*Bytes));
/* Compute 18.14 fixed point step */
if(ALSource->Params.Pitch > (float)MAX_PITCH)
increment = MAX_PITCH << FRACTIONBITS;
else if(!(ALSource->Params.Pitch > 0.f))
increment = (1<<FRACTIONBITS);
else
{
increment = (ALint)(ALSource->Params.Pitch*(1L<<FRACTIONBITS));
if(increment == 0) increment = 1;
}
/* Figure out how many samples we can mix. */
DataSize64 = LoopEnd;
DataSize64 <<= FRACTIONBITS;