summaryrefslogtreecommitdiff
path: root/src/audio_core/time_stretch.h
diff options
context:
space:
mode:
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 @@
1// Copyright 2016 Citra Emulator Project
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#include <cstddef>
6#include <memory>
7#include <vector>
8
9#include "common/common_types.h"
10
11namespace AudioCore {
12
13class TimeStretcher final {
14public:
15 TimeStretcher();
16 ~TimeStretcher();
17
18 /**
19 * Set sample rate for the samples that Process returns.
20 * @param sample_rate The sample rate.
21 */
22 void SetOutputSampleRate(unsigned int sample_rate);
23
24 /**
25 * Add samples to be processed.
26 * @param sample_buffer Buffer of samples in interleaved stereo PCM16 format.
27 * @param num_sample Number of samples.
28 */
29 void AddSamples(const s16* sample_buffer, size_t num_samples);
30
31 /// Flush audio remaining in internal buffers.
32 void Flush();
33
34 /// Resets internal state and clears buffers.
35 void Reset();
36
37 /**
38 * Does audio stretching and produces the time-stretched samples.
39 * Timer calculations use sample_delay to determine how much of a margin we have.
40 * @param sample_delay How many samples are buffered downstream of this module and haven't been played yet.
41 * @return Samples to play in interleaved stereo PCM16 format.
42 */
43 std::vector<s16> Process(size_t sample_delay);
44
45private:
46 struct Impl;
47 std::unique_ptr<Impl> impl;
48
49 /// INTERNAL: ratio = wallclock time / emulated time
50 double CalculateCurrentRatio();
51 /// INTERNAL: If we have too many or too few samples downstream, nudge ratio in the appropriate direction.
52 double CorrectForUnderAndOverflow(double ratio, size_t sample_delay) const;
53 /// INTERNAL: Gets the time-stretched samples from SoundTouch.
54 std::vector<s16> GetSamples();
55};
56
57} // namespace AudioCore