Change RealMixParams::ChannelName to better reflect its use

This commit is contained in:
Chris Robinson
2019-04-02 15:53:27 -07:00
parent 9ac3524521
commit d04f9326c9
5 changed files with 86 additions and 91 deletions
+66 -68
View File
@@ -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 */
+11 -10
View File
@@ -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],
+4 -2
View File
@@ -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 :
+1 -1
View File
@@ -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)";
}
+4 -10
View File
@@ -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);