OSDN Git Service

[OSD][Qt][SOUND][CONFIG] Important: Now, sound output device has recorded as NAME...
authorK.Ohta <whatisthis.sowhat@gmail.com>
Tue, 19 Jul 2022 14:24:18 +0000 (23:24 +0900)
committerK.Ohta <whatisthis.sowhat@gmail.com>
Tue, 19 Jul 2022 14:24:18 +0000 (23:24 +0900)
[OSD][Qt][SOUND][QT_MULTIMEDIA] Available to set master volume.Will implement better.

20 files changed:
source/src/config.cpp
source/src/config.h
source/src/qt/CMakeLists.txt
source/src/qt/avio/CMakeLists.txt
source/src/qt/common/menu_flags.cpp
source/src/qt/common/menu_flags_ext.h
source/src/qt/common/qt_utils.cpp
source/src/qt/emuutils/CMakeLists.txt
source/src/qt/gui/CMakeLists.txt
source/src/qt/gui/mainwidget_base.h
source/src/qt/gui/menu_flags.h
source/src/qt/gui/menu_flags_tmpl.cpp
source/src/qt/gui/menu_sound.cpp
source/src/qt/gui/sound_dialog.cpp
source/src/qt/gui/sound_dialog.h
source/src/qt/osd_base.cpp
source/src/qt/osd_base.h
source/src/qt/osd_sound.cpp
source/src/vm/common_vm/CMakeLists.txt
source/src/vm/fmgen/CMakeLists.txt

index 56ac3e6..4adcc79 100644 (file)
@@ -133,7 +133,7 @@ void initialize_config()
        #endif
                config.sound_latency = 1;       // 100msec
                config.sound_strict_rendering = true;
-               config.sound_device_num = 0; // Add 20190221
+               my_stprintf_s(config.sound_device_name, 1024, _T("Default")); // Replace 20220719
        #ifdef USE_FLOPPY_DISK
                config.sound_noise_fdd = true;
        #endif
@@ -422,7 +422,7 @@ void load_config(const _TCHAR *config_path)
        config.sound_frequency = MyGetPrivateProfileInt(_T("Sound"), _T("Frequency"), config.sound_frequency, config_path);
        config.sound_latency = MyGetPrivateProfileInt(_T("Sound"), _T("Latency"), config.sound_latency, config_path);
        config.sound_strict_rendering = MyGetPrivateProfileInt(_T("Sound"), _T("StrictRendering"), config.sound_strict_rendering, config_path);
-       config.sound_device_num = MyGetPrivateProfileInt(_T("Sound"), _T("DeviceNumber"), config.sound_device_num, config_path);
+       MyGetPrivateProfileString(_T("Sound"), _T("DeviceName"), _T("Default"), config.sound_device_name, 1024, config_path);
        #ifdef USE_FLOPPY_DISK
                config.sound_noise_fdd = MyGetPrivateProfileBool(_T("Sound"), _T("NoiseFDD"), config.sound_noise_fdd, config_path);;
        #endif
@@ -833,7 +833,7 @@ void save_config(const _TCHAR *config_path)
                MyWritePrivateProfileInt(_T("Sound"), _T("Frequency"), config.sound_frequency, config_path);
                MyWritePrivateProfileInt(_T("Sound"), _T("Latency"), config.sound_latency, config_path);
                MyWritePrivateProfileBool(_T("Sound"), _T("StrictRendering"), config.sound_strict_rendering, config_path);
-               MyWritePrivateProfileInt(_T("Sound"), _T("DeviceNumber"), config.sound_device_num, config_path);
+               MyWritePrivateProfileString(_T("Sound"), _T("DeviceName"), config.sound_device_name, config_path);
        #ifdef USE_FLOPPY_DISK
                MyWritePrivateProfileBool(_T("Sound"), _T("NoiseFDD"), config.sound_noise_fdd, config_path);
        #endif
