Store the buffer format and frequency in the source when updated

This commit is contained in:
Chris Robinson
2009-10-25 05:03:22 -07:00
parent c003d6032d
commit b0a82aa420
3 changed files with 40 additions and 39 deletions
+32 -39
View File
@@ -835,8 +835,9 @@ static void MixSomeSources(ALCcontext *ALContext, float (*DryBuffer)[OUTPUTCHANN
ALuint frequency;
ALint increment;
ALuint DataPosInt, DataPosFrac;
ALboolean FirstStart;
ALuint Channels, Bytes;
ALuint BuffersPlayed;
ALfloat Pitch;
ALenum State;
if(!(ALSource=ALContext->Source))
@@ -861,12 +862,30 @@ another_source:
BuffersPlayed = ALSource->BuffersPlayed;
DataPosInt = ALSource->position;
DataPosFrac = ALSource->position_fraction;
FirstStart = ALSource->FirstStart;
for(i = 0;i < OUTPUTCHANNELS;i++)
DrySend[i] = ALSource->DryGains[i];
for(i = 0;i < MAX_SENDS;i++)
WetSend[i] = ALSource->WetGains[i];
Channels = aluChannelsFromFormat(ALSource->Format);
Bytes = aluBytesFromFormat(ALSource->Format);
CalcSourceParams(ALContext, ALSource, (Channels==1)?AL_TRUE:AL_FALSE);
Pitch = (ALSource->Params.Pitch*ALSource->Frequency) / frequency;
if(Pitch > (float)MAX_PITCH)
Pitch = (float)MAX_PITCH;
/* Compute the gain steps for each output channel */
if(ALSource->FirstStart)
{
for(i = 0;i < OUTPUTCHANNELS;i++)
DrySend[i] = ALSource->Params.DryGains[i];
for(i = 0;i < MAX_SENDS;i++)
WetSend[i] = ALSource->Params.WetGains[i];
}
else
{
for(i = 0;i < OUTPUTCHANNELS;i++)
DrySend[i] = ALSource->DryGains[i];
for(i = 0;i < MAX_SENDS;i++)
WetSend[i] = ALSource->WetGains[i];
}
DryFilter = &ALSource->Params.iirFilter;
for(i = 0;i < MAX_SENDS;i++)
@@ -886,53 +905,27 @@ another_source:
ALuint DataSize = 0;
ALbuffer *ALBuffer;
ALshort *Data;
ALuint Channels, Bytes;
ALuint BufferSize;
ALfloat Pitch;
/* Get buffer info */
if((ALBuffer=BufferListItem->buffer) != NULL)
{
Data = ALBuffer->data;
Channels = aluChannelsFromFormat(ALBuffer->format);
Bytes = aluBytesFromFormat(ALBuffer->format);
DataSize = ALBuffer->size;
DataSize /= Channels * Bytes;
}
if(DataPosInt >= DataSize)
goto skipmix;
CalcSourceParams(ALContext, ALSource, (Channels==1)?AL_TRUE:AL_FALSE);
Pitch = (ALSource->Params.Pitch*ALBuffer->frequency) / frequency;
/* Compute the gain steps for each output channel */
if(FirstStart)
{
FirstStart = AL_FALSE;
for(i = 0;i < OUTPUTCHANNELS;i++)
{
DrySend[i] = ALSource->Params.DryGains[i];
dryGainStep[i] = 0.0f;
}
for(i = 0;i < MAX_SENDS;i++)
{
WetSend[i] = ALSource->Params.WetGains[i];
wetGainStep[i] = 0.0f;
}
}
else
{
for(i = 0;i < OUTPUTCHANNELS;i++)
dryGainStep[i] = (ALSource->Params.DryGains[i]-
DrySend[i]) / rampLength;
for(i = 0;i < MAX_SENDS;i++)
wetGainStep[i] = (ALSource->Params.WetGains[i]-
WetSend[i]) / rampLength;
}
for(i = 0;i < OUTPUTCHANNELS;i++)
dryGainStep[i] = (ALSource->Params.DryGains[i]-
DrySend[i]) / rampLength;
for(i = 0;i < MAX_SENDS;i++)
wetGainStep[i] = (ALSource->Params.WetGains[i]-
WetSend[i]) / rampLength;
/* Compute 18.14 fixed point step */
if(Pitch > (float)MAX_PITCH)
Pitch = (float)MAX_PITCH;
increment = (ALint)(Pitch*(ALfloat)(1L<<FRACTIONBITS));
if(increment <= 0)
increment = (1<<FRACTIONBITS);
@@ -1158,7 +1151,7 @@ another_source:
for(i = 0;i < MAX_SENDS;i++)
ALSource->WetGains[i] = WetSend[i];
ALSource->FirstStart = FirstStart;
ALSource->FirstStart = AL_FALSE;
if((ALSource=ALSource->next) != NULL)
goto another_source;
+2
View File
@@ -52,6 +52,8 @@ typedef struct ALsource
ALuint position_fraction;
struct ALbuffer *Buffer;
ALenum Format;
ALuint Frequency;
struct ALbufferlistitem *queue; // Linked list of buffers in queue
ALuint BuffersInQueue; // Number of buffers in queue
+6
View File
@@ -535,6 +535,9 @@ ALAPI ALvoid ALAPIENTRY alSourcei(ALuint source,ALenum eParam,ALint lValue)
// Source is now in STATIC mode
pSource->lSourceType = AL_STATIC;
pSource->Format = buffer->format;
pSource->Frequency = buffer->frequency;
// Add the selected buffer to the queue
pALBufferListItem = malloc(sizeof(ALbufferlistitem));
pALBufferListItem->buffer = buffer;
@@ -1586,6 +1589,9 @@ ALAPI ALvoid ALAPIENTRY alSourceQueueBuffers( ALuint source, ALsizei n, const AL
// Change Source Type
ALSource->lSourceType = AL_STREAMING;
ALSource->Format = iFormat;
ALSource->Frequency = iFrequency;
if(buffers[0])
buffer = (ALbuffer*)ALTHUNK_LOOKUPENTRY(buffers[0]);