diff options
author | Chris Robinson <[email protected]> | 2017-06-24 10:52:26 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2017-06-25 04:07:06 -0700 |
commit | c465718ddd59b3d137b5e50c0b11835646bc2c5b (patch) | |
tree | e9b1fcaf85444eade9df3266e950d8b149935323 /Alc/converter.c | |
parent | d1bb04d588f444d4e1f7318fcd05eb7c298a129e (diff) |
Use the bsinc resampler for the converter
Diffstat (limited to 'Alc/converter.c')
-rw-r--r-- | Alc/converter.c | 20 |
1 files changed, 14 insertions, 6 deletions
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; } |