Separate ALCdevice from the implementation
[openal-soft.git] / core / converter.h
blob01649c36157016ef501fbec7140101e5aefa6ee1
1 #ifndef CORE_CONVERTER_H
2 #define CORE_CONVERTER_H
4 #include <chrono>
5 #include <cstddef>
6 #include <memory>
8 #include "almalloc.h"
9 #include "devformat.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{};
20 uint mSrcTypeSize{};
21 uint mDstTypeSize{};
23 uint mSrcPrepCount{};
25 uint mFracOffset{};
26 uint mIncrement{};
27 InterpState mState{};
28 ResamplerFunc mResample{};
30 alignas(16) FloatBufferLine mSrcSamples{};
31 alignas(16) FloatBufferLine mDstSamples{};
33 struct ChanSamples {
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{};
60 uint mSrcStep{};
61 uint mChanMask{};
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 */