Avoid static constexpr for arrays iterated over at run-time
[openal-soft.git] / alc / converter.h
blob5842df07fdbc6463532291db31aa790f3288174c
1 #ifndef CONVERTER_H
2 #define CONVERTER_H
4 #include <cstddef>
5 #include <memory>
7 #include "AL/al.h"
9 #include "alcmain.h"
10 #include "almalloc.h"
11 #include "alnumeric.h"
12 #include "alu.h"
13 #include "devformat.h"
14 #include "voice.h"
17 struct SampleConverter {
18 DevFmtType mSrcType{};
19 DevFmtType mDstType{};
20 ALuint mSrcTypeSize{};
21 ALuint mDstTypeSize{};
23 ALint mSrcPrepCount{};
25 ALuint mFracOffset{};
26 ALuint mIncrement{};
27 InterpState mState{};
28 ResamplerFunc mResample{};
30 alignas(16) ALfloat mSrcSamples[BUFFERSIZE]{};
31 alignas(16) ALfloat mDstSamples[BUFFERSIZE]{};
33 struct ChanSamples {
34 alignas(16) ALfloat PrevSamples[MAX_RESAMPLER_PADDING];
36 al::FlexArray<ChanSamples> mChan;
38 SampleConverter(size_t numchans) : mChan{numchans} { }
40 ALuint convert(const ALvoid **src, ALuint *srcframes, ALvoid *dst, ALuint dstframes);
41 ALuint availableOut(ALuint srcframes) const;
43 DEF_FAM_NEWDEL(SampleConverter, mChan)
45 using SampleConverterPtr = std::unique_ptr<SampleConverter>;
47 SampleConverterPtr CreateSampleConverter(DevFmtType srcType, DevFmtType dstType, size_t numchans,
48 ALuint srcRate, ALuint dstRate, Resampler resampler);
51 struct ChannelConverter {
52 DevFmtType mSrcType;
53 DevFmtChannels mSrcChans;
54 DevFmtChannels mDstChans;
56 bool is_active() const noexcept { return mSrcChans != mDstChans; }
58 void convert(const ALvoid *src, ALfloat *dst, ALuint frames) const;
61 #endif /* CONVERTER_H */