diff options
-rw-r--r-- | Alc/ALu.c | 2 | ||||
-rw-r--r-- | Alc/converter.c | 20 | ||||
-rw-r--r-- | Alc/converter.h | 1 | ||||
-rw-r--r-- | OpenAL32/Include/alu.h | 2 |
4 files changed, 18 insertions, 7 deletions
@@ -214,7 +214,7 @@ static aluVector aluMatrixfVector(const aluMatrixf *mtx, const aluVector *vec) * modified for use with an interpolated increment for buttery-smooth pitch * changes. */ -static ALboolean BsincPrepare(const ALuint increment, BsincState *state) +ALboolean BsincPrepare(const ALuint increment, BsincState *state) { static const ALfloat scaleBase = 1.510578918e-01f, scaleRange = 1.177936623e+00f; static const ALuint m[BSINC_SCALE_COUNT] = { 24, 24, 24, 24, 24, 24, 24, 20, 20, 20, 16, 16, 16, 12, 12, 12 }; diff --git a/Alc/converter.c b/Alc/converter.c index c6e60454..558f5e40 100644 --- a/Alc/converter.c +++ b/Alc/converter.c @@ -9,6 +9,7 @@ SampleConverter *CreateSampleConverter(enum DevFmtType srcType, enum DevFmtType dstType, ALsizei numchans, ALsizei srcRate, ALsizei dstRate) { SampleConverter *converter; + FPUCtl oldMode; if(numchans <= 0 || srcRate <= 0 || dstRate <= 0) return NULL; @@ -21,8 +22,10 @@ SampleConverter *CreateSampleConverter(enum DevFmtType srcType, enum DevFmtType converter->mDstTypeSize = BytesFromDevFmt(dstType); converter->mSrcPrepCount = 0; - converter->mFracOffset = 0; + + /* Have to set the mixer FPU mode since that's what the resampler code expects. */ + SetMixerFPUMode(&oldMode); converter->mIncrement = (ALsizei)clampu64((ALuint64)srcRate*FRACTIONONE/dstRate, 1, MAX_PITCH*FRACTIONONE); if(converter->mIncrement == FRACTIONONE) @@ -30,8 +33,10 @@ SampleConverter *CreateSampleConverter(enum DevFmtType srcType, enum DevFmtType else { /* TODO: Allow other resamplers. */ - converter->mResample = SelectResampler(LinearResampler); + BsincPrepare(converter->mIncrement, &converter->mState.bsinc); + converter->mResample = SelectResampler(BSincResampler); } + RestoreFPUMode(&oldMode); return converter; } @@ -113,17 +118,17 @@ static void LoadSamples(ALfloat *dst, const ALvoid *src, ALint srcstep, enum Dev static inline ALbyte ALbyte_Sample(ALfloat val) -{ return (ALbyte)clampf(val*128.0f, -128.0f, 127.0f); } +{ return fastf2i(clampf(val*128.0f, -128.0f, 127.0f)); } static inline ALubyte ALubyte_Sample(ALfloat val) { return ALbyte_Sample(val)+128; } static inline ALshort ALshort_Sample(ALfloat val) -{ return (ALshort)clampf(val*32768.0f, -32768.0f, 32767.0f); } +{ return fastf2i(clampf(val*32768.0f, -32768.0f, 32767.0f)); } static inline ALushort ALushort_Sample(ALfloat val) { return ALshort_Sample(val)+32768; } static inline ALint ALint_Sample(ALfloat val) -{ return (ALint)clampf(val*16777216.0f, -16777216.0f, 16777215.0f) << 7; } +{ return fastf2i(clampf(val*16777216.0f, -16777216.0f, 16777215.0f)) << 7; } static inline ALuint ALuint_Sample(ALfloat val) { return ALint_Sample(val)+INT_MAX+1; } @@ -224,7 +229,9 @@ ALsizei SampleConverterInput(SampleConverter *converter, const ALvoid **src, ALs const ALsizei DstFrameSize = converter->mNumChannels * converter->mDstTypeSize; const ALsizei increment = converter->mIncrement; ALsizei pos = 0; + FPUCtl oldMode; + SetMixerFPUMode(&oldMode); while(pos < dstframes && *srcframes > 0) { ALfloat *restrict SrcData = ASSUME_ALIGNED(converter->mSrcSamples, 16); @@ -312,7 +319,7 @@ ALsizei SampleConverterInput(SampleConverter *converter, const ALvoid **src, ALs } /* Now resample, and store the result in the output buffer. */ - ResampledData = converter->mResample(NULL, + ResampledData = converter->mResample(&converter->mState, SrcData+MAX_PRE_SAMPLES, DataPosFrac, increment, DstData, DstSize ); @@ -336,6 +343,7 @@ ALsizei SampleConverterInput(SampleConverter *converter, const ALvoid **src, ALs dst = (ALbyte*)dst + DstFrameSize*DstSize; pos += DstSize; } + RestoreFPUMode(&oldMode); return pos; } diff --git a/Alc/converter.h b/Alc/converter.h index db3f1daa..9934fa4b 100644 --- a/Alc/converter.h +++ b/Alc/converter.h @@ -19,6 +19,7 @@ typedef struct SampleConverter { ALsizei mFracOffset; ALsizei mIncrement; + InterpState mState; ResamplerFunc mResample; alignas(16) ALfloat mSrcSamples[BUFFERSIZE]; diff --git a/OpenAL32/Include/alu.h b/OpenAL32/Include/alu.h index 0b3799c0..5cda214e 100644 --- a/OpenAL32/Include/alu.h +++ b/OpenAL32/Include/alu.h @@ -85,6 +85,8 @@ typedef union InterpState { BsincState bsinc; } InterpState; +ALboolean BsincPrepare(const ALuint increment, BsincState *state); + typedef const ALfloat* (*ResamplerFunc)(const InterpState *state, const ALfloat *restrict src, ALsizei frac, ALint increment, ALfloat *restrict dst, ALsizei dstlen |