summaryrefslogtreecommitdiffstats
path: root/src/audio_core/time_stretch.h
diff options
context:
space:
mode:
authorMaribel <MerryMage@users.noreply.github.com>2016-05-15 04:04:03 +0200
committerbunnei <bunneidev@gmail.com>2016-05-15 04:04:03 +0200
commit6f6af6928fdff8c807e4a4d03cfd8906e0c7c7cd (patch)
treec857bb669cb13a0358ec6f5bee504963254534c6 /src/audio_core/time_stretch.h
parentMerge pull request #1794 from Subv/regression_fix (diff)
downloadyuzu-6f6af6928fdff8c807e4a4d03cfd8906e0c7c7cd.tar
yuzu-6f6af6928fdff8c807e4a4d03cfd8906e0c7c7cd.tar.gz
yuzu-6f6af6928fdff8c807e4a4d03cfd8906e0c7c7cd.tar.bz2
yuzu-6f6af6928fdff8c807e4a4d03cfd8906e0c7c7cd.tar.lz
yuzu-6f6af6928fdff8c807e4a4d03cfd8906e0c7c7cd.tar.xz
yuzu-6f6af6928fdff8c807e4a4d03cfd8906e0c7c7cd.tar.zst
yuzu-6f6af6928fdff8c807e4a4d03cfd8906e0c7c7cd.zip
Diffstat (limited to 'src/audio_core/time_stretch.h')
-rw-r--r--src/audio_core/time_stretch.h57
1 files changed, 57 insertions, 0 deletions
diff --git a/src/audio_core/time_stretch.h b/src/audio_core/time_stretch.h
new file mode 100644
index 000000000..1fde3f72a
--- /dev/null
+++ b/src/audio_core/time_stretch.h
@@ -0,0 +1,57 @@
+// Copyright 2016 Citra Emulator Project
+// Licensed under GPLv2 or any later version
+// Refer to the license.txt file included.
+
+#include <cstddef>
+#include <memory>
+#include <vector>
+
+#include "common/common_types.h"
+
+namespace AudioCore {
+
+class TimeStretcher final {
+public:
+ TimeStretcher();
+ ~TimeStretcher();
+
+ /**
+ * Set sample rate for the samples that Process returns.
+ * @param sample_rate The sample rate.
+ */
+ void SetOutputSampleRate(unsigned int sample_rate);
+
+ /**
+ * Add samples to be processed.
+ * @param sample_buffer Buffer of samples in interleaved stereo PCM16 format.
+ * @param num_sample Number of samples.
+ */
+ void AddSamples(const s16* sample_buffer, size_t num_samples);
+
+ /// Flush audio remaining in internal buffers.
+ void Flush();
+
+ /// Resets internal state and clears buffers.
+ void Reset();
+
+ /**
+ * Does audio stretching and produces the time-stretched samples.
+ * Timer calculations use sample_delay to determine how much of a margin we have.
+ * @param sample_delay How many samples are buffered downstream of this module and haven't been played yet.
+ * @return Samples to play in interleaved stereo PCM16 format.
+ */
+ std::vector<s16> Process(size_t sample_delay);
+
+private:
+ struct Impl;
+ std::unique_ptr<Impl> impl;
+
+ /// INTERNAL: ratio = wallclock time / emulated time
+ double CalculateCurrentRatio();
+ /// INTERNAL: If we have too many or too few samples downstream, nudge ratio in the appropriate direction.
+ double CorrectForUnderAndOverflow(double ratio, size_t sample_delay) const;
+ /// INTERNAL: Gets the time-stretched samples from SoundTouch.
+ std::vector<s16> GetSamples();
+};
+
+} // namespace AudioCore