openal-soft/core/converter.h

60 lines
1.4 KiB
C
Raw Normal View History

2021-04-24 03:47:23 -07:00
#ifndef CORE_CONVERTER_H
#define CORE_CONVERTER_H
2019-07-28 21:29:59 -07:00
#include <cstddef>
#include <memory>
2018-11-28 22:42:46 -08:00
#include "almalloc.h"
2021-04-24 03:47:23 -07:00
#include "devformat.h"
#include "mixer/defs.h"
2019-07-28 21:29:59 -07:00
2020-11-27 21:40:02 -08:00
using uint = unsigned int;
2018-11-17 07:35:11 -08:00
struct SampleConverter {
DevFmtType mSrcType{};
DevFmtType mDstType{};
2020-11-27 21:40:02 -08:00
uint mSrcTypeSize{};
uint mDstTypeSize{};
int mSrcPrepCount{};
2020-11-27 21:40:02 -08:00
uint mFracOffset{};
uint mIncrement{};
InterpState mState{};
ResamplerFunc mResample{};
alignas(16) float mSrcSamples[BufferLineSize]{};
alignas(16) float mDstSamples[BufferLineSize]{};
struct ChanSamples {
alignas(16) float PrevSamples[MaxResamplerPadding];
};
al::FlexArray<ChanSamples> mChan;
SampleConverter(size_t numchans) : mChan{numchans} { }
2018-11-28 22:42:46 -08:00
2020-11-27 21:40:02 -08:00
uint convert(const void **src, uint *srcframes, void *dst, uint dstframes);
uint availableOut(uint srcframes) const;
2019-09-11 03:59:53 -07:00
DEF_FAM_NEWDEL(SampleConverter, mChan)
2018-11-17 07:35:11 -08:00
};
using SampleConverterPtr = std::unique_ptr<SampleConverter>;
2019-09-11 06:58:27 -07:00
SampleConverterPtr CreateSampleConverter(DevFmtType srcType, DevFmtType dstType, size_t numchans,
2020-11-27 21:40:02 -08:00
uint srcRate, uint dstRate, Resampler resampler);
2018-11-17 07:35:11 -08:00
struct ChannelConverter {
DevFmtType mSrcType{};
2020-11-27 21:40:02 -08:00
uint mSrcStep{};
uint mChanMask{};
DevFmtChannels mDstChans{};
bool is_active() const noexcept { return mChanMask != 0; }
2020-11-27 21:40:02 -08:00
void convert(const void *src, float *dst, uint frames) const;
2018-11-17 07:35:11 -08:00
};
2021-04-24 03:47:23 -07:00
#endif /* CORE_CONVERTER_H */