From 87c9eb7f69b1aef4ebc9670b430b27790a459be3 Mon Sep 17 00:00:00 2001 From: trialuser02 Date: Mon, 11 Mar 2019 19:48:14 +0000 Subject: optimization git-svn-id: http://svn.code.sf.net/p/qmmp-dev/code/trunk/qmmp@8761 90c681e8-e032-0410-971d-27865f9a5e38 --- src/qmmp/volumehandler.cpp | 8 +++++++- src/qmmp/volumehandler.h | 5 +++-- 2 files changed, 10 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/qmmp/volumehandler.cpp b/src/qmmp/volumehandler.cpp index aadc4bd5f..0c57b4a44 100644 --- a/src/qmmp/volumehandler.cpp +++ b/src/qmmp/volumehandler.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2008-2016 by Ilya Kotov * + * Copyright (C) 2008-2019 by Ilya Kotov * * forkotov02@ya.ru * * * * This program is free software; you can redistribute it and/or modify * @@ -65,8 +65,10 @@ void VolumeHandler::setVolume(int left, int right) else if(m_settings != v) { m_settings = v; + m_mutex.lock(); m_scaleLeft = double(m_settings.left) / 100.0; m_scaleRight = double(m_settings.right) / 100.0; + m_mutex.unlock(); checkVolume(); } } @@ -149,6 +151,7 @@ void VolumeHandler::apply(Buffer *b, int chan) return; } + m_mutex.lock(); if(chan == 1) { for(size_t i = 0; i < b->samples; ++i) @@ -164,6 +167,7 @@ void VolumeHandler::apply(Buffer *b, int chan) b->data[i+1] *= m_scaleRight; } } + m_mutex.unlock(); } } @@ -244,8 +248,10 @@ void VolumeHandler::reload() } else { + m_mutex.lock(); m_scaleLeft = double(m_settings.left) / 100.0; m_scaleRight = double(m_settings.right) / 100.0; + m_mutex.unlock(); m_apply = true; blockSignals(true); checkVolume(); diff --git a/src/qmmp/volumehandler.h b/src/qmmp/volumehandler.h index f550da3f6..3c509359d 100644 --- a/src/qmmp/volumehandler.h +++ b/src/qmmp/volumehandler.h @@ -21,6 +21,7 @@ #define VOLUMEHANDLER_H #include +#include #include #include "qmmp.h" #include "volume.h" @@ -125,8 +126,8 @@ private: bool m_prev_block = false; std::atomic_bool m_muted = ATOMIC_VAR_INIT(false); std::atomic_bool m_apply = ATOMIC_VAR_INIT(false); - std::atomic m_scaleLeft = ATOMIC_VAR_INIT(0); - std::atomic m_scaleRight = ATOMIC_VAR_INIT(0); + QMutex m_mutex; + double m_scaleLeft = 0, m_scaleRight = 0; Volume *m_volume = nullptr; QTimer *m_timer; static VolumeHandler *m_instance; -- cgit v1.2.3-13-gbd6f