summaryrefslogtreecommitdiffstats
path: root/src/audio_core/hle/dsp.cpp
diff options
context:
space:
mode:
authorbunnei <bunneidev@gmail.com>2016-09-01 04:19:38 +0200
committerGitHub <noreply@github.com>2016-09-01 04:19:38 +0200
commit549d0c171563423f024de754a82ab033d31294d1 (patch)
tree547ec290bfa04497c63f10603d801e473a0b1f84 /src/audio_core/hle/dsp.cpp
parentMerge pull request #2034 from JayFoxRox/avoid-glsl-error (diff)
parentconfigure_audio: User-configuratble option to enable/disable audio stretching (diff)
downloadyuzu-549d0c171563423f024de754a82ab033d31294d1.tar
yuzu-549d0c171563423f024de754a82ab033d31294d1.tar.gz
yuzu-549d0c171563423f024de754a82ab033d31294d1.tar.bz2
yuzu-549d0c171563423f024de754a82ab033d31294d1.tar.lz
yuzu-549d0c171563423f024de754a82ab033d31294d1.tar.xz
yuzu-549d0c171563423f024de754a82ab033d31294d1.tar.zst
yuzu-549d0c171563423f024de754a82ab033d31294d1.zip
Diffstat (limited to 'src/audio_core/hle/dsp.cpp')
-rw-r--r--src/audio_core/hle/dsp.cpp45
1 files changed, 37 insertions, 8 deletions
diff --git a/src/audio_core/hle/dsp.cpp b/src/audio_core/hle/dsp.cpp
index 0640e1eff..0cddeb82a 100644
--- a/src/audio_core/hle/dsp.cpp
+++ b/src/audio_core/hle/dsp.cpp
@@ -85,12 +85,45 @@ static StereoFrame16 GenerateCurrentFrame() {
// Audio output
+static bool perform_time_stretching = true;
static std::unique_ptr<AudioCore::Sink> sink;
static AudioCore::TimeStretcher time_stretcher;
+static void FlushResidualStretcherAudio() {
+ time_stretcher.Flush();
+ while (true) {
+ std::vector<s16> residual_audio = time_stretcher.Process(sink->SamplesInQueue());
+ if (residual_audio.empty())
+ break;
+ sink->EnqueueSamples(residual_audio.data(), residual_audio.size() / 2);
+ }
+}
+
static void OutputCurrentFrame(const StereoFrame16& frame) {
- time_stretcher.AddSamples(&frame[0][0], frame.size());
- sink->EnqueueSamples(time_stretcher.Process(sink->SamplesInQueue()));
+ if (perform_time_stretching) {
+ time_stretcher.AddSamples(&frame[0][0], frame.size());
+ std::vector<s16> stretched_samples = time_stretcher.Process(sink->SamplesInQueue());
+ sink->EnqueueSamples(stretched_samples.data(), stretched_samples.size() / 2);
+ } else {
+ constexpr size_t maximum_sample_latency = 1024; // about 32 miliseconds
+ if (sink->SamplesInQueue() > maximum_sample_latency) {
+ // This can occur if we're running too fast and samples are starting to back up.
+ // Just drop the samples.
+ return;
+ }
+
+ sink->EnqueueSamples(&frame[0][0], frame.size());
+ }
+}
+
+void EnableStretching(bool enable) {
+ if (perform_time_stretching == enable)
+ return;
+
+ if (!enable) {
+ FlushResidualStretcherAudio();
+ }
+ perform_time_stretching = enable;
}
// Public Interface
@@ -111,12 +144,8 @@ void Init() {
}
void Shutdown() {
- time_stretcher.Flush();
- while (true) {
- std::vector<s16> residual_audio = time_stretcher.Process(sink->SamplesInQueue());
- if (residual_audio.empty())
- break;
- sink->EnqueueSamples(residual_audio);
+ if (perform_time_stretching) {
+ FlushResidualStretcherAudio();
}
}