From 6699f3cf1cd563814ec5c4513613d588a05e2941 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Thu, 12 Sep 2019 04:17:21 -0700 Subject: Use unsigned channel indices --- alc/alc.cpp | 6 +++--- alc/alcmain.h | 9 +++++---- alc/alu.cpp | 37 ++++++++++++++++++------------------- alc/backends/pulseaudio.cpp | 4 ++-- alc/bformatdec.cpp | 11 +++++------ alc/bformatdec.h | 4 ++-- alc/effects/dedicated.cpp | 10 ++++++---- alc/mixvoice.cpp | 5 ++--- alc/panning.cpp | 34 ++++++++++++++++++---------------- 9 files changed, 61 insertions(+), 59 deletions(-) (limited to 'alc') diff --git a/alc/alc.cpp b/alc/alc.cpp index 10ab3b94..a819bbf7 100644 --- a/alc/alc.cpp +++ b/alc/alc.cpp @@ -1409,7 +1409,7 @@ static ALCboolean IsValidAmbiScaling(ALCenum scaling) */ void SetDefaultWFXChannelOrder(ALCdevice *device) { - device->RealOut.ChannelIndex.fill(-1); + device->RealOut.ChannelIndex.fill(INVALID_CHANNEL_INDEX); switch(device->FmtChans) { @@ -1497,7 +1497,7 @@ void SetDefaultWFXChannelOrder(ALCdevice *device) */ void SetDefaultChannelOrder(ALCdevice *device) { - device->RealOut.ChannelIndex.fill(-1); + device->RealOut.ChannelIndex.fill(INVALID_CHANNEL_INDEX); switch(device->FmtChans) { @@ -1849,7 +1849,7 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList) device->Dry.AmbiMap.fill(BFChannelConfig{}); device->Dry.Buffer = {}; std::fill(std::begin(device->NumChannelsPerOrder), std::end(device->NumChannelsPerOrder), 0u); - device->RealOut.ChannelIndex.fill(-1); + device->RealOut.ChannelIndex.fill(INVALID_CHANNEL_INDEX); device->RealOut.Buffer = {}; device->MixBuffer.clear(); device->MixBuffer.shrink_to_fit(); diff --git a/alc/alcmain.h b/alc/alcmain.h index 556268ce..fb93488f 100644 --- a/alc/alcmain.h +++ b/alc/alcmain.h @@ -183,7 +183,7 @@ struct MixParams { }; struct RealMixParams { - std::array ChannelIndex{}; + std::array ChannelIndex{}; al::span Buffer; }; @@ -374,11 +374,12 @@ const ALCchar *DevFmtChannelsString(DevFmtChannels chans) noexcept; /** * GetChannelIdxByName * - * Returns the index for the given channel name (e.g. FrontCenter), or -1 if it - * doesn't exist. + * Returns the index for the given channel name (e.g. FrontCenter), or + * INVALID_CHANNEL_INDEX if it doesn't exist. */ -inline ALint GetChannelIdxByName(const RealMixParams &real, Channel chan) noexcept +inline ALuint GetChannelIdxByName(const RealMixParams &real, Channel chan) noexcept { return real.ChannelIndex[chan]; } +#define INVALID_CHANNEL_INDEX ~0u al::vector SearchDataFiles(const char *match, const char *subdir); diff --git a/alc/alu.cpp b/alc/alu.cpp index e58ff3b4..a1c6ab7a 100644 --- a/alc/alu.cpp +++ b/alc/alu.cpp @@ -155,9 +155,8 @@ void aluInit(void) void ALCdevice::ProcessHrtf(const size_t SamplesToDo) { /* HRTF is stereo output only. */ - const int lidx{RealOut.ChannelIndex[FrontLeft]}; - const int ridx{RealOut.ChannelIndex[FrontRight]}; - ASSUME(lidx >= 0 && ridx >= 0); + const ALuint lidx{RealOut.ChannelIndex[FrontLeft]}; + const ALuint ridx{RealOut.ChannelIndex[FrontRight]}; MixDirectHrtf(RealOut.Buffer[lidx], RealOut.Buffer[ridx], Dry.Buffer, HrtfAccumData, mHrtfState.get(), SamplesToDo); @@ -171,9 +170,8 @@ void ALCdevice::ProcessAmbiDec(const size_t SamplesToDo) void ALCdevice::ProcessUhj(const size_t SamplesToDo) { /* UHJ is stereo output only. */ - const int lidx{RealOut.ChannelIndex[FrontLeft]}; - const int ridx{RealOut.ChannelIndex[FrontRight]}; - ASSUME(lidx >= 0 && ridx >= 0); + const ALuint lidx{RealOut.ChannelIndex[FrontLeft]}; + const ALuint ridx{RealOut.ChannelIndex[FrontRight]}; /* Encode to stereo-compatible 2-channel UHJ output. */ Uhj_Encoder->encode(RealOut.Buffer[lidx], RealOut.Buffer[ridx], Dry.Buffer.data(), @@ -186,9 +184,8 @@ void ALCdevice::ProcessBs2b(const size_t SamplesToDo) AmbiDecoder->process(RealOut.Buffer, Dry.Buffer.data(), SamplesToDo); /* BS2B is stereo output only. */ - const int lidx{RealOut.ChannelIndex[FrontLeft]}; - const int ridx{RealOut.ChannelIndex[FrontRight]}; - ASSUME(lidx >= 0 && ridx >= 0); + const ALuint lidx{RealOut.ChannelIndex[FrontLeft]}; + const ALuint ridx{RealOut.ChannelIndex[FrontRight]}; /* Now apply the BS2B binaural/crossfeed filter. */ bs2b_cross_feed(Bs2b.get(), RealOut.Buffer[lidx].data(), RealOut.Buffer[ridx].data(), @@ -662,8 +659,9 @@ void CalcPanningAndFilters(ALvoice *voice, const ALfloat xpos, const ALfloat ypo for(ALsizei c{0};c < num_channels;c++) { - int idx{GetChannelIdxByName(Device->RealOut, chans[c].channel)}; - if(idx != -1) voice->mChans[c].mDryParams.Gains.Target[idx] = DryGain; + const ALuint idx{GetChannelIdxByName(Device->RealOut, chans[c].channel)}; + if(idx != INVALID_CHANNEL_INDEX) + voice->mChans[c].mDryParams.Gains.Target[idx] = DryGain; } /* Auxiliary sends still use normal channel panning since they mix to @@ -807,8 +805,9 @@ void CalcPanningAndFilters(ALvoice *voice, const ALfloat xpos, const ALfloat ypo { if(Device->Dry.Buffer.data() == Device->RealOut.Buffer.data()) { - int idx = GetChannelIdxByName(Device->RealOut, chans[c].channel); - if(idx != -1) voice->mChans[c].mDryParams.Gains.Target[idx] = DryGain; + const ALuint idx{GetChannelIdxByName(Device->RealOut, chans[c].channel)}; + if(idx != INVALID_CHANNEL_INDEX) + voice->mChans[c].mDryParams.Gains.Target[idx] = DryGain; } continue; } @@ -854,8 +853,9 @@ void CalcPanningAndFilters(ALvoice *voice, const ALfloat xpos, const ALfloat ypo { if(Device->Dry.Buffer.data() == Device->RealOut.Buffer.data()) { - int idx = GetChannelIdxByName(Device->RealOut, chans[c].channel); - if(idx != -1) voice->mChans[c].mDryParams.Gains.Target[idx] = DryGain; + const ALuint idx{GetChannelIdxByName(Device->RealOut, chans[c].channel)}; + if(idx != INVALID_CHANNEL_INDEX) + voice->mChans[c].mDryParams.Gains.Target[idx] = DryGain; } continue; } @@ -1667,10 +1667,9 @@ void aluMixData(ALCdevice *device, ALvoid *OutBuffer, const ALuint NumSamples) /* Apply front image stablization for surround sound, if applicable. */ if(device->Stablizer) { - const int lidx{GetChannelIdxByName(device->RealOut, FrontLeft)}; - const int ridx{GetChannelIdxByName(device->RealOut, FrontRight)}; - const int cidx{GetChannelIdxByName(device->RealOut, FrontCenter)}; - assert(lidx >= 0 && ridx >= 0 && cidx >= 0); + const ALuint lidx{GetChannelIdxByName(device->RealOut, FrontLeft)}; + const ALuint ridx{GetChannelIdxByName(device->RealOut, FrontRight)}; + const ALuint cidx{GetChannelIdxByName(device->RealOut, FrontCenter)}; ApplyStablizer(device->Stablizer.get(), RealOut, lidx, ridx, cidx, SamplesToDo); } diff --git a/alc/backends/pulseaudio.cpp b/alc/backends/pulseaudio.cpp index 499a192f..c1e615ae 100644 --- a/alc/backends/pulseaudio.cpp +++ b/alc/backends/pulseaudio.cpp @@ -278,8 +278,8 @@ size_t ChannelFromPulse(pa_channel_position_t chan) void SetChannelOrderFromMap(ALCdevice *device, const pa_channel_map &chanmap) { - device->RealOut.ChannelIndex.fill(-1); - for(int i{0};i < chanmap.channels;++i) + device->RealOut.ChannelIndex.fill(INVALID_CHANNEL_INDEX); + for(ALuint i{0};i < chanmap.channels;++i) device->RealOut.ChannelIndex[ChannelFromPulse(chanmap.map[i])] = i; } diff --git a/alc/bformatdec.cpp b/alc/bformatdec.cpp index c2137b33..17b0d3d9 100644 --- a/alc/bformatdec.cpp +++ b/alc/bformatdec.cpp @@ -49,7 +49,7 @@ inline auto GetAmbiScales(AmbDecScale scaletype) noexcept -> const std::arrayFreqBands == 2); if(!mDualBand) @@ -64,7 +64,7 @@ BFormatDec::BFormatDec(const AmbDecConf *conf, const bool allow_2band, const ALu mNumChannels = inchans; mEnabled = std::accumulate(std::begin(chanmap), std::begin(chanmap)+conf->Speakers.size(), 0u, - [](ALuint mask, const ALsizei &chan) noexcept -> ALuint + [](ALuint mask, const ALuint &chan) noexcept -> ALuint { return mask | (1 << chan); } ); @@ -120,21 +120,20 @@ BFormatDec::BFormatDec(const AmbDecConf *conf, const bool allow_2band, const ALu BFormatDec::BFormatDec(const ALuint inchans, const ALsizei chancount, const ChannelDec (&chancoeffs)[MAX_OUTPUT_CHANNELS], - const ALsizei (&chanmap)[MAX_OUTPUT_CHANNELS]) + const ALuint (&chanmap)[MAX_OUTPUT_CHANNELS]) { mSamples.resize(2); mNumChannels = inchans; ASSUME(chancount > 0); mEnabled = std::accumulate(std::begin(chanmap), std::begin(chanmap)+chancount, 0u, - [](ALuint mask, const ALsizei &chan) noexcept -> ALuint + [](ALuint mask, const ALuint &chan) noexcept -> ALuint { return mask | (1 << chan); } ); const ChannelDec *incoeffs{chancoeffs}; - auto set_coeffs = [this,inchans,&incoeffs](const ALsizei chanidx) noexcept -> void + auto set_coeffs = [this,inchans,&incoeffs](const ALuint chanidx) noexcept -> void { - ASSUME(chanidx >= 0); ALfloat (&mtx)[MAX_AMBI_CHANNELS] = mMatrix.Single[chanidx]; const ALfloat (&coeffs)[MAX_AMBI_CHANNELS] = *(incoeffs++); diff --git a/alc/bformatdec.h b/alc/bformatdec.h index 98cbb022..dc8059b0 100644 --- a/alc/bformatdec.h +++ b/alc/bformatdec.h @@ -43,10 +43,10 @@ class BFormatDec { public: BFormatDec(const AmbDecConf *conf, const bool allow_2band, const ALuint inchans, - const ALuint srate, const ALsizei (&chanmap)[MAX_OUTPUT_CHANNELS]); + const ALuint srate, const ALuint (&chanmap)[MAX_OUTPUT_CHANNELS]); BFormatDec(const ALuint inchans, const ALsizei chancount, const ChannelDec (&chancoeffs)[MAX_OUTPUT_CHANNELS], - const ALsizei (&chanmap)[MAX_OUTPUT_CHANNELS]); + const ALuint (&chanmap)[MAX_OUTPUT_CHANNELS]); /* Decodes the ambisonic input to the given output channels. */ void process(const al::span OutBuffer, const FloatBufferLine *InSamples, diff --git a/alc/effects/dedicated.cpp b/alc/effects/dedicated.cpp index 02fdcc78..aa81e13b 100644 --- a/alc/effects/dedicated.cpp +++ b/alc/effects/dedicated.cpp @@ -58,8 +58,9 @@ void DedicatedState::update(const ALCcontext*, const ALeffectslot *slot, const E if(slot->Params.EffectType == AL_EFFECT_DEDICATED_LOW_FREQUENCY_EFFECT) { - const int idx{!target.RealOut ? -1 : GetChannelIdxByName(*target.RealOut, LFE)}; - if(idx != -1) + const ALuint idx{!target.RealOut ? INVALID_CHANNEL_INDEX : + GetChannelIdxByName(*target.RealOut, LFE)}; + if(idx != INVALID_CHANNEL_INDEX) { mOutTarget = target.RealOut->Buffer; mTargetGains[idx] = Gain; @@ -69,8 +70,9 @@ void DedicatedState::update(const ALCcontext*, const ALeffectslot *slot, const E { /* Dialog goes to the front-center speaker if it exists, otherwise it * plays from the front-center location. */ - const int idx{!target.RealOut ? -1 : GetChannelIdxByName(*target.RealOut, FrontCenter)}; - if(idx != -1) + const ALuint idx{!target.RealOut ? INVALID_CHANNEL_INDEX : + GetChannelIdxByName(*target.RealOut, FrontCenter)}; + if(idx != INVALID_CHANNEL_INDEX) { mOutTarget = target.RealOut->Buffer; mTargetGains[idx] = Gain; diff --git a/alc/mixvoice.cpp b/alc/mixvoice.cpp index 09b76fb7..98b86c9a 100644 --- a/alc/mixvoice.cpp +++ b/alc/mixvoice.cpp @@ -641,9 +641,8 @@ void ALvoice::mix(State vstate, ALCcontext *Context, const ALuint SamplesToDo) if((mFlags&VOICE_HAS_HRTF)) { - const int OutLIdx{GetChannelIdxByName(Device->RealOut, FrontLeft)}; - const int OutRIdx{GetChannelIdxByName(Device->RealOut, FrontRight)}; - ASSUME(OutLIdx >= 0 && OutRIdx >= 0); + const ALuint OutLIdx{GetChannelIdxByName(Device->RealOut, FrontLeft)}; + const ALuint OutRIdx{GetChannelIdxByName(Device->RealOut, FrontRight)}; auto &HrtfSamples = Device->HrtfSourceData; auto &AccumSamples = Device->HrtfAccumData; diff --git a/alc/panning.cpp b/alc/panning.cpp index a33b9387..31daf455 100644 --- a/alc/panning.cpp +++ b/alc/panning.cpp @@ -147,9 +147,9 @@ struct ChannelMap { ALfloat Config[MAX_AMBI2D_CHANNELS]; }; -bool MakeSpeakerMap(ALCdevice *device, const AmbDecConf *conf, ALsizei (&speakermap)[MAX_OUTPUT_CHANNELS]) +bool MakeSpeakerMap(ALCdevice *device, const AmbDecConf *conf, ALuint (&speakermap)[MAX_OUTPUT_CHANNELS]) { - auto map_spkr = [device](const AmbDecConf::SpeakerConf &speaker) -> ALsizei + auto map_spkr = [device](const AmbDecConf::SpeakerConf &speaker) -> ALuint { /* NOTE: AmbDec does not define any standard speaker names, however * for this to work we have to by able to find the output channel @@ -222,15 +222,15 @@ bool MakeSpeakerMap(ALCdevice *device, const AmbDecConf *conf, ALsizei (&speaker return -1; } } - const int chidx{GetChannelIdxByName(device->RealOut, ch)}; - if(chidx == -1) + const ALuint chidx{GetChannelIdxByName(device->RealOut, ch)}; + if(chidx == INVALID_CHANNEL_INDEX) ERR("Failed to lookup AmbDec speaker label %s\n", speaker.Name.c_str()); return chidx; }; std::transform(conf->Speakers.begin(), conf->Speakers.end(), std::begin(speakermap), map_spkr); /* Return success if no invalid entries are found. */ - auto speakermap_end = std::begin(speakermap) + conf->Speakers.size(); - return std::find(std::begin(speakermap), speakermap_end, -1) == speakermap_end; + auto spkrmap_end = std::begin(speakermap) + conf->Speakers.size(); + return std::find(std::begin(speakermap), spkrmap_end, INVALID_CHANNEL_INDEX) == spkrmap_end; } @@ -285,7 +285,8 @@ void InitNearFieldCtrl(ALCdevice *device, ALfloat ctrl_dist, ALsizei order, std::fill(iter, std::end(device->NumChannelsPerOrder), 0u); } -void InitDistanceComp(ALCdevice *device, const AmbDecConf *conf, const ALsizei (&speakermap)[MAX_OUTPUT_CHANNELS]) +void InitDistanceComp(ALCdevice *device, const AmbDecConf *conf, + const ALuint (&speakermap)[MAX_OUTPUT_CHANNELS]) { auto get_max = std::bind(maxf, _1, std::bind(std::mem_fn(&AmbDecConf::SpeakerConf::Distance), _2)); @@ -302,7 +303,7 @@ void InitDistanceComp(ALCdevice *device, const AmbDecConf *conf, const ALsizei ( for(size_t i{0u};i < conf->Speakers.size();i++) { const AmbDecConf::SpeakerConf &speaker = conf->Speakers[i]; - const ALsizei chan{speakermap[i]}; + const ALuint chan{speakermap[i]}; /* Distance compensation only delays in steps of the sample rate. This * is a bit less accurate since the delay time falls to the nearest @@ -429,11 +430,11 @@ void InitPanning(ALCdevice *device) else { ChannelDec chancoeffs[MAX_OUTPUT_CHANNELS]{}; - ALsizei idxmap[MAX_OUTPUT_CHANNELS]{}; + ALuint idxmap[MAX_OUTPUT_CHANNELS]{}; for(size_t i{0u};i < chanmap.size();++i) { - const ALint idx{GetChannelIdxByName(device->RealOut, chanmap[i].ChanName)}; - if(idx < 0) + const ALuint idx{GetChannelIdxByName(device->RealOut, chanmap[i].ChanName)}; + if(idx == INVALID_CHANNEL_INDEX) { ERR("Failed to find %s channel in device\n", GetLabelFromChannel(chanmap[i].ChanName)); @@ -465,7 +466,8 @@ void InitPanning(ALCdevice *device) } } -void InitCustomPanning(ALCdevice *device, bool hqdec, const AmbDecConf *conf, const ALsizei (&speakermap)[MAX_OUTPUT_CHANNELS]) +void InitCustomPanning(ALCdevice *device, bool hqdec, const AmbDecConf *conf, + const ALuint (&speakermap)[MAX_OUTPUT_CHANNELS]) { static constexpr ALuint chans_per_order2d[MAX_AMBI_ORDER+1] = { 1, 2, 2, 2 }; static constexpr ALuint chans_per_order3d[MAX_AMBI_ORDER+1] = { 1, 3, 5, 7 }; @@ -474,9 +476,9 @@ void InitCustomPanning(ALCdevice *device, bool hqdec, const AmbDecConf *conf, co ERR("Basic renderer uses the high-frequency matrix as single-band (xover_freq = %.0fhz)\n", conf->XOverFreq); - ALsizei order{(conf->ChanMask > AMBI_2ORDER_MASK) ? 3 : - (conf->ChanMask > AMBI_1ORDER_MASK) ? 2 : 1}; - device->mAmbiOrder = order; + const ALuint order{(conf->ChanMask > AMBI_2ORDER_MASK) ? 3u : + (conf->ChanMask > AMBI_1ORDER_MASK) ? 2u : 1u}; + device->mAmbiOrder = static_cast(order); ALuint count; if((conf->ChanMask&AMBI_PERIPHONIC_MASK)) @@ -692,7 +694,7 @@ void aluInitRenderer(ALCdevice *device, ALint hrtf_id, HrtfRequestMode hrtf_appr } const char *devname{device->DeviceName.c_str()}; - ALsizei speakermap[MAX_OUTPUT_CHANNELS]; + ALuint speakermap[MAX_OUTPUT_CHANNELS]; AmbDecConf *pconf{nullptr}; AmbDecConf conf{}; if(layout) -- cgit v1.2.3