aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2022-11-12 19:25:08 -0800
committerChris Robinson <[email protected]>2022-11-12 19:25:08 -0800
commit50ba074fe1b0d0ddc4604a0a6bb723382d9e60ad (patch)
treea2e66361639bf69b6ec32c23195ef8e1ba60a7c1 /core
parent68e04624b1f94d9bf8f9ebce5d90e64ab143efea (diff)
Add a method for the input sample delay for the SampleConverter
Diffstat (limited to 'core')
-rw-r--r--core/converter.cpp7
-rw-r--r--core/converter.h8
2 files changed, 14 insertions, 1 deletions
diff --git a/core/converter.cpp b/core/converter.cpp
index 6a06b464..f4c36c87 100644
--- a/core/converter.cpp
+++ b/core/converter.cpp
@@ -167,8 +167,13 @@ SampleConverterPtr CreateSampleConverter(DevFmtType srcType, DevFmtType dstType,
converter->mSrcTypeSize = BytesFromDevFmt(srcType);
converter->mDstTypeSize = BytesFromDevFmt(dstType);
- converter->mSrcPrepCount = 0;
+ converter->mSrcPrepCount = MaxResamplerEdge;
converter->mFracOffset = 0;
+ for(auto &chan : converter->mChan)
+ {
+ const al::span<float> buffer{chan.PrevSamples};
+ std::fill(buffer.begin(), buffer.end(), 0.0f);
+ }
/* Have to set the mixer FPU mode since that's what the resampler code expects. */
FPUCtl mixer_mode{};
diff --git a/core/converter.h b/core/converter.h
index 2d22ae38..46d9b83e 100644
--- a/core/converter.h
+++ b/core/converter.h
@@ -1,6 +1,7 @@
#ifndef CORE_CONVERTER_H
#define CORE_CONVERTER_H
+#include <chrono>
#include <cstddef>
#include <memory>
@@ -37,6 +38,13 @@ struct SampleConverter {
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};
+ }
+
DEF_FAM_NEWDEL(SampleConverter, mChan)
};
using SampleConverterPtr = std::unique_ptr<SampleConverter>;