Improve handling of voice's AmbiScales for upsampling

This commit is contained in:
Chris Robinson
2019-03-10 15:46:46 -07:00
parent 663a6ce4e7
commit 030b24a40d
3 changed files with 25 additions and 10 deletions
+1 -5
View File
@@ -607,11 +607,7 @@ void MixSource(ALvoice *voice, const ALuint SourceID, ALCcontext *Context, const
Device->ResampledData, DstBufferSize)};
if((voice->Flags&VOICE_IS_AMBISONIC))
{
/* TODO: Does not properly handle HOA sources. Currently only
* first-order sources are possible, but in the future it would
* be desirable.
*/
const ALfloat hfscale{(chan==0) ? voice->AmbiScales[0] : voice->AmbiScales[1]};
const ALfloat hfscale{voice->AmbiScales[chan]};
/* Beware the evil const_cast. It's safe since it's pointing to
* either SrcData or Device->ResampledData (both non-const),
* but the resample method takes its input as const float* and
+1 -1
View File
@@ -256,7 +256,7 @@ struct ALvoice {
InterpState ResampleState;
std::array<ALfloat,MAX_AMBI_ORDER+1> AmbiScales;
std::array<ALfloat,MAX_INPUT_CHANNELS> AmbiScales;
BandSplitter AmbiSplitter[MAX_INPUT_CHANNELS];
struct {
+23 -4
View File
@@ -2871,13 +2871,32 @@ AL_API ALvoid AL_APIENTRY alSourcePlayv(ALsizei n, const ALuint *sources)
/* Don't need to set the VOICE_IS_AMBISONIC flag if the device is
* mixing in first order. No HF scaling is necessary to mix it.
*/
if(((*buffer)->mFmtChannels == FmtBFormat2D || (*buffer)->mFmtChannels == FmtBFormat3D) &&
if((voice->Channels == FmtBFormat2D || voice->Channels == FmtBFormat3D) &&
device->mAmbiOrder > 1)
{
voice->AmbiScales = BFormatDec::GetHFOrderScales(1, device->mAmbiOrder);
auto scales = BFormatDec::GetHFOrderScales(1, device->mAmbiOrder);
if(voice->Channels == FmtBFormat2D)
{
static constexpr int Order2DFromChan[MAX_AMBI2D_CHANNELS]{
0, 1,1, 2,2, 3,3
};
const size_t count{Ambi2DChannelsFromOrder(1u)};
std::transform(Order2DFromChan, Order2DFromChan+count, voice->AmbiScales.begin(),
[&scales](size_t idx) -> ALfloat { return scales[idx]; });
}
else
{
static constexpr int OrderFromChan[MAX_AMBI_CHANNELS]{
0, 1,1,1, 2,2,2,2,2, 3,3,3,3,3,3,3,
};
const size_t count{Ambi2DChannelsFromOrder(1u)};
std::transform(OrderFromChan, OrderFromChan+count, voice->AmbiScales.begin(),
[&scales](size_t idx) -> ALfloat { return scales[idx]; });
}
voice->AmbiSplitter[0].init(400.0f / static_cast<ALfloat>(device->Frequency));
for(ALsizei i{1};i < voice->NumChannels;++i)
voice->AmbiSplitter[i] = voice->AmbiSplitter[0];
std::fill(std::begin(voice->AmbiSplitter)+1,
std::begin(voice->AmbiSplitter)+voice->NumChannels, voice->AmbiSplitter[0]);
voice->Flags |= VOICE_IS_AMBISONIC;
}