aboutsummaryrefslogtreecommitdiffstats
path: root/OpenAL32
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2017-02-14 19:59:39 -0800
committerChris Robinson <[email protected]>2017-02-14 19:59:39 -0800
commit5a50c46c22e7e6c5f119613584d826bc7b7b4a61 (patch)
tree2c0420dd6bc84dda8efabb5bd099abe85ee58b84 /OpenAL32
parent69dd57096183c4e381cc3f5c0a8ac4e33048b346 (diff)
Make ALsourceProps' Send array dynamically sized
ALsourceProps' Send[] array is placed at the end of the struct, and given an indeterminate size. Extra space is allocated at the end of each struct given the number of auxiliary sends set for the device.
Diffstat (limited to 'OpenAL32')
-rw-r--r--OpenAL32/Include/alMain.h9
-rw-r--r--OpenAL32/Include/alSource.h8
-rw-r--r--OpenAL32/alSource.c21
3 files changed, 19 insertions, 19 deletions
diff --git a/OpenAL32/Include/alMain.h b/OpenAL32/Include/alMain.h
index 2573c836..947a16ba 100644
--- a/OpenAL32/Include/alMain.h
+++ b/OpenAL32/Include/alMain.h
@@ -356,6 +356,13 @@ inline ALuint NextPowerOf2(ALuint value)
return value+1;
}
+/** Round up a value to the next multiple. */
+inline size_t RoundUp(size_t value, size_t r)
+{
+ value += r-1;
+ return value - (value%r);
+}
+
/* Fast float-to-int conversion. Assumes the FPU is already in round-to-zero
* mode. */
inline ALint fastf2i(ALfloat f)
@@ -813,6 +820,8 @@ ALCcontext *GetContextRef(void);
void ALCcontext_IncRef(ALCcontext *context);
void ALCcontext_DecRef(ALCcontext *context);
+void AllocateVoices(ALCcontext *context, ALsizei num_voices, ALsizei old_sends);
+
void AppendAllDevicesList(const ALCchar *name);
void AppendCaptureDeviceList(const ALCchar *name);
diff --git a/OpenAL32/Include/alSource.h b/OpenAL32/Include/alSource.h
index d45e5d9c..cc9dd763 100644
--- a/OpenAL32/Include/alSource.h
+++ b/OpenAL32/Include/alSource.h
@@ -23,6 +23,8 @@ typedef struct ALbufferlistitem {
struct ALsourceProps {
+ ATOMIC(struct ALsourceProps*) next;
+
ATOMIC(ALfloat) Pitch;
ATOMIC(ALfloat) Gain;
ATOMIC(ALfloat) OuterGain;
@@ -69,14 +71,12 @@ struct ALsourceProps {
ATOMIC(ALfloat) HFReference;
ATOMIC(ALfloat) GainLF;
ATOMIC(ALfloat) LFReference;
- } Send[MAX_SENDS];
-
- ATOMIC(struct ALsourceProps*) next;
+ } Send[];
};
typedef struct ALvoice {
- struct ALsourceProps Props;
+ struct ALsourceProps *Props;
struct ALsource *Source;
diff --git a/OpenAL32/alSource.c b/OpenAL32/alSource.c
index 036b7542..56d2b415 100644
--- a/OpenAL32/alSource.c
+++ b/OpenAL32/alSource.c
@@ -2306,23 +2306,13 @@ AL_API ALvoid AL_APIENTRY alSourcePlayv(ALsizei n, const ALuint *sources)
ALCdevice_Lock(context->Device);
while(n > context->MaxVoices-context->VoiceCount)
{
- ALvoice *temp = NULL;
- ALsizei newcount;
-
- newcount = context->MaxVoices << 1;
- if(newcount > 0)
- temp = al_malloc(16, newcount * sizeof(context->Voices[0]));
- if(!temp)
+ ALsizei newcount = context->MaxVoices << 1;
+ if(context->MaxVoices >= newcount)
{
ALCdevice_Unlock(context->Device);
SET_ERROR_AND_GOTO(context, AL_OUT_OF_MEMORY, done);
}
- memcpy(temp, context->Voices, context->MaxVoices * sizeof(temp[0]));
- memset(&temp[context->MaxVoices], 0, (newcount-context->MaxVoices) * sizeof(temp[0]));
-
- al_free(context->Voices);
- context->Voices = temp;
- context->MaxVoices = newcount;
+ AllocateVoices(context, newcount, context->Device->NumAuxSends);
}
if(ATOMIC_LOAD(&context->DeferUpdates, almemory_order_acquire) == DeferAll)
@@ -2757,6 +2747,7 @@ static void InitSourceParams(ALsource *Source)
Source->Direct.LFReference = HIGHPASSFREQREF;
for(i = 0;i < MAX_SENDS;i++)
{
+ Source->Send[i].Slot = NULL;
Source->Send[i].Gain = 1.0f;
Source->Send[i].GainHF = 1.0f;
Source->Send[i].HFReference = LOWPASSFREQREF;
@@ -2819,7 +2810,7 @@ static void DeinitSource(ALsource *source)
BufferList = next;
}
- for(i = 0;i < MAX_SENDS;++i)
+ for(i = 0;i < MAX_SENDS;i++)
{
if(source->Send[i].Slot)
DecrementRef(&source->Send[i].Slot->ref);
@@ -2835,7 +2826,7 @@ static void UpdateSourceProps(ALsource *source, ALuint num_sends)
/* Get an unused property container, or allocate a new one as needed. */
props = ATOMIC_LOAD(&source->FreeList, almemory_order_acquire);
if(!props)
- props = al_calloc(16, sizeof(*props));
+ props = al_calloc(16, offsetof(struct ALsourceProps, Send[num_sends]));
else
{
struct ALsourceProps *next;