📄 raresampler.cpp
字号:
return HXR_OK ;}HX_RESULT RAAnyResampler::SetupConverter(int _intype, int _restype){ static const int bps[] = {2,4,4} ; intype = _intype; resType = _restype ; m_converter[0].pfCvt = cvtFunc[intype][resType] ; m_converter[1].pfCvt = cvtFunc[intype][resType] ; m_converter[0].pStateMachine = new struct CVTSTATEMACHINE[1] ; m_converter[1].pStateMachine = new struct CVTSTATEMACHINE[2] ; // mono converter m_converter[0].pStateMachine[0].pNext = m_converter[0].pStateMachine ; m_converter[0].pStateMachine[0].incInput = m_nChannelsTotal ; m_converter[0].pStateMachine[0].incOutput = 1 ; // stereo converter m_converter[1].pStateMachine[0].pNext = &(m_converter[1].pStateMachine[1]) ; m_converter[1].pStateMachine[0].incInput = 1 ; m_converter[1].pStateMachine[0].incOutput = 1 ; m_converter[1].pStateMachine[1].pNext = &(m_converter[1].pStateMachine[0]) ; m_converter[1].pStateMachine[1].incInput = m_nChannelsTotal - 1 ; m_converter[1].pStateMachine[1].incOutput = 1 ; m_nBytesPerSampleIn = bps[intype] ; return HXR_OK ;}int RAAnyResampler::Resample(void *_inbuf, int _insamps, signed short *_outbuf){ int i ; int outsamps ; for (i = 0 ; i < m_nResamplers; i++) { int insamps = _insamps ; int nChannels = m_nChannels[i] ; char* inbuf = (char*)_inbuf + m_nOffsetIn[i] * m_nBytesPerSampleIn ; signed short* outbuf = _outbuf + m_nOffsetIn[i] ; outsamps = 0 ; while (insamps) { int nin = min(insamps, m_nBlock[i]); int nout = m_pfResample[nChannels-1](inbuf, nin, &m_converter[nChannels-1], outbuf, m_nChannelsTotal, m_pResampler[i]); inbuf += nin * m_nBytesPerSampleIn ; insamps -= nin; outbuf += nout; outsamps += nout; } } return outsamps;}int RAAnyResampler::Resample(void *_inbuf, int _insamps, signed int *_outbuf){ // fake it! int outsamps = Resample(_inbuf, _insamps, (signed short*) _outbuf) ; for (int j=outsamps-1; j>=0; --j) { _outbuf[j] = ((signed short*)_outbuf)[j] << 16 ; } return outsamps;}/* * Arbitrary resampler -- any rate to any rate */class RAArbitraryResampler : public RAAnyResampler{public: static HX_RESULT Create(RAExactResampler **pRes, int inrate, int outrate, int chans, int intype, float atten, float passband, float stopband, float dcgain) { HX_RESULT res = HXR_OK ; RAArbitraryResampler *pr = new RAArbitraryResampler() ; if (!pr) res = HXR_OUTOFMEMORY ; if (SUCCEEDED(res)) res = pr->Init(inrate, outrate, chans, intype, atten, passband, stopband, dcgain) ; if (FAILED(res)) { delete pr ; pr = 0 ; } *pRes = pr ; return res ; } HX_RESULT SetupFunctionPointers(void) { m_pfResample[0] = &RAResampleMonoArb ; m_pfResample[1] = &RAResampleStereoArb ; m_pfGetMaxOutput = &RAGetMaxOutputArb ; m_pfGetMinInput = &RAGetMinInputArb ; m_pfGetDelay = &RAGetDelayArb ; m_pfFreeResampler = &RAFreeResamplerArb ; m_pfInitResamplerCopy = &RAInitResamplerCopyArb; return HXR_OK ; } int GetResamplerInputType(void) {return _FLOAT; } void* InitResampler(int inrate, int outrate, int nchans, float atten, float passband, float stopband, float dcgain) { return RAInitResamplerArb(inrate, outrate, nchans, atten, passband, stopband, dcgain) ; }} ;/* * Rational resampler -- many rates to many rates, as long as the fraction * inrate/outrate is reducible to "small numbers" */class RARationalResampler : public RAAnyResampler{public: static HX_RESULT Create(RAExactResampler **pRes, int inrate, int outrate, int chans, int intype, float atten, float passband, float stopband, float dcgain) { HX_RESULT res = HXR_OK ; RARationalResampler *pr = new RARationalResampler() ; if (!pr) res = HXR_OUTOFMEMORY ; if (SUCCEEDED(res)) res = pr->Init(inrate, outrate, chans, intype, atten, passband, stopband, dcgain) ; if (FAILED(res)) { delete pr ; pr = 0 ; } *pRes = pr ; return res ; } int GetResamplerInputType(void) {return _FLOAT; } HX_RESULT SetupFunctionPointers(void) { m_pfResample[0] = &RAResampleMonoRat ; m_pfResample[1] = &RAResampleStereoRat ; m_pfGetMaxOutput = &RAGetMaxOutputRat ; m_pfGetMinInput = &RAGetMinInputRat ; m_pfGetDelay = &RAGetDelayRat ; m_pfFreeResampler = &RAFreeResamplerRat ; m_pfInitResamplerCopy = &RAInitResamplerCopyRat; return HXR_OK ; } void* InitResampler(int inrate, int outrate, int nchans, float atten, float passband, float stopband, float dcgain) { return RAInitResamplerRat(inrate, outrate, nchans, atten, passband, stopband, dcgain) ; }} ;#if defined(_M_IX86) /* || defined(__i386__) */ /* no unix mmx code yet */class RAMMXResampler : public RAAnyResampler{public: static HX_RESULT Create(RAExactResampler **pRes, int inrate, int outrate, int chans, int intype, float atten, float passband, float stopband, float dcgain) { HX_RESULT res = HXR_OK ; RAMMXResampler *pr = new RAMMXResampler() ; if (!pr) res = HXR_OUTOFMEMORY ; if (SUCCEEDED(res)) res = pr->Init(inrate, outrate, chans, intype, atten, passband, stopband, dcgain) ; if (FAILED(res)) { delete pr ; pr = 0 ; } *pRes = pr ; return res ; } int GetResamplerInputType(void) {return _INT16; } HX_RESULT SetupFunctionPointers(void) { m_pfResample[0] = &RAResampleMonoMMX ; m_pfResample[1] = &RAResampleStereoMMX ; m_pfGetMaxOutput = &RAGetMaxOutputMMX ; m_pfGetMinInput = &RAGetMinInputMMX ; m_pfGetDelay = &RAGetDelayMMX ; m_pfFreeResampler = &RAFreeResamplerMMX ; m_pfInitResamplerCopy = &RAInitResamplerCopyMMX; return HXR_OK ; } void* InitResampler(int inrate, int outrate, int nchans, float atten, float passband, float stopband, float dcgain) { // should maybe check for atten etc. return RAInitResamplerMMX(inrate, outrate, nchans) ; }} ;#endif /* defined(_M_IX86) */#if defined(HELIX_CONFIG_FIXEDPOINT)class RAHermiteResampler : public RAAnyResampler{public: static HX_RESULT Create(RAExactResampler **pRes, int inrate, int outrate, int chans, int intype, float atten, float passband, float stopband, float dcgain) { HX_RESULT res = HXR_OK ; /* intype must be _INT16 for the Hermite resampler */ if (intype != _INT16 || chans > 2) return HXR_FAIL ; RAHermiteResampler *pr = new RAHermiteResampler() ; if (!pr) res = HXR_OUTOFMEMORY ; if (SUCCEEDED(res)) res = pr->Init(inrate, outrate, chans, intype, atten, passband, stopband, dcgain) ; if (FAILED(res)) { delete pr ; pr = 0 ; } *pRes = pr ; return res ; } int GetResamplerInputType(void) {return _INT16; } HX_RESULT SetupFunctionPointers(void) { m_pfResample[0] = &RAResampleMonoHermite ; m_pfResample[1] = &RAResampleStereoHermite ; m_pfGetMaxOutput = &RAGetMaxOutputHermite ; m_pfGetMinInput = &RAGetMinInputHermite ; m_pfGetDelay = &RAGetDelayHermite ; m_pfFreeResampler = &RAFreeResamplerHermite ; m_pfInitResamplerCopy = &RAInitResamplerCopyHermite; return HXR_OK ; } void* InitResampler(int inrate, int outrate, int nchans, float atten, float passband, float stopband, float dcgain) { // should maybe check for atten etc. return RAInitResamplerHermite(inrate, outrate, nchans) ; }};#endif /* defined(HELIX_CONFIG_FIXEDPOINT) */HX_RESULT RAExactResampler::Create(RAExactResampler** pRes, int inrate, int outrate, int chans, int intype, int quality){ float dcgain = DEF_DCGAIN ; float atten ; float passband ; float stopband ; switch(quality) { case qualityVeryLow: passband = 0.77f ; // 32 tap stopband = 1.09f ; atten = 80.0f ; break ; case qualityLow: passband = 0.82f ; // 48 tap stopband = 1.05f ; atten = 85.0f ; break ; case qualityMedium: passband = 0.85f ; // 64 tap stopband = 1.03f ; atten = 90.0f ; break ; case qualityHigh: passband = 0.88f ; // 96 tap stopband = 1.00f ; atten = 90.0f ; break ; case qualityHyper: passband = 0.904f ; // 128 tap stopband = 1.000f ; atten = 96.00f ; break ; default: return HXR_INVALID_PARAMETER ; } return Create(pRes, inrate, outrate, chans, intype, atten, passband, stopband, dcgain) ;}HX_RESULT RAExactResampler::Create(RAExactResampler** pRes, int inrate, int outrate, int chans, int intype, float atten, float trans, float dcgain){ return Create(pRes, inrate, outrate, chans, intype, atten, 1.0f-trans, 1.0f, dcgain) ;}HX_RESULT RAExactResampler::Create(RAExactResampler** pRes, int inrate, int outrate, int chans, int intype, float atten, float passband, float stopband, float dcgain){ HX_RESULT res = HXR_FAIL ;#if defined (HELIX_CONFIG_FIXEDPOINT) if (FAILED(res)) res = RAHermiteResampler::Create(pRes, inrate, outrate, chans, intype, atten, passband, stopband, dcgain);#else /* only instantiate the MMX resampler if we are compiling on an x86 architecture and running on a machine with MMX */#if defined(_M_IX86) /* || defined(__i386__) */ /* no unix mmx code yet */ CPUInformation info ; CPUIdentify(&info) ; /* don't use the MMX resampler if the quality is "hyper" */ if (atten <= 90.0 && info.architecture == ulArchitectureIntel && info.specific.m_x86.hasMMX) { res = RAMMXResampler::Create(pRes, inrate, outrate, chans, intype, atten, passband, stopband, dcgain) ; }#endif if (FAILED(res)) { res = RARationalResampler::Create(pRes, inrate, outrate, chans, intype, atten, passband, stopband, dcgain) ; } if (FAILED(res)) { res = RAArbitraryResampler::Create(pRes, inrate, outrate, chans, intype, atten, passband, stopband, dcgain) ; }#endif /*HELIX_CONFIG_FIXEDPOINT*/ return res ;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -