From 377325e794c77f5372a8fc7991eac85809e60e64 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Sat, 24 Nov 2018 19:16:21 -0800 Subject: Use C++ methods a bit more --- Alc/alc.cpp | 14 ++++++-------- Alc/mixvoice.cpp | 21 ++++++++------------- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/Alc/alc.cpp b/Alc/alc.cpp index 434e4660..ec7af970 100644 --- a/Alc/alc.cpp +++ b/Alc/alc.cpp @@ -3535,11 +3535,10 @@ ALC_API ALCvoid* ALC_APIENTRY alcGetProcAddress(ALCdevice *device, const ALCchar } else { - size_t i = 0; - for(i = 0;i < COUNTOF(alcFunctions);i++) + for(const auto &func : alcFunctions) { - if(strcmp(alcFunctions[i].funcName, funcName) == 0) - return alcFunctions[i].address; + if(strcmp(func.funcName, funcName) == 0) + return func.address; } } @@ -3560,11 +3559,10 @@ ALC_API ALCenum ALC_APIENTRY alcGetEnumValue(ALCdevice *device, const ALCchar *e } else { - size_t i = 0; - for(i = 0;i < COUNTOF(alcEnumerations);i++) + for(const auto &enm : alcEnumerations) { - if(strcmp(alcEnumerations[i].enumName, enumName) == 0) - return alcEnumerations[i].value; + if(strcmp(enm.enumName, enumName) == 0) + return enm.value; } } diff --git a/Alc/mixvoice.cpp b/Alc/mixvoice.cpp index c902c66a..6cd170f9 100644 --- a/Alc/mixvoice.cpp +++ b/Alc/mixvoice.cpp @@ -367,15 +367,12 @@ ALboolean MixSource(ALvoice *voice, ALuint SourceID, ALCcontext *Context, ALsize for(chan = 0;chan < NumChannels;chan++) { - const ALfloat *ResampledData; - ALfloat *SrcData = Device->TempBuffer[SOURCE_DATA_BUF]; - ALsizei FilledAmt; + ALfloat *SrcData{Device->TempBuffer[SOURCE_DATA_BUF]}; /* Load the previous samples into the source data first, and clear the rest. */ - memcpy(SrcData, voice->PrevSamples[chan], MAX_RESAMPLE_PADDING*sizeof(ALfloat)); - memset(SrcData+MAX_RESAMPLE_PADDING, 0, (BUFFERSIZE-MAX_RESAMPLE_PADDING)* - sizeof(ALfloat)); - FilledAmt = MAX_RESAMPLE_PADDING; + std::copy_n(voice->PrevSamples[chan], MAX_RESAMPLE_PADDING, SrcData); + std::fill_n(SrcData+MAX_RESAMPLE_PADDING, BUFFERSIZE-MAX_RESAMPLE_PADDING, 0.0f); + ALsizei FilledAmt{MAX_RESAMPLE_PADDING}; if(isstatic) { @@ -513,16 +510,14 @@ ALboolean MixSource(ALvoice *voice, ALuint SourceID, ALCcontext *Context, ALsize } /* Store the last source samples used for next time. */ - memcpy(voice->PrevSamples[chan], - &SrcData[(increment*DstBufferSize + DataPosFrac)>>FRACTIONBITS], - MAX_RESAMPLE_PADDING*sizeof(ALfloat) - ); + std::copy_n(&SrcData[(increment*DstBufferSize + DataPosFrac)>>FRACTIONBITS], + MAX_RESAMPLE_PADDING, voice->PrevSamples[chan]); /* Now resample, then filter and mix to the appropriate outputs. */ - ResampledData = Resample(&voice->ResampleState, + const ALfloat *ResampledData{Resample(&voice->ResampleState, &SrcData[MAX_RESAMPLE_PADDING], DataPosFrac, increment, Device->TempBuffer[RESAMPLED_BUF], DstBufferSize - ); + )}; { DirectParams *parms = &voice->Direct.Params[chan]; const ALfloat *samples; -- cgit v1.2.3