diff options
author | Chris Robinson <[email protected]> | 2019-05-26 21:28:51 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2019-05-26 21:28:51 -0700 |
commit | f57fedec7f8878230fb77be1d91d7c056f7e6de4 (patch) | |
tree | b10f6bf16db0f2e792b64f74388ec9ffde47791a | |
parent | f6f220025bd9674a33d896258b315c006cfd78f1 (diff) |
Get rid of the COUNTOF macro
-rw-r--r-- | Alc/alc.cpp | 17 | ||||
-rw-r--r-- | Alc/backends/opensl.cpp | 21 | ||||
-rw-r--r-- | OpenAL32/Include/alMain.h | 6 | ||||
-rw-r--r-- | OpenAL32/alEffect.cpp | 24 | ||||
-rw-r--r-- | OpenAL32/alState.cpp | 5 |
5 files changed, 34 insertions, 39 deletions
diff --git a/Alc/alc.cpp b/Alc/alc.cpp index 8a340b18..eb6269ec 100644 --- a/Alc/alc.cpp +++ b/Alc/alc.cpp @@ -1151,11 +1151,11 @@ static void alc_initconfig(void) continue; size_t len{next ? static_cast<size_t>(next-str) : strlen(str)}; - for(size_t n{0u};n < countof(gEffectList);n++) + for(const EffectList &effectitem : gEffectList) { - if(len == strlen(gEffectList[n].name) && - strncmp(gEffectList[n].name, str, len) == 0) - DisabledEffects[gEffectList[n].type] = AL_TRUE; + if(len == strlen(effectitem.name) && + strncmp(effectitem.name, str, len) == 0) + DisabledEffects[effectitem.type] = AL_TRUE; } } while(next++); } @@ -1280,14 +1280,13 @@ static ALboolean DecomposeDevFormat(ALenum format, DevFmtChannels *chans, DevFmt { AL_FORMAT_71CHN16, DevFmtX71, DevFmtShort }, { AL_FORMAT_71CHN32, DevFmtX71, DevFmtFloat }, }; - ALuint i; - for(i = 0;i < COUNTOF(list);i++) + for(const auto &item : list) { - if(list[i].format == format) + if(item.format == format) { - *chans = list[i].channels; - *type = list[i].type; + *chans = item.channels; + *type = item.type; return AL_TRUE; } } diff --git a/Alc/backends/opensl.cpp b/Alc/backends/opensl.cpp index 2072f99c..1cf309f7 100644 --- a/Alc/backends/opensl.cpp +++ b/Alc/backends/opensl.cpp @@ -27,6 +27,7 @@ #include <jni.h> #include <new> +#include <array> #include <thread> #include <functional> @@ -352,8 +353,6 @@ ALCboolean OpenSLPlayback::reset() SLDataLocator_OutputMix loc_outmix; SLDataSource audioSrc; SLDataSink audioSnk; - SLInterfaceID ids[2]; - SLboolean reqs[2]; SLresult result; if(mBufferQueueObj) @@ -437,6 +436,9 @@ ALCboolean OpenSLPlayback::reset() mFrameSize = mDevice->frameSizeFromFmt(); + const std::array<SLInterfaceID,2> ids{{ SL_IID_ANDROIDSIMPLEBUFFERQUEUE, SL_IID_ANDROIDCONFIGURATION }}; + const std::array<SLboolean,2> reqs{{ SL_BOOLEAN_TRUE, SL_BOOLEAN_FALSE }}; + loc_bufq.locatorType = SL_DATALOCATOR_ANDROIDSIMPLEBUFFERQUEUE; loc_bufq.numBuffers = mDevice->BufferSize / mDevice->UpdateSize; @@ -472,13 +474,8 @@ ALCboolean OpenSLPlayback::reset() audioSnk.pFormat = nullptr; - ids[0] = SL_IID_ANDROIDSIMPLEBUFFERQUEUE; - reqs[0] = SL_BOOLEAN_TRUE; - ids[1] = SL_IID_ANDROIDCONFIGURATION; - reqs[1] = SL_BOOLEAN_FALSE; - - result = VCALL(mEngine,CreateAudioPlayer)(&mBufferQueueObj, &audioSrc, &audioSnk, COUNTOF(ids), - ids, reqs); + result = VCALL(mEngine,CreateAudioPlayer)(&mBufferQueueObj, &audioSrc, &audioSnk, ids.size(), + ids.data(), reqs.data()); PRINTERR(result, "engine->CreateAudioPlayer"); if(SL_RESULT_SUCCESS == result) { @@ -704,8 +701,8 @@ ALCenum OpenSLCapture::open(const ALCchar* name) } if(SL_RESULT_SUCCESS == result) { - const SLInterfaceID ids[2] = { SL_IID_ANDROIDSIMPLEBUFFERQUEUE, SL_IID_ANDROIDCONFIGURATION }; - const SLboolean reqs[2] = { SL_BOOLEAN_TRUE, SL_BOOLEAN_FALSE }; + const std::array<SLInterfaceID,2> ids{{ SL_IID_ANDROIDSIMPLEBUFFERQUEUE, SL_IID_ANDROIDCONFIGURATION }}; + const std::array<SLboolean,2> reqs{{ SL_BOOLEAN_TRUE, SL_BOOLEAN_FALSE }}; SLDataLocator_IODevice loc_dev{}; loc_dev.locatorType = SL_DATALOCATOR_IODEVICE; @@ -747,7 +744,7 @@ ALCenum OpenSLCapture::open(const ALCchar* name) audioSnk.pFormat = &format_pcm; result = VCALL(mEngine,CreateAudioRecorder)(&mRecordObj, &audioSrc, &audioSnk, - COUNTOF(ids), ids, reqs); + ids.size(), ids.data(), reqs.data()); PRINTERR(result, "engine->CreateAudioRecorder"); } if(SL_RESULT_SUCCESS == result) diff --git a/OpenAL32/Include/alMain.h b/OpenAL32/Include/alMain.h index a8c7f3cd..7019a6d4 100644 --- a/OpenAL32/Include/alMain.h +++ b/OpenAL32/Include/alMain.h @@ -33,12 +33,6 @@ #include "hrtf.h" -template<typename T, size_t N> -constexpr inline size_t countof(const T(&)[N]) noexcept -{ return N; } -#define COUNTOF countof - - #ifndef UNUSED #if defined(__cplusplus) #define UNUSED(x) diff --git a/OpenAL32/alEffect.cpp b/OpenAL32/alEffect.cpp index 36a09442..51474af0 100644 --- a/OpenAL32/alEffect.cpp +++ b/OpenAL32/alEffect.cpp @@ -320,11 +320,17 @@ START_API_FUNC { if(param == AL_EFFECT_TYPE) { - ALboolean isOk = (value == AL_EFFECT_NULL); - for(size_t i{0u};!isOk && i < countof(gEffectList);i++) + ALboolean isOk{value == AL_EFFECT_NULL}; + if(!isOk) { - if(value == gEffectList[i].val && !DisabledEffects[gEffectList[i].type]) - isOk = AL_TRUE; + for(const EffectList &effectitem : gEffectList) + { + if(value == effectitem.val && !DisabledEffects[effectitem.type]) + { + isOk = AL_TRUE; + break; + } + } } if(isOk) @@ -669,8 +675,6 @@ static const struct { void LoadReverbPreset(const char *name, ALeffect *effect) { - size_t i; - if(strcasecmp(name, "NONE") == 0) { InitEffectParams(effect, AL_EFFECT_NULL); @@ -684,15 +688,15 @@ void LoadReverbPreset(const char *name, ALeffect *effect) InitEffectParams(effect, AL_EFFECT_REVERB); else InitEffectParams(effect, AL_EFFECT_NULL); - for(i = 0;i < COUNTOF(reverblist);i++) + for(const auto &reverbitem : reverblist) { const EFXEAXREVERBPROPERTIES *props; - if(strcasecmp(name, reverblist[i].name) != 0) + if(strcasecmp(name, reverbitem.name) != 0) continue; - TRACE("Loading reverb '%s'\n", reverblist[i].name); - props = &reverblist[i].props; + TRACE("Loading reverb '%s'\n", reverbitem.name); + props = &reverbitem.props; effect->Props.Reverb.Density = props->flDensity; effect->Props.Reverb.Diffusion = props->flDiffusion; effect->Props.Reverb.Gain = props->flGain; diff --git a/OpenAL32/alState.cpp b/OpenAL32/alState.cpp index 3f6a0388..0c447645 100644 --- a/OpenAL32/alState.cpp +++ b/OpenAL32/alState.cpp @@ -30,6 +30,7 @@ #include "alu.h" #include "alError.h" #include "alexcpt.h" +#include "alspan.h" #include "backends/base.h" @@ -788,7 +789,7 @@ START_API_FUNC alCubicResampler, alBSinc12Resampler, alBSinc24Resampler, }; - static_assert(COUNTOF(ResamplerNames) == ResamplerMax+1, "Incorrect ResamplerNames list"); + static_assert(al::size(ResamplerNames) == ResamplerMax+1, "Incorrect ResamplerNames list"); ContextRef context{GetContextRef()}; if(UNLIKELY(!context)) return nullptr; @@ -797,7 +798,7 @@ START_API_FUNC switch(pname) { case AL_RESAMPLER_NAME_SOFT: - if(index < 0 || static_cast<size_t>(index) >= COUNTOF(ResamplerNames)) + if(index < 0 || static_cast<size_t>(index) >= al::size(ResamplerNames)) alSetError(context.get(), AL_INVALID_VALUE, "Resampler name index %d out of range", index); else |