index dedaee4..af4deec 100644 (file)
@@ -264,7 +264,7 @@ typedef struct {
        int sound_frequency;
        int sound_latency;
        bool sound_strict_rendering;
-       int sound_device_num;
+       _TCHAR sound_device_name[1024];
        
 #if defined(_USE_QT)   
        int general_sound_level;
index e7d60a4..aec0f35 100644 (file)
@@ -1,5 +1,5 @@
 message("* qt/osd")
-SET(THIS_LIB_VERSION 6.0.0)
+SET(THIS_LIB_VERSION 7.0.0)
 
 set(s_qt_osd_headers
        osd_base.h
index a1672de..4a9c7a6 100644 (file)
@@ -1,6 +1,6 @@
 message("* qt/avio")
 
-SET(THIS_LIB_VERSION 6.0.0)
+SET(THIS_LIB_VERSION 6.1.0)
 set(s_qt_avio_headers
        csp_avio_basic.h
        movie_saver.h
index aa93645..7df73eb 100644 (file)
@@ -524,13 +524,27 @@ _TCHAR *USING_FLAGS_EXT::get_vm_node_name(int id)
 
 const _TCHAR *USING_FLAGS_EXT::get_sound_device_name(int num)
 {
-       if(p_emu == NULL) return NULL;
+       if(p_emu == nullptr) return NULL;
        return (const _TCHAR *)(p_emu->get_osd()->get_sound_device_name(num));
 }
 
-int USING_FLAGS_EXT::get_sound_device_num()
+const _TCHAR *USING_FLAGS_EXT::get_sound_device_name()
 {
-       if(p_emu == NULL) return -1;
-       return p_emu->get_osd()->get_sound_device_num();
+       if(p_emu == nullptr) return NULL;
+       return (const _TCHAR *)(p_emu->get_osd()->get_sound_device_name(-1));
 }
 
+const int USING_FLAGS_EXT::get_sound_sample_rate(int num)
+{
+       const int sound_frequency_table[8] = {
+               2000, 4000, 8000, 11025, 22050, 44100,
+#ifdef OVERRIDE_SOUND_FREQ_48000HZ
+               OVERRIDE_SOUND_FREQ_48000HZ,
+#else
+               48000,
+#endif
+               96000,
+       };
+       if((num < 0) || (num >= 8)) return 44100;
+       return sound_frequency_table[num];
+}
index ed86866..c96624b 100644 (file)
@@ -26,8 +26,8 @@ public:
        void set_vm_node_name(int id, const _TCHAR *name);
        _TCHAR *get_vm_node_name(int id);
        const _TCHAR *get_sound_device_name(int num);
-       int get_sound_device_num();
-       
+       const _TCHAR *get_sound_device_name();
+       const int get_sound_sample_rate(int num);
 };
        
 
index 3b5d0ff..81b2d50 100644 (file)
@@ -1316,23 +1316,21 @@ int MainLoop(int argc, char *argv[])
        }
        csp_logger->set_osd((OSD*)(emu->get_osd()));
        csp_logger->debug_log(CSP_LOG_INFO, CSP_LOG_TYPE_GENERAL, "InitInstance() OK.");
+       
        // ToDo: Update raltime.
-       for(int i = 0; i < 16; i++) {
-               const _TCHAR* sp = emu->get_osd()->get_sound_device_name(i);
-               QString sname;
-               sname.clear();
-               if(sp != NULL) {
-                       sname = QString::fromUtf8(sp);
-               }
-               rMainWindow->do_set_host_sound_name(i, sname);
-       }
+       QObject::connect(rMainWindow, SIGNAL(sig_osd_sound_output_device(QString)), (OSD*)(emu->get_osd()), SLOT(do_set_host_sound_output_device(QString)));
+       rMainWindow->do_update_sound_output_list();
+
+       QObject::connect(rMainWindow, SIGNAL(sig_update_master_volume(int)), (OSD*)(emu->get_osd()), SLOT(do_update_master_volume(int)));
+       
        QObject::connect(GuiMain, SIGNAL(lastWindowClosed()),
                                         rMainWindow, SLOT(on_actionExit_triggered()));
 
        QObject::connect((OSD*)(emu->get_osd()), SIGNAL(sig_clear_keyname_table()),      rMainWindow, SLOT(do_clear_keyname_table()));
        QObject::connect((OSD*)(emu->get_osd()), SIGNAL(sig_add_keyname_table(uint32_t, QString)),       rMainWindow, SLOT(do_add_keyname_table(uint32_t, QString)));
        emu->get_osd()->update_keyname_table();
-       
+
+
        GLDrawClass *pgl = rMainWindow->getGraphicsView();
        pgl->do_set_texture_size(NULL, -1, -1);  // It's very ugly workaround (;_;) 20191028 K.Ohta
 //     pgl->setFixedSize(pgl->width(), pgl->height());
index 881c0da..213fa33 100644 (file)
@@ -1,6 +1,6 @@
 message("* qt/emuutils")
 
-SET(THIS_LIB_VERSION 5.0.0)
+SET(THIS_LIB_VERSION 6.0.0)
 
 set(s_qt_emuutils_headers
        ../gui/csp_logger.h
index b67f640..6831f9e 100644 (file)
@@ -1,6 +1,6 @@
 message("* qt/gui")
 
-set(THIS_LIB_VERSION 5.0.0)
+set(THIS_LIB_VERSION 6.0.0)
 
 set(s_qt_gui_headers
          qt_dialogs.h
index ed58fd1..8349482 100644 (file)
@@ -860,7 +860,7 @@ public slots:
        void do_set_sound_strict_rendering(bool f);
        void do_set_sound_tape_signal(bool f);
        void do_set_sound_tape_voice(bool f);
-       void do_set_host_sound_device(void);
+       void do_set_host_sound_output_device(void);
        void do_set_host_sound_name(int num, QString sname);    
        void set_monitor_type(void);
        void message_status_bar(QString);
@@ -920,6 +920,7 @@ public slots:
        void do_set_single_dipswitch(bool f);
        void do_set_single_dipswitch_negative(bool f);
        void do_set_multi_dipswitch();
+       void do_update_sound_output_list();
        
        void do_start_emu_thread();
        void do_start_draw_thread();
@@ -953,9 +954,10 @@ signals:
        int sig_emu_set_display_size(int, int, int, int);
        int sig_emu_update_volume_level(int, int);
        int sig_emu_update_volume_balance(int, int);
-
+       int sig_osd_sound_output_device(QString);
        int sig_resize_osd(int);
        int sig_screen_multiply(double);
+       int sig_update_master_volume(int);
        
        int sig_write_protect_disk(int drv, bool flag);
        int sig_open_disk(int, QString, int);
@@ -995,7 +997,7 @@ signals:
        int sig_set_roma_kana(bool);
        int quit_debugger_thread(void);
        int sig_quit_widgets(void);
-
+       
        int sig_emu_thread_to_fixed_cpu(int);
        int sig_add_keyname_table(uint32_t, QString);
 
index b07a831..4981f03 100644 (file)
@@ -372,8 +372,14 @@ public:
        void set_osd(OSD_BASE *p);
        OSD_BASE *get_osd(void);
        virtual const _TCHAR *get_sound_device_name(int num);
-       virtual int get_sound_device_num();
-       
+       virtual const _TCHAR *get_sound_device_name();
+       virtual const int get_sound_sample_rate(int num);
+       virtual const double get_sound_latency(int num)
+       {
+               const double sound_latency_table[5] = {0.05, 0.1, 0.2, 0.3, 0.4};
+               if((num < 0) || (num >= 5)) num = 1;
+               return sound_latency_table[num];
+       }
        virtual int get_vm_node_size();
        virtual void set_vm_node_name(int id, const _TCHAR *name);
        virtual _TCHAR *get_vm_node_name(int id);
index ddd44c6..0bc5299 100644 (file)
@@ -277,11 +277,23 @@ const _TCHAR *USING_FLAGS::get_sound_device_name(int num)
        return NULL;
 }
 
-int USING_FLAGS::get_sound_device_num()
+const _TCHAR *USING_FLAGS::get_sound_device_name()
 {
-       return -1;
+       return NULL;
 }
 
+const int USING_FLAGS::get_sound_sample_rate(int num)
+{
+       const int sound_frequency_table[8] = {
+               2000, 4000, 8000, 11025, 22050, 44100,
+               48000,
+               96000,
+       };
+       if((num < 0) || (num >= 8)) return 44100;
+       return sound_frequency_table[num];
+}
+
+
 bool USING_FLAGS::is_support_phy_key_name()
 {
        return false;
index 944ec0f..6313035 100644 (file)
@@ -10,6 +10,8 @@
 #include <QMenu>
 #include <QActionGroup>
 
+#include <cstdint>
+
 #include "commonclasses.h"
 #include "mainwidget_base.h"
 //#include "menuclasses.h"
 
 // WIP: Will move to another file
 const double s_late_table[5] = {0.05, 0.1, 0.2, 0.3, 0.4};
-extern USING_FLAGS *using_flags;
 
+void Ui_MainWindowBase::do_update_sound_output_list(void)
+{
+       if((p_config == nullptr) || (using_flags == nullptr)) return;
+       int _match = -1;
+       QString matched_devname = QString::fromUtf8("Default");
+       do_set_host_sound_name(0, QString::fromUtf8("Default"));
+       
+       if(action_HostSoundDevice[0] != nullptr) {
+               action_HostSoundDevice[0]->setChecked(true);
+       }
+       QString _setname = QString::fromLocal8Bit(p_config->sound_device_name);
+       _setname.truncate(1023);
+       for(int i = 1; i < 16; i++) {
+               if(action_HostSoundDevice[i] != nullptr) {
+                       action_HostSoundDevice[i]->setChecked(false);
+               }
+               const _TCHAR* sp = using_flags->get_sound_device_name(i - 1);
+               QString sname;
+               sname.clear();
+               if(sp != NULL) {
+                       sname = QString::fromUtf8(sp);
+                       sname.truncate(1023);
+               }
+               
+               if(sname == _setname) {
+                       _match = i;
+                       matched_devname = sname;
+               }
+               do_set_host_sound_name(i, sname);
+       }
+       if(_match > 0) {
+               if(action_HostSoundDevice[_match] != nullptr) {
+                       action_HostSoundDevice[_match]->setChecked(true);
+               }
+       } else {
+               if(action_HostSoundDevice[0] != nullptr) {
+                       action_HostSoundDevice[0]->setChecked(true);
+               }
+       }
+       emit sig_osd_sound_output_device(matched_devname);
+}
 
-void Ui_MainWindowBase::do_set_host_sound_device(void)
+void Ui_MainWindowBase::do_set_host_sound_output_device(void)
 {
        QAction *cp = qobject_cast<QAction*>(QObject::sender());
        if(cp == nullptr) return;
-       int num = cp->data().value<int>();
+       QString _name = cp->data().value<QString>();
        
        if(p_config != NULL) {
-               p_config->sound_device_num = num;
+               QString _old = QString::fromLocal8Bit(p_config->sound_device_name, 1023);
+               _name.truncate(1023);
+               if((_old != _name) && !(_name.isEmpty())) {
+                       my_tcscpy_s(p_config->sound_device_name, 1023, _name.toLocal8Bit().constData());
+                       emit sig_osd_sound_output_device(_name);
+               }
        }
        emit sig_emu_update_config();
 }
@@ -42,11 +89,15 @@ void Ui_MainWindowBase::do_set_host_sound_name(int num, QString s)
        if(s.isEmpty()) {
                if(action_HostSoundDevice[num] != NULL) {
                        action_HostSoundDevice[num]->setVisible(false);
+                       QVariant v = QVariant(QString::fromUtf8(""));
+                       action_HostSoundDevice[num]->setData(v);
                }
        } else {
                if(action_HostSoundDevice[num] != NULL) {
                        action_HostSoundDevice[num]->setVisible(true);
                        action_HostSoundDevice[num]->setText(s);
+                       QVariant v = QVariant(s);
+                       action_HostSoundDevice[num]->setData(v);
                }
        }
 }
@@ -130,7 +181,7 @@ void Ui_MainWindowBase::CreateSoundMenu(void)
                if(action_HostSoundDevice[i] != NULL) {
                        menuSound_HostDevices->addAction(action_HostSoundDevice[i]);
                        connect(action_HostSoundDevice[i], SIGNAL(triggered()),
-                                       this, SLOT(do_set_host_sound_device()));
+                                       this, SLOT(do_set_host_sound_output_device()));
                }
        }
        
