aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2010-08-07 00:38:02 -0700
committerChris Robinson <[email protected]>2010-08-07 00:38:02 -0700
commitf4304ca062564bbe8604d734524f4e58f506fce7 (patch)
tree693deebc01a4d027d8533294125c4ef74ec12c05
parent044662e4b709e0c446e16a849088c418c91d205c (diff)
Calculate the actual stepping value in the source update method
-rw-r--r--Alc/ALu.c46
-rw-r--r--Alc/mixer.c51
2 files changed, 61 insertions, 36 deletions
diff --git a/Alc/ALu.c b/Alc/ALu.c
index 9797908c..effa5e2d 100644
--- a/Alc/ALu.c
+++ b/Alc/ALu.c
@@ -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);
diff --git a/Alc/mixer.c b/Alc/mixer.c
index 54ec28be..1d4c388e 100644
--- a/Alc/mixer.c
+++ b/Alc/mixer.c
@@ -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;