2021-04-24 10:47:23 +00:00
|
|
|
#ifndef CORE_CONVERTER_H
|
|
|
|
#define CORE_CONVERTER_H
|
2017-04-10 16:17:10 +00:00
|
|
|
|
2022-11-13 03:25:08 +00:00
|
|
|
#include <chrono>
|
2019-07-29 04:29:59 +00:00
|
|
|
#include <cstddef>
|
2018-12-27 20:55:43 +00:00
|
|
|
#include <memory>
|
|
|
|
|
2018-11-29 06:42:46 +00:00
|
|
|
#include "almalloc.h"
|
2021-04-24 10:47:23 +00:00
|
|
|
#include "devformat.h"
|
|
|
|
#include "mixer/defs.h"
|
2019-07-29 04:29:59 +00:00
|
|
|
|
2020-11-28 05:40:02 +00:00
|
|
|
using uint = unsigned int;
|
|
|
|
|
2017-04-10 16:17:10 +00:00
|
|
|
|
2018-11-17 15:35:11 +00:00
|
|
|
struct SampleConverter {
|
2018-12-01 19:28:11 +00:00
|
|
|
DevFmtType mSrcType{};
|
|
|
|
DevFmtType mDstType{};
|
2020-11-28 05:40:02 +00:00
|
|
|
uint mSrcTypeSize{};
|
|
|
|
uint mDstTypeSize{};
|
2017-04-10 16:17:10 +00:00
|
|
|
|
2022-11-13 07:15:33 +00:00
|
|
|
uint mSrcPrepCount{};
|
2017-04-10 16:17:10 +00:00
|
|
|
|
2020-11-28 05:40:02 +00:00
|
|
|
uint mFracOffset{};
|
|
|
|
uint mIncrement{};
|
2018-12-01 19:28:11 +00:00
|
|
|
InterpState mState{};
|
|
|
|
ResamplerFunc mResample{};
|
2017-04-10 16:17:10 +00:00
|
|
|
|
2020-11-28 11:38:20 +00:00
|
|
|
alignas(16) float mSrcSamples[BufferLineSize]{};
|
|
|
|
alignas(16) float mDstSamples[BufferLineSize]{};
|
2017-04-10 16:17:10 +00:00
|
|
|
|
2019-01-12 06:09:57 +00:00
|
|
|
struct ChanSamples {
|
2020-11-28 11:38:20 +00:00
|
|
|
alignas(16) float PrevSamples[MaxResamplerPadding];
|
2019-01-12 06:09:57 +00:00
|
|
|
};
|
|
|
|
al::FlexArray<ChanSamples> mChan;
|
|
|
|
|
|
|
|
SampleConverter(size_t numchans) : mChan{numchans} { }
|
2018-11-29 06:42:46 +00:00
|
|
|
|
2020-11-28 05:40:02 +00:00
|
|
|
uint convert(const void **src, uint *srcframes, void *dst, uint dstframes);
|
|
|
|
uint availableOut(uint srcframes) const;
|
2018-12-29 20:26:45 +00:00
|
|
|
|
2022-11-13 03:25:08 +00:00
|
|
|
using SampleOffset = std::chrono::duration<int64_t, std::ratio<1,MixerFracOne>>;
|
|
|
|
SampleOffset currentInputDelay() const noexcept
|
|
|
|
{
|
|
|
|
const int64_t prep{mSrcPrepCount - MaxResamplerEdge};
|
|
|
|
return SampleOffset{(prep<<MixerFracBits) + mFracOffset};
|
|
|
|
}
|
|
|
|
|
2022-11-13 22:10:15 +00:00
|
|
|
static std::unique_ptr<SampleConverter> Create(DevFmtType srcType, DevFmtType dstType,
|
|
|
|
size_t numchans, uint srcRate, uint dstRate, Resampler resampler);
|
|
|
|
|
2019-09-11 10:59:53 +00:00
|
|
|
DEF_FAM_NEWDEL(SampleConverter, mChan)
|
2018-11-17 15:35:11 +00:00
|
|
|
};
|
2018-12-27 20:55:43 +00:00
|
|
|
using SampleConverterPtr = std::unique_ptr<SampleConverter>;
|
2017-04-10 16:17:10 +00:00
|
|
|
|
2018-11-17 15:35:11 +00:00
|
|
|
struct ChannelConverter {
|
2020-10-06 05:30:23 +00:00
|
|
|
DevFmtType mSrcType{};
|
2020-11-28 05:40:02 +00:00
|
|
|
uint mSrcStep{};
|
|
|
|
uint mChanMask{};
|
2020-10-06 05:30:23 +00:00
|
|
|
DevFmtChannels mDstChans{};
|
2018-12-01 19:28:11 +00:00
|
|
|
|
2020-10-06 05:30:23 +00:00
|
|
|
bool is_active() const noexcept { return mChanMask != 0; }
|
2018-12-29 20:26:45 +00:00
|
|
|
|
2020-11-28 05:40:02 +00:00
|
|
|
void convert(const void *src, float *dst, uint frames) const;
|
2018-11-17 15:35:11 +00:00
|
|
|
};
|
2017-04-11 14:25:55 +00:00
|
|
|
|
2021-04-24 10:47:23 +00:00
|
|
|
#endif /* CORE_CONVERTER_H */
|