summaryrefslogtreecommitdiff
path: root/src/audio_core/hle/dsp.cpp
diff options
context:
space:
mode:
authorGravatar bunnei2016-08-31 22:19:38 -0400
committerGravatar GitHub2016-08-31 22:19:38 -0400
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.gz
yuzu-549d0c171563423f024de754a82ab033d31294d1.tar.xz
yuzu-549d0c171563423f024de754a82ab033d31294d1.zip
Merge pull request #2035 from MerryMage/disable-stretch
User-configurable option to enable/disable time-stretching of audio
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() {
85 85
86// Audio output 86// Audio output
87 87
88static bool perform_time_stretching = true;
88static std::unique_ptr<AudioCore::Sink> sink; 89static std::unique_ptr<AudioCore::Sink> sink;
89static AudioCore::TimeStretcher time_stretcher; 90static AudioCore::TimeStretcher time_stretcher;
90 91
92static void FlushResidualStretcherAudio() {
93 time_stretcher.Flush();
94 while (true) {
95 std::vector<s16> residual_audio = time_stretcher.Process(sink->SamplesInQueue());
96 if (residual_audio.empty())
97 break;
98 sink->EnqueueSamples(residual_audio.data(), residual_audio.size() / 2);
99 }
100}
101
91static void OutputCurrentFrame(const StereoFrame16& frame) { 102static void OutputCurrentFrame(const StereoFrame16& frame) {
92 time_stretcher.AddSamples(&frame[0][0], frame.size()); 103 if (perform_time_stretching) {
93 sink->EnqueueSamples(time_stretcher.Process(sink->SamplesInQueue())); 104 time_stretcher.AddSamples(&frame[0][0], frame.size());
105 std::vector<s16> stretched_samples = time_stretcher.Process(sink->SamplesInQueue());
106 sink->EnqueueSamples(stretched_samples.data(), stretched_samples.size() / 2);
107 } else {
108 constexpr size_t maximum_sample_latency = 1024; // about 32 miliseconds
109 if (sink->SamplesInQueue() > maximum_sample_latency) {
110 // This can occur if we're running too fast and samples are starting to back up.
111 // Just drop the samples.
112 return;
113 }
114
115 sink->EnqueueSamples(&frame[0][0], frame.size());
116 }
117}
118
119void EnableStretching(bool enable) {
120 if (perform_time_stretching == enable)
121 return;
122
123 if (!enable) {
124 FlushResidualStretcherAudio();
125 }
126 perform_time_stretching = enable;
94} 127}
95 128
96// Public Interface 129// Public Interface
@@ -111,12 +144,8 @@ void Init() {
111} 144}
112 145
113void Shutdown() { 146void Shutdown() {
114 time_stretcher.Flush(); 147 if (perform_time_stretching) {
115 while (true) { 148 FlushResidualStretcherAudio();
116 std::vector<s16> residual_audio = time_stretcher.Process(sink->SamplesInQueue());
117 if (residual_audio.empty())
118 break;
119 sink->EnqueueSamples(residual_audio);
120 } 149 }
121} 150}
122 151