AuroraOpenALSoft/core/converter.h

67 lines
1.7 KiB
C
Raw Normal View History

2021-04-24 10:47:23 +00:00
#ifndef CORE_CONVERTER_H
#define CORE_CONVERTER_H
#include <chrono>
2019-07-29 04:29:59 +00:00
#include <cstddef>
#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;
2018-11-17 15:35:11 +00:00
struct SampleConverter {
DevFmtType mSrcType{};
DevFmtType mDstType{};
2020-11-28 05:40:02 +00:00
uint mSrcTypeSize{};
uint mDstTypeSize{};
2022-11-13 07:15:33 +00:00
uint mSrcPrepCount{};
2020-11-28 05:40:02 +00: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-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;
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
};
using SampleConverterPtr = std::unique_ptr<SampleConverter>;
2018-11-17 15:35:11 +00:00
struct ChannelConverter {
DevFmtType mSrcType{};
2020-11-28 05:40:02 +00:00
uint mSrcStep{};
uint mChanMask{};
DevFmtChannels mDstChans{};
bool is_active() const noexcept { return mChanMask != 0; }
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
};
2021-04-24 10:47:23 +00:00
#endif /* CORE_CONVERTER_H */