diff options
| -rw-r--r-- | src/qmmp/volumehandler.cpp | 8 | ||||
| -rw-r--r-- | src/qmmp/volumehandler.h | 5 |
2 files changed, 10 insertions, 3 deletions
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 <QObject> +#include <QMutex> #include <atomic> #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<double> m_scaleLeft = ATOMIC_VAR_INIT(0); - std::atomic<double> 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; |
