]> git.tdb.fi Git - ext/openal.git/blob - core/converter.h
Tweak some types to work around an MSVC compile error
[ext/openal.git] / core / converter.h
1 #ifndef CORE_CONVERTER_H
2 #define CORE_CONVERTER_H
3
4 #include <chrono>
5 #include <cstddef>
6 #include <memory>
7
8 #include "almalloc.h"
9 #include "devformat.h"
10 #include "mixer/defs.h"
11
12 using uint = unsigned int;
13
14
15 struct SampleConverter {
16     DevFmtType mSrcType{};
17     DevFmtType mDstType{};
18     uint mSrcTypeSize{};
19     uint mDstTypeSize{};
20
21     uint mSrcPrepCount{};
22
23     uint mFracOffset{};
24     uint mIncrement{};
25     InterpState mState{};
26     ResamplerFunc mResample{};
27
28     alignas(16) float mSrcSamples[BufferLineSize]{};
29     alignas(16) float mDstSamples[BufferLineSize]{};
30
31     struct ChanSamples {
32         alignas(16) float PrevSamples[MaxResamplerPadding];
33     };
34     al::FlexArray<ChanSamples> mChan;
35
36     SampleConverter(size_t numchans) : mChan{numchans} { }
37
38     uint convert(const void **src, uint *srcframes, void *dst, uint dstframes);
39     uint availableOut(uint srcframes) const;
40
41     using SampleOffset = std::chrono::duration<int64_t, std::ratio<1,MixerFracOne>>;
42     SampleOffset currentInputDelay() const noexcept
43     {
44         const int64_t prep{int64_t{mSrcPrepCount} - MaxResamplerEdge};
45         return SampleOffset{(prep<<MixerFracBits) + mFracOffset};
46     }
47
48     static std::unique_ptr<SampleConverter> Create(DevFmtType srcType, DevFmtType dstType,
49         size_t numchans, uint srcRate, uint dstRate, Resampler resampler);
50
51     DEF_FAM_NEWDEL(SampleConverter, mChan)
52 };
53 using SampleConverterPtr = std::unique_ptr<SampleConverter>;
54
55 struct ChannelConverter {
56     DevFmtType mSrcType{};
57     uint mSrcStep{};
58     uint mChanMask{};
59     DevFmtChannels mDstChans{};
60
61     bool is_active() const noexcept { return mChanMask != 0; }
62
63     void convert(const void *src, float *dst, uint frames) const;
64 };
65
66 #endif /* CORE_CONVERTER_H */