diff options
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; } |