Common Source Code Project for Qt (a.k.a for FM-7).
Revision | 4e258c760687132a80cc46b63891b9a1c9f093b6 (tree) |
---|---|
Zeit | 2023-02-02 00:09:47 |
Autor | K.Ohta <whatisthis.sowhat@gmai...> |
Commiter | K.Ohta |
[OSD][Qt][SOUND] Fix volume and samples calculation for sound-drivers.
@@ -458,7 +458,7 @@ void OSD_BASE::update_sound(int* extra_frames) | ||
458 | 458 | __LIKELY_IF(!(sound_ok)) { |
459 | 459 | sound_drv->start(); |
460 | 460 | __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)); | |
462 | 462 | } |
463 | 463 | } |
464 | 464 | sound_ok = true; |
@@ -553,9 +553,8 @@ void OSD_BASE::initialize_sound(int rate, int samples, int* presented_rate, int* | ||
553 | 553 | nullptr, |
554 | 554 | 0)); |
555 | 555 | init_sound_device_list(); |
556 | - emit sig_update_sound_output_list(); | |
557 | 556 | 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)); | |
559 | 558 | } |
560 | 559 | } |
561 | 560 | std::shared_ptr<SOUND_MODULE::OUTPUT::M_BASE>sound_drv = m_sound_driver; |
@@ -45,7 +45,7 @@ namespace SOUND_MODULE { | ||
45 | 45 | set_osd(parent); |
46 | 46 | m_fileio.reset(); |
47 | 47 | |
48 | - if(m_channels.load() < 1) m_channels = 1; | |
48 | + if(m_channels.load() <= 1) m_channels = 2; | |
49 | 49 | recalc_samples(m_rate.load(), m_latency_ms.load(), true, false); |
50 | 50 | |
51 | 51 | 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 | ||
108 | 108 | if(latency_ms < 1) latency_ms = 1; |
109 | 109 | int64_t _samples = |
110 | 110 | ((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()); | |
112 | 112 | int64_t _buffer_bytes = _chunk_bytes * 2; |
113 | 113 | |
114 | 114 | bool _need_restart = false; |
@@ -443,7 +443,7 @@ int64_t M_BASE::update_sound(void* datasrc, int samples) | ||
443 | 443 | int64_t _result = -1; |
444 | 444 | qint64 _size = m_chunk_bytes.load(); |
445 | 445 | if(samples > 0) { |
446 | - _size = (qint64)(samples * m_channels) * (qint64)m_wordsize; | |
446 | + _size = (qint64)samples * (qint64)(m_channels.load() * m_wordsize.load()); | |
447 | 447 | } else if(samples == 0) { |
448 | 448 | return _result; |
449 | 449 | } |
@@ -451,7 +451,7 @@ int64_t M_BASE::update_sound(void* datasrc, int samples) | ||
451 | 451 | _result = (int64_t)q->write((const char *)datasrc, _size); |
452 | 452 | } |
453 | 453 | if(_result > 0) { |
454 | - _result = _result / (qint64)(m_channels * m_wordsize); | |
454 | + _result = _result / (qint64)(m_channels.load() * m_wordsize.load()); | |
455 | 455 | |
456 | 456 | } |
457 | 457 | return _result; |
@@ -241,10 +241,7 @@ bool M_QT_MULTIMEDIA::initialize_driver() | ||
241 | 241 | int _channels = m_channels.load(); |
242 | 242 | int _rate = m_rate.load(); |
243 | 243 | 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)) { | |
248 | 245 | tmp_output_format = tmp_output_device.preferredFormat(); |
249 | 246 | _channels = tmp_output_format.channelCount(); |
250 | 247 | _rate = tmp_output_format.sampleRate(); |
@@ -268,9 +265,11 @@ bool M_QT_MULTIMEDIA::initialize_driver() | ||
268 | 265 | m_config_ok = true; |
269 | 266 | } |
270 | 267 | 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; | |
273 | 270 | } |
271 | + m_chunk_bytes = m_samples.load() * m_wordsize.load() * m_channels.load(); | |
272 | + m_buffer_bytes = m_chunk_bytes.load() * 2; | |
274 | 273 | update_driver_fileio(); |
275 | 274 | |
276 | 275 | __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& | ||
472 | 471 | memset(_ccp->sound_device_name, 0x00, sizeof(_ccp->sound_device_name)); |
473 | 472 | my_tcscpy_s(_ccp->sound_device_name, (sizeof(_ccp->sound_device_name) / sizeof(_TCHAR)) - 1, _tmpname.toUtf8().constData()); |
474 | 473 | } |
475 | - | |
474 | + m_channels = channels; | |
476 | 475 | recalc_samples(rate, latency_ms, true, true); |
477 | 476 | |
478 | 477 | 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& | ||
486 | 485 | |
487 | 486 | int64_t _samples = |
488 | 487 | ((int64_t)rate * latency_ms) / 1000; |
489 | - if(_samples < 100) _samples = 100; | |
488 | + if(_samples <= 100) _samples = 100; | |
490 | 489 | if(m_fileio.get() != nullptr) { |
491 | 490 | std::lock_guard<std::recursive_timed_mutex> locker(m_locker); |
492 | 491 | if(m_fileio->isOpen()) { |
@@ -499,6 +498,8 @@ void M_QT_MULTIMEDIA::setup_device(QAudioDeviceInfo dest_device, int& rate,int& | ||
499 | 498 | m_latency_ms = latency_ms; |
500 | 499 | m_rate = rate; |
501 | 500 | 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; | |
502 | 503 | } |
503 | 504 | } |
504 | 505 | __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 | ||
554 | 555 | channels = 2; |
555 | 556 | m_config_ok = false; |
556 | 557 | } |
558 | + m_channels = channels; | |
557 | 559 | if(recalc_samples(rate, latency_ms, true, false)) { |
558 | 560 | m_prev_started = m_mute = false; |
559 | 561 | } |