OSDN Git Service

[OSD][Qt][SOUND] Fix volume and samples calculation for sound-drivers.
authorK.Ohta <whatisthis.sowhat@gmail.com>
Wed, 1 Feb 2023 15:09:47 +0000 (00:09 +0900)
committerK.Ohta <whatisthis.sowhat@gmail.com>
Wed, 1 Feb 2023 15:09:47 +0000 (00:09 +0900)
source/src/qt/osd_sound.cpp
source/src/qt/sound-drivers/common/osd_sound_mod_template.cpp
source/src/qt/sound-drivers/qt_multimedia/osd_sound_mod_qtmultimedia.cpp

index 228fb2e..df86f44 100644 (file)
@@ -458,7 +458,7 @@ void OSD_BASE::update_sound(int* extra_frames)
                        __LIKELY_IF(!(sound_ok)) {
                                sound_drv->start();
                                __UNLIKELY_IF(p_config != nullptr) {
-                                       sound_drv->set_volume((int)(p_config->general_sound_level));
+                                       do_update_master_volume((int)(p_config->general_sound_level));
                                }
                        }
                        sound_ok = true;
@@ -553,9 +553,8 @@ void OSD_BASE::initialize_sound(int rate, int samples, int* presented_rate, int*
                                                                                                         nullptr,
                                                                                                         0));
                init_sound_device_list();
-               emit sig_update_sound_output_list();
                if(p_config != nullptr) {
-                       m_sound_driver->set_volume((int)(p_config->general_sound_level));
+                       do_update_master_volume((int)(p_config->general_sound_level));
                }
        }
        std::shared_ptr<SOUND_MODULE::OUTPUT::M_BASE>sound_drv = m_sound_driver;
index 670e3f7..767ed80 100644 (file)
@@ -45,7 +45,7 @@ namespace SOUND_MODULE {
        set_osd(parent);
        m_fileio.reset();
        
-       if(m_channels.load() < 1) m_channels = 1;
+       if(m_channels.load() <= 1) m_channels = 2;
        recalc_samples(m_rate.load(), m_latency_ms.load(), true, false);
        
        bool _reinit = (deviceIO == nullptr) ? true : false;
@@ -108,7 +108,7 @@ bool M_BASE::recalc_samples(int rate, int latency_ms, bool need_update, bool nee
        if(latency_ms < 1) latency_ms = 1;
        int64_t _samples =
                ((int64_t)rate * latency_ms) / 1000;
-       size_t _chunk_bytes = (size_t)(_samples * m_wordsize.load());
+       size_t _chunk_bytes = (size_t)(_samples * m_wordsize.load() * m_channels.load());
        int64_t _buffer_bytes = _chunk_bytes * 2;
        
        bool _need_restart = false;
@@ -443,7 +443,7 @@ int64_t M_BASE::update_sound(void* datasrc, int samples)
        int64_t _result = -1;
        qint64 _size = m_chunk_bytes.load();
        if(samples > 0) {
-               _size = (qint64)(samples * m_channels) * (qint64)m_wordsize;
+               _size = (qint64)samples * (qint64)(m_channels.load() * m_wordsize.load());
        } else if(samples == 0) {
                return _result;
        }
@@ -451,7 +451,7 @@ int64_t M_BASE::update_sound(void* datasrc, int samples)
                _result = (int64_t)q->write((const char *)datasrc, _size);
        }
        if(_result > 0) {
-               _result = _result / (qint64)(m_channels * m_wordsize);
+               _result = _result / (qint64)(m_channels.load() * m_wordsize.load());
                
        }
        return _result;
index 0e16fcc..d140406 100644 (file)
@@ -241,10 +241,7 @@ bool M_QT_MULTIMEDIA::initialize_driver()
        int _channels = m_channels.load();
        int _rate = m_rate.load();
        set_audio_format(tmp_output_device, tmp_output_format, _channels, _rate);
-       if((_channels > 0) && (_rate > 0)) {
-               m_channels = _channels;
-               m_rate = _rate;
-       } else {
+       if((_channels <= 0) || (_rate <= 0)) {
                tmp_output_format = tmp_output_device.preferredFormat();
                _channels = tmp_output_format.channelCount();
                _rate     = tmp_output_format.sampleRate();
@@ -268,9 +265,11 @@ bool M_QT_MULTIMEDIA::initialize_driver()
                m_config_ok = true;
        }
        m_samples = ((qint64)m_latency_ms.load() * (qint64)(m_rate.load())) / 1000;
-       if(m_samples.load() <= 0) {
-               m_samples = 4800;
+       if(m_samples.load() <= 100) {
+               m_samples = 100;
        }
+       m_chunk_bytes = m_samples.load() * m_wordsize.load() * m_channels.load();
+       m_buffer_bytes = m_chunk_bytes.load() * 2;
        update_driver_fileio();
 
        __debug_log_func(_T("status=%s"), (m_config_ok) ? _T("OK") : _T("NG"));
@@ -472,7 +471,7 @@ void M_QT_MULTIMEDIA::setup_device(QAudioDeviceInfo dest_device, int& rate,int&
                                memset(_ccp->sound_device_name, 0x00, sizeof(_ccp->sound_device_name));
                                my_tcscpy_s(_ccp->sound_device_name, (sizeof(_ccp->sound_device_name) / sizeof(_TCHAR)) - 1, _tmpname.toUtf8().constData());
                        }
-
+                       m_channels = channels;
                        recalc_samples(rate, latency_ms, true, true);
                        
                        std::lock_guard<std::recursive_timed_mutex> locker(m_locker);
@@ -486,7 +485,7 @@ void M_QT_MULTIMEDIA::setup_device(QAudioDeviceInfo dest_device, int& rate,int&
                        
                        int64_t _samples =
                                ((int64_t)rate * latency_ms) / 1000;
-                       if(_samples < 100) _samples = 100;
+                       if(_samples <= 100) _samples = 100;
                        if(m_fileio.get() != nullptr) {
                                std::lock_guard<std::recursive_timed_mutex> locker(m_locker);
                                if(m_fileio->isOpen()) {
@@ -499,6 +498,8 @@ void M_QT_MULTIMEDIA::setup_device(QAudioDeviceInfo dest_device, int& rate,int&
                        m_latency_ms = latency_ms;
                        m_rate = rate;
                        m_channels = channels;
+                       m_chunk_bytes = m_samples.load() * m_wordsize.load() * m_channels.load();
+                       m_buffer_bytes = m_chunk_bytes.load() * 2;
                }
        }
        __debug_log_func(_T("Result: rate=%d channels=%d latency=%dmSec reinit=%d"), m_rate.load(), m_channels.load(), m_latency_ms.load(), force_reinit);
@@ -554,6 +555,7 @@ bool M_QT_MULTIMEDIA::real_reconfig_sound(int& rate,int& channels,int& latency_m
                channels = 2;
                m_config_ok = false;
        }
+       m_channels = channels;
        if(recalc_samples(rate, latency_ms, true, false)) {
                m_prev_started = m_mute = false;
        }