🛠️🐜 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.

70 lines
2.0 KiB

  1. #ifndef CONVERTER_H
  2. #define CONVERTER_H
  3. #include <memory>
  4. #include "alMain.h"
  5. #include "alu.h"
  6. #include "almalloc.h"
  7. struct SampleConverter {
  8. DevFmtType mSrcType{};
  9. DevFmtType mDstType{};
  10. ALsizei mSrcTypeSize{};
  11. ALsizei mDstTypeSize{};
  12. ALint mSrcPrepCount{};
  13. ALsizei mFracOffset{};
  14. ALsizei mIncrement{};
  15. InterpState mState{};
  16. ResamplerFunc mResample{};
  17. alignas(16) ALfloat mSrcSamples[BUFFERSIZE]{};
  18. alignas(16) ALfloat mDstSamples[BUFFERSIZE]{};
  19. struct ChanSamples {
  20. alignas(16) ALfloat PrevSamples[MAX_RESAMPLE_PADDING*2];
  21. };
  22. al::FlexArray<ChanSamples> mChan;
  23. SampleConverter(size_t numchans) : mChan{numchans} { }
  24. SampleConverter(const SampleConverter&) = delete;
  25. SampleConverter& operator=(const SampleConverter&) = delete;
  26. ALsizei convert(const ALvoid **src, ALsizei *srcframes, ALvoid *dst, ALsizei dstframes);
  27. ALsizei availableOut(ALsizei srcframes) const;
  28. static constexpr size_t Sizeof(size_t length) noexcept
  29. {
  30. return maxz(sizeof(SampleConverter),
  31. al::FlexArray<ChanSamples>::Sizeof(length, offsetof(SampleConverter, mChan)));
  32. }
  33. DEF_PLACE_NEWDEL()
  34. };
  35. using SampleConverterPtr = std::unique_ptr<SampleConverter>;
  36. SampleConverterPtr CreateSampleConverter(DevFmtType srcType, DevFmtType dstType, ALsizei numchans,
  37. ALsizei srcRate, ALsizei dstRate, Resampler resampler);
  38. struct ChannelConverter {
  39. DevFmtType mSrcType;
  40. DevFmtChannels mSrcChans;
  41. DevFmtChannels mDstChans;
  42. ChannelConverter(DevFmtType srctype, DevFmtChannels srcchans, DevFmtChannels dstchans)
  43. : mSrcType(srctype), mSrcChans(srcchans), mDstChans(dstchans)
  44. { }
  45. void convert(const ALvoid *src, ALfloat *dst, ALsizei frames) const;
  46. DEF_NEWDEL(ChannelConverter)
  47. };
  48. using ChannelConverterPtr = std::unique_ptr<ChannelConverter>;
  49. ChannelConverterPtr CreateChannelConverter(DevFmtType srcType, DevFmtChannels srcChans,
  50. DevFmtChannels dstChans);
  51. #endif /* CONVERTER_H */