2021-04-24 03:47:23 -07:00
|
|
|
#ifndef CORE_CONVERTER_H
|
|
|
|
#define CORE_CONVERTER_H
|
2017-04-10 09:17:10 -07:00
|
|
|
|
2019-07-28 21:29:59 -07:00
|
|
|
#include <cstddef>
|
2018-12-27 12:55:43 -08:00
|
|
|
#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;
|
|
|
|
|
2017-04-10 09:17:10 -07:00
|
|
|
|
2018-11-17 07:35:11 -08:00
|
|
|
struct SampleConverter {
|
2018-12-01 11:28:11 -08:00
|
|
|
DevFmtType mSrcType{};
|
|
|
|
DevFmtType mDstType{};
|
2020-11-27 21:40:02 -08:00
|
|
|
uint mSrcTypeSize{};
|
|
|
|
uint mDstTypeSize{};
|
2017-04-10 09:17:10 -07:00
|
|
|
|
2020-04-08 10:15:43 -07:00
|
|
|
int mSrcPrepCount{};
|
2017-04-10 09:17:10 -07:00
|
|
|
|
2020-11-27 21:40:02 -08:00
|
|
|
uint mFracOffset{};
|
|
|
|
uint mIncrement{};
|
2018-12-01 11:28:11 -08:00
|
|
|
InterpState mState{};
|
|
|
|
ResamplerFunc mResample{};
|
2017-04-10 09:17:10 -07:00
|
|
|
|
2020-11-28 03:38:20 -08:00
|
|
|
alignas(16) float mSrcSamples[BufferLineSize]{};
|
|
|
|
alignas(16) float mDstSamples[BufferLineSize]{};
|
2017-04-10 09:17:10 -07:00
|
|
|
|
2019-01-11 22:09:57 -08:00
|
|
|
struct ChanSamples {
|
2020-11-28 03:38:20 -08:00
|
|
|
alignas(16) float PrevSamples[MaxResamplerPadding];
|
2019-01-11 22:09:57 -08:00
|
|
|
};
|
|
|
|
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;
|
2018-12-29 12:26:45 -08:00
|
|
|
|
2019-09-11 03:59:53 -07:00
|
|
|
DEF_FAM_NEWDEL(SampleConverter, mChan)
|
2018-11-17 07:35:11 -08:00
|
|
|
};
|
2018-12-27 12:55:43 -08:00
|
|
|
using SampleConverterPtr = std::unique_ptr<SampleConverter>;
|
2017-04-10 09:17:10 -07:00
|
|
|
|
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);
|
2017-04-10 09:17:10 -07:00
|
|
|
|
2017-04-11 07:25:55 -07:00
|
|
|
|
2018-11-17 07:35:11 -08:00
|
|
|
struct ChannelConverter {
|
2020-10-05 22:30:23 -07:00
|
|
|
DevFmtType mSrcType{};
|
2020-11-27 21:40:02 -08:00
|
|
|
uint mSrcStep{};
|
|
|
|
uint mChanMask{};
|
2020-10-05 22:30:23 -07:00
|
|
|
DevFmtChannels mDstChans{};
|
2018-12-01 11:28:11 -08:00
|
|
|
|
2020-10-05 22:30:23 -07:00
|
|
|
bool is_active() const noexcept { return mChanMask != 0; }
|
2018-12-29 12:26:45 -08:00
|
|
|
|
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
|
|
|
};
|
2017-04-11 07:25:55 -07:00
|
|
|
|
2021-04-24 03:47:23 -07:00
|
|
|
#endif /* CORE_CONVERTER_H */
|