@@ -181,14 +232,10 @@ void Ui_MainWindowBase::ConfigSoundMenu(void)
                action_HostSoundDevice[i] = new Action_Control(this, using_flags);
                tmps.setNum(i); 
                tmps = QString::fromUtf8("action_HostSoundDevice") + tmps;
-          
                action_HostSoundDevice[i]->setObjectName(tmps);
                action_HostSoundDevice[i]->setCheckable(true);
-               action_HostSoundDevice[i]->setData(QVariant(i));
-               if(i == p_config->sound_device_num) {
-                       action_HostSoundDevice[i]->setChecked(true);
-                       //freq = using_flags->get_s_freq_table(i);
-               }
+               QVariant v = QVariant(QString::fromUtf8(""));
+               action_HostSoundDevice[i]->setData(v);
                actionGroup_Sound_HostDevices->addAction(action_HostSoundDevice[i]);
        }
        
@@ -239,7 +286,7 @@ void Ui_MainWindowBase::ConfigSoundMenu(void)
 void Ui_MainWindowBase::do_update_volume(int level)
 {
        if(using_flags->is_without_sound()) return;
-       if(level <= -32768) {
+       if(level <= INT16_MIN) {
                action_VolumeDialog->setIcon(VolumeMutedIcon);
        } else if(level < -4096) {
                action_VolumeDialog->setIcon(VolumeLowIcon);
@@ -248,6 +295,7 @@ void Ui_MainWindowBase::do_update_volume(int level)
        } else {
                action_VolumeDialog->setIcon(VolumeHighIcon);
        }
+       emit sig_update_master_volume(level);
 }
        
 void Ui_MainWindowBase::retranslateSoundMenu(void)
index c84dab1..71cf850 100644 (file)
@@ -24,7 +24,7 @@ Ui_SndSliderObject::Ui_SndSliderObject(USING_FLAGS *p, Qt::Orientation orientati
 Ui_SndSliderObject::~Ui_SndSliderObject()
 {
 }
-
+#include "../osd_base.h"
 #include <cstdint>
 
 void Ui_SndSliderObject::setValue(int level)
@@ -38,10 +38,11 @@ void Ui_SndSliderObject::setValue(int level)
                p_config->general_sound_level = level;
                
                tmps = QApplication::translate("Ui_SoundDialog", "Set Volume", 0);
-               n = (float)(((level + 32768) * 1000) / 65535) / 10.0;
+               n = (float)(((level + INT16_MAX) * 1000) / 65535) / 10.0;
                s_val.setNum(n, 'f', 1);
                tmps = tmps + QString::fromUtf8(" (") + s_val + QString::fromUtf8("%)");
                parent_widget->setWindowTitle(tmps);
+               emit sig_update_master_osd_volume(level);
                emit sig_update_master_volume(level);
                emit sig_emu_update_config();
        }
@@ -124,7 +125,9 @@ Ui_SoundDialog::Ui_SoundDialog(USING_FLAGS *p, QWidget *parent) : QWidget(0)
        VBoxMasterVolume->addWidget(sliderMasterVolume);
        boxMasterVolume->setLayout(VBoxMasterVolume);
        connect(sliderMasterVolume, SIGNAL(sig_update_master_volume(int)), parent_widget, SLOT(do_update_volume(int)));
-
+       if(using_flags->get_osd() != nullptr) {
+               connect(sliderMasterVolume, SIGNAL(sig_update_master_osd_volume(int)), using_flags->get_osd(), SLOT(do_update_master_volume(int)));
+       }
        if(using_flags->get_use_sound_volume() > 0) {
                MasterLayout->addWidget(boxMasterVolume, 0, 0, 1, 2);
        } else {
index 9a38beb..833eff7 100644 (file)
@@ -58,6 +58,7 @@ signals:
        int sig_emu_update_volume_label(int, int);
        int sig_emu_update_volume_balance(int, int);
        int sig_update_master_volume(int);
+       int sig_update_master_osd_volume(int);
 };
 
 class DLL_PREFIX Ui_SoundDialog : public QWidget
index b5d8e12..5573d5a 100644 (file)
@@ -66,6 +66,7 @@ OSD_BASE::OSD_BASE(USING_FLAGS *p, CSP_Logger *logger) : QObject(0)
        m_audioInputSource = nullptr;
        m_audioInputBuffer = nullptr;
        m_audioInput = nullptr;
+       sound_initialized = false;
        
 #if QT_VERSION >= 0x051400
        vm_mutex = new QRecursiveMutex();
index 7c9c119..9984c68 100644 (file)
@@ -176,7 +176,6 @@ private:
        QAudioFormat m_audioOutputFormat;
        QAudioDevice m_audioOutputDevice;
 
-       
        QAudioFormat m_audioInputFormat;
        QAudioDevice m_audioInputDevice;
        QAudioSource *m_audioInputSource;
@@ -732,6 +731,10 @@ public slots:
        void set_dbg_completion_list(std::list<std::string> *p);
        void clear_dbg_completion_list(void);
        void set_hdd_image_name(int drv, _TCHAR *filename);
+
+       virtual void do_set_host_sound_output_device(QString device_name);
+       virtual void do_update_master_volume(int level);
+
        void handleStateChanged(QAudio::State newState);
 
 signals:
index f97a82e..4142d37 100644 (file)
@@ -195,12 +195,18 @@ const _TCHAR *OSD_BASE::get_vm_device_name()
        return (const _TCHAR*)"";
 }
 
+
+int OSD_BASE::get_sound_device_num()
+{
+       return sound_device_list.count();
+}
+#if 0
 const _TCHAR *OSD_BASE::get_sound_device_name(int num)
 {
        if(num < 0) return NULL;
        if(num >= sound_device_list.count()) return NULL;
        QString sdev = sound_device_list.at(num);
-       sdev.truncate(64);
+       sdev.truncate(1023);
        static QByteArray _n;
        _n.clear();
        _n = sdev.toUtf8().constData();
@@ -208,11 +214,6 @@ const _TCHAR *OSD_BASE::get_sound_device_name(int num)
        return (const _TCHAR*)(_n.constData());
 }
 
-int OSD_BASE::get_sound_device_num()
-{
-       return sound_device_list.count();
-}
-#if 0
 void OSD_BASE::get_sound_device_list()
 {
        sound_device_list.clear();
@@ -446,7 +447,6 @@ void OSD_BASE::initialize_sound(int rate, int samples, int* presented_rate, int*
 {
        // ToDo: Sound Input
        QAudioFormat desired;
-
        if(m_audioOutputSink != nullptr) {
                m_audioOutputSink->stop();
                delete m_audioOutputSink;
@@ -462,8 +462,8 @@ void OSD_BASE::initialize_sound(int rate, int samples, int* presented_rate, int*
                    desired = m_audioOutputDevice.preferredFormat();
        }
        m_audioOutputFormat = desired;
-       //m_audioOutputSink = new QAudioSink(m_audioOutputDevice, m_audioOutputFormat, this);
-       m_audioOutputSink = new QAudioSink(m_audioOutputFormat, this);
+       m_audioOutputSink = new QAudioSink(m_audioOutputDevice, m_audioOutputFormat, this);
+       //m_audioOutputSink = new QAudioSink(m_audioOutputFormat, this);
 
        if(m_audioOutput != nullptr) {
                if(m_audioOutput->isOpen()) {
@@ -525,6 +525,10 @@ void OSD_BASE::initialize_sound(int rate, int samples, int* presented_rate, int*
                if(m_audioOutputSink != nullptr) {
                        sound_ok = true;
                        sound_initialized = true;
+                       if(p_config != nullptr) {
+                               double _ll = (double)(p_config->general_sound_level + INT16_MAX) / 65535.0;
+                               m_audioOutputSink->setVolume(_ll);
+                       }
                        connect(m_audioOutputSink, SIGNAL(stateChanged(QAudio::State)), this, SLOT(handleStateChanged(QAudio::State)));
                        //m_audioOutputSink->setBufferSize(1024);
                        //m_audioOutputSink->setBufferSize(sound_samples * 2 * sizeof(int16_t) * 2);
@@ -567,28 +571,77 @@ void OSD_BASE::release_sound()
                m_audioOutput = nullptr;
        }
 #endif
-#if 0
-       if(m_audioOutInternalBuffer != nullptr) {
-               delete m_audioOutInternalBuffer;
-               m_audioOutInternalBuffer = nullptr;
-       }
-       
-       if(m_audioOutputBuffer != nullptr) {
-               delete m_audioOutputBuffer;
-               m_audioOutputBuffer = nullptr;
-       }
-#endif
        sound_ok = false;
        sound_initialized = false;
 }
 
+void OSD_BASE::do_update_master_volume(int level)
+{
+       QMutexLocker l(vm_mutex);
+       double _ll = (double)(level + INT16_MAX) / 65535.0;
+       debug_log(CSP_LOG_INFO, CSP_LOG_TYPE_SOUND,
+                         "Set Master Volume to %f .", _ll);
+       if(m_audioOutputSink != nullptr) {
+               m_audioOutputSink->setVolume(_ll);
+       }
+}
+
+void OSD_BASE::do_set_host_sound_output_device(QString device_name)
+{
+       if(device_name.isEmpty()) return;
+       QString _older = m_audioOutputDevice.description();
+       if(device_name == QString::fromUtf8("Default")) {
+               m_audioOutputDevice = QMediaDevices::defaultAudioOutput();
+       } else {
+               QList<QAudioDevice> devlist = QMediaDevices::audioOutputs(); 
+               for(auto p = devlist.begin(); p != devlist.end() ; ++p) {
+                       if((*p).description() == device_name) {
+                               m_audioOutputDevice = *p;
+                               break;
+                       }
+               }
+       }
+       QString _newer = m_audioOutputDevice.description();
+       if(_older.compare(_newer) != 0) {
+               QMutexLocker l(vm_mutex);
+               if((p_config != nullptr) && (using_flags != nullptr)) {
+                       int freq_val = using_flags->get_sound_sample_rate(p_config->sound_frequency);
+                       double latency_val = using_flags->get_sound_latency(p_config->sound_latency);
+                       sound_rate = freq_val;
+                       sound_samples = (int)((double)sound_rate * latency_val + 0.5);
+               }
+               int dummy_rate;
+               int dummy_samples;
+               if(sound_initialized) {
+                       initialize_sound(sound_rate, sound_samples, &dummy_rate, &dummy_samples);
+               }
+               if((dummy_rate != sound_rate) || (dummy_samples != sound_samples)) {
+                       sound_rate = dummy_rate;
+                       sound_samples = dummy_samples;
+               }
+       }
+}
+
+const _TCHAR *OSD_BASE::get_sound_device_name(int num)
+{
+       if((num < 0) || (num >= sound_device_list.count())) return (const _TCHAR *)nullptr;
+
+       QString sdev = sound_device_list.at(num);
+       sdev.truncate(1023);
+       static QByteArray _n;
+       _n.clear();
+       _n = sdev.toUtf8().constData();
+
+       return (const _TCHAR*)(_n.constData());
+}
+
 void OSD_BASE::get_sound_device_list()
 {
        sound_device_list.clear();
        QList<QAudioDevice> tmplist = QMediaDevices::audioOutputs();
        int i = 0;
        for(auto p = tmplist.begin(); p != tmplist.end(); ++p) {
-               QString tmps = (*p).description();
+               QString tmps = (*p).description().toUtf8();
                sound_device_list.append(tmps);
                debug_log(CSP_LOG_INFO, CSP_LOG_TYPE_SOUND,
                                  "Audio Device #%d: %s", i, tmps.toLocal8Bit().constData());
@@ -1207,6 +1260,8 @@ void OSD_BASE::update_sound(int* extra_frames)
                                        }
                                } 
                                if(m_audioOutputSink->state() != QAudio::StoppedState) {
+                                       double _ll = (double)(p_config->general_sound_level + INT16_MAX) / 65535.0;
+                                       m_audioOutputSink->setVolume(_ll);
                                        qint64 _result = m_audioOutput->write((const char *)sound_buffer, _count * sizeof(int16_t));
                                }
                                //debug_log(CSP_LOG_INFO, CSP_LOG_TYPE_SOUND, "write_to_buffer: desired=%d wrote=%d", _count * sizeof(int16_t), _result);
index 28a1098..9ad8614 100644 (file)
@@ -1,6 +1,6 @@
 message("* vm/common_vm")
 
-SET(THIS_LIB_VERSION 4.0.0)
+SET(THIS_LIB_VERSION 4.1.0)
 
 #include(cotire)
 set(s_vm_common_vm_srcs
index d53b0a2..44e86f5 100644 (file)
@@ -1,7 +1,7 @@
 cmake_minimum_required (VERSION 3.0)
 
 message("* vm/fmgen")
-SET(THIS_LIB_VERSION 4.0.0)
+SET(THIS_LIB_VERSION 4.1.0)
 add_definitions(-D__LIBFMGEN_VERSION=\"libCSPfmgen.${THIS_LIB_VERSION}\")
 
 SET(s_vm_fmgen_srcs