Don't bother making ALvoiceProps dynamically sized

This commit is contained in:
Chris Robinson
2018-11-30 16:56:23 -08:00
parent 364850e8f9
commit 4b7ac4a6ed
5 changed files with 26 additions and 47 deletions
+9 -21
View File
@@ -2320,8 +2320,8 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList)
ALvoiceProps *vprops{context->FreeVoiceProps.exchange(nullptr, std::memory_order_acq_rel)};
while(vprops)
{
struct ALvoiceProps *next = vprops->next.load(std::memory_order_relaxed);
al_free(vprops);
ALvoiceProps *next = vprops->next.load(std::memory_order_relaxed);
delete vprops;
vprops = next;
}
@@ -2330,7 +2330,7 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList)
std::for_each(context->Voices, voices_end,
[device](ALvoice *voice) -> void
{
al_free(voice->Update.exchange(nullptr, std::memory_order_acq_rel));
delete voice->Update.exchange(nullptr, std::memory_order_acq_rel);
if(voice->SourceID.load(std::memory_order_acquire) == 0u)
return;
@@ -2615,7 +2615,7 @@ ALCcontext_struct::~ALCcontext_struct()
while(vprops)
{
ALvoiceProps *next{vprops->next.load(std::memory_order_relaxed)};
al_free(vprops);
delete vprops;
vprops = next;
++count;
}
@@ -2780,15 +2780,10 @@ void AllocateVoices(ALCcontext *context, ALsizei num_voices, ALsizei old_sends)
* chunk.
*/
size_t sizeof_voice{RoundUp(FAM_SIZE(ALvoice, Send, num_sends), 16)};
size_t sizeof_props{RoundUp(FAM_SIZE(struct ALvoiceProps, Send, num_sends), 16)};
size_t size{sizeof(ALvoice*) + sizeof_voice + sizeof_props};
size_t size{sizeof(ALvoice*) + sizeof_voice};
auto voices = static_cast<ALvoice**>(al_calloc(16, RoundUp(size*num_voices, 16)));
/* The voice and property objects are stored interleaved since they're
* paired together.
*/
auto voice = reinterpret_cast<ALvoice*>((char*)voices + RoundUp(num_voices*sizeof(ALvoice*), 16));
auto props = reinterpret_cast<ALvoiceProps*>((char*)voice + sizeof_voice);
ALsizei v{0};
if(context->Voices)
@@ -2806,17 +2801,12 @@ void AllocateVoices(ALCcontext *context, ALsizei num_voices, ALsizei old_sends)
*/
memcpy(voice, old_voice, sizeof(*voice));
std::copy_n(old_voice->Send, s_count, voice->Send);
memcpy(props, old_voice->Props, sizeof(*props));
std::copy_n(old_voice->Props->Send, s_count, props->Send);
/* Set this voice's property set pointer and voice reference. */
voice->Props = props;
/* Set this voice's reference. */
voices[v] = voice;
/* Increment pointers to the next storage space. */
voice = reinterpret_cast<ALvoice*>((char*)props + sizeof_props);
props = reinterpret_cast<ALvoiceProps*>((char*)voice + sizeof_voice);
/* Increment pointer to the next storage space. */
voice = reinterpret_cast<ALvoice*>((char*)voice + sizeof_voice);
}
/* Deinit any left over voices that weren't copied over to the new
* array. NOTE: If this does anything, v equals num_voices and
@@ -2833,11 +2823,9 @@ void AllocateVoices(ALCcontext *context, ALsizei num_voices, ALsizei old_sends)
{
voice->Update.store(nullptr, std::memory_order_relaxed);
voice->Props = props;
voices[v] = voice;
voice = reinterpret_cast<ALvoice*>((char*)props + sizeof_props);
props = reinterpret_cast<ALvoiceProps*>((char*)voice + sizeof_voice);
voice = reinterpret_cast<ALvoice*>((char*)voice + sizeof_voice);
}
al_free(context->Voices);
+6 -8
View File
@@ -101,7 +101,7 @@ void aluInit(void)
void DeinitVoice(ALvoice *voice) noexcept
{
al_free(voice->Update.exchange(nullptr));
delete voice->Update.exchange(nullptr, std::memory_order_acq_rel);
}
@@ -505,7 +505,7 @@ void CalcPanningAndFilters(ALvoice *voice, const ALfloat Azi, const ALfloat Elev
const ALfloat DryGainLF, const ALfloat *WetGain,
const ALfloat *WetGainLF, const ALfloat *WetGainHF,
ALeffectslot **SendSlots, const ALbuffer *Buffer,
const struct ALvoiceProps *props, const ALlistener &Listener,
const ALvoiceProps *props, const ALlistener &Listener,
const ALCdevice *Device)
{
struct ChanMap StereoMap[2] = {
@@ -1023,7 +1023,7 @@ void CalcPanningAndFilters(ALvoice *voice, const ALfloat Azi, const ALfloat Elev
}
}
void CalcNonAttnSourceParams(ALvoice *voice, const struct ALvoiceProps *props, const ALbuffer *ALBuffer, const ALCcontext *ALContext)
void CalcNonAttnSourceParams(ALvoice *voice, const ALvoiceProps *props, const ALbuffer *ALBuffer, const ALCcontext *ALContext)
{
const ALCdevice *Device = ALContext->Device;
const ALlistener &Listener = ALContext->Listener;
@@ -1086,7 +1086,7 @@ void CalcNonAttnSourceParams(ALvoice *voice, const struct ALvoiceProps *props, c
WetGainLF, WetGainHF, SendSlots, ALBuffer, props, Listener, Device);
}
void CalcAttnSourceParams(ALvoice *voice, const struct ALvoiceProps *props, const ALbuffer *ALBuffer, const ALCcontext *ALContext)
void CalcAttnSourceParams(ALvoice *voice, const ALvoiceProps *props, const ALbuffer *ALBuffer, const ALCcontext *ALContext)
{
const ALCdevice *Device = ALContext->Device;
const ALlistener &Listener = ALContext->Listener;
@@ -1461,13 +1461,11 @@ void CalcSourceParams(ALvoice *voice, ALCcontext *context, bool force)
if(props)
{
memcpy(voice->Props, props,
FAM_SIZE(struct ALvoiceProps, Send, context->Device->NumAuxSends)
);
memcpy(&voice->Props, props, FAM_SIZE(ALvoiceProps, Send, context->Device->NumAuxSends));
AtomicReplaceHead(context->FreeVoiceProps, props);
}
props = voice->Props;
props = &voice->Props;
ALbufferlistitem *BufferListItem{voice->current_buffer.load(std::memory_order_relaxed)};
while(BufferListItem)
-1
View File
@@ -7,7 +7,6 @@
#include "almalloc.h"
#include "atomic.h"
#define MAX_SENDS 16
#define DEFAULT_SENDS 2
#ifdef __cplusplus
+10 -14
View File
@@ -17,11 +17,13 @@
#include "math_defs.h"
#include "filters/defs.h"
#include "filters/nfc.h"
#include "almalloc.h"
enum class DistanceModel;
#define MAX_PITCH (255)
#define MAX_PITCH 255
#define MAX_SENDS 16
/* Maximum number of samples to pad on either end of a buffer for resampling.
* Note that both the beginning and end need padding!
@@ -29,10 +31,6 @@ enum class DistanceModel;
#define MAX_RESAMPLE_PADDING 24
#ifdef __cplusplus
extern "C" {
#endif
struct BSincTable;
struct ALsource;
struct ALbufferlistitem;
@@ -144,8 +142,6 @@ typedef struct SendParams {
struct ALvoiceProps {
std::atomic<ALvoiceProps*> next;
ALfloat Pitch;
ALfloat Gain;
ALfloat OuterGain;
@@ -194,7 +190,11 @@ struct ALvoiceProps {
ALfloat HFReference;
ALfloat GainLF;
ALfloat LFReference;
} Send[];
} Send[MAX_SENDS];
std::atomic<ALvoiceProps*> next;
DEF_NEWDEL(ALvoiceProps)
};
#define VOICE_IS_STATIC (1<<0)
@@ -203,13 +203,13 @@ struct ALvoiceProps {
#define VOICE_HAS_NFC (1<<3)
typedef struct ALvoice {
ALvoiceProps *Props;
std::atomic<ALvoiceProps*> Update;
std::atomic<ALuint> SourceID;
std::atomic<bool> Playing;
ALvoiceProps Props;
/**
* Source offset in samples, relative to the currently playing buffer, NOT
* the whole queue, and the fractional (fixed-point) offset to the next
@@ -487,8 +487,4 @@ extern ALfloat ConeScale;
extern ALfloat ZScale;
extern ALboolean OverrideReverbSpeedOfSound;
#ifdef __cplusplus
}
#endif
#endif
+1 -3
View File
@@ -68,9 +68,7 @@ void UpdateSourceProps(ALsource *source, ALvoice *voice, ALCcontext *context)
/* Get an unused property container, or allocate a new one as needed. */
ALvoiceProps *props{context->FreeVoiceProps.load(std::memory_order_acquire)};
if(!props)
props = static_cast<ALvoiceProps*>(al_calloc(16,
FAM_SIZE(ALvoiceProps, Send, source->Send.size()))
);
props = new ALvoiceProps{};
else
{
ALvoiceProps *next;