diff options
author | Chris Robinson <[email protected]> | 2019-04-02 15:53:27 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2019-04-02 16:06:45 -0700 |
commit | d04f9326c95696413a26f6a2d004138f42686e4d (patch) | |
tree | bb25f6b50b05aa132e953bda837c6902b1d9f167 | |
parent | 9ac3524521e23e667e69dccee6a928a18267a440 (diff) |
Change RealMixParams::ChannelName to better reflect its use
-rw-r--r-- | Alc/alc.cpp | 134 | ||||
-rw-r--r-- | Alc/alu.cpp | 21 | ||||
-rw-r--r-- | Alc/mixvoice.cpp | 6 | ||||
-rw-r--r-- | Alc/panning.cpp | 2 | ||||
-rw-r--r-- | OpenAL32/Include/alMain.h | 14 |
5 files changed, 86 insertions, 91 deletions
diff --git a/Alc/alc.cpp b/Alc/alc.cpp index 7060036d..887da871 100644 --- a/Alc/alc.cpp +++ b/Alc/alc.cpp @@ -1375,84 +1375,83 @@ static ALCboolean IsValidAmbiScaling(ALCenum scaling) */ void SetDefaultWFXChannelOrder(ALCdevice *device) { - std::fill(std::begin(device->RealOut.ChannelName), std::end(device->RealOut.ChannelName), - InvalidChannel); + device->RealOut.ChannelIndex.fill(-1); switch(device->FmtChans) { case DevFmtMono: - device->RealOut.ChannelName[0] = FrontCenter; + device->RealOut.ChannelIndex[FrontCenter] = 0; break; case DevFmtStereo: - device->RealOut.ChannelName[0] = FrontLeft; - device->RealOut.ChannelName[1] = FrontRight; + device->RealOut.ChannelIndex[FrontLeft] = 0; + device->RealOut.ChannelIndex[FrontRight] = 1; break; case DevFmtQuad: - device->RealOut.ChannelName[0] = FrontLeft; - device->RealOut.ChannelName[1] = FrontRight; - device->RealOut.ChannelName[2] = BackLeft; - device->RealOut.ChannelName[3] = BackRight; + device->RealOut.ChannelIndex[FrontLeft] = 0; + device->RealOut.ChannelIndex[FrontRight] = 1; + device->RealOut.ChannelIndex[BackLeft] = 2; + device->RealOut.ChannelIndex[BackRight] = 3; break; case DevFmtX51: - device->RealOut.ChannelName[0] = FrontLeft; - device->RealOut.ChannelName[1] = FrontRight; - device->RealOut.ChannelName[2] = FrontCenter; - device->RealOut.ChannelName[3] = LFE; - device->RealOut.ChannelName[4] = SideLeft; - device->RealOut.ChannelName[5] = SideRight; + device->RealOut.ChannelIndex[FrontLeft] = 0; + device->RealOut.ChannelIndex[FrontRight] = 1; + device->RealOut.ChannelIndex[FrontCenter] = 2; + device->RealOut.ChannelIndex[LFE] = 3; + device->RealOut.ChannelIndex[SideLeft] = 4; + device->RealOut.ChannelIndex[SideRight] = 5; break; case DevFmtX51Rear: - device->RealOut.ChannelName[0] = FrontLeft; - device->RealOut.ChannelName[1] = FrontRight; - device->RealOut.ChannelName[2] = FrontCenter; - device->RealOut.ChannelName[3] = LFE; - device->RealOut.ChannelName[4] = BackLeft; - device->RealOut.ChannelName[5] = BackRight; + device->RealOut.ChannelIndex[FrontLeft] = 0; + device->RealOut.ChannelIndex[FrontRight] = 1; + device->RealOut.ChannelIndex[FrontCenter] = 2; + device->RealOut.ChannelIndex[LFE] = 3; + device->RealOut.ChannelIndex[BackLeft] = 4; + device->RealOut.ChannelIndex[BackRight] = 5; break; case DevFmtX61: - device->RealOut.ChannelName[0] = FrontLeft; - device->RealOut.ChannelName[1] = FrontRight; - device->RealOut.ChannelName[2] = FrontCenter; - device->RealOut.ChannelName[3] = LFE; - device->RealOut.ChannelName[4] = BackCenter; - device->RealOut.ChannelName[5] = SideLeft; - device->RealOut.ChannelName[6] = SideRight; + device->RealOut.ChannelIndex[FrontLeft] = 0; + device->RealOut.ChannelIndex[FrontRight] = 1; + device->RealOut.ChannelIndex[FrontCenter] = 2; + device->RealOut.ChannelIndex[LFE] = 3; + device->RealOut.ChannelIndex[BackCenter] = 4; + device->RealOut.ChannelIndex[SideLeft] = 5; + device->RealOut.ChannelIndex[SideRight] = 6; break; case DevFmtX71: - device->RealOut.ChannelName[0] = FrontLeft; - device->RealOut.ChannelName[1] = FrontRight; - device->RealOut.ChannelName[2] = FrontCenter; - device->RealOut.ChannelName[3] = LFE; - device->RealOut.ChannelName[4] = BackLeft; - device->RealOut.ChannelName[5] = BackRight; - device->RealOut.ChannelName[6] = SideLeft; - device->RealOut.ChannelName[7] = SideRight; + device->RealOut.ChannelIndex[FrontLeft] = 0; + device->RealOut.ChannelIndex[FrontRight] = 1; + device->RealOut.ChannelIndex[FrontCenter] = 2; + device->RealOut.ChannelIndex[LFE] = 3; + device->RealOut.ChannelIndex[BackLeft] = 4; + device->RealOut.ChannelIndex[BackRight] = 5; + device->RealOut.ChannelIndex[SideLeft] = 6; + device->RealOut.ChannelIndex[SideRight] = 7; break; case DevFmtAmbi3D: - device->RealOut.ChannelName[0] = Aux0; + device->RealOut.ChannelIndex[Aux0] = 0; if(device->mAmbiOrder > 0) { - device->RealOut.ChannelName[1] = Aux1; - device->RealOut.ChannelName[2] = Aux2; - device->RealOut.ChannelName[3] = Aux3; + device->RealOut.ChannelIndex[Aux1] = 1; + device->RealOut.ChannelIndex[Aux2] = 2; + device->RealOut.ChannelIndex[Aux3] = 3; } if(device->mAmbiOrder > 1) { - device->RealOut.ChannelName[4] = Aux4; - device->RealOut.ChannelName[5] = Aux5; - device->RealOut.ChannelName[6] = Aux6; - device->RealOut.ChannelName[7] = Aux7; - device->RealOut.ChannelName[8] = Aux8; + device->RealOut.ChannelIndex[Aux4] = 4; + device->RealOut.ChannelIndex[Aux5] = 5; + device->RealOut.ChannelIndex[Aux6] = 6; + device->RealOut.ChannelIndex[Aux7] = 7; + device->RealOut.ChannelIndex[Aux8] = 8; } if(device->mAmbiOrder > 2) { - device->RealOut.ChannelName[9] = Aux9; - device->RealOut.ChannelName[10] = Aux10; - device->RealOut.ChannelName[11] = Aux11; - device->RealOut.ChannelName[12] = Aux12; - device->RealOut.ChannelName[13] = Aux13; - device->RealOut.ChannelName[14] = Aux14; - device->RealOut.ChannelName[15] = Aux15; + device->RealOut.ChannelIndex[Aux9] = 9; + device->RealOut.ChannelIndex[Aux10] = 10; + device->RealOut.ChannelIndex[Aux11] = 11; + device->RealOut.ChannelIndex[Aux12] = 12; + device->RealOut.ChannelIndex[Aux13] = 13; + device->RealOut.ChannelIndex[Aux14] = 14; + device->RealOut.ChannelIndex[Aux15] = 15; } break; } @@ -1464,28 +1463,27 @@ void SetDefaultWFXChannelOrder(ALCdevice *device) */ void SetDefaultChannelOrder(ALCdevice *device) { - std::fill(std::begin(device->RealOut.ChannelName), std::end(device->RealOut.ChannelName), - InvalidChannel); + device->RealOut.ChannelIndex.fill(-1); switch(device->FmtChans) { case DevFmtX51Rear: - device->RealOut.ChannelName[0] = FrontLeft; - device->RealOut.ChannelName[1] = FrontRight; - device->RealOut.ChannelName[2] = BackLeft; - device->RealOut.ChannelName[3] = BackRight; - device->RealOut.ChannelName[4] = FrontCenter; - device->RealOut.ChannelName[5] = LFE; + device->RealOut.ChannelIndex[FrontLeft] = 0; + device->RealOut.ChannelIndex[FrontRight] = 1; + device->RealOut.ChannelIndex[BackLeft] = 2; + device->RealOut.ChannelIndex[BackRight] = 3; + device->RealOut.ChannelIndex[FrontCenter] = 4; + device->RealOut.ChannelIndex[LFE] = 5; return; case DevFmtX71: - device->RealOut.ChannelName[0] = FrontLeft; - device->RealOut.ChannelName[1] = FrontRight; - device->RealOut.ChannelName[2] = BackLeft; - device->RealOut.ChannelName[3] = BackRight; - device->RealOut.ChannelName[4] = FrontCenter; - device->RealOut.ChannelName[5] = LFE; - device->RealOut.ChannelName[6] = SideLeft; - device->RealOut.ChannelName[7] = SideRight; + device->RealOut.ChannelIndex[FrontLeft] = 0; + device->RealOut.ChannelIndex[FrontRight] = 1; + device->RealOut.ChannelIndex[BackLeft] = 2; + device->RealOut.ChannelIndex[BackRight] = 3; + device->RealOut.ChannelIndex[FrontCenter] = 4; + device->RealOut.ChannelIndex[LFE] = 5; + device->RealOut.ChannelIndex[SideLeft] = 6; + device->RealOut.ChannelIndex[SideRight] = 7; return; /* Same as WFX order */ diff --git a/Alc/alu.cpp b/Alc/alu.cpp index d26597df..86425086 100644 --- a/Alc/alu.cpp +++ b/Alc/alu.cpp @@ -128,14 +128,13 @@ inline HrtfDirectMixerFunc SelectHrtfMixer(void) void ProcessHrtf(ALCdevice *device, const ALsizei SamplesToDo) { /* HRTF is stereo output only. */ - const int lidx{(device->RealOut.ChannelName[0]==FrontLeft) ? 0 : 1}; - const int ridx{(device->RealOut.ChannelName[0]==FrontLeft) ? 1 : 0}; - ALfloat *LeftOut{device->RealOut.Buffer[lidx]}; - ALfloat *RightOut{device->RealOut.Buffer[ridx]}; + const int lidx{device->RealOut.ChannelIndex[FrontLeft]}; + const int ridx{device->RealOut.ChannelIndex[FrontRight]}; + ASSUME(lidx >= 0 && ridx >= 0); DirectHrtfState *state{device->mHrtfState.get()}; - MixDirectHrtf(LeftOut, RightOut, device->Dry.Buffer, device->HrtfAccumData, state, - device->Dry.NumChannels, SamplesToDo); + MixDirectHrtf(device->RealOut.Buffer[lidx], device->RealOut.Buffer[ridx], device->Dry.Buffer, + device->HrtfAccumData, state, device->Dry.NumChannels, SamplesToDo); } void ProcessAmbiDec(ALCdevice *device, const ALsizei SamplesToDo) @@ -148,8 +147,9 @@ void ProcessAmbiDec(ALCdevice *device, const ALsizei SamplesToDo) void ProcessUhj(ALCdevice *device, const ALsizei SamplesToDo) { /* UHJ is stereo output only. */ - const int lidx{(device->RealOut.ChannelName[0]==FrontLeft) ? 0 : 1}; - const int ridx{(device->RealOut.ChannelName[0]==FrontLeft) ? 1 : 0}; + const int lidx{device->RealOut.ChannelIndex[FrontLeft]}; + const int ridx{device->RealOut.ChannelIndex[FrontRight]}; + ASSUME(lidx >= 0 && ridx >= 0); /* Encode to stereo-compatible 2-channel UHJ output. */ Uhj2Encoder *uhj2enc{device->Uhj_Encoder.get()}; @@ -160,8 +160,9 @@ void ProcessUhj(ALCdevice *device, const ALsizei SamplesToDo) void ProcessBs2b(ALCdevice *device, const ALsizei SamplesToDo) { /* BS2B is stereo output only. */ - const int lidx{(device->RealOut.ChannelName[0]==FrontLeft) ? 0 : 1}; - const int ridx{(device->RealOut.ChannelName[0]==FrontLeft) ? 1 : 0}; + const int lidx{device->RealOut.ChannelIndex[FrontLeft]}; + const int ridx{device->RealOut.ChannelIndex[FrontRight]}; + ASSUME(lidx >= 0 && ridx >= 0); /* Apply binaural/crossfeed filter */ bs2b_cross_feed(device->Bs2b.get(), device->RealOut.Buffer[lidx], diff --git a/Alc/mixvoice.cpp b/Alc/mixvoice.cpp index 20cfdfe2..210ddf4f 100644 --- a/Alc/mixvoice.cpp +++ b/Alc/mixvoice.cpp @@ -467,8 +467,6 @@ void MixVoice(ALvoice *voice, ALvoice::State vstate, const ALuint SourceID, ALCc ALCdevice *Device{Context->Device}; const ALsizei IrSize{Device->mHrtf ? Device->mHrtf->irSize : 0}; - const int OutLIdx{GetChannelIdxByName(Device->RealOut, FrontLeft)}; - const int OutRIdx{GetChannelIdxByName(Device->RealOut, FrontRight)}; ASSUME(IrSize >= 0); @@ -624,6 +622,10 @@ void MixVoice(ALvoice *voice, ALvoice::State vstate, const ALuint SourceID, ALCc if((voice->mFlags&VOICE_HAS_HRTF)) { + const int OutLIdx{GetChannelIdxByName(Device->RealOut, FrontLeft)}; + const int OutRIdx{GetChannelIdxByName(Device->RealOut, FrontRight)}; + ASSUME(OutLIdx >= 0 && OutRIdx >= 0); + auto &HrtfSamples = Device->HrtfSourceData; auto &AccumSamples = Device->HrtfAccumData; const ALfloat TargetGain{UNLIKELY(vstate == ALvoice::Stopping) ? 0.0f : diff --git a/Alc/panning.cpp b/Alc/panning.cpp index f24f59d6..eb1a7e16 100644 --- a/Alc/panning.cpp +++ b/Alc/panning.cpp @@ -98,7 +98,7 @@ inline const char *GetLabelFromChannel(Channel channel) case Aux14: return "aux-14"; case Aux15: return "aux-15"; - case InvalidChannel: break; + case MaxChannels: break; } return "(unknown)"; } diff --git a/OpenAL32/Include/alMain.h b/OpenAL32/Include/alMain.h index daa3a09a..947b6f1b 100644 --- a/OpenAL32/Include/alMain.h +++ b/OpenAL32/Include/alMain.h @@ -123,7 +123,7 @@ enum Channel { Aux14, Aux15, - InvalidChannel + MaxChannels }; @@ -326,7 +326,7 @@ struct MixParams { }; struct RealMixParams { - Channel ChannelName[MAX_OUTPUT_CHANNELS]{}; + std::array<ALint,MaxChannels> ChannelIndex{}; ALfloat (*Buffer)[BUFFERSIZE]{nullptr}; ALsizei NumChannels{0}; @@ -553,20 +553,14 @@ void SetDefaultWFXChannelOrder(ALCdevice *device); const ALCchar *DevFmtTypeString(DevFmtType type) noexcept; const ALCchar *DevFmtChannelsString(DevFmtChannels chans) noexcept; -inline ALint GetChannelIndex(const Channel (&names)[MAX_OUTPUT_CHANNELS], Channel chan) -{ - auto iter = std::find(std::begin(names), std::end(names), chan); - if(iter == std::end(names)) return -1; - return static_cast<ALint>(std::distance(std::begin(names), iter)); -} /** * GetChannelIdxByName * * Returns the index for the given channel name (e.g. FrontCenter), or -1 if it * doesn't exist. */ -inline ALint GetChannelIdxByName(const RealMixParams &real, Channel chan) -{ return GetChannelIndex(real.ChannelName, chan); } +inline ALint GetChannelIdxByName(const RealMixParams &real, Channel chan) noexcept +{ return real.ChannelIndex[chan]; } void StartEventThrd(ALCcontext *ctx); |