1
0
mirror of https://github.com/rwengine/openrw.git synced 2024-11-01 16:32:31 +01:00

Optimize usage of mutexes in streaming audio

This commit is contained in:
Filip Gawin 2019-04-16 19:37:16 +02:00
parent a5ac546601
commit 1d6290f605

View File

@ -1,4 +1,4 @@
#include "audio/SoundSource.hpp" #include "audio/SoundSource.hpp"
#include <loaders/LoaderSDT.hpp> #include <loaders/LoaderSDT.hpp>
#include <rw/types.hpp> #include <rw/types.hpp>
@ -285,10 +285,10 @@ void SoundSource::decodeFramesLegacy(size_t framesToDecode) {
&decodingPacket); &decodingPacket);
if (len >= 0 && gotFrame) { if (len >= 0 && gotFrame) {
std::lock_guard<std::mutex> lock(mutex);
// Write samples to audio buffer // Write samples to audio buffer
for (size_t i = 0; for (size_t i = 0;
i < static_cast<size_t>(frame->nb_samples); i++) { i < static_cast<size_t>(frame->nb_samples); i++) {
std::lock_guard<std::mutex> lock(mutex);
// Interleave left/right channels // Interleave left/right channels
for (size_t channel = 0; channel < channels; for (size_t channel = 0; channel < channels;
channel++) { channel++) {
@ -334,11 +334,10 @@ void SoundSource::decodeFrames(size_t framesToDecode) {
// Decode audio packet // Decode audio packet
if (receiveFrame == 0 && sendPacket == 0) { if (receiveFrame == 0 && sendPacket == 0) {
std::lock_guard<std::mutex> lock(mutex);
// Write samples to audio buffer // Write samples to audio buffer
for (size_t i = 0; for (size_t i = 0;
i < static_cast<size_t>(frame->nb_samples); i++) { i < static_cast<size_t>(frame->nb_samples); i++) {
std::lock_guard<std::mutex> lock(mutex);
// Interleave left/right channels // Interleave left/right channels
for (size_t channel = 0; channel < channels; for (size_t channel = 0; channel < channels;
channel++) { channel++) {