diff options
author | Chris Robinson <[email protected]> | 2021-04-24 03:47:23 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2021-04-24 03:47:23 -0700 |
commit | 519672c8e54585bc6d827dd3efed943e06b3e6cd (patch) | |
tree | d2756c6137b246e70b2cab5cdc3a51a617006234 /core/converter.h | |
parent | 738714800621cc7d8f74321883c301a14e3a04c3 (diff) |
Move some more sources to core
Diffstat (limited to 'core/converter.h')
-rw-r--r-- | core/converter.h | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/core/converter.h b/core/converter.h new file mode 100644 index 00000000..2d22ae38 --- /dev/null +++ b/core/converter.h @@ -0,0 +1,59 @@ +#ifndef CORE_CONVERTER_H +#define CORE_CONVERTER_H + +#include <cstddef> +#include <memory> + +#include "almalloc.h" +#include "devformat.h" +#include "mixer/defs.h" + +using uint = unsigned int; + + +struct SampleConverter { + DevFmtType mSrcType{}; + DevFmtType mDstType{}; + uint mSrcTypeSize{}; + uint mDstTypeSize{}; + + int mSrcPrepCount{}; + + uint mFracOffset{}; + uint mIncrement{}; + InterpState mState{}; + ResamplerFunc mResample{}; + + alignas(16) float mSrcSamples[BufferLineSize]{}; + alignas(16) float mDstSamples[BufferLineSize]{}; + + struct ChanSamples { + alignas(16) float PrevSamples[MaxResamplerPadding]; + }; + al::FlexArray<ChanSamples> mChan; + + SampleConverter(size_t numchans) : mChan{numchans} { } + + uint convert(const void **src, uint *srcframes, void *dst, uint dstframes); + uint availableOut(uint srcframes) const; + + DEF_FAM_NEWDEL(SampleConverter, mChan) +}; +using SampleConverterPtr = std::unique_ptr<SampleConverter>; + +SampleConverterPtr CreateSampleConverter(DevFmtType srcType, DevFmtType dstType, size_t numchans, + uint srcRate, uint dstRate, Resampler resampler); + + +struct ChannelConverter { + DevFmtType mSrcType{}; + uint mSrcStep{}; + uint mChanMask{}; + DevFmtChannels mDstChans{}; + + bool is_active() const noexcept { return mChanMask != 0; } + + void convert(const void *src, float *dst, uint frames) const; +}; + +#endif /* CORE_CONVERTER_H */ |