1 #ifndef CORE_CONVERTER_H
2 #define CORE_CONVERTER_H
10 #include "flexarray.h"
11 #include "mixer/defs.h"
12 #include "resampler_limits.h"
14 using uint
= unsigned int;
17 struct SampleConverter
{
18 DevFmtType mSrcType
{};
19 DevFmtType mDstType
{};
28 ResamplerFunc mResample
{};
30 alignas(16) FloatBufferLine mSrcSamples
{};
31 alignas(16) FloatBufferLine mDstSamples
{};
34 alignas(16) std::array
<float,MaxResamplerPadding
> PrevSamples
;
36 al::FlexArray
<ChanSamples
> mChan
;
38 SampleConverter(size_t numchans
) : mChan
{numchans
} { }
40 [[nodiscard
]] auto convert(const void **src
, uint
*srcframes
, void *dst
, uint dstframes
) -> uint
;
41 [[nodiscard
]] auto convertPlanar(const void **src
, uint
*srcframes
, void *const*dst
, uint dstframes
) -> uint
;
42 [[nodiscard
]] auto availableOut(uint srcframes
) const -> uint
;
44 using SampleOffset
= std::chrono::duration
<int64_t, std::ratio
<1,MixerFracOne
>>;
45 [[nodiscard
]] auto currentInputDelay() const noexcept
-> SampleOffset
47 const int64_t prep
{int64_t{mSrcPrepCount
} - MaxResamplerEdge
};
48 return SampleOffset
{(prep
<<MixerFracBits
) + mFracOffset
};
51 static std::unique_ptr
<SampleConverter
> Create(DevFmtType srcType
, DevFmtType dstType
,
52 size_t numchans
, uint srcRate
, uint dstRate
, Resampler resampler
);
54 DEF_FAM_NEWDEL(SampleConverter
, mChan
)
56 using SampleConverterPtr
= std::unique_ptr
<SampleConverter
>;
58 struct ChannelConverter
{
59 DevFmtType mSrcType
{};
62 DevFmtChannels mDstChans
{};
64 [[nodiscard
]] auto is_active() const noexcept
-> bool { return mChanMask
!= 0; }
66 void convert(const void *src
, float *dst
, uint frames
) const;
69 #endif /* CORE_CONVERTER_H */