1 #ifndef CORE_CONVERTER_H
2 #define CORE_CONVERTER_H
10 #include "mixer/defs.h"
12 using uint = unsigned int;
15 struct SampleConverter {
16 DevFmtType mSrcType{};
17 DevFmtType mDstType{};
26 ResamplerFunc mResample{};
28 alignas(16) float mSrcSamples[BufferLineSize]{};
29 alignas(16) float mDstSamples[BufferLineSize]{};
32 alignas(16) float PrevSamples[MaxResamplerPadding];
34 al::FlexArray<ChanSamples> mChan;
36 SampleConverter(size_t numchans) : mChan{numchans} { }
38 uint convert(const void **src, uint *srcframes, void *dst, uint dstframes);
39 uint availableOut(uint srcframes) const;
41 using SampleOffset = std::chrono::duration<int64_t, std::ratio<1,MixerFracOne>>;
42 SampleOffset currentInputDelay() const noexcept
44 const int64_t prep{int64_t{mSrcPrepCount} - MaxResamplerEdge};
45 return SampleOffset{(prep<<MixerFracBits) + mFracOffset};
48 static std::unique_ptr<SampleConverter> Create(DevFmtType srcType, DevFmtType dstType,
49 size_t numchans, uint srcRate, uint dstRate, Resampler resampler);
51 DEF_FAM_NEWDEL(SampleConverter, mChan)
53 using SampleConverterPtr = std::unique_ptr<SampleConverter>;
55 struct ChannelConverter {
56 DevFmtType mSrcType{};
59 DevFmtChannels mDstChans{};
61 bool is_active() const noexcept { return mChanMask != 0; }
63 void convert(const void *src, float *dst, uint frames) const;
66 #endif /* CORE_CONVERTER_H */