• R/O
  • HTTP
  • SSH
  • HTTPS

common_source_project-fm7: Commit

Common Source Code Project for Qt (a.k.a for FM-7).


Commit MetaInfo

Revision4e258c760687132a80cc46b63891b9a1c9f093b6 (tree)
Zeit2023-02-02 00:09:47
AutorK.Ohta <whatisthis.sowhat@gmai...>
CommiterK.Ohta

Log Message

[OSD][Qt][SOUND] Fix volume and samples calculation for sound-drivers.

Ändern Zusammenfassung

Diff

--- a/source/src/qt/osd_sound.cpp
+++ b/source/src/qt/osd_sound.cpp
@@ -458,7 +458,7 @@ void OSD_BASE::update_sound(int* extra_frames)
458458 __LIKELY_IF(!(sound_ok)) {
459459 sound_drv->start();
460460 __UNLIKELY_IF(p_config != nullptr) {
461- sound_drv->set_volume((int)(p_config->general_sound_level));
461+ do_update_master_volume((int)(p_config->general_sound_level));
462462 }
463463 }
464464 sound_ok = true;
@@ -553,9 +553,8 @@ void OSD_BASE::initialize_sound(int rate, int samples, int* presented_rate, int*
553553 nullptr,
554554 0));
555555 init_sound_device_list();
556- emit sig_update_sound_output_list();
557556 if(p_config != nullptr) {
558- m_sound_driver->set_volume((int)(p_config->general_sound_level));
557+ do_update_master_volume((int)(p_config->general_sound_level));
559558 }
560559 }
561560 std::shared_ptr<SOUND_MODULE::OUTPUT::M_BASE>sound_drv = m_sound_driver;
--- a/source/src/qt/sound-drivers/common/osd_sound_mod_template.cpp
+++ b/source/src/qt/sound-drivers/common/osd_sound_mod_template.cpp
@@ -45,7 +45,7 @@ namespace SOUND_MODULE {
4545 set_osd(parent);
4646 m_fileio.reset();
4747
48- if(m_channels.load() < 1) m_channels = 1;
48+ if(m_channels.load() <= 1) m_channels = 2;
4949 recalc_samples(m_rate.load(), m_latency_ms.load(), true, false);
5050
5151 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
108108 if(latency_ms < 1) latency_ms = 1;
109109 int64_t _samples =
110110 ((int64_t)rate * latency_ms) / 1000;
111- size_t _chunk_bytes = (size_t)(_samples * m_wordsize.load());
111+ size_t _chunk_bytes = (size_t)(_samples * m_wordsize.load() * m_channels.load());
112112 int64_t _buffer_bytes = _chunk_bytes * 2;
113113
114114 bool _need_restart = false;
@@ -443,7 +443,7 @@ int64_t M_BASE::update_sound(void* datasrc, int samples)
443443 int64_t _result = -1;
444444 qint64 _size = m_chunk_bytes.load();
445445 if(samples > 0) {
446- _size = (qint64)(samples * m_channels) * (qint64)m_wordsize;
446+ _size = (qint64)samples * (qint64)(m_channels.load() * m_wordsize.load());
447447 } else if(samples == 0) {
448448 return _result;
449449 }
@@ -451,7 +451,7 @@ int64_t M_BASE::update_sound(void* datasrc, int samples)
451451 _result = (int64_t)q->write((const char *)datasrc, _size);
452452 }
453453 if(_result > 0) {
454- _result = _result / (qint64)(m_channels * m_wordsize);
454+ _result = _result / (qint64)(m_channels.load() * m_wordsize.load());
455455
456456 }
457457 return _result;
--- a/source/src/qt/sound-drivers/qt_multimedia/osd_sound_mod_qtmultimedia.cpp
+++ b/source/src/qt/sound-drivers/qt_multimedia/osd_sound_mod_qtmultimedia.cpp
@@ -241,10 +241,7 @@ bool M_QT_MULTIMEDIA::initialize_driver()
241241 int _channels = m_channels.load();
242242 int _rate = m_rate.load();
243243 set_audio_format(tmp_output_device, tmp_output_format, _channels, _rate);
244- if((_channels > 0) && (_rate > 0)) {
245- m_channels = _channels;
246- m_rate = _rate;
247- } else {
244+ if((_channels <= 0) || (_rate <= 0)) {
248245 tmp_output_format = tmp_output_device.preferredFormat();
249246 _channels = tmp_output_format.channelCount();
250247 _rate = tmp_output_format.sampleRate();
@@ -268,9 +265,11 @@ bool M_QT_MULTIMEDIA::initialize_driver()
268265 m_config_ok = true;
269266 }
270267 m_samples = ((qint64)m_latency_ms.load() * (qint64)(m_rate.load())) / 1000;
271- if(m_samples.load() <= 0) {
272- m_samples = 4800;
268+ if(m_samples.load() <= 100) {
269+ m_samples = 100;
273270 }
271+ m_chunk_bytes = m_samples.load() * m_wordsize.load() * m_channels.load();
272+ m_buffer_bytes = m_chunk_bytes.load() * 2;
274273 update_driver_fileio();
275274
276275 __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&
472471 memset(_ccp->sound_device_name, 0x00, sizeof(_ccp->sound_device_name));
473472 my_tcscpy_s(_ccp->sound_device_name, (sizeof(_ccp->sound_device_name) / sizeof(_TCHAR)) - 1, _tmpname.toUtf8().constData());
474473 }
475-
474+ m_channels = channels;
476475 recalc_samples(rate, latency_ms, true, true);
477476
478477 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&
486485
487486 int64_t _samples =
488487 ((int64_t)rate * latency_ms) / 1000;
489- if(_samples < 100) _samples = 100;
488+ if(_samples <= 100) _samples = 100;
490489 if(m_fileio.get() != nullptr) {
491490 std::lock_guard<std::recursive_timed_mutex> locker(m_locker);
492491 if(m_fileio->isOpen()) {
@@ -499,6 +498,8 @@ void M_QT_MULTIMEDIA::setup_device(QAudioDeviceInfo dest_device, int& rate,int&
499498 m_latency_ms = latency_ms;
500499 m_rate = rate;
501500 m_channels = channels;
501+ m_chunk_bytes = m_samples.load() * m_wordsize.load() * m_channels.load();
502+ m_buffer_bytes = m_chunk_bytes.load() * 2;
502503 }
503504 }
504505 __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
554555 channels = 2;
555556 m_config_ok = false;
556557 }
558+ m_channels = channels;
557559 if(recalc_samples(rate, latency_ms, true, false)) {
558560 m_prev_started = m_mute = false;
559561 }
Show on old repository browser