aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2018-01-09 23:55:59 -0800
committerChris Robinson <[email protected]>2018-01-09 23:55:59 -0800
commitef63ec3fe9364d2036878fa871f49ee60f84482b (patch)
tree5c818196e004bfc4278b5c6ddd4763b598456ac6
parentde8c5b18248ee5d121cbd4b34b9af94f5e16df35 (diff)
Use one macro to handle both resample padding sizes
-rw-r--r--Alc/converter.c22
-rw-r--r--Alc/converter.h2
-rw-r--r--Alc/effects/chorus.c2
-rw-r--r--Alc/mixer.c18
-rw-r--r--OpenAL32/Include/alu.h11
5 files changed, 27 insertions, 28 deletions
diff --git a/Alc/converter.c b/Alc/converter.c
index 56dbc79e..8cba04a1 100644
--- a/Alc/converter.c
+++ b/Alc/converter.c
@@ -205,8 +205,8 @@ ALsizei SampleConverterAvailableOut(SampleConverter *converter, ALsizei srcframe
return 0;
}
- if(prepcount < MAX_POST_SAMPLES+MAX_PRE_SAMPLES &&
- MAX_POST_SAMPLES+MAX_PRE_SAMPLES-prepcount >= srcframes)
+ if(prepcount < MAX_RESAMPLE_PADDING*2 &&
+ MAX_RESAMPLE_PADDING*2 - prepcount >= srcframes)
{
/* Not enough input samples to generate an output sample. */
return 0;
@@ -214,7 +214,7 @@ ALsizei SampleConverterAvailableOut(SampleConverter *converter, ALsizei srcframe
DataSize64 = prepcount;
DataSize64 += srcframes;
- DataSize64 -= MAX_POST_SAMPLES+MAX_PRE_SAMPLES;
+ DataSize64 -= MAX_RESAMPLE_PADDING*2;
DataSize64 <<= FRACTIONBITS;
DataSize64 -= DataPosFrac;
@@ -256,10 +256,10 @@ ALsizei SampleConverterInput(SampleConverter *converter, const ALvoid **src, ALs
converter->mSrcPrepCount = 0;
continue;
}
- toread = mini(*srcframes, BUFFERSIZE-(MAX_POST_SAMPLES+MAX_PRE_SAMPLES));
+ toread = mini(*srcframes, BUFFERSIZE - MAX_RESAMPLE_PADDING*2);
- if(prepcount < MAX_POST_SAMPLES+MAX_PRE_SAMPLES &&
- MAX_POST_SAMPLES+MAX_PRE_SAMPLES-prepcount >= toread)
+ if(prepcount < MAX_RESAMPLE_PADDING*2 &&
+ MAX_RESAMPLE_PADDING*2 - prepcount >= toread)
{
/* Not enough input samples to generate an output sample. Store
* what we're given for later.
@@ -277,7 +277,7 @@ ALsizei SampleConverterInput(SampleConverter *converter, const ALvoid **src, ALs
DataSize64 = prepcount;
DataSize64 += toread;
- DataSize64 -= MAX_POST_SAMPLES+MAX_PRE_SAMPLES;
+ DataSize64 -= MAX_RESAMPLE_PADDING*2;
DataSize64 <<= FRACTIONBITS;
DataSize64 -= DataPosFrac;
@@ -310,7 +310,7 @@ ALsizei SampleConverterInput(SampleConverter *converter, const ALvoid **src, ALs
sizeof(converter->Chan[chan].mPrevSamples));
else
{
- size_t len = mini(MAX_PRE_SAMPLES+MAX_POST_SAMPLES, prepcount+toread-SrcDataEnd);
+ size_t len = mini(MAX_RESAMPLE_PADDING*2, prepcount+toread-SrcDataEnd);
memcpy(converter->Chan[chan].mPrevSamples, &SrcData[SrcDataEnd],
len*sizeof(ALfloat));
memset(converter->Chan[chan].mPrevSamples+len, 0,
@@ -319,7 +319,7 @@ ALsizei SampleConverterInput(SampleConverter *converter, const ALvoid **src, ALs
/* Now resample, and store the result in the output buffer. */
ResampledData = converter->mResample(&converter->mState,
- SrcData+MAX_PRE_SAMPLES, DataPosFrac, increment,
+ SrcData+MAX_RESAMPLE_PADDING, DataPosFrac, increment,
DstData, DstSize
);
@@ -331,8 +331,8 @@ ALsizei SampleConverterInput(SampleConverter *converter, const ALvoid **src, ALs
* fractional offset.
*/
DataPosFrac += increment*DstSize;
- converter->mSrcPrepCount = mini(MAX_PRE_SAMPLES+MAX_POST_SAMPLES,
- prepcount+toread-(DataPosFrac>>FRACTIONBITS));
+ converter->mSrcPrepCount = mini(prepcount + toread - (DataPosFrac>>FRACTIONBITS),
+ MAX_RESAMPLE_PADDING*2);
converter->mFracOffset = DataPosFrac & FRACTIONMASK;
/* Update the src and dst pointers in case there's still more to do. */
diff --git a/Alc/converter.h b/Alc/converter.h
index 9934fa4b..b58fd831 100644
--- a/Alc/converter.h
+++ b/Alc/converter.h
@@ -26,7 +26,7 @@ typedef struct SampleConverter {
alignas(16) ALfloat mDstSamples[BUFFERSIZE];
struct {
- alignas(16) ALfloat mPrevSamples[MAX_PRE_SAMPLES+MAX_POST_SAMPLES];
+ alignas(16) ALfloat mPrevSamples[MAX_RESAMPLE_PADDING*2];
} Chan[];
} SampleConverter;
diff --git a/Alc/effects/chorus.c b/Alc/effects/chorus.c
index d028dbb0..65d2225b 100644
--- a/Alc/effects/chorus.c
+++ b/Alc/effects/chorus.c
@@ -120,7 +120,7 @@ static ALboolean ALchorusState_deviceUpdate(ALchorusState *state, ALCdevice *Dev
static ALvoid ALchorusState_update(ALchorusState *state, const ALCcontext *Context, const ALeffectslot *Slot, const ALeffectProps *props)
{
- const ALsizei mindelay = maxi(MAX_PRE_SAMPLES, MAX_POST_SAMPLES) << FRACTIONBITS;
+ const ALsizei mindelay = MAX_RESAMPLE_PADDING << FRACTIONBITS;
const ALCdevice *device = Context->Device;
ALfloat frequency = (ALfloat)device->Frequency;
ALfloat coeffs[MAX_AMBI_COEFFS];
diff --git a/Alc/mixer.c b/Alc/mixer.c
index 4a1230a7..e6459fce 100644
--- a/Alc/mixer.c
+++ b/Alc/mixer.c
@@ -45,8 +45,7 @@ extern inline void InitiatePositionArrays(ALsizei frac, ALint increment, ALsizei
/* BSinc24 requires up to 23 extra samples before the current position, and 24 after. */
-static_assert(MAX_PRE_SAMPLES >= 23, "MAX_PRE_SAMPLES must be at least 23!");
-static_assert(MAX_POST_SAMPLES >= 24, "MAX_POST_SAMPLES must be at least 24!");
+static_assert(MAX_RESAMPLE_PADDING >= 24, "MAX_RESAMPLE_PADDING must be at least 24!");
enum Resampler ResamplerDefault = LinearResampler;
@@ -320,12 +319,12 @@ ALboolean MixSource(ALvoice *voice, ALsource *Source, ALCdevice *Device, ALsizei
DataSize64 *= increment;
DataSize64 += DataPosFrac+FRACTIONMASK;
DataSize64 >>= FRACTIONBITS;
- DataSize64 += MAX_POST_SAMPLES+MAX_PRE_SAMPLES;
+ DataSize64 += MAX_RESAMPLE_PADDING*2;
SrcBufferSize = (ALsizei)mini64(DataSize64, BUFFERSIZE);
/* Figure out how many samples we can actually mix from this. */
DataSize64 = SrcBufferSize;
- DataSize64 -= MAX_POST_SAMPLES+MAX_PRE_SAMPLES;
+ DataSize64 -= MAX_RESAMPLE_PADDING*2;
DataSize64 <<= FRACTIONBITS;
DataSize64 -= DataPosFrac;
DstBufferSize = (ALsizei)mini64((DataSize64+(increment-1)) / increment,
@@ -346,9 +345,10 @@ ALboolean MixSource(ALvoice *voice, ALsource *Source, ALCdevice *Device, ALsizei
ALsizei FilledAmt;
/* Load the previous samples into the source data first, and clear the rest. */
- memcpy(SrcData, voice->PrevSamples[chan], MAX_PRE_SAMPLES*sizeof(ALfloat));
- memset(SrcData+MAX_PRE_SAMPLES, 0, (SrcBufferSize-MAX_PRE_SAMPLES)*sizeof(ALfloat));
- FilledAmt = MAX_PRE_SAMPLES;
+ memcpy(SrcData, voice->PrevSamples[chan], MAX_RESAMPLE_PADDING*sizeof(ALfloat));
+ memset(SrcData+MAX_RESAMPLE_PADDING, 0, (BUFFERSIZE-MAX_RESAMPLE_PADDING)*
+ sizeof(ALfloat));
+ FilledAmt = MAX_RESAMPLE_PADDING;
if(isstatic)
{
@@ -488,12 +488,12 @@ ALboolean MixSource(ALvoice *voice, ALsource *Source, ALCdevice *Device, ALsizei
/* Store the last source samples used for next time. */
memcpy(voice->PrevSamples[chan],
&SrcData[(increment*DstBufferSize + DataPosFrac)>>FRACTIONBITS],
- MAX_PRE_SAMPLES*sizeof(ALfloat)
+ MAX_RESAMPLE_PADDING*sizeof(ALfloat)
);
/* Now resample, then filter and mix to the appropriate outputs. */
ResampledData = Resample(&voice->ResampleState,
- &SrcData[MAX_PRE_SAMPLES], DataPosFrac, increment,
+ &SrcData[MAX_RESAMPLE_PADDING], DataPosFrac, increment,
Device->TempBuffer[RESAMPLED_BUF], DstBufferSize
);
{
diff --git a/OpenAL32/Include/alu.h b/OpenAL32/Include/alu.h
index 3fc677b2..fe1b19e9 100644
--- a/OpenAL32/Include/alu.h
+++ b/OpenAL32/Include/alu.h
@@ -23,11 +23,10 @@
#define MAX_PITCH (255)
-/* Maximum number of buffer samples before the current pos needed for resampling. */
-#define MAX_PRE_SAMPLES 24
-
-/* Maximum number of buffer samples after the current pos needed for resampling. */
-#define MAX_POST_SAMPLES 24
+/* Maximum number of samples to pad on either end of a buffer for resampling.
+ * Note that both the beginning and end need padding!
+ */
+#define MAX_RESAMPLE_PADDING 24
#ifdef __cplusplus
@@ -282,7 +281,7 @@ typedef struct ALvoice {
ALuint Offset; /* Number of output samples mixed since starting. */
- alignas(16) ALfloat PrevSamples[MAX_INPUT_CHANNELS][MAX_PRE_SAMPLES];
+ alignas(16) ALfloat PrevSamples[MAX_INPUT_CHANNELS][MAX_RESAMPLE_PADDING];
InterpState ResampleState;