2017-04-10 09:17:10 -07:00
|
|
|
#ifndef CONVERTER_H
|
|
|
|
#define CONVERTER_H
|
|
|
|
|
2018-12-27 12:55:43 -08:00
|
|
|
#include <memory>
|
|
|
|
|
2017-04-10 09:17:10 -07:00
|
|
|
#include "alMain.h"
|
|
|
|
#include "alu.h"
|
2018-11-28 22:42:46 -08:00
|
|
|
#include "almalloc.h"
|
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{};
|
|
|
|
ALsizei mSrcTypeSize{};
|
|
|
|
ALsizei mDstTypeSize{};
|
2017-04-10 09:17:10 -07:00
|
|
|
|
2018-12-01 11:28:11 -08:00
|
|
|
ALint mSrcPrepCount{};
|
2017-04-10 09:17:10 -07:00
|
|
|
|
2018-12-01 11:28:11 -08:00
|
|
|
ALsizei mFracOffset{};
|
|
|
|
ALsizei mIncrement{};
|
|
|
|
InterpState mState{};
|
|
|
|
ResamplerFunc mResample{};
|
2017-04-10 09:17:10 -07:00
|
|
|
|
2018-12-01 11:28:11 -08:00
|
|
|
alignas(16) ALfloat mSrcSamples[BUFFERSIZE]{};
|
|
|
|
alignas(16) ALfloat mDstSamples[BUFFERSIZE]{};
|
2017-04-10 09:17:10 -07:00
|
|
|
|
2019-01-11 22:09:57 -08:00
|
|
|
struct ChanSamples {
|
2018-12-29 13:21:47 -08:00
|
|
|
alignas(16) ALfloat PrevSamples[MAX_RESAMPLE_PADDING*2];
|
2019-01-11 22:09:57 -08:00
|
|
|
};
|
|
|
|
al::FlexArray<ChanSamples> mChan;
|
|
|
|
|
|
|
|
SampleConverter(size_t numchans) : mChan{numchans} { }
|
|
|
|
SampleConverter(const SampleConverter&) = delete;
|
|
|
|
SampleConverter& operator=(const SampleConverter&) = delete;
|
2018-11-28 22:42:46 -08:00
|
|
|
|
2018-12-29 12:26:45 -08:00
|
|
|
ALsizei convert(const ALvoid **src, ALsizei *srcframes, ALvoid *dst, ALsizei dstframes);
|
|
|
|
ALsizei availableOut(ALsizei srcframes) const;
|
|
|
|
|
2019-01-11 22:09:57 -08:00
|
|
|
static constexpr size_t Sizeof(size_t length) noexcept
|
|
|
|
{
|
|
|
|
return maxz(sizeof(SampleConverter),
|
|
|
|
al::FlexArray<ChanSamples>::Sizeof(length, offsetof(SampleConverter, mChan)));
|
|
|
|
}
|
|
|
|
|
2018-11-28 22:42:46 -08:00
|
|
|
DEF_PLACE_NEWDEL()
|
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
|
|
|
|
2018-12-27 12:55:43 -08:00
|
|
|
SampleConverterPtr CreateSampleConverter(DevFmtType srcType, DevFmtType dstType, ALsizei numchans,
|
2018-12-24 19:29:01 -08:00
|
|
|
ALsizei srcRate, ALsizei 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 {
|
2018-12-01 11:28:11 -08:00
|
|
|
DevFmtType mSrcType;
|
|
|
|
DevFmtChannels mSrcChans;
|
|
|
|
DevFmtChannels mDstChans;
|
|
|
|
|
|
|
|
ChannelConverter(DevFmtType srctype, DevFmtChannels srcchans, DevFmtChannels dstchans)
|
|
|
|
: mSrcType(srctype), mSrcChans(srcchans), mDstChans(dstchans)
|
|
|
|
{ }
|
2018-12-29 12:26:45 -08:00
|
|
|
|
|
|
|
void convert(const ALvoid *src, ALfloat *dst, ALsizei frames) const;
|
|
|
|
|
2018-12-01 11:28:11 -08:00
|
|
|
DEF_NEWDEL(ChannelConverter)
|
2018-11-17 07:35:11 -08:00
|
|
|
};
|
2018-12-27 12:55:43 -08:00
|
|
|
using ChannelConverterPtr = std::unique_ptr<ChannelConverter>;
|
2017-04-11 07:25:55 -07:00
|
|
|
|
2018-12-27 12:55:43 -08:00
|
|
|
ChannelConverterPtr CreateChannelConverter(DevFmtType srcType, DevFmtChannels srcChans,
|
|
|
|
DevFmtChannels dstChans);
|
2017-04-11 07:25:55 -07:00
|
|
|
|
2017-04-10 09:17:10 -07:00
|
|
|
#endif /* CONVERTER_H */
|