Common Source Code Project for Qt (a.k.a for FM-7).
修订版 | e8cf4ede2bece3bb64726ff93934fffd9e1f445f (tree) |
---|---|
时间 | 2022-09-21 23:33:19 |
作者 | K.Ohta <whatisthis.sowhat@gmai...> |
Commiter | K.Ohta |
[OSD][SOUND][WIP] New Driver:QT_MULTIMEDIA: Still don't available to sound.
@@ -63,7 +63,7 @@ EmuThreadClass::EmuThreadClass(Ui_MainWindowBase *rootWindow, std::shared_ptr<US | ||
63 | 63 | connect(this, SIGNAL(sig_set_b77_num(int, int)), MainWindow, SLOT(set_b77_slot(int, int))); |
64 | 64 | |
65 | 65 | p_osd->setParent(this); |
66 | - p_osd->moveToThread(this); | |
66 | + //p_osd->moveToThread(this); | |
67 | 67 | } |
68 | 68 | |
69 | 69 | EmuThreadClass::~EmuThreadClass() |
@@ -96,9 +96,10 @@ OSD_BASE::OSD_BASE(std::shared_ptr<USING_FLAGS> p, std::shared_ptr<CSP_Logger> l | ||
96 | 96 | 2, |
97 | 97 | nullptr, |
98 | 98 | 0)); |
99 | - | |
100 | - #endif /* END Note: */ | |
101 | 99 | get_sound_device_list(); |
100 | + #else | |
101 | + m_sound_driver.reset(); | |
102 | + #endif /* END Note: */ | |
102 | 103 | } |
103 | 104 | |
104 | 105 | OSD_BASE::~OSD_BASE() |
@@ -249,7 +249,7 @@ void OSD_BASE::initialize_sound(int rate, int samples, int* presented_rate, int* | ||
249 | 249 | } |
250 | 250 | |
251 | 251 | sound_capture_device_list.clear(); |
252 | -#if 0 | |
252 | + #if 0 | |
253 | 253 | for(int ch = 0 ; ch < MAX_CAPTURE_SOUND; ch++) { |
254 | 254 | // ToDo: Allocation. |
255 | 255 | // ToDo: Close physical device. |
@@ -292,7 +292,7 @@ void OSD_BASE::initialize_sound(int rate, int samples, int* presented_rate, int* | ||
292 | 292 | sound_capture_dev_desc[num].userdata.read_buffer_ptr = NULL; |
293 | 293 | capturing_sound[num] = false; |
294 | 294 | } |
295 | -#endif | |
295 | + #endif | |
296 | 296 | |
297 | 297 | sound_rate = rate; |
298 | 298 | sound_samples = samples; |
@@ -327,7 +327,7 @@ void OSD_BASE::initialize_sound(int rate, int samples, int* presented_rate, int* | ||
327 | 327 | snd_spec_req.samples = samples; |
328 | 328 | snd_spec_req.callback = &(this->audio_callback); |
329 | 329 | snd_spec_req.userdata = (void *)&snddata; |
330 | -#if defined(USE_SDL2) | |
330 | + #if defined(USE_SDL2) | |
331 | 331 | audio_dev_id = 0; |
332 | 332 | if(!(sound_device_list.isEmpty())) { |
333 | 333 | QString sdev; |
@@ -351,12 +351,12 @@ void OSD_BASE::initialize_sound(int rate, int samples, int* presented_rate, int* | ||
351 | 351 | p_config->sound_device_num, (audio_dev_id <= 0) ? "FAIL" : "SUCCESS", audio_dev_id); |
352 | 352 | |
353 | 353 | } |
354 | -#else | |
354 | + #else | |
355 | 355 | audio_dev_id = 1; |
356 | 356 | SDL_OpenAudio(&snd_spec_req, &snd_spec_presented); |
357 | -#endif | |
357 | + #endif | |
358 | 358 | |
359 | -#if defined(USE_SDL2) | |
359 | + #if defined(USE_SDL2) | |
360 | 360 | if(audio_dev_id <= 0) { |
361 | 361 | debug_log(CSP_LOG_INFO, CSP_LOG_TYPE_SOUND,"Failed to initialize sound\n"); |
362 | 362 | if(presented_rate != NULL) { |
@@ -369,7 +369,7 @@ void OSD_BASE::initialize_sound(int rate, int samples, int* presented_rate, int* | ||
369 | 369 | sound_ok = sound_first_half = false; |
370 | 370 | return; |
371 | 371 | } |
372 | -#endif | |
372 | + #endif | |
373 | 373 | snddata.sound_format = snd_spec_presented.format; |
374 | 374 | if((snd_spec_presented.freq != sound_rate) || |
375 | 375 | (snd_spec_presented.samples != sound_samples)) { // DEINI |
@@ -404,11 +404,11 @@ void OSD_BASE::initialize_sound(int rate, int samples, int* presented_rate, int* | ||
404 | 404 | sound_buffer_size = sound_samples * snd_spec_presented.channels * 2; |
405 | 405 | sound_buf_ptr = (uint8_t *)malloc(sound_buffer_size * format_len); |
406 | 406 | if(sound_buf_ptr == NULL) { |
407 | -#if defined(USE_SDL2) | |
407 | + #if defined(USE_SDL2) | |
408 | 408 | SDL_CloseAudioDevice(audio_dev_id); |
409 | -#else | |
409 | + #else | |
410 | 410 | SDL_CloseAudio(); |
411 | -#endif | |
411 | + #endif | |
412 | 412 | return; |
413 | 413 | } |
414 | 414 |
@@ -424,7 +424,7 @@ void OSD_BASE::release_sound() | ||
424 | 424 | // release SDL sound |
425 | 425 | sound_exit = true; |
426 | 426 | sound_initialized = false; |
427 | -#if 0 | |
427 | + #if 0 | |
428 | 428 | for(int num = 0; num < MAX_SOUND_CAPTURE_DEVICES; num++) { |
429 | 429 | if(capturing_sound[num]) { |
430 | 430 | close_sound_capture_device(num, true); |
@@ -436,13 +436,13 @@ void OSD_BASE::release_sound() | ||
436 | 436 | close_capture_sound_emu(ch); |
437 | 437 | } |
438 | 438 | } |
439 | -#endif | |
440 | -#if defined(USE_SDL2) | |
439 | + #endif | |
440 | + #if defined(USE_SDL2) | |
441 | 441 | //SDL_PauseAudioDevice(audio_dev_id, 1); |
442 | 442 | SDL_CloseAudioDevice(audio_dev_id); |
443 | -#else | |
443 | + #else | |
444 | 444 | SDL_CloseAudio(); |
445 | -#endif | |
445 | + #endif | |
446 | 446 | stop_record_sound(); |
447 | 447 | if(sound_buf_ptr != NULL) free(sound_buf_ptr); |
448 | 448 | sound_buf_ptr = NULL; |
@@ -451,7 +451,7 @@ void OSD_BASE::release_sound() | ||
451 | 451 | #else |
452 | 452 | #if 1 /* Note: Below are new sound driver. */ |
453 | 453 | #include "./osd_sound_mod_template.h" |
454 | -//#include "./osd_sound_mod_qtmultimedia.h" | |
454 | + #include "./osd_sound_mod_qtmultimedia.h" | |
455 | 455 | void OSD_BASE::update_sound(int* extra_frames) |
456 | 456 | { |
457 | 457 | *extra_frames = 0; |
@@ -521,15 +521,33 @@ void OSD_BASE::update_sound(int* extra_frames) | ||
521 | 521 | } |
522 | 522 | // ToDo: Convert sound format. |
523 | 523 | 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); | |
524 | 526 | sound_drv->update_render_point_usec(); |
525 | 527 | } |
526 | 528 | } |
527 | 529 | |
528 | 530 | void OSD_BASE::initialize_sound(int rate, int samples, int* presented_rate, int* presented_samples) |
529 | 531 | { |
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 | + } | |
530 | 544 | 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())); | |
531 | 548 | if(sound_drv.get() != nullptr) { |
532 | 549 | sound_drv->initialize_sound(rate, samples, presented_rate, presented_samples); |
550 | + sound_ok = true; | |
533 | 551 | } |
534 | 552 | } |
535 | 553 | void OSD_BASE::release_sound() |
@@ -605,314 +623,8 @@ int OSD_BASE::get_sound_rate() | ||
605 | 623 | } |
606 | 624 | return 0; |
607 | 625 | } |
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: */ | |
756 | 627 | |
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 */ | |
916 | 628 | #endif |
917 | 629 | void OSD_BASE::convert_sound_format(uint8_t* dst1, uint8_t* dst2, int16_t* src1, int16_t* src2, int samples1, int samples2) |
918 | 630 | { |
@@ -1424,250 +1136,6 @@ void OSD_BASE::handleAudioOutputStateChanged(QAudio::State newState) | ||
1424 | 1136 | break; |
1425 | 1137 | } |
1426 | 1138 | } |
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 | |
1671 | 1139 | #endif |
1672 | 1140 | void OSD_BASE::start_record_sound() |
1673 | 1141 | { |
@@ -1752,15 +1220,11 @@ int OSD_BASE::get_sound_rate() | ||
1752 | 1220 | #if 0 /* Temporally Disable Caoptuing Sound 20220921 K.O */ |
1753 | 1221 | int OSD_BASE::get_sound_rate() |
1754 | 1222 | { |
1755 | -#if 1 | |
1756 | 1223 | std::shared_ptr<SOUND_OUTPUT_MODULE::M_BASE>out_driver = m_output_driver; |
1757 | 1224 | if(out_driver.get() != nullptr) { |
1758 | 1225 | return out_driver->get_sample_rate(); |
1759 | 1226 | } |
1760 | 1227 | return 48000; |
1761 | -#else | |
1762 | - return (int)(m_audioOutputFormat.sampleRate()); | |
1763 | -#endif | |
1764 | 1228 | } |
1765 | 1229 | #endif /* Temporally Disable Caoptuing Sound 20220921 K.O */ |
1766 | 1230 |
@@ -1,3 +1,5 @@ | ||
1 | +#include "./config.h" | |
2 | +#include "./gui/menu_flags.h" | |
1 | 3 | #include "./osd_base.h" |
2 | 4 | #include "./sound_buffer_qt.h" |
3 | 5 | #include "./osd_sound_mod_qtmultimedia.h" |
@@ -24,6 +26,8 @@ M_QT_MULTIMEDIA::M_QT_MULTIMEDIA( | ||
24 | 26 | extra_config_values, |
25 | 27 | extra_config_bytes ) |
26 | 28 | { |
29 | + m_classname = "SOUND_OUTPUT_MODULE::M_QT_MULTIMEDIA"; | |
30 | + | |
27 | 31 | connect(this, SIGNAL(sig_start_audio()), this, SLOT(do_sound_start()), Qt::QueuedConnection); |
28 | 32 | connect(this, SIGNAL(sig_stop_audio()), this, SLOT(do_sound_stop()), Qt::QueuedConnection); |
29 | 33 | connect(this, SIGNAL(sig_pause_audio()), this, SLOT(do_sound_suspend()), Qt::QueuedConnection); |
@@ -36,7 +40,14 @@ M_QT_MULTIMEDIA::M_QT_MULTIMEDIA( | ||
36 | 40 | connect(parent, SIGNAL(sig_set_sound_device(QString)), this, SLOT(do_set_device_by_name(QString)), Qt::QueuedConnection); |
37 | 41 | |
38 | 42 | 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); | |
40 | 51 | m_config_ok = true; |
41 | 52 | } |
42 | 53 |
@@ -50,19 +61,19 @@ void M_QT_MULTIMEDIA::driver_state_changed(QAudio::State newState) | ||
50 | 61 | { |
51 | 62 | switch(newState) { |
52 | 63 | case QAudio::ActiveState: |
53 | - debug_log(_T("AUDIO:ACTIVE")); | |
64 | + __debug_log_func(_T("AUDIO:ACTIVE")); | |
54 | 65 | break; |
55 | 66 | case QAudio::IdleState: |
56 | - debug_log(_T("AUDIO:IDLE")); | |
67 | + __debug_log_func(_T("AUDIO:IDLE")); | |
57 | 68 | //if(m_audioOutputSink != nullptr) { |
58 | 69 | // m_audioOutputSink->stop(); |
59 | 70 | //} |
60 | 71 | break; |
61 | 72 | case QAudio::StoppedState: |
62 | - debug_log(_T("AUDIO:STOP")); | |
73 | + __debug_log_func(_T("AUDIO:STOP")); | |
63 | 74 | break; |
64 | 75 | case QAudio::SuspendedState: |
65 | - debug_log(_T("AUDIO:SUSPEND")); | |
76 | + __debug_log_func(_T("AUDIO:SUSPEND")); | |
66 | 77 | break; |
67 | 78 | } |
68 | 79 | } |
@@ -175,7 +186,7 @@ bool M_QT_MULTIMEDIA::initialize_driver() | ||
175 | 186 | } |
176 | 187 | m_fileio.reset(new SOUND_BUFFER_QT(m_samples * (qint64)m_channels * sizeof(int16_t) * 4)); |
177 | 188 | 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")); | |
179 | 190 | return result; |
180 | 191 | } |
181 | 192 |
@@ -215,7 +226,7 @@ const std::string M_QT_MULTIMEDIA::set_device_sound(const _TCHAR* driver_name, i | ||
215 | 226 | #endif |
216 | 227 | } |
217 | 228 | } |
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()); | |
219 | 230 | |
220 | 231 | bool req_reinit = false; |
221 | 232 | if(dest_device != m_audioOutputDevice) { |
@@ -284,7 +295,7 @@ const std::string M_QT_MULTIMEDIA::set_device_sound(const _TCHAR* driver_name, i | ||
284 | 295 | m_latency_ms = latency_ms; |
285 | 296 | } |
286 | 297 | } |
287 | - if((req_restart) && (m_audioOutputSink.get() != nullptr)) { | |
298 | + if(/*(req_restart) && */(m_audioOutputSink.get() != nullptr)) { | |
288 | 299 | update_driver_fileio(); |
289 | 300 | emit sig_start_audio(); |
290 | 301 | } |
@@ -307,7 +318,7 @@ bool M_QT_MULTIMEDIA::real_reconfig_sound(int& rate,int& channels,int& latency_m | ||
307 | 318 | if((rate != m_rate) || (_samples != m_samples)) { |
308 | 319 | m_device_name = set_device_sound((const _TCHAR *)(m_device_name.c_str()), rate, channels, latency_ms); |
309 | 320 | } |
310 | - if(m_config_ok.load()) { | |
321 | +// if(m_config_ok.load()) { | |
311 | 322 | std::shared_ptr<SOUND_BUFFER_QT> sp = m_fileio; |
312 | 323 | if(sp.get() != nullptr) { |
313 | 324 | if(!(sp->isOpen())) { |
@@ -317,10 +328,10 @@ bool M_QT_MULTIMEDIA::real_reconfig_sound(int& rate,int& channels,int& latency_m | ||
317 | 328 | sp->open(QIODevice::ReadWrite | QIODevice::Truncate | QIODevice::Unbuffered); |
318 | 329 | #endif |
319 | 330 | } |
320 | - m_config_ok = m_prev_started = m_mute = false; | |
331 | + m_prev_started = m_mute = false; | |
321 | 332 | sp->reset(); |
322 | 333 | } |
323 | - } | |
334 | +// } | |
324 | 335 | |
325 | 336 | if((rate <= 0) || (latency_ms <= 0)) { |
326 | 337 | rate = 48000; |
@@ -365,11 +376,12 @@ void M_QT_MULTIMEDIA::do_sound_start() | ||
365 | 376 | #elif QT_VERSION < QT_VERSION_CHECK(6, 0, 0) |
366 | 377 | std::shared_ptr<QAudioOutput> p = m_audioOutputSink; |
367 | 378 | #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 | + } | |
371 | 382 | if(p.get() != nullptr) { |
372 | 383 | p->start(m_driver_fileio.get()); |
384 | + __debug_log_func("GO. fileio=%0llx", m_driver_fileio.get()); | |
373 | 385 | } |
374 | 386 | m_prev_started = true; |
375 | 387 | } |
@@ -5,7 +5,6 @@ | ||
5 | 5 | #include "./osd_base.h" |
6 | 6 | #include "./sound_buffer_qt.h" |
7 | 7 | #include "./osd_sound_mod_template.h" |
8 | - | |
9 | 8 | #include "./gui/menu_flags.h" |
10 | 9 | |
11 | 10 | namespace SOUND_OUTPUT_MODULE { |
@@ -29,6 +28,7 @@ M_BASE::M_BASE(OSD_BASE *parent, | ||
29 | 28 | m_before_rendered(0), |
30 | 29 | m_samples(0), |
31 | 30 | m_mute(false), |
31 | + m_classname("SOUND_OUTPUT_MODULE::M_BASE"), | |
32 | 32 | QObject(qobject_cast<QObject*>(parent)) |
33 | 33 | { |
34 | 34 |
@@ -50,7 +50,7 @@ M_BASE::M_BASE(OSD_BASE *parent, | ||
50 | 50 | |
51 | 51 | m_loglevel = CSP_LOG_INFO; |
52 | 52 | m_logdomain = CSP_LOG_TYPE_SOUND; |
53 | - debug_log(_T("%s: Initializing")); | |
53 | + __debug_log_func(_T("Initializing")); | |
54 | 54 | |
55 | 55 | initialize_driver(); |
56 | 56 | } |
@@ -65,7 +65,41 @@ M_BASE::~M_BASE() | ||
65 | 65 | m_config_ok = false; |
66 | 66 | } |
67 | 67 | |
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); | |
68 | 97 | |
98 | + QString _tmps; | |
99 | + _tmps = QString::fromUtf8(buf, sizeof(buf)); | |
100 | + return do_send_log(m_loglevel.load(), m_logdomain.load(), _tmps); | |
101 | +} | |
102 | + | |
69 | 103 | void M_BASE::request_to_release() |
70 | 104 | { |
71 | 105 | if(m_config_ok.load()) { |
@@ -232,17 +266,14 @@ void M_BASE::initialize_sound(int rate, int samples, int* presented_rate, int* p | ||
232 | 266 | int channels = m_channels; |
233 | 267 | if(real_reconfig_sound(rate, channels, _latency_ms)) { |
234 | 268 | 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)); | |
240 | 272 | } |
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); | |
243 | 274 | } else { |
244 | 275 | m_config_ok = false; |
245 | - debug_log("initialize_sound() : Failed."); | |
276 | + __debug_log_func("Failed."); | |
246 | 277 | } |
247 | 278 | if(presented_rate != nullptr) { |
248 | 279 | *presented_rate = m_rate; |
@@ -282,6 +313,16 @@ bool M_BASE::check_elapsed_to_render() | ||
282 | 313 | return true; |
283 | 314 | } |
284 | 315 | |
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 | + | |
285 | 326 | void M_BASE::update_render_point_usec() |
286 | 327 | { |
287 | 328 | std::lock_guard<std::recursive_timed_mutex> locker(m_locker); |
@@ -297,7 +338,7 @@ bool M_BASE::check_enough_to_render() | ||
297 | 338 | int64_t M_BASE::update_sound(void* datasrc, int samples) |
298 | 339 | { |
299 | 340 | 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())); | |
301 | 342 | if(q.get() == nullptr) return -1; |
302 | 343 | |
303 | 344 | if(samples > 0) { |
@@ -436,8 +477,8 @@ void M_BASE::set_logger(const std::shared_ptr<CSP_Logger> logger) | ||
436 | 477 | m_logger = logger; |
437 | 478 | if(m_logger.get() != nullptr) { |
438 | 479 | 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); | |
441 | 482 | } |
442 | 483 | } |
443 | 484 |
@@ -12,8 +12,10 @@ | ||
12 | 12 | #include <QObject> |
13 | 13 | #include <mutex> |
14 | 14 | #include <memory> |
15 | +#include <string> | |
15 | 16 | |
16 | 17 | #include "../common.h" |
18 | +#include "./config.h" | |
17 | 19 | |
18 | 20 | QT_BEGIN_NAMESPACE |
19 | 21 |
@@ -22,12 +24,16 @@ class OSD_BASE; | ||
22 | 24 | class USING_FLAGS; |
23 | 25 | class CSP_Logger; |
24 | 26 | |
27 | +#define __debug_log_func(...) debug_log_func(__func__, __VA_ARGS__) | |
28 | + | |
25 | 29 | namespace SOUND_OUTPUT_MODULE { |
26 | 30 | class DLL_PREFIX M_BASE : public QObject |
27 | 31 | { |
28 | 32 | Q_OBJECT |
29 | 33 | protected: |
30 | 34 | OSD_BASE* m_OSD; |
35 | + std::string m_classname; | |
36 | + | |
31 | 37 | std::shared_ptr<SOUND_BUFFER_QT> m_fileio; |
32 | 38 | std::shared_ptr<SOUND_BUFFER_QT> m_driver_fileio; |
33 | 39 | std::shared_ptr<USING_FLAGS> m_using_flags; |
@@ -63,20 +69,11 @@ protected: | ||
63 | 69 | // Maybe disconnect some signals via m_fileio. |
64 | 70 | virtual bool release_driver_fileio(); |
65 | 71 | 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); | |
75 | 72 | |
76 | - return do_send_log(m_loglevel.load(), m_logdomain.load(), | |
77 | - QString::fromUtf8(buf, sizeof(buf))); | |
78 | - } | |
73 | + config_t* get_config_ptr(); | |
79 | 74 | |
75 | + bool debug_log_func(const _TCHAR *_funcname, const _TCHAR *_fmt, ...); | |
76 | + bool debug_log(const _TCHAR *_fmt, ...); | |
80 | 77 | |
81 | 78 | public: |
82 | 79 | M_BASE(OSD_BASE *parent, |
@@ -105,8 +102,8 @@ public: | ||
105 | 102 | // connect(this, SIGNAL(sig_req_open_sound(int, int, QString)), ..., QObject::QueuedConnection); |
106 | 103 | |
107 | 104 | // 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); | |
110 | 107 | return true; |
111 | 108 | } |
112 | 109 | virtual bool release_driver() |