🛠️🐜 Antkeeper superbuild with dependencies included https://antkeeper.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

59 lines
1.4 KiB

  1. #ifndef CORE_CONVERTER_H
  2. #define CORE_CONVERTER_H
  3. #include <cstddef>
  4. #include <memory>
  5. #include "almalloc.h"
  6. #include "devformat.h"
  7. #include "mixer/defs.h"
  8. using uint = unsigned int;
  9. struct SampleConverter {
  10. DevFmtType mSrcType{};
  11. DevFmtType mDstType{};
  12. uint mSrcTypeSize{};
  13. uint mDstTypeSize{};
  14. int mSrcPrepCount{};
  15. uint mFracOffset{};
  16. uint mIncrement{};
  17. InterpState mState{};
  18. ResamplerFunc mResample{};
  19. alignas(16) float mSrcSamples[BufferLineSize]{};
  20. alignas(16) float mDstSamples[BufferLineSize]{};
  21. struct ChanSamples {
  22. alignas(16) float PrevSamples[MaxResamplerPadding];
  23. };
  24. al::FlexArray<ChanSamples> mChan;
  25. SampleConverter(size_t numchans) : mChan{numchans} { }
  26. uint convert(const void **src, uint *srcframes, void *dst, uint dstframes);
  27. uint availableOut(uint srcframes) const;
  28. DEF_FAM_NEWDEL(SampleConverter, mChan)
  29. };
  30. using SampleConverterPtr = std::unique_ptr<SampleConverter>;
  31. SampleConverterPtr CreateSampleConverter(DevFmtType srcType, DevFmtType dstType, size_t numchans,
  32. uint srcRate, uint dstRate, Resampler resampler);
  33. struct ChannelConverter {
  34. DevFmtType mSrcType{};
  35. uint mSrcStep{};
  36. uint mChanMask{};
  37. DevFmtChannels mDstChans{};
  38. bool is_active() const noexcept { return mChanMask != 0; }
  39. void convert(const void *src, float *dst, uint frames) const;
  40. };
  41. #endif /* CORE_CONVERTER_H */