From 1d6290f60534a376688ade15863725d28e2babd1 Mon Sep 17 00:00:00 2001 From: Filip Gawin Date: Tue, 16 Apr 2019 19:37:16 +0200 Subject: [PATCH] Optimize usage of mutexes in streaming audio --- rwengine/src/audio/SoundSource.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/rwengine/src/audio/SoundSource.cpp b/rwengine/src/audio/SoundSource.cpp index 871ba41d..d2edcc2f 100644 --- a/rwengine/src/audio/SoundSource.cpp +++ b/rwengine/src/audio/SoundSource.cpp @@ -1,4 +1,4 @@ -#include "audio/SoundSource.hpp" +#include "audio/SoundSource.hpp" #include #include @@ -285,10 +285,10 @@ void SoundSource::decodeFramesLegacy(size_t framesToDecode) { &decodingPacket); if (len >= 0 && gotFrame) { + std::lock_guard lock(mutex); // Write samples to audio buffer for (size_t i = 0; i < static_cast(frame->nb_samples); i++) { - std::lock_guard lock(mutex); // Interleave left/right channels for (size_t channel = 0; channel < channels; channel++) { @@ -334,11 +334,10 @@ void SoundSource::decodeFrames(size_t framesToDecode) { // Decode audio packet if (receiveFrame == 0 && sendPacket == 0) { + std::lock_guard lock(mutex); // Write samples to audio buffer - for (size_t i = 0; i < static_cast(frame->nb_samples); i++) { - std::lock_guard lock(mutex); // Interleave left/right channels for (size_t channel = 0; channel < channels; channel++) {