• R/O
  • HTTP
  • SSH
  • HTTPS

common_source_project-fm7: 提交

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


Commit MetaInfo

修订版e8cf4ede2bece3bb64726ff93934fffd9e1f445f (tree)
时间2022-09-21 23:33:19
作者K.Ohta <whatisthis.sowhat@gmai...>
CommiterK.Ohta

Log Message

[OSD][SOUND][WIP] New Driver:QT_MULTIMEDIA: Still don't available to sound.

更改概述

差异

--- a/source/src/qt/common/emu_thread.cpp
+++ b/source/src/qt/common/emu_thread.cpp
@@ -63,7 +63,7 @@ EmuThreadClass::EmuThreadClass(Ui_MainWindowBase *rootWindow, std::shared_ptr<US
6363 connect(this, SIGNAL(sig_set_b77_num(int, int)), MainWindow, SLOT(set_b77_slot(int, int)));
6464
6565 p_osd->setParent(this);
66- p_osd->moveToThread(this);
66+ //p_osd->moveToThread(this);
6767 }
6868
6969 EmuThreadClass::~EmuThreadClass()
--- a/source/src/qt/osd_base.cpp
+++ b/source/src/qt/osd_base.cpp
@@ -96,9 +96,10 @@ OSD_BASE::OSD_BASE(std::shared_ptr<USING_FLAGS> p, std::shared_ptr<CSP_Logger> l
9696 2,
9797 nullptr,
9898 0));
99-
100- #endif /* END Note: */
10199 get_sound_device_list();
100+ #else
101+ m_sound_driver.reset();
102+ #endif /* END Note: */
102103 }
103104
104105 OSD_BASE::~OSD_BASE()
--- a/source/src/qt/osd_sound.cpp
+++ b/source/src/qt/osd_sound.cpp
@@ -249,7 +249,7 @@ void OSD_BASE::initialize_sound(int rate, int samples, int* presented_rate, int*
249249 }
250250
251251 sound_capture_device_list.clear();
252-#if 0
252+ #if 0
253253 for(int ch = 0 ; ch < MAX_CAPTURE_SOUND; ch++) {
254254 // ToDo: Allocation.
255255 // ToDo: Close physical device.
@@ -292,7 +292,7 @@ void OSD_BASE::initialize_sound(int rate, int samples, int* presented_rate, int*
292292 sound_capture_dev_desc[num].userdata.read_buffer_ptr = NULL;
293293 capturing_sound[num] = false;
294294 }
295-#endif
295+ #endif
296296
297297 sound_rate = rate;
298298 sound_samples = samples;
@@ -327,7 +327,7 @@ void OSD_BASE::initialize_sound(int rate, int samples, int* presented_rate, int*
327327 snd_spec_req.samples = samples;
328328 snd_spec_req.callback = &(this->audio_callback);
329329 snd_spec_req.userdata = (void *)&snddata;
330-#if defined(USE_SDL2)
330+ #if defined(USE_SDL2)
331331 audio_dev_id = 0;
332332 if(!(sound_device_list.isEmpty())) {
333333 QString sdev;
@@ -351,12 +351,12 @@ void OSD_BASE::initialize_sound(int rate, int samples, int* presented_rate, int*
351351 p_config->sound_device_num, (audio_dev_id <= 0) ? "FAIL" : "SUCCESS", audio_dev_id);
352352
353353 }
354-#else
354+ #else
355355 audio_dev_id = 1;
356356 SDL_OpenAudio(&snd_spec_req, &snd_spec_presented);
357-#endif
357+ #endif
358358
359-#if defined(USE_SDL2)
359+ #if defined(USE_SDL2)
360360 if(audio_dev_id <= 0) {
361361 debug_log(CSP_LOG_INFO, CSP_LOG_TYPE_SOUND,"Failed to initialize sound\n");
362362 if(presented_rate != NULL) {
@@ -369,7 +369,7 @@ void OSD_BASE::initialize_sound(int rate, int samples, int* presented_rate, int*
369369 sound_ok = sound_first_half = false;
370370 return;
371371 }
372-#endif
372+ #endif
373373 snddata.sound_format = snd_spec_presented.format;
374374 if((snd_spec_presented.freq != sound_rate) ||
375375 (snd_spec_presented.samples != sound_samples)) { // DEINI
@@ -404,11 +404,11 @@ void OSD_BASE::initialize_sound(int rate, int samples, int* presented_rate, int*
404404 sound_buffer_size = sound_samples * snd_spec_presented.channels * 2;
405405 sound_buf_ptr = (uint8_t *)malloc(sound_buffer_size * format_len);
406406 if(sound_buf_ptr == NULL) {
407-#if defined(USE_SDL2)
407+ #if defined(USE_SDL2)
408408 SDL_CloseAudioDevice(audio_dev_id);
409-#else
409+ #else
410410 SDL_CloseAudio();
411-#endif
411+ #endif
412412 return;
413413 }
414414
@@ -424,7 +424,7 @@ void OSD_BASE::release_sound()
424424 // release SDL sound
425425 sound_exit = true;
426426 sound_initialized = false;
427-#if 0
427+ #if 0
428428 for(int num = 0; num < MAX_SOUND_CAPTURE_DEVICES; num++) {
429429 if(capturing_sound[num]) {
430430 close_sound_capture_device(num, true);
@@ -436,13 +436,13 @@ void OSD_BASE::release_sound()
436436 close_capture_sound_emu(ch);
437437 }
438438 }
439-#endif
440-#if defined(USE_SDL2)
439+ #endif
440+ #if defined(USE_SDL2)
441441 //SDL_PauseAudioDevice(audio_dev_id, 1);
442442 SDL_CloseAudioDevice(audio_dev_id);
443-#else
443+ #else
444444 SDL_CloseAudio();
445-#endif
445+ #endif
446446 stop_record_sound();
447447 if(sound_buf_ptr != NULL) free(sound_buf_ptr);
448448 sound_buf_ptr = NULL;
@@ -451,7 +451,7 @@ void OSD_BASE::release_sound()
451451 #else
452452 #if 1 /* Note: Below are new sound driver. */
453453 #include "./osd_sound_mod_template.h"
454-//#include "./osd_sound_mod_qtmultimedia.h"
454+ #include "./osd_sound_mod_qtmultimedia.h"
455455 void OSD_BASE::update_sound(int* extra_frames)
456456 {
457457 *extra_frames = 0;
@@ -521,15 +521,33 @@ void OSD_BASE::update_sound(int* extra_frames)
521521 }
522522 // ToDo: Convert sound format.
523523 int64_t _result = sound_drv->update_sound((void*)sound_buffer, sound_samples);
524+ debug_log(CSP_LOG_DEBUG, CSP_LOG_TYPE_SOUND,
525+ _T("OSD::%s() : sound result=%d"), __func__, _result);
524526 sound_drv->update_render_point_usec();
525527 }
526528 }
527529
528530 void OSD_BASE::initialize_sound(int rate, int samples, int* presented_rate, int* presented_samples)
529531 {
532+ // If sound driver hasn't initialized, initialize.
533+ if(m_sound_driver.get() == nullptr) {
534+ m_sound_driver.reset(
535+ new SOUND_OUTPUT_MODULE::M_QT_MULTIMEDIA(this,
536+ nullptr,
537+ rate,
538+ (samples * 1000) / rate,
539+ 2,
540+ nullptr,
541+ 0));
542+ get_sound_device_list();
543+ }
530544 std::shared_ptr<SOUND_OUTPUT_MODULE::M_BASE>sound_drv = m_sound_driver;
545+
546+ debug_log(CSP_LOG_DEBUG, CSP_LOG_TYPE_SOUND,
547+ "OSD::%s rate=%d samples=%d m_sound_driver=%llx", __func__, rate, samples, (uintptr_t)(sound_drv.get()));
531548 if(sound_drv.get() != nullptr) {
532549 sound_drv->initialize_sound(rate, samples, presented_rate, presented_samples);
550+ sound_ok = true;
533551 }
534552 }
535553 void OSD_BASE::release_sound()
@@ -605,314 +623,8 @@ int OSD_BASE::get_sound_rate()
605623 }
606624 return 0;
607625 }
608-
609- #else /* Note */
610- #if 0
611-// QT_Multimedia
612-#include <QtMultimedia>
613-void OSD_BASE::initialize_sound(int rate, int samples, int* presented_rate, int* presented_samples)
614-{
615- // ToDo: Sound Input
616- QAudioFormat desired;
617-
618- //m_audioOutputSink.get()->moveToThread(QThread::currentThread());
619- if(m_audioOutputSink->state() != QAudio::StoppedState) {
620- m_audioOutputSink->stop();
621- }
622- sound_us_before_rendered = 0;
623- if(m_audioOutput != nullptr) {
624- //m_audioOutput->moveToThread(this->thread());
625- if(m_audioOutput->isOpen()) {
626- m_audioOutput->close();
627- }
628- delete m_audioOutput;
629- m_audioOutput = nullptr;
630- }
631- m_audioOutputSink->moveToThread(this->thread());
632-
633-#if QT_VERSION >= QT_VERSION_CHECK(6, 2, 0)
634- desired.setChannelCount(2);
635- desired.setSampleRate(rate);
636- desired.setSampleFormat(QAudioFormat::Int16);
637- desired.setChannelConfig(QAudioFormat::ChannelConfigStereo);
638-#elif QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
639- desired.setChannelCount(2);
640- desired.setSampleRate(rate);
641- desired.setSampleSize(16);
642- desired.setSampleType(QAudioFormat::SignedInt);
643- #if Q_BYTE_ORDER == Q_BIG_ENDIAN
644- desired.setByteOrder(QAudioFormat::BigEndian);
645- #else
646- desired.setByteOrder(QAudioFormat::LittleEndian);
647- #endif
648-#endif
649-
650-// if(!(m_audioOutputDevice.isFormatSupported(desired))) {
651-// desired = m_audioOutputDevice.preferredFormat();
652-// }
653- m_audioOutputFormat = desired;
654- m_audioOutputSink->disconnect();
655-
656-#if QT_VERSION >= QT_VERSION_CHECK(6, 2, 0)
657- m_audioOutputSink.reset(new QAudioSink(m_audioOutputDevice, m_audioOutputFormat));
658-#elif QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
659- m_audioOutputSink.reset(new QAudioOutput(m_audioOutputDevice, m_audioOutputFormat));
660-#endif
661-
662- rate = m_audioOutputFormat.sampleRate();
663- if(rate <= 0) rate = 8000;
664- int outbuffer_length = samples * 2;
665-
666- sound_us_before_rendered = 0;
667- m_audioOutput = new SOUND_BUFFER_QT(samples * 2 * sizeof(int16_t) * 4);
668- if(m_audioOutput != nullptr) {
669- #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
670- m_audioOutput->open(QIODeviceBase::ReadWrite | QIODeviceBase::Truncate | QIODeviceBase::Unbuffered);
671- #else
672- m_audioOutput->open(QIODevice::ReadWrite | QIODevice::Truncate | QIODevice::Unbuffered);
673- #endif
674- m_audioOutput->reset();
675- #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
676- m_audioOutputSink->start(m_audioOutput);
677- #endif
678- elapsed_us_before_rendered = 0;
679- sound_us_before_rendered = 0;
680- #if QT_VERSION >= QT_VERSION_CHECK(6, 2, 0)
681- debug_log(CSP_LOG_INFO, CSP_LOG_TYPE_SOUND,
682- "Sound Device to: %s",
683- m_audioOutputDevice.description().toLocal8Bit().constData());
684- #else
685- debug_log(CSP_LOG_INFO, CSP_LOG_TYPE_SOUND,
686- "Sound Device to: %s",
687- m_audioOutputDevice.deviceName().toLocal8Bit().constData());
688- #endif
689- }
690-
691- sound_samples = samples;
692- sound_rate = rate;
693-
694- debug_log(CSP_LOG_INFO, CSP_LOG_TYPE_SOUND,"Sample rate=%d samples=%d\n", sound_rate, sound_samples);
695-
696- rec_sound_buffer_ptr = 0;
697- sound_ok = sound_started = now_mute = now_record_sound = false;
698- sound_write_pos = 0;
699- sound_data_len = 0;
700- sound_buffer_size = 0;
701- sound_data_pos = 0;
702- sound_exit = false;
703- sound_debug = false;
704- //sound_debug = true;
705- sound_buf_ptr = NULL;
706-
707- if(presented_rate != nullptr) {
708- *presented_rate = sound_rate;
709- }
710- if(presented_samples != nullptr) {
711- *presented_samples = sound_samples;
712- }
713-
714- sound_ok = true;
715- #if 0
716- if(out_driver.get() != nullptr) {
717- double _ll = 1.0;
718- if(p_config != nullptr) {
719- _ll = (double)(p_config->general_sound_level + INT16_MAX) / 65535.0;
720- }
721- emit sig_set_volume(_ll);
722- }
723- #else
724- if(p_config != nullptr) {
725- double _ll = (double)(p_config->general_sound_level + INT16_MAX) / 65535.0;
726- m_audioOutputSink->setVolume(_ll);
727- }
728- connect(m_audioOutputSink.get(), SIGNAL(stateChanged(QAudio::State)), this, SLOT(handleAudioOutputStateChanged(QAudio::State)));
729- #endif
730- sound_initialized = true;
731- debug_log(CSP_LOG_INFO, CSP_LOG_TYPE_SOUND,
732- "Sound OK: BufSize = %d", outbuffer_length);
733-}
734-
735-void OSD_BASE::release_sound()
736-{
737- // ToDo: Sound Input
738- // release Qt Multimedia sound
739- sound_exit = true;
740- sound_initialized = false;
741-#if 1
742- if(m_output_driver.get() != nullptr) {
743- m_output_driver->stop();
744- m_output_driver->reset_to_default();
745- disconnect(m_output_driver.get());
746- }
747- m_output_driver.reset();
748-
749-#else
750- m_audioOutputSink->stop();
751- m_audioOutputSink->disconnect();
752-
753- #if QT_VERSION >= QT_VERSION_CHECK(6, 2, 0)
754- m_audioOutputDevice = QMediaDevices::defaultAudioOutput();
755- m_audioInputDevice = QMediaDevices::defaultAudioInput();
626+ #endif /* End Note: */
756627
757- m_audioOutputSink.reset(new QAudioSink(m_audioOutputDevice, m_audioOutputDevice.preferredFormat()));
758- #else
759- m_audioOutputDevice = QAudioDeviceInfo::defaultOutputDevice();
760- m_audioInputDevice = QAudioDeviceInfo::defaultInputDevice();
761-
762- m_audioOutputSink.reset(new QAudioOutput(m_audioOutputDevice, m_audioOutputDevice.preferredFormat(), this));
763- #endif
764-
765- if(m_audioOutput != nullptr) {
766- if(m_audioOutput->isOpen()) {
767- m_audioOutput->close();
768- }
769- delete m_audioOutput;
770- m_audioOutput = nullptr;
771- }
772-#endif
773- sound_ok = false;
774- sound_initialized = false;
775-}
776-
777-void OSD_BASE::do_update_master_volume(int level)
778-{
779- //std::lock_guard<std::recursive_timed_mutex> l(vm_mutex);
780- double _ll = (double)(level + INT16_MAX) / 65535.0;
781-#if 1
782- emit sig_set_sound_volume(_ll);
783-#else
784- m_audioOutputSink->setVolume(_ll);
785-#endif
786-}
787-
788-
789-void OSD_BASE::do_set_host_sound_output_device(QString device_name)
790-{
791- if(device_name.isEmpty()) return;
792-#if 1
793- emit sig_set_device(device_name);
794- debug_log(CSP_LOG_INFO, CSP_LOG_TYPE_SOUND,
795- "Set Audio Device to %s", device_name.toLocal8Bit().constData());
796-#else
797- #if QT_VERSION >= QT_VERSION_CHECK(6, 2, 0)
798- QString _older;
799- _older = m_audioOutputDevice.description();
800- if(device_name == QString::fromUtf8("Default")) {
801- m_audioOutputDevice = QMediaDevices::defaultAudioOutput();
802- } else {
803- QList<QAudioDevice> devlist = QMediaDevices::audioOutputs();
804- for(auto p = devlist.begin(); p != devlist.end() ; ++p) {
805- if((*p).description() == device_name) {
806- m_audioOutputDevice = QAudioDevice((const QAudioDevice)(*p));
807- break;
808- }
809- }
810- }
811- QString _newer;
812- _newer = m_audioOutputDevice.description();
813- #elif QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
814- QString _older;
815- _older = m_audioOutputDevice.deviceName();
816- if(device_name == QString::fromUtf8("Default")) {
817- m_audioOutputDevice = QAudioDeviceInfo::defaultOutputDevice();
818- } else {
819- QList<QAudioDeviceInfo> devlist = QAudioDeviceInfo::availableDevices(QAudio::AudioOutput);
820- for(auto p = devlist.begin(); p != devlist.end() ; ++p) {
821- if((*p).deviceName() == device_name) {
822- m_audioOutputDevice = *p;
823- break;
824- }
825- }
826-
827- }
828- QString _newer;
829- _newer = m_audioOutputDevice.deviceName();
830- #endif
831- debug_log(CSP_LOG_INFO, CSP_LOG_TYPE_SOUND,
832- "Set Audio Device to %s", _newer.toLocal8Bit().constData());
833- /*if(_older.compare(_newer) != 0) */{
834- std::lock_guard<std::recursive_timed_mutex> l(vm_mutex);
835- if((p_config != nullptr) && (using_flags != nullptr)) {
836- int freq_val = using_flags->get_sound_sample_rate(p_config->sound_frequency);
837- double latency_val = using_flags->get_sound_latency(p_config->sound_latency);
838- sound_rate = freq_val;
839- sound_samples = (int)((double)sound_rate * latency_val + 0.5);
840- }
841- int dummy_rate;
842- int dummy_samples;
843- //if(sound_initialized) {
844- initialize_sound(sound_rate, sound_samples, &dummy_rate, &dummy_samples);
845- //}
846- if((dummy_rate != sound_rate) || (dummy_samples != sound_samples)) {
847- sound_rate = dummy_rate;
848- sound_samples = dummy_samples;
849- }
850- }
851-#endif
852-}
853-
854-const _TCHAR *OSD_BASE::get_sound_device_name(int num)
855-{
856-#if 1
857- std::shared_ptr<SOUND_OUTPUT_MODULE::M_BASE>out_driver = m_output_driver;
858- if(out_driver.get() != nullptr) {
859- return out_driver->get_sound_device_name(num);
860- }
861- return (const _TCHAR*)nullptr;
862-#else
863- if((num < 0) || (num >= sound_device_list.count())) return (const _TCHAR *)nullptr;
864-
865- QString sdev = sound_device_list.at(num);
866- sdev.truncate(1023);
867- static QByteArray _n;
868- _n.clear();
869- _n = sdev.toUtf8().constData();
870- return (const _TCHAR*)(_n.constData());
871-#endif
872-}
873-
874-void OSD_BASE::get_sound_device_list()
875-{
876- sound_device_list.clear();
877-#if 1
878- std::shared_ptr<SOUND_OUTPUT_MODULE::M_BASE>out_driver = m_output_driver;
879- if(out_driver.get() != nullptr) {
880- std::list<std::string> _l = out_driver->get_sound_devices_list();
881- int i = 0;
882- for(auto s = _l.begin(); s != _l.end(); ++s) {
883- QString ss = QString::fromStdString(*s);
884- sound_device_list.append(ss);
885- debug_log(CSP_LOG_INFO, CSP_LOG_TYPE_SOUND,
886- "Audio Device #%d: %s", i, ss.toLocal8Bit().constData());
887- i++;
888- }
889- }
890-#else
891- #if QT_VERSION >= QT_VERSION_CHECK(6, 2, 0)
892- QList<QAudioDevice> tmplist = QMediaDevices::audioOutputs();
893- int i = 0;
894- for(auto p = tmplist.begin(); p != tmplist.end(); ++p) {
895- QString tmps = (*p).description().toUtf8();
896- sound_device_list.append(tmps);
897- debug_log(CSP_LOG_INFO, CSP_LOG_TYPE_SOUND,
898- "Audio Device #%d: %s", i, tmps.toLocal8Bit().constData());
899- i++;
900- }
901- #elif QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
902- QList<QAudioDeviceInfo> tmplist = QAudioDeviceInfo::availableDevices(QAudio::AudioOutput);
903- int i = 0;
904- for(auto p = tmplist.begin(); p != tmplist.end(); ++p) {
905- QString tmps = (*p).deviceName().toUtf8();
906- sound_device_list.append(tmps);
907- debug_log(CSP_LOG_INFO, CSP_LOG_TYPE_SOUND,
908- "Audio Device #%d: %s", i, tmps.toLocal8Bit().constData());
909- i++;
910- }
911- #endif
912-#endif
913-}
914- #endif
915- #endif /* END Note */
916628 #endif
917629 void OSD_BASE::convert_sound_format(uint8_t* dst1, uint8_t* dst2, int16_t* src1, int16_t* src2, int samples1, int samples2)
918630 {
@@ -1424,250 +1136,6 @@ void OSD_BASE::handleAudioOutputStateChanged(QAudio::State newState)
14241136 break;
14251137 }
14261138 }
1427-#if 0
1428-void OSD_BASE::update_sound(int* extra_frames)
1429-{
1430- if(extra_frames != nullptr) {
1431- *extra_frames = 0;
1432- }
1433- #if 1
1434- std::shared_ptr<SOUND_OUTPUT_MODULE::M_BASE>out_driver = m_output_driver;
1435- #else
1436- #if QT_VERSION >= QT_VERSION_CHECK(6, 2, 0)
1437- std::shared_ptr<QAudioSink>sink_ptr = m_audioOutputSink;
1438- #else
1439- std::shared_ptr<QAudioOutput>sink_ptr = m_audioOutputSink;
1440- #endif
1441- #endif
1442- now_mute = false;
1443- if(sound_ok) {
1444- #if 1
1445- int64_t elapsed_us_now = 0;
1446- int64_t sound_us_now = 0;
1447- int64_t _period_usec = 100 * 1000;
1448- if(out_driver.get() != nullptr) {
1449- elapsed_us_now = out_driver->driver_elapsed_usec();
1450- sound_us_now = out_driver->driver_processed_usec();
1451- _period_usec = out_driver->get_latency_ms() * 1000;
1452- }
1453- #else
1454- //debug_log(CSP_LOG_INFO, CSP_LOG_TYPE_SOUND, "Sink->bytesFree() = %d", m_audioOutputSink->bytesFree());
1455- const int64_t elapsed_us_now = (int64_t)(sink_ptr->elapsedUSecs());
1456- const int64_t sound_us_now = (int64_t)(sink_ptr->processedUSecs());
1457- const int64_t _period_usec = (((int64_t)sound_samples * (int64_t)10000) / (int64_t)sound_rate) * 100;
1458- #endif
1459- int64_t _diff = sound_us_now - (int64_t)sound_us_before_rendered;
1460- if((_diff < 0) && ((INT64_MAX - (int64_t)sound_us_before_rendered + 1) <= _period_usec)) {
1461- // For uS overflow
1462- _diff = sound_us_now + (INT64_MAX - (int64_t)sound_us_before_rendered + 1);
1463- }
1464- int64_t _diff2 = elapsed_us_now - (int64_t)elapsed_us_before_rendered;
1465- if((_diff2 < 0) && ((INT64_MAX - (int64_t)elapsed_us_before_rendered + 1) <= _period_usec)) {
1466- // For uS overflow
1467- _diff2 = elapsed_us_now + (INT64_MAX - (int64_t)elapsed_us_before_rendered + 1);
1468- }
1469-
1470- if((sound_started) && (_diff2 < (_period_usec - 2000))) { // 2mSec
1471- return;
1472- }
1473- #if 1
1474- if(out_driver.get() != nullptr) {
1475- if(out_driver->get_bytes_left() < out_driver->get_chunk_bytes()) {
1476- return;
1477- }
1478- }
1479- #else
1480- qint64 left = 0;
1481- qint64 _size = sound_samples * 2 * sizeof(int16_t) * 4;
1482- if(m_audioOutput != nullptr) {
1483- left = _size - m_audioOutput->bytesAvailable();
1484- }
1485- if(left < (sound_samples * 2 * sizeof(int16_t))) {
1486- return;
1487- }
1488- #endif
1489-
1490- // Input
1491- int16_t* sound_buffer = (int16_t*)create_sound(extra_frames);
1492-
1493- if(sound_buffer != nullptr) {
1494- #if 1
1495- if(out_driver.get() != nullptr) {
1496- if(!(sound_started)) {
1497- out_driver->start();
1498- elapse_us_before_rendered = out_driver->driver_elapsed_usec();
1499- sound_us_before_rendered = out_driver->driver_processed_usec();
1500- } else {
1501- if(_diff2 > (_period_usec * 2)) {
1502- out_driver->discard();
1503- elapse_us_before_rendered = out_driver->driver_elapsed_usec();
1504- sound_us_before_rendered = out_driver->driver_processed_usec();
1505- }
1506- }
1507- }
1508- #else
1509- if(!(sound_started)) {
1510- m_audioOutput->reset();
1511- #if QT_VERSION >= QT_VERSION_CHECK(6, 2, 0)
1512- sink_ptr->start(m_audioOutput);
1513- sound_us_before_rendered = 0;
1514- #elif QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
1515- sound_us_before_rendered = sink_ptr->processedUSecs();
1516- #endif
1517- elapsed_us_before_rendered = sink_ptr->elapsedUSecs();
1518- } else {
1519- if(_diff2 > (_period_usec * 2)) {
1520- #if QT_VERSION >= QT_VERSION_CHECK(6, 2, 0)
1521- sink_ptr->suspend();
1522- sink_ptr->reset();
1523- m_audioOutput->reset();
1524- sink_ptr->start(m_audioOutput);
1525- elapsed_us_before_rendered = 0;
1526- sound_us_before_rendered = 0;
1527- #elif QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
1528- m_audioOutput->reset();
1529- //sink_ptr->resume();
1530- elapsed_us_before_rendered = sink_ptr->elapsedUSecs();
1531- sound_us_before_rendered = sink_ptr->processedUSecs();
1532- #endif
1533- }
1534- }
1535- #endif
1536- sound_started = true;
1537- }
1538- if(now_record_sound || now_record_video) {
1539- if(sound_samples > rec_sound_buffer_ptr) {
1540- int samples = sound_samples - rec_sound_buffer_ptr;
1541- int length = samples * sizeof(int16_t) * 2; // stereo
1542- rec_sound_bytes += length;
1543- if(now_record_video) {
1544- //AGAR_DebugLog(AGAR_LOG_DEBUG, "Push Sound %d bytes\n", length);
1545- emit sig_enqueue_audio((int16_t *)(&(sound_buffer[rec_sound_buffer_ptr * 2])), length);
1546- }
1547- // record sound
1548- if(now_record_sound) {
1549- rec_sound_fio->Fwrite(sound_buffer + rec_sound_buffer_ptr * 2, length, 1);
1550- }
1551- //if(now_record_video) {
1552- // // sync video recording
1553- // static double frames = 0;
1554- // static int prev_samples = -1;
1555- // static double prev_fps = -1;
1556- // double fps = this->vm_frame_rate();
1557- // frames = fps * (double)samples / (double)sound_rate;
1558- //}
1559- //printf("Wrote %d samples ptr=%d\n", samples, rec_sound_buffer_ptr);
1560- rec_sound_buffer_ptr += samples;
1561- if(rec_sound_buffer_ptr >= sound_samples) rec_sound_buffer_ptr = 0;
1562- }
1563- }
1564- //if(sound_initialized) return;
1565- if(sound_buffer != nullptr) {
1566- #if 1
1567- if(out_driver.get() != nullptr) {
1568- out_driver->update_sound((void *)sound_buffer, -1);
1569- elapse_us_before_rendered = out_driver->driver_elapsed_usec();
1570- sound_us_before_rendered = out_driver->driver_processed_usec();
1571- } else {
1572- elapse_us_before_rendered = 0;
1573- sound_us_before_rendered = 0;
1574- }
1575- #else
1576- if((m_audioOutput != nullptr) /*&& (m_audioOutputSink != nullptr)*/) {
1577- // ToDo: Not Int16.
1578- //qint64 sound_len = sound_samples * sound_rate * 2 * wordsize;
1579- qint64 sound_len = sound_samples * 2;
1580- qint64 written = 0;
1581- int _count = sound_samples * 2;
1582-
1583- qint64 _result = m_audioOutput->write((const char *)sound_buffer, _count * sizeof(int16_t));
1584- sound_us_before_rendered = sink_ptr->processedUSecs();
1585- elapsed_us_before_rendered = sink_ptr->elapsedUSecs();
1586- }
1587- }
1588- #endif
1589- }
1590-}
1591-#endif
1592-#if 0
1593-void OSD_BASE::mute_sound()
1594-{
1595-#if 1
1596- if(!(now_mute) && (sound_ok)) {
1597- std::shared_ptr<SOUND_OUTPUT_MODULE::M_BASE>out_driver = m_output_driver;
1598- if(out_driver.get() != nullptr) {
1599- int64_t _samples = out_driver->get_buffer_bytes();
1600- uint8_t* p = new uint8_t[_samples];
1601- out_driver->discard();
1602- if(p != nullptr) {
1603- memset(p, 0x00, _samples);
1604- out_driver->update_sound((void *)p, _samples);
1605- delete[] p;
1606- }
1607- sound_us_before_rendered = out_driver->driver_processed_usec();
1608- elapsed_us_before_rendered = out_driver->driver_elapsed_usec();
1609- }
1610- }
1611-#else
1612- if(!(now_mute) && (sound_ok)) {
1613- #if QT_VERSION >= QT_VERSION_CHECK(6, 2, 0)
1614- std::shared_ptr<QAudioSink>sink_ptr = m_audioOutputSink;
1615- #else
1616- std::shared_ptr<QAudioOutput>sink_ptr = m_audioOutputSink;
1617- #endif
1618- size_t _samples = sound_samples * 2 * 4;
1619- if(m_audioOutput != nullptr) {
1620- int16_t* p = new int16_t[_samples];
1621- m_audioOutput->reset();
1622- if(p != nullptr) {
1623- memset(p, 0x00, sizeof(int16_t) * _samples);
1624- qint64 _result = m_audioOutput->write((const char *)p, _samples * sizeof(int16_t));
1625- delete[] p;
1626- }
1627- }
1628- sound_us_before_rendered = sink_ptr->processedUSecs();
1629- elapsed_us_before_rendered = sink_ptr->elapsedUSecs();
1630- }
1631-#endif
1632- now_mute = true;
1633-}
1634-void OSD_BASE::stop_sound()
1635-{
1636-#if 1
1637- if((sound_ok) && (sound_started)) {
1638- std::shared_ptr<SOUND_OUTPUT_MODULE::M_BASE>out_driver = m_output_driver;
1639- if(out_driver.get() != nullptr) {
1640- out_driver->stop();
1641- }
1642- sound_us_before_rendered = 0;
1643- elapsed_us_before_rendered = 0;
1644- }
1645-#else
1646- if((sound_ok) && (sound_started)) {
1647- #if QT_VERSION >= QT_VERSION_CHECK(6, 2, 0)
1648- std::shared_ptr<QAudioSink>sink_ptr = m_audioOutputSink;
1649- #else
1650- std::shared_ptr<QAudioOutput>sink_ptr = m_audioOutputSink;
1651- #endif
1652-
1653- switch(sink_ptr->state()) {
1654- case QAudio::ActiveState:
1655- case QAudio::IdleState:
1656- case QAudio::SuspendedState:
1657- sink_ptr->stop();
1658- sink_ptr->reset();
1659- sound_us_before_rendered = 0;
1660- break;
1661- default:
1662- break;
1663- }
1664- if(m_audioOutput != nullptr) {
1665- m_audioOutput->reset();
1666- }
1667- }
1668-#endif
1669-}
1670-#endif
16711139 #endif
16721140 void OSD_BASE::start_record_sound()
16731141 {
@@ -1752,15 +1220,11 @@ int OSD_BASE::get_sound_rate()
17521220 #if 0 /* Temporally Disable Caoptuing Sound 20220921 K.O */
17531221 int OSD_BASE::get_sound_rate()
17541222 {
1755-#if 1
17561223 std::shared_ptr<SOUND_OUTPUT_MODULE::M_BASE>out_driver = m_output_driver;
17571224 if(out_driver.get() != nullptr) {
17581225 return out_driver->get_sample_rate();
17591226 }
17601227 return 48000;
1761-#else
1762- return (int)(m_audioOutputFormat.sampleRate());
1763-#endif
17641228 }
17651229 #endif /* Temporally Disable Caoptuing Sound 20220921 K.O */
17661230
--- a/source/src/qt/osd_sound_mod_qtmultimedia.cpp
+++ b/source/src/qt/osd_sound_mod_qtmultimedia.cpp
@@ -1,3 +1,5 @@
1+#include "./config.h"
2+#include "./gui/menu_flags.h"
13 #include "./osd_base.h"
24 #include "./sound_buffer_qt.h"
35 #include "./osd_sound_mod_qtmultimedia.h"
@@ -24,6 +26,8 @@ M_QT_MULTIMEDIA::M_QT_MULTIMEDIA(
2426 extra_config_values,
2527 extra_config_bytes )
2628 {
29+ m_classname = "SOUND_OUTPUT_MODULE::M_QT_MULTIMEDIA";
30+
2731 connect(this, SIGNAL(sig_start_audio()), this, SLOT(do_sound_start()), Qt::QueuedConnection);
2832 connect(this, SIGNAL(sig_stop_audio()), this, SLOT(do_sound_stop()), Qt::QueuedConnection);
2933 connect(this, SIGNAL(sig_pause_audio()), this, SLOT(do_sound_suspend()), Qt::QueuedConnection);
@@ -36,7 +40,14 @@ M_QT_MULTIMEDIA::M_QT_MULTIMEDIA(
3640 connect(parent, SIGNAL(sig_set_sound_device(QString)), this, SLOT(do_set_device_by_name(QString)), Qt::QueuedConnection);
3741
3842 if(initialize_driver()) {
39- m_device_name = set_device_sound(_T("Default"), m_rate, m_channels, m_latency_ms);
43+ QString _drv = QString::fromUtf8("Default");
44+ config_t* _ccp = get_config_ptr();
45+ if(_ccp != nullptr) {
46+ if(strlen(_ccp->sound_device_name) > 0) {
47+ _drv = QString::fromUtf8(_ccp->sound_device_name);
48+ }
49+ }
50+ m_device_name = set_device_sound(_drv.toUtf8().constData(), m_rate, m_channels, m_latency_ms);
4051 m_config_ok = true;
4152 }
4253
@@ -50,19 +61,19 @@ void M_QT_MULTIMEDIA::driver_state_changed(QAudio::State newState)
5061 {
5162 switch(newState) {
5263 case QAudio::ActiveState:
53- debug_log(_T("AUDIO:ACTIVE"));
64+ __debug_log_func(_T("AUDIO:ACTIVE"));
5465 break;
5566 case QAudio::IdleState:
56- debug_log(_T("AUDIO:IDLE"));
67+ __debug_log_func(_T("AUDIO:IDLE"));
5768 //if(m_audioOutputSink != nullptr) {
5869 // m_audioOutputSink->stop();
5970 //}
6071 break;
6172 case QAudio::StoppedState:
62- debug_log(_T("AUDIO:STOP"));
73+ __debug_log_func(_T("AUDIO:STOP"));
6374 break;
6475 case QAudio::SuspendedState:
65- debug_log(_T("AUDIO:SUSPEND"));
76+ __debug_log_func(_T("AUDIO:SUSPEND"));
6677 break;
6778 }
6879 }
@@ -175,7 +186,7 @@ bool M_QT_MULTIMEDIA::initialize_driver()
175186 }
176187 m_fileio.reset(new SOUND_BUFFER_QT(m_samples * (qint64)m_channels * sizeof(int16_t) * 4));
177188 m_driver_fileio = m_fileio;
178- debug_log(_T("M_QT_MULTIMEDIA::%s status=%s"), __func__ , (m_config_ok) ? _T("OK") : _T("NG"));
189+ __debug_log_func(_T("status=%s"), (m_config_ok) ? _T("OK") : _T("NG"));
179190 return result;
180191 }
181192
@@ -215,7 +226,7 @@ const std::string M_QT_MULTIMEDIA::set_device_sound(const _TCHAR* driver_name, i
215226 #endif
216227 }
217228 }
218- debug_log(_T("M_QT_MULTIMEDIA::%s desired_driver=%s using=%s"), __func__ , driver_name, dest_device.description().toLocal8Bit().constData());
229+ __debug_log_func(_T("desired_driver=%s using=%s"), driver_name, dest_device.description().toLocal8Bit().constData());
219230
220231 bool req_reinit = false;
221232 if(dest_device != m_audioOutputDevice) {
@@ -284,7 +295,7 @@ const std::string M_QT_MULTIMEDIA::set_device_sound(const _TCHAR* driver_name, i
284295 m_latency_ms = latency_ms;
285296 }
286297 }
287- if((req_restart) && (m_audioOutputSink.get() != nullptr)) {
298+ if(/*(req_restart) && */(m_audioOutputSink.get() != nullptr)) {
288299 update_driver_fileio();
289300 emit sig_start_audio();
290301 }
@@ -307,7 +318,7 @@ bool M_QT_MULTIMEDIA::real_reconfig_sound(int& rate,int& channels,int& latency_m
307318 if((rate != m_rate) || (_samples != m_samples)) {
308319 m_device_name = set_device_sound((const _TCHAR *)(m_device_name.c_str()), rate, channels, latency_ms);
309320 }
310- if(m_config_ok.load()) {
321+// if(m_config_ok.load()) {
311322 std::shared_ptr<SOUND_BUFFER_QT> sp = m_fileio;
312323 if(sp.get() != nullptr) {
313324 if(!(sp->isOpen())) {
@@ -317,10 +328,10 @@ bool M_QT_MULTIMEDIA::real_reconfig_sound(int& rate,int& channels,int& latency_m
317328 sp->open(QIODevice::ReadWrite | QIODevice::Truncate | QIODevice::Unbuffered);
318329 #endif
319330 }
320- m_config_ok = m_prev_started = m_mute = false;
331+ m_prev_started = m_mute = false;
321332 sp->reset();
322333 }
323- }
334+// }
324335
325336 if((rate <= 0) || (latency_ms <= 0)) {
326337 rate = 48000;
@@ -365,11 +376,12 @@ void M_QT_MULTIMEDIA::do_sound_start()
365376 #elif QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
366377 std::shared_ptr<QAudioOutput> p = m_audioOutputSink;
367378 #endif
368-// if(m_driver_fileio.get() != nullptr) {
369-// m_driver_fileio->reset();
370-// }
379+ if(m_driver_fileio.get() != nullptr) {
380+ m_driver_fileio->reset();
381+ }
371382 if(p.get() != nullptr) {
372383 p->start(m_driver_fileio.get());
384+ __debug_log_func("GO. fileio=%0llx", m_driver_fileio.get());
373385 }
374386 m_prev_started = true;
375387 }
--- a/source/src/qt/osd_sound_mod_template.cpp
+++ b/source/src/qt/osd_sound_mod_template.cpp
@@ -5,7 +5,6 @@
55 #include "./osd_base.h"
66 #include "./sound_buffer_qt.h"
77 #include "./osd_sound_mod_template.h"
8-
98 #include "./gui/menu_flags.h"
109
1110 namespace SOUND_OUTPUT_MODULE {
@@ -29,6 +28,7 @@ M_BASE::M_BASE(OSD_BASE *parent,
2928 m_before_rendered(0),
3029 m_samples(0),
3130 m_mute(false),
31+ m_classname("SOUND_OUTPUT_MODULE::M_BASE"),
3232 QObject(qobject_cast<QObject*>(parent))
3333 {
3434
@@ -50,7 +50,7 @@ M_BASE::M_BASE(OSD_BASE *parent,
5050
5151 m_loglevel = CSP_LOG_INFO;
5252 m_logdomain = CSP_LOG_TYPE_SOUND;
53- debug_log(_T("%s: Initializing"));
53+ __debug_log_func(_T("Initializing"));
5454
5555 initialize_driver();
5656 }
@@ -65,7 +65,41 @@ M_BASE::~M_BASE()
6565 m_config_ok = false;
6666 }
6767
68+bool M_BASE::debug_log_func(const _TCHAR *_funcname, const _TCHAR *_fmt, ...)
69+{
70+ _TCHAR buf[768] = {0};
71+ va_list ap;
72+ va_start(ap, _fmt);
73+ int result = vsnprintf(buf, (sizeof(buf) / sizeof(_TCHAR)), _fmt, ap);
74+ va_end(ap);
75+
76+ QString _tmps;
77+ bool _stat = (_funcname != nullptr);
78+ if(_stat) {
79+ _stat = strlen(_funcname);
80+ }
81+ __LIKELY_IF(_stat) {
82+ _tmps = QString::fromUtf8("::") + QString::fromUtf8(_funcname) + QString::fromUtf8("(): ");
83+ _tmps = QString::fromStdString(m_classname) + _tmps + QString::fromUtf8(buf, sizeof(buf));
84+ } else {
85+ _tmps = QString::fromUtf8(buf, sizeof(buf));
86+ }
87+ return do_send_log(m_loglevel.load(), m_logdomain.load(), _tmps);
88+}
89+
90+bool M_BASE::debug_log(const _TCHAR *_fmt, ...)
91+{
92+ _TCHAR buf[768] = {0};
93+ va_list ap;
94+ va_start(ap, _fmt);
95+ int result = vsnprintf(buf, (sizeof(buf) / sizeof(_TCHAR)), _fmt, ap);
96+ va_end(ap);
6897
98+ QString _tmps;
99+ _tmps = QString::fromUtf8(buf, sizeof(buf));
100+ return do_send_log(m_loglevel.load(), m_logdomain.load(), _tmps);
101+}
102+
69103 void M_BASE::request_to_release()
70104 {
71105 if(m_config_ok.load()) {
@@ -232,17 +266,14 @@ void M_BASE::initialize_sound(int rate, int samples, int* presented_rate, int* p
232266 int channels = m_channels;
233267 if(real_reconfig_sound(rate, channels, _latency_ms)) {
234268 m_config_ok = true;
235- if(m_using_flags.get() != nullptr) {
236- config_t* p_config = m_using_flags->get_config_ptr();
237- if(p_config != nullptr) {
238- set_volume((int)(p_config->general_sound_level));
239- }
269+ config_t* p_config = get_config_ptr();
270+ if(p_config != nullptr) {
271+ set_volume((int)(p_config->general_sound_level));
240272 }
241-
242- debug_log("initialize_sound() : Success. Sample rate=%d samples=%d", m_rate, m_samples);
273+ __debug_log_func("Success. Sample rate=%d samples=%d", m_rate, m_samples);
243274 } else {
244275 m_config_ok = false;
245- debug_log("initialize_sound() : Failed.");
276+ __debug_log_func("Failed.");
246277 }
247278 if(presented_rate != nullptr) {
248279 *presented_rate = m_rate;
@@ -282,6 +313,16 @@ bool M_BASE::check_elapsed_to_render()
282313 return true;
283314 }
284315
316+config_t* M_BASE::get_config_ptr()
317+{
318+ config_t* _np = nullptr;
319+ std::shared_ptr<USING_FLAGS> _cp = m_using_flags;
320+ if(_cp.get() != nullptr) {
321+ _np = _cp->get_config_ptr();
322+ }
323+ return _np;
324+}
325+
285326 void M_BASE::update_render_point_usec()
286327 {
287328 std::lock_guard<std::recursive_timed_mutex> locker(m_locker);
@@ -297,7 +338,7 @@ bool M_BASE::check_enough_to_render()
297338 int64_t M_BASE::update_sound(void* datasrc, int samples)
298339 {
299340 std::shared_ptr<SOUND_BUFFER_QT>q = m_fileio;
300-
341+ __debug_log_func(_T("SRC=%0llx samples=%d fileio=%0llx"), (uintptr_t)datasrc, samples, (uintptr_t)(q.get()));
301342 if(q.get() == nullptr) return -1;
302343
303344 if(samples > 0) {
@@ -436,8 +477,8 @@ void M_BASE::set_logger(const std::shared_ptr<CSP_Logger> logger)
436477 m_logger = logger;
437478 if(m_logger.get() != nullptr) {
438479 connect(this, SIGNAL(sig_send_log(int, int, QString)),
439- m_logger.get(), SLOT(do_send_log(int, int, QString)),
440- Qt::QueuedConnection);
480+ m_logger.get(), SLOT(do_debug_log(int, int, QString))
481+ ,Qt::QueuedConnection);
441482 }
442483 }
443484
--- a/source/src/qt/osd_sound_mod_template.h
+++ b/source/src/qt/osd_sound_mod_template.h
@@ -12,8 +12,10 @@
1212 #include <QObject>
1313 #include <mutex>
1414 #include <memory>
15+#include <string>
1516
1617 #include "../common.h"
18+#include "./config.h"
1719
1820 QT_BEGIN_NAMESPACE
1921
@@ -22,12 +24,16 @@ class OSD_BASE;
2224 class USING_FLAGS;
2325 class CSP_Logger;
2426
27+#define __debug_log_func(...) debug_log_func(__func__, __VA_ARGS__)
28+
2529 namespace SOUND_OUTPUT_MODULE {
2630 class DLL_PREFIX M_BASE : public QObject
2731 {
2832 Q_OBJECT
2933 protected:
3034 OSD_BASE* m_OSD;
35+ std::string m_classname;
36+
3137 std::shared_ptr<SOUND_BUFFER_QT> m_fileio;
3238 std::shared_ptr<SOUND_BUFFER_QT> m_driver_fileio;
3339 std::shared_ptr<USING_FLAGS> m_using_flags;
@@ -63,20 +69,11 @@ protected:
6369 // Maybe disconnect some signals via m_fileio.
6470 virtual bool release_driver_fileio();
6571 virtual bool real_reconfig_sound(int& rate,int& channels,int& latency_ms);
66-
67- bool debug_log(const _TCHAR *_fmt, ...)
68- {
69- _TCHAR buf[1024] = {0};
70-
71- va_list ap;
72- va_start(ap, _fmt);
73- int result = vsnprintf(buf, (sizeof(buf) / sizeof(_TCHAR)), _fmt, ap);
74- va_end(ap);
7572
76- return do_send_log(m_loglevel.load(), m_logdomain.load(),
77- QString::fromUtf8(buf, sizeof(buf)));
78- }
73+ config_t* get_config_ptr();
7974
75+ bool debug_log_func(const _TCHAR *_funcname, const _TCHAR *_fmt, ...);
76+ bool debug_log(const _TCHAR *_fmt, ...);
8077
8178 public:
8279 M_BASE(OSD_BASE *parent,
@@ -105,8 +102,8 @@ public:
105102 // connect(this, SIGNAL(sig_req_open_sound(int, int, QString)), ..., QObject::QueuedConnection);
106103
107104 // For Logging
108- // connect(real_driver, SIGNAL(sig_log(QString)), this, SLOT(do_send_log(QString)), QObject::QueuedConnection);
109- // connect(real_driver, SIGNAL(sig_log(int, int, QString)), this, SLOT(do_send_log(int, int, QString)), QObject::QueuedConnection);
105+ // connect(real_driver, SIGNAL(sig_log(QString)), this, SLOT(do_debug_log(QString)), QObject::QueuedConnection);
106+ // connect(real_driver, SIGNAL(sig_log(int, int, QString)), this, SLOT(do_debug_log(int, int, QString)), QObject::QueuedConnection);
110107 return true;
111108 }
112109 virtual bool release_driver()
Show on old repository browser