aboutsummaryrefslogtreecommitdiffstats
path: root/Alc/bformatdec.c
diff options
context:
space:
mode:
Diffstat (limited to 'Alc/bformatdec.c')
-rw-r--r--Alc/bformatdec.c115
1 files changed, 12 insertions, 103 deletions
diff --git a/Alc/bformatdec.c b/Alc/bformatdec.c
index 549cd42c..5b848ee0 100644
--- a/Alc/bformatdec.c
+++ b/Alc/bformatdec.c
@@ -156,10 +156,6 @@ static void init_bformatdec(void)
}
-#define MAX_DELAY_LENGTH 128
-
-#define INVALID_UPSAMPLE_INDEX INT_MAX
-
/* NOTE: BandSplitter filters are unused with single-band decoding */
typedef struct BFormatDec {
ALboolean Enabled[MAX_OUTPUT_CHANNELS];
@@ -179,11 +175,6 @@ typedef struct BFormatDec {
alignas(16) ALfloat ChannelMix[BUFFERSIZE];
struct {
- alignas(16) ALfloat Buffer[MAX_DELAY_LENGTH];
- ALsizei Length; /* Valid range is [0...MAX_DELAY_LENGTH). */
- } Delay[MAX_OUTPUT_CHANNELS];
-
- struct {
BandSplitter XOver;
ALfloat Gains[FB_Max];
} UpSampler[4];
@@ -235,14 +226,13 @@ int bformatdec_isPeriphonic(const struct BFormatDec *dec)
return dec->Periphonic;
}
-void bformatdec_reset(BFormatDec *dec, const AmbDecConf *conf, ALsizei chancount, ALuint srate, const ALsizei chanmap[MAX_OUTPUT_CHANNELS], int flags)
+void bformatdec_reset(BFormatDec *dec, const AmbDecConf *conf, ALsizei chancount, ALuint srate, const ALsizei chanmap[MAX_OUTPUT_CHANNELS])
{
static const ALsizei map2DTo3D[MAX_AMBI2D_COEFFS] = {
0, 1, 3, 4, 8, 9, 15
};
const ALfloat *coeff_scale = UnitScale;
- ALfloat distgain[MAX_OUTPUT_CHANNELS];
- ALfloat maxdist, ratio;
+ ALfloat ratio;
ALsizei i;
al_free(dec->Samples);
@@ -300,41 +290,6 @@ void bformatdec_reset(BFormatDec *dec, const AmbDecConf *conf, ALsizei chancount
dec->UpSampler[3].Gains[FB_LowFreq] = 0.0f;
}
- maxdist = 0.0f;
- for(i = 0;i < conf->NumSpeakers;i++)
- {
- maxdist = maxf(maxdist, conf->Speakers[i].Distance);
- distgain[i] = 1.0f;
- }
-
- memset(dec->Delay, 0, sizeof(dec->Delay));
- if((flags&BFDF_DistanceComp) && maxdist > 0.0f)
- {
- for(i = 0;i < conf->NumSpeakers;i++)
- {
- ALsizei chan = chanmap[i];
- ALfloat delay;
-
- /* Distance compensation only delays in steps of the sample rate.
- * This is a bit less accurate since the delay time falls to the
- * nearest sample time, but it's far simpler as it doesn't have to
- * deal with phase offsets. This means at 48khz, for instance, the
- * distance delay will be in steps of about 7 millimeters.
- */
- delay = floorf((maxdist-conf->Speakers[i].Distance) / SPEEDOFSOUNDMETRESPERSEC *
- (ALfloat)srate + 0.5f);
- if(delay >= (ALfloat)MAX_DELAY_LENGTH)
- ERR("Delay for speaker \"%s\" exceeds buffer length (%f >= %u)\n",
- al_string_get_cstr(conf->Speakers[i].Name), delay, MAX_DELAY_LENGTH);
-
- dec->Delay[chan].Length = (ALuint)clampf(delay, 0.0f, (ALfloat)(MAX_DELAY_LENGTH-1));
- distgain[i] = conf->Speakers[i].Distance / maxdist;
- TRACE("Channel %u \"%s\" distance compensation: %d samples, %f gain\n", chan,
- al_string_get_cstr(conf->Speakers[i].Name), dec->Delay[chan].Length, distgain[i]
- );
- }
- }
-
memset(&dec->Matrix, 0, sizeof(dec->Matrix));
if(conf->FreqBands == 1)
{
@@ -356,7 +311,7 @@ void bformatdec_reset(BFormatDec *dec, const AmbDecConf *conf, ALsizei chancount
else if(j == 5) gain = conf->HFOrderGain[3];
if((conf->ChanMask&(1<<l)))
dec->Matrix.Single[chan][j] = conf->HFMatrix[i][k++] / coeff_scale[l] *
- gain * distgain[i];
+ gain;
}
}
else
@@ -369,7 +324,7 @@ void bformatdec_reset(BFormatDec *dec, const AmbDecConf *conf, ALsizei chancount
else if(j == 9) gain = conf->HFOrderGain[3];
if((conf->ChanMask&(1<<j)))
dec->Matrix.Single[chan][j] = conf->HFMatrix[i][k++] / coeff_scale[j] *
- gain * distgain[i];
+ gain;
}
}
}
@@ -400,8 +355,7 @@ void bformatdec_reset(BFormatDec *dec, const AmbDecConf *conf, ALsizei chancount
else if(j == 5) gain = conf->HFOrderGain[3] * ratio;
if((conf->ChanMask&(1<<l)))
dec->Matrix.Dual[chan][FB_HighFreq][j] = conf->HFMatrix[i][k++] /
- coeff_scale[l] * gain *
- distgain[i];
+ coeff_scale[l] * gain;
}
for(j = 0,k = 0;j < MAX_AMBI2D_COEFFS;j++)
{
@@ -412,8 +366,7 @@ void bformatdec_reset(BFormatDec *dec, const AmbDecConf *conf, ALsizei chancount
else if(j == 5) gain = conf->LFOrderGain[3] / ratio;
if((conf->ChanMask&(1<<l)))
dec->Matrix.Dual[chan][FB_LowFreq][j] = conf->LFMatrix[i][k++] /
- coeff_scale[l] * gain *
- distgain[i];
+ coeff_scale[l] * gain;
}
}
else
@@ -426,8 +379,7 @@ void bformatdec_reset(BFormatDec *dec, const AmbDecConf *conf, ALsizei chancount
else if(j == 9) gain = conf->HFOrderGain[3] * ratio;
if((conf->ChanMask&(1<<j)))
dec->Matrix.Dual[chan][FB_HighFreq][j] = conf->HFMatrix[i][k++] /
- coeff_scale[j] * gain *
- distgain[i];
+ coeff_scale[j] * gain;
}
for(j = 0,k = 0;j < MAX_AMBI_COEFFS;j++)
{
@@ -437,8 +389,7 @@ void bformatdec_reset(BFormatDec *dec, const AmbDecConf *conf, ALsizei chancount
else if(j == 9) gain = conf->LFOrderGain[3] / ratio;
if((conf->ChanMask&(1<<j)))
dec->Matrix.Dual[chan][FB_LowFreq][j] = conf->LFMatrix[i][k++] /
- coeff_scale[j] * gain *
- distgain[i];
+ coeff_scale[j] * gain;
}
}
}
@@ -471,29 +422,7 @@ void bformatdec_process(struct BFormatDec *dec, ALfloat (*restrict OutBuffer)[BU
SamplesToDo
);
- if(dec->Delay[chan].Length > 0)
- {
- const ALsizei base = dec->Delay[chan].Length;
- if(SamplesToDo >= base)
- {
- for(i = 0;i < base;i++)
- OutBuffer[chan][i] += dec->Delay[chan].Buffer[i];
- for(;i < SamplesToDo;i++)
- OutBuffer[chan][i] += dec->ChannelMix[i-base];
- memcpy(dec->Delay[chan].Buffer, &dec->ChannelMix[SamplesToDo-base],
- base*sizeof(ALfloat));
- }
- else
- {
- for(i = 0;i < SamplesToDo;i++)
- OutBuffer[chan][i] += dec->Delay[chan].Buffer[i];
- memmove(dec->Delay[chan].Buffer, dec->Delay[chan].Buffer+SamplesToDo,
- base - SamplesToDo);
- memcpy(dec->Delay[chan].Buffer+base-SamplesToDo, dec->ChannelMix,
- SamplesToDo*sizeof(ALfloat));
- }
- }
- else for(i = 0;i < SamplesToDo;i++)
+ for(i = 0;i < SamplesToDo;i++)
OutBuffer[chan][i] += dec->ChannelMix[i];
}
}
@@ -508,29 +437,7 @@ void bformatdec_process(struct BFormatDec *dec, ALfloat (*restrict OutBuffer)[BU
MixMatrixRow(dec->ChannelMix, dec->Matrix.Single[chan], InSamples,
dec->NumChannels, 0, SamplesToDo);
- if(dec->Delay[chan].Length > 0)
- {
- const ALsizei base = dec->Delay[chan].Length;
- if(SamplesToDo >= base)
- {
- for(i = 0;i < base;i++)
- OutBuffer[chan][i] += dec->Delay[chan].Buffer[i];
- for(;i < SamplesToDo;i++)
- OutBuffer[chan][i] += dec->ChannelMix[i-base];
- memcpy(dec->Delay[chan].Buffer, &dec->ChannelMix[SamplesToDo-base],
- base*sizeof(ALfloat));
- }
- else
- {
- for(i = 0;i < SamplesToDo;i++)
- OutBuffer[chan][i] += dec->Delay[chan].Buffer[i];
- memmove(dec->Delay[chan].Buffer, dec->Delay[chan].Buffer+SamplesToDo,
- base - SamplesToDo);
- memcpy(dec->Delay[chan].Buffer+base-SamplesToDo, dec->ChannelMix,
- SamplesToDo*sizeof(ALfloat));
- }
- }
- else for(i = 0;i < SamplesToDo;i++)
+ for(i = 0;i < SamplesToDo;i++)
OutBuffer[chan][i] += dec->ChannelMix[i];
}
}
@@ -570,6 +477,8 @@ void bformatdec_upSample(struct BFormatDec *dec, ALfloat (*restrict OutBuffer)[B
}
+#define INVALID_UPSAMPLE_INDEX INT_MAX
+
static ALsizei GetACNIndex(const BFChannelConfig *chans, ALsizei numchans, ALsizei acn)
{
ALsizei i;