Avoid several uses of memset

This commit is contained in:
Chris Robinson 2018-12-08 14:22:20 -08:00
parent fc8da0c16b
commit c9f5617f06
13 changed files with 38 additions and 46 deletions

View File

@ -1263,8 +1263,8 @@ static void alc_deinit(void)
alc_cleanup();
memset(&PlaybackBackend, 0, sizeof(PlaybackBackend));
memset(&CaptureBackend, 0, sizeof(CaptureBackend));
PlaybackBackend = BackendInfo{};
CaptureBackend = BackendInfo{};
for(i = 0;i < BackendListSize;i++)
BackendList[i].getFactory().deinit();

View File

@ -68,7 +68,7 @@ static void ALCcoreAudioPlayback_Construct(ALCcoreAudioPlayback *self, ALCdevice
SET_VTABLE2(ALCcoreAudioPlayback, ALCbackend, self);
self->FrameSize = 0;
memset(&self->Format, 0, sizeof(self->Format));
self->Format = AudioStreamBasicDescription{};
}
static void ALCcoreAudioPlayback_Destruct(ALCcoreAudioPlayback *self)

View File

@ -637,7 +637,7 @@ FORCE_ALIGN int ALCwasapiPlayback_mixerProc(ALCwasapiPlayback *self)
ALCboolean MakeExtensible(WAVEFORMATEXTENSIBLE *out, const WAVEFORMATEX *in)
{
memset(out, 0, sizeof(*out));
*out = WAVEFORMATEXTENSIBLE{};
if(in->wFormatTag == WAVE_FORMAT_EXTENSIBLE)
*out = *(const WAVEFORMATEXTENSIBLE*)in;
else if(in->wFormatTag == WAVE_FORMAT_PCM)

View File

@ -246,7 +246,7 @@ ALCenum ALCwinmmPlayback_open(ALCwinmmPlayback *self, const ALCchar *deviceName)
UINT DeviceID{static_cast<UINT>(std::distance(PlaybackDevices.cbegin(), iter))};
retry_open:
memset(&self->Format, 0, sizeof(WAVEFORMATEX));
self->Format = WAVEFORMATEX{};
if(device->FmtType == DevFmtFloat)
{
self->Format.wFormatTag = WAVE_FORMAT_IEEE_FLOAT;
@ -554,7 +554,7 @@ ALCenum ALCwinmmCapture_open(ALCwinmmCapture *self, const ALCchar *deviceName)
return ALC_INVALID_ENUM;
}
memset(&self->Format, 0, sizeof(WAVEFORMATEX));
self->Format = WAVEFORMATEX{};
self->Format.wFormatTag = (device->FmtType == DevFmtFloat) ?
WAVE_FORMAT_IEEE_FLOAT : WAVE_FORMAT_PCM;
self->Format.nChannels = ChannelsFromDevFmt(device->FmtChans, device->mAmbiOrder);

View File

@ -170,7 +170,7 @@ void BFormatDec::reset(const AmbDecConf *conf, ALsizei chancount, ALuint srate,
mUpSampler[3].Gains[LF_BAND] = 0.0f;
}
memset(&mMatrix, 0, sizeof(mMatrix));
mMatrix = MatrixU{};
if(conf->FreqBands == 1)
{
mDualBand = AL_FALSE;
@ -358,7 +358,7 @@ void AmbiUpsampler::reset(const ALCdevice *device, const ALfloat w_scale, const
mXOver[0].init(400.0f / (float)device->Frequency);
std::fill(std::begin(mXOver)+1, std::end(mXOver), mXOver[0]);
memset(mGains, 0, sizeof(mGains));
mGains.fill({});
if(device->Dry.CoeffCount > 0)
{
ALfloat encgains[8][MAX_OUTPUT_CHANNELS];
@ -411,6 +411,6 @@ void AmbiUpsampler::process(ALfloat (*RESTRICT OutBuffer)[BUFFERSIZE], const ALs
mXOver[i].process(mSamples[HF_BAND], mSamples[LF_BAND], InSamples[i], SamplesToDo);
for(ALsizei j{0};j < OutChannels;j++)
MixRowSamples(OutBuffer[j], mGains[i][j], mSamples, sNumBands, 0, SamplesToDo);
MixRowSamples(OutBuffer[j], mGains[i][j].data(), mSamples, sNumBands, 0, SamplesToDo);
}
}

View File

@ -41,7 +41,7 @@ public:
private:
ALuint mEnabled; /* Bitfield of enabled channels. */
union {
union MatrixU {
alignas(16) ALfloat Dual[MAX_OUTPUT_CHANNELS][sNumBands][MAX_AMBI_COEFFS];
alignas(16) ALfloat Single[MAX_OUTPUT_CHANNELS][MAX_AMBI_COEFFS];
} mMatrix;
@ -89,7 +89,7 @@ private:
BandSplitter mXOver[4];
ALfloat mGains[4][MAX_OUTPUT_CHANNELS][sNumBands];
std::array<std::array<std::array<ALfloat,sNumBands>,MAX_OUTPUT_CHANNELS>,4> mGains;
public:
void reset(const ALCdevice *device, const ALfloat w_scale, const ALfloat xyz_scale);

View File

@ -127,7 +127,7 @@ int bs2b_get_srate(struct bs2b *bs2b)
void bs2b_clear(struct bs2b *bs2b)
{
std::memset(&bs2b->last_sample, 0, sizeof(bs2b->last_sample));
std::fill(std::begin(bs2b->last_sample), std::end(bs2b->last_sample), bs2b::t_last_sample{});
} /* bs2b_clear */
void bs2b_cross_feed(struct bs2b *bs2b, float *RESTRICT Left, float *RESTRICT Right, int SamplesToDo)

View File

@ -821,14 +821,12 @@ static ALvoid Update3DPanning(const ALCdevice *Device, const ALfloat *Reflection
*/
rot = GetTransformFromVector(ReflectionsPan);
MATRIX_MULT(transform, rot, A2B);
memset(&State->mEarly.PanGain, 0, sizeof(State->mEarly.PanGain));
for(i = 0;i < MAX_EFFECT_CHANNELS;i++)
ComputePanGains(&Device->FOAOut, transform.m[i], earlyGain,
State->mEarly.PanGain[i]);
rot = GetTransformFromVector(LateReverbPan);
MATRIX_MULT(transform, rot, A2B);
memset(&State->mLate.PanGain, 0, sizeof(State->mLate.PanGain));
for(i = 0;i < MAX_EFFECT_CHANNELS;i++)
ComputePanGains(&Device->FOAOut, transform.m[i], lateGain,
State->mLate.PanGain[i]);
@ -1379,11 +1377,13 @@ void ReverbState::process(ALsizei SamplesToDo, const ALfloat (*RESTRICT SamplesI
todo &= ~3;
/* Convert B-Format to A-Format for processing. */
memset(afmt, 0, sizeof(*afmt)*NUM_LINES);
for(c = 0;c < NUM_LINES;c++)
{
std::fill(std::begin(afmt[c]), std::end(afmt[c]), 0.0f);
MixRowSamples(afmt[c], B2A.m[c],
SamplesIn, MAX_EFFECT_CHANNELS, base, todo
);
}
/* Process the samples for reverb. */
for(c = 0;c < NUM_LINES;c++)

View File

@ -26,6 +26,8 @@
#include <ctype.h>
#include <assert.h>
#include <algorithm>
#include "alMain.h"
#include "alAuxEffectSlot.h"
#include "alu.h"
@ -147,29 +149,25 @@ void CalcAmbiCoeffs(const ALfloat y, const ALfloat z, const ALfloat x, const ALf
}
void ComputePanningGainsMC(const ChannelConfig *chancoeffs, ALsizei numchans, ALsizei numcoeffs, const ALfloat*RESTRICT coeffs, ALfloat ingain, ALfloat gains[MAX_OUTPUT_CHANNELS])
void ComputePanningGainsMC(const ChannelConfig *chancoeffs, ALsizei numchans, ALsizei numcoeffs, const ALfloat*RESTRICT coeffs, ALfloat ingain, ALfloat (&gains)[MAX_OUTPUT_CHANNELS])
{
ALsizei i, j;
ALsizei i;
for(i = 0;i < numchans;i++)
{
float gain = 0.0f;
for(j = 0;j < numcoeffs;j++)
for(ALsizei j{0};j < numcoeffs;j++)
gain += chancoeffs[i][j]*coeffs[j];
gains[i] = clampf(gain, 0.0f, 1.0f) * ingain;
}
for(;i < MAX_OUTPUT_CHANNELS;i++)
gains[i] = 0.0f;
std::fill(std::begin(gains)+i, std::end(gains), 0.0f);
}
void ComputePanningGainsBF(const BFChannelConfig *chanmap, ALsizei numchans, const ALfloat*RESTRICT coeffs, ALfloat ingain, ALfloat gains[MAX_OUTPUT_CHANNELS])
void ComputePanningGainsBF(const BFChannelConfig *chanmap, ALsizei numchans, const ALfloat*RESTRICT coeffs, ALfloat ingain, ALfloat (&gains)[MAX_OUTPUT_CHANNELS])
{
ALsizei i;
for(i = 0;i < numchans;i++)
gains[i] = chanmap[i].Scale * coeffs[chanmap[i].Index] * ingain;
for(;i < MAX_OUTPUT_CHANNELS;i++)
gains[i] = 0.0f;
std::fill(std::begin(gains)+i, std::end(gains), 0.0f);
}
@ -543,7 +541,7 @@ static void InitPanning(ALCdevice *device)
/* FOA output is always ACN+N3D for higher-order ambisonic output.
* The upsampler expects this and will convert it for output.
*/
memset(&device->FOAOut.Ambi, 0, sizeof(device->FOAOut.Ambi));
device->FOAOut.Ambi = AmbiConfig{};
for(i = 0;i < 4;i++)
{
device->FOAOut.Ambi.Map[i].Scale = 1.0f;
@ -588,7 +586,7 @@ static void InitPanning(ALCdevice *device)
xyz_scale = (device->Dry.CoeffCount > 9) ? XYZ_SCALE_3H0P :
(device->Dry.CoeffCount > 4) ? XYZ_SCALE_2H0P : 1.0f;
memset(&device->FOAOut.Ambi, 0, sizeof(device->FOAOut.Ambi));
device->FOAOut.Ambi = AmbiConfig{};
for(i = 0;i < device->Dry.NumChannels;i++)
{
device->FOAOut.Ambi.Coeffs[i][0] = device->Dry.Ambi.Coeffs[i][0] * w_scale;
@ -671,7 +669,7 @@ static void InitCustomPanning(ALCdevice *device, const AmbDecConf *conf, const A
device->Dry.CoeffCount = (conf->ChanMask > 0x1ff) ? 16 :
(conf->ChanMask > 0xf) ? 9 : 4;
memset(&device->FOAOut.Ambi, 0, sizeof(device->FOAOut.Ambi));
device->FOAOut.Ambi = AmbiConfig{};
for(i = 0;i < device->Dry.NumChannels;i++)
{
device->FOAOut.Ambi.Coeffs[i][0] = device->Dry.Ambi.Coeffs[i][0] * w_scale;
@ -734,7 +732,7 @@ static void InitHQPanning(ALCdevice *device, const AmbDecConf *conf, const ALsiz
}
else
{
memset(&device->FOAOut.Ambi, 0, sizeof(device->FOAOut.Ambi));
device->FOAOut.Ambi = AmbiConfig{};
if((conf->ChanMask&AMBI_PERIPHONIC_MASK))
{
count = 4;
@ -869,7 +867,7 @@ static void InitHrtfPanning(ALCdevice *device)
if(device->AmbiUp)
{
memset(&device->FOAOut.Ambi, 0, sizeof(device->FOAOut.Ambi));
device->FOAOut.Ambi = AmbiConfig{};
for(i = 0;i < 4;i++)
{
device->FOAOut.Ambi.Map[i].Scale = 1.0f;
@ -1207,15 +1205,11 @@ no_hrtf:
void aluInitEffectPanning(ALeffectslot *slot)
{
ALsizei i;
memset(slot->ChanMap, 0, sizeof(slot->ChanMap));
slot->NumChannels = 0;
for(i = 0;i < MAX_EFFECT_CHANNELS;i++)
ALsizei i{0};
for(auto &chanmap : slot->ChanMap)
{
slot->ChanMap[i].Scale = 1.0f;
slot->ChanMap[i].Index = i;
chanmap.Scale = 1.0f;
chanmap.Index = i++;
}
slot->NumChannels = i;
}

View File

@ -84,7 +84,7 @@ void ll_ringbuffer_reset(ll_ringbuffer_t *rb)
{
rb->write_ptr.store(0, std::memory_order_relaxed);
rb->read_ptr.store(0, std::memory_order_relaxed);
memset(rb->buf, 0, (rb->size_mask+1)*rb->elem_size);
std::fill_n(rb->buf+0, (rb->size_mask+1)*rb->elem_size, 0);
}

View File

@ -457,8 +457,8 @@ inline float ScaleAzimuthFront(float azimuth, float scale)
}
void ComputePanningGainsMC(const ChannelConfig *chancoeffs, ALsizei numchans, ALsizei numcoeffs, const ALfloat*RESTRICT coeffs, ALfloat ingain, ALfloat gains[MAX_OUTPUT_CHANNELS]);
void ComputePanningGainsBF(const BFChannelConfig *chanmap, ALsizei numchans, const ALfloat*RESTRICT coeffs, ALfloat ingain, ALfloat gains[MAX_OUTPUT_CHANNELS]);
void ComputePanningGainsMC(const ChannelConfig *chancoeffs, ALsizei numchans, ALsizei numcoeffs, const ALfloat*RESTRICT coeffs, ALfloat ingain, ALfloat (&gains)[MAX_OUTPUT_CHANNELS]);
void ComputePanningGainsBF(const BFChannelConfig *chanmap, ALsizei numchans, const ALfloat*RESTRICT coeffs, ALfloat ingain, ALfloat (&gains)[MAX_OUTPUT_CHANNELS]);
/**
* ComputePanGains
@ -468,7 +468,7 @@ void ComputePanningGainsBF(const BFChannelConfig *chanmap, ALsizei numchans, con
* coeffs are a 'slice' of a transform matrix for the input channel, used to
* scale and orient the sound samples.
*/
inline void ComputePanGains(const MixParams *dry, const ALfloat*RESTRICT coeffs, ALfloat ingain, ALfloat gains[MAX_OUTPUT_CHANNELS])
inline void ComputePanGains(const MixParams *dry, const ALfloat*RESTRICT coeffs, ALfloat ingain, ALfloat (&gains)[MAX_OUTPUT_CHANNELS])
{
if(dry->CoeffCount > 0)
ComputePanningGainsMC(dry->Ambi.Coeffs, dry->NumChannels, dry->CoeffCount,

View File

@ -532,7 +532,7 @@ ALenum InitializeEffect(ALCcontext *Context, ALeffectslot *EffectSlot, ALeffect
if(!effect)
{
EffectSlot->Effect.Type = AL_EFFECT_NULL;
memset(&EffectSlot->Effect.Props, 0, sizeof(EffectSlot->Effect.Props));
EffectSlot->Effect.Props = ALeffectProps{};
}
else
{

View File

@ -88,9 +88,7 @@ size_t al_get_page_size(void) noexcept
#ifdef _WIN32
if(!psize)
{
SYSTEM_INFO sysinfo;
memset(&sysinfo, 0, sizeof(sysinfo));
SYSTEM_INFO sysinfo{};
GetSystemInfo(&sysinfo);
psize = sysinfo.dwPageSize;
}