OSDN Git Service

[Qt][OSD][Sound] Update OSD API, initialize_sound() has 4 args, not 2.
authorK.Ohta <whatisthis.sowhat@gmail.com>
Wed, 20 Feb 2019 17:29:27 +0000 (02:29 +0900)
committerK.Ohta <whatisthis.sowhat@gmail.com>
Wed, 20 Feb 2019 17:29:27 +0000 (02:29 +0900)
[Qt][OSD][Sound] SDL_MixAudioFormat() *MUST* use for SDL2, shouldm't use SDL_MixAudio for SDL2.
[Qt][UI] Select sound output devices.

22 files changed:
source/src/config.cpp
source/src/config.h
source/src/emu.cpp
source/src/qt/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/commonclasses.h
source/src/qt/gui/gl4_5/qt_glutil_gl4_5.cpp
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/osd.cpp
source/src/qt/osd.h
source/src/qt/osd_base.cpp
source/src/qt/osd_base.h
source/src/qt/osd_sound.cpp
source/src/qt/osd_types.h
source/src/qt/osd_wrapper.cpp

index bec19cf..3b7aff8 100644 (file)
@@ -127,6 +127,7 @@ void initialize_config()
        #endif
                config.sound_latency = 1;       // 100msec
                config.sound_strict_rendering = true;
+               config.sound_device_num = 0; // Add 20190221
        #ifdef USE_FLOPPY_DISK
                config.sound_noise_fdd = true;
        #endif
@@ -380,7 +381,8 @@ void load_config(const _TCHAR *config_path)
        // sound
        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 = MyGetPrivateProfileBool(_T("Sound"), _T("StrictRendering"), config.sound_strict_rendering, config_path);
+       config.sound_strict_rendering = MyGetPrivateProfileInt(_T("Sound"), _T("StrictRendering"), config.sound_strict_rendering, config_path);
+       config.sound_device_num = MyGetPrivateProfileBool(_T("Sound"), _T("DeviceNumber"), config.sound_device_num, config_path);
        #ifdef USE_FLOPPY_DISK
                config.sound_noise_fdd = MyGetPrivateProfileBool(_T("Sound"), _T("NoiseFDD"), config.sound_noise_fdd, config_path);;
        #endif
@@ -755,6 +757,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);
        #ifdef USE_FLOPPY_DISK
                MyWritePrivateProfileBool(_T("Sound"), _T("NoiseFDD"), config.sound_noise_fdd, config_path);
        #endif
index 5ebb7ef..27a4ec7 100644 (file)
@@ -250,6 +250,8 @@ typedef struct {
        int sound_frequency;
        int sound_latency;
        bool sound_strict_rendering;
+       int sound_device_num;
+       
 #if defined(_USE_QT)   
        int general_sound_level;
 #endif
index a0d5347..5a48fff 100644 (file)
@@ -95,7 +95,10 @@ EMU::EMU()
        osd->main_window_handle = hwnd;
        osd->instance_handle = hinst;
 #endif
-       osd->initialize(sound_rate, sound_samples);
+       int presented_rate, presented_samples;
+       osd->initialize(sound_rate, sound_samples, &presented_rate, &presented_samples);
+       sound_rate = presented_rate;
+       sound_samples = presented_samples;
        // initialize vm
        vm = new VM(this);
        osd->vm = vm;
@@ -265,8 +268,16 @@ void EMU::reset()
 #if defined(_USE_QT)
                osd->reset_vm_node();
 #endif
+               int presented_rate;
+               int presented_samples;
                sound_rate = sound_frequency_table[config.sound_frequency];
                sound_samples = (int)(sound_rate * sound_latency_table[config.sound_latency] + 0.5);
+               osd->initialize_sound(sound_rate, sound_samples, &presented_rate, &presented_samples);
+               if((sound_rate != presented_rate) ||
+                  (sound_samples != presented_samples)) {
+                       sound_rate = presented_rate;
+                       sound_samples = presented_samples;
+               }
                vm->initialize_sound(sound_rate, sound_samples);
 #ifdef USE_SOUND_VOLUME
                for(int i = 0; i < USE_SOUND_VOLUME; i++) {
index 6732174..1d985fc 100644 (file)
@@ -1,5 +1,5 @@
 message("* qt/osd")
-SET(THIS_LIB_VERSION 2.18.0)
+SET(THIS_LIB_VERSION 2.18.2)
 
 set(s_qt_osd_headers
        osd_base.h
index bf78a04..da9fa41 100644 (file)
@@ -513,3 +513,16 @@ _TCHAR *USING_FLAGS_EXT::get_vm_node_name(int id)
        if(p_emu == NULL) return NULL;
        return (_TCHAR *)p_emu->get_osd()->get_vm_node_name(id);
 }
+
+const _TCHAR *USING_FLAGS_EXT::get_sound_device_name(int num)
+{
+       if(p_emu == NULL) return NULL;
+       return (const _TCHAR *)(p_emu->get_osd()->get_sound_device_name(num));
+}
+
+int USING_FLAGS_EXT::get_sound_device_num()
+{
+       if(p_emu == NULL) return -1;
+       return p_emu->get_osd()->get_sound_device_num();
+}
+
index b02d984..ed86866 100644 (file)
@@ -25,6 +25,8 @@ public:
        int get_vm_node_size();
        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();
        
 };
        
index 6bc7e5a..2a4235a 100644 (file)
@@ -1264,7 +1264,16 @@ int MainLoop(int argc, char *argv[])
        }
        csp_logger->set_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(GuiMain, SIGNAL(lastWindowClosed()),
                                         rMainWindow, SLOT(on_actionExit_triggered()));
 
index a57a1ed..e248af2 100644 (file)
@@ -1,6 +1,6 @@
 message("* qt/emuutils")
 
-SET(THIS_LIB_VERSION 2.15.2)
+SET(THIS_LIB_VERSION 2.15.3)
 
 set(s_qt_emuutils_headers
        ../gui/csp_logger.h
index f4431eb..c66a774 100644 (file)
@@ -1,6 +1,6 @@
 message("* qt/gui")
 
-set(THIS_LIB_VERSION 2.18.2)
+set(THIS_LIB_VERSION 2.18.3)
 #include(cotire)
 #include(PrecompiledHeader)
 
index 77a9186..fd4cd02 100644 (file)
@@ -66,6 +66,7 @@ protected:
        void setWriteProtect(bool b) {write_protect = b;}
 
 public slots:
+       void on_set_host_sound_device(void);
        void set_boot_mode(void);
        void set_cpu_type(void);
        void set_cpupower(void);
@@ -173,6 +174,7 @@ signals:
        int sig_freq(int);
        int sig_latency(int);
        int sig_sounddevice(int);
+       int sig_set_host_sound_device(int);
        int sig_set_dipsw(int, bool);
        int sig_screen_aspect(int);
        int sig_screen_size(int, int);
index 13c8bee..5d6bc1c 100644 (file)
@@ -128,15 +128,15 @@ QOpenGLTexture *GLDraw_4_5::createMainTexture(QImage *img)
        //tx->setFormat(QOpenGLTexture::RGBA8_UNorm);
        
        if(main_texture_buffer != 0) {
-               main_mutex->lock();
+               //main_mutex->lock();
                this->unmap_vram_texture();
                map_base_address = NULL;
                extfunc->glDeleteBuffers(1, &main_texture_buffer);
                main_texture_buffer = 0;
-               main_mutex->unlock();
+               //main_mutex->unlock();
        }
        {
-               main_mutex->lock();
+               //main_mutex->lock();
                extfunc->glGenBuffers(1, &main_texture_buffer);
                extfunc->glBindBuffer(GL_PIXEL_UNPACK_BUFFER, main_texture_buffer);
                //extfunc->glBufferData(GL_PIXEL_UNPACK_BUFFER, w * h * sizeof(uint32_t), ip->constBits(), GL_DYNAMIC_COPY);
@@ -152,7 +152,7 @@ QOpenGLTexture *GLDraw_4_5::createMainTexture(QImage *img)
                map_vram_texture();
                pixel_width = w;
                pixel_height = h;
-               main_mutex->unlock();
+               //main_mutex->unlock();
                
        }
 
@@ -816,7 +816,7 @@ void GLDraw_4_5::uploadMainTexture(QImage *p, bool use_chromakey, bool was_mappe
                                extfunc->glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
                        
                        } else {
-                               main_mutex->lock();
+                               //main_mutex->lock();
                                extfunc->glFlushMappedBufferRange(GL_PIXEL_UNPACK_BUFFER, 0, pixel_width *pixel_height * sizeof(scrntype_t));
                                extfunc->glClientWaitSync(sync_fence, GL_SYNC_FLUSH_COMMANDS_BIT, 0);
                                extfunc->glDeleteSync(sync_fence);
@@ -832,7 +832,7 @@ void GLDraw_4_5::uploadMainTexture(QImage *p, bool use_chromakey, bool was_mappe
                                extfunc->glClientWaitSync(sync_fence, GL_SYNC_FLUSH_COMMANDS_BIT, 0);
                                extfunc->glDeleteSync(sync_fence);
                                sync_fence = extfunc->glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE,  0);
-                               main_mutex->unlock();
+                               //main_mutex->unlock();
                        }
 #else
                        uVramTextureID->setData(*p, QOpenGLTexture::DontGenerateMipMaps);
@@ -1839,12 +1839,12 @@ scrntype_t *GLDraw_4_5::get_screen_buffer(int y)
        if(map_base_address == NULL) {
                return NULL;
        } else {
-               main_mutex->lock();
+               //main_mutex->lock();
                //extfunc->glClientWaitSync(sync_fence, GL_SYNC_FLUSH_COMMANDS_BIT, 0);
                scrntype_t *p = (scrntype_t *)map_base_address;
                p = p + (pixel_width * y);
                //printf("%08x\n", (uintptr_t)p);   
-               main_mutex->unlock();
+               //main_mutex->unlock();
                return p;
        }
 }
index 239b4ab..f01882c 100644 (file)
@@ -184,12 +184,14 @@ private:
        // Sound
        QActionGroup   *actionGroup_Sound_Freq;
        QActionGroup   *actionGroup_Sound_Latency;
+       QActionGroup   *actionGroup_Sound_HostDevices;
        //class Action_Control *actionSoundCMT;
        class Action_Control *action_VolumeDialog;
        class Action_Control *actionSoundPlayTape;
        class Action_Control *actionSoundStrictRendering;
        class Action_Control *action_SoundFilesFDD;
        class Action_Control *action_SoundFilesRelay;
+       class Action_Control *action_HostSoundDevice[16];
        //QMenu *menuLogToConsole;
        //QMenu *menuLogToSyslog;
        QMenu *menuDevLogToConsole;
@@ -425,6 +427,7 @@ protected:
        QMenu *menuSound;
        QMenu *menuOutput_Frequency;
        QMenu *menuSound_Latency;
+       QMenu *menuSound_HostDevices;
        QMenu *menuMachine;
        QMenu *menuRecord;
        QMenu *menuRecord_sound;
@@ -648,7 +651,8 @@ public slots:
        void set_sound_device(int);
        void do_set_sound_strict_rendering(bool f);
        void do_set_sound_play_tape(bool f);
-       
+       void do_set_host_sound_device(int num);
+       void do_set_host_sound_name(int num, QString sname);    
        void set_monitor_type(int);
        void message_status_bar(QString);
        void resize_statusbar(int w, int h);
index f682fd7..9b29746 100644 (file)
@@ -343,6 +343,8 @@ public:
        EMU *get_emu(void);
        void set_osd(OSD *p);
        OSD *get_osd(void);
+       virtual const _TCHAR *get_sound_device_name(int num);
+       virtual int get_sound_device_num();
        
        virtual int get_vm_node_size();
        virtual void set_vm_node_name(int id, const _TCHAR *name);
index b4a8a6e..a3bb5cf 100644 (file)
@@ -265,3 +265,13 @@ EMU *USING_FLAGS::get_emu(void)
 {
        return p_emu;
 }
+
+const _TCHAR *USING_FLAGS::get_sound_device_name(int num)
+{
+       return NULL;
+}
+
+int USING_FLAGS::get_sound_device_num()
+{
+       return -1;
+}
index 26b989a..9fb7f70 100644 (file)
@@ -28,6 +28,33 @@ void Object_Menu_Control::on_set_latency(void) {
    emit sig_latency(s_num);
 }
 
+void Object_Menu_Control::on_set_host_sound_device(void) {
+   emit sig_set_host_sound_device(s_num);
+}
+
+void Ui_MainWindowBase::do_set_host_sound_device(int num)
+{
+       if(p_config != NULL) {
+               p_config->sound_device_num = num;
+       }
+}
+
+void Ui_MainWindowBase::do_set_host_sound_name(int num, QString s)
+{
+       if(num < 0) return;
+       if(num >= 16) return;
+       
+       if(s.isEmpty()) {
+               if(action_HostSoundDevice[num] != NULL) {
+                       action_HostSoundDevice[num]->setVisible(false);
+               }
+       } else {
+               if(action_HostSoundDevice[num] != NULL) {
+                       action_HostSoundDevice[num]->setVisible(true);
+                       action_HostSoundDevice[num]->setText(s);
+               }
+       }
+}
 
 void Ui_MainWindowBase::do_set_sound_strict_rendering(bool f)
 {
@@ -89,6 +116,21 @@ void Ui_MainWindowBase::CreateSoundMenu(void)
        //connect(actionSoundStrictRendering, SIGNAL(toggled(bool)),
        //              this, SLOT(do_set_sound_strict_rendering(bool)));
        //menuSound->addAction(actionSoundStrictRendering);
+
+       menuSound_HostDevices = new QMenu(menuSound);
+       menuSound_HostDevices->setObjectName(QString::fromUtf8("menuSound_HostDevices"));
+       menuSound->addAction(menuSound_HostDevices->menuAction());
+       for(i = 0; i < 16; i++) {
+               if(action_HostSoundDevice[i] != NULL) {
+                       menuSound_HostDevices->addAction(action_HostSoundDevice[i]);
+                       connect(action_HostSoundDevice[i], SIGNAL(triggered()),
+                                       action_HostSoundDevice[i]->binds, SLOT(on_set_host_sound_device()));
+                       connect(action_HostSoundDevice[i]->binds, SIGNAL(sig_set_host_sound_device(int)),
+                                       this, SLOT(do_set_host_sound_device(int)));
+               }
+       }
+       
+       menuSound->addSeparator();
        
        menuOutput_Frequency = new QMenu(menuSound);
        menuOutput_Frequency->setObjectName(QString::fromUtf8("menuOutput_Frequency"));
@@ -121,6 +163,23 @@ void Ui_MainWindowBase::ConfigSoundMenu(void)
        QString tmps;
        double dval;
        //int freq = 48000;
+
+       actionGroup_Sound_HostDevices = new QActionGroup(this);
+       for(i = 0; i < 16; i++) {
+               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]->binds->setNumber(i);
+               if(i == p_config->sound_device_num) {
+                       action_HostSoundDevice[i]->setChecked(true);
+                       //freq = using_flags->get_s_freq_table(i);
+               }
+               actionGroup_Sound_HostDevices->addAction(action_HostSoundDevice[i]);
+       }
+       
        actionGroup_Sound_Freq = new QActionGroup(this);
        actionGroup_Sound_Freq->setExclusive(true);
        for(i = 0; i < 8; i++) {
@@ -210,6 +269,9 @@ void Ui_MainWindowBase::retranslateSoundMenu(void)
                actionSoundPlayTape->setEnabled(false);
        }
 
+       menuSound_HostDevices->setTitle(QApplication::translate("MenuSound", "Output to:", 0));
+       menuSound_HostDevices->setToolTip(QApplication::translate("MenuSound", "Select sound device to output.\nThis effects after re-start this emulator.", 0));
+       
        menuSound->setTitle(QApplication::translate("MenuSound", "Sound", 0));
        menuOutput_Frequency->setTitle(QApplication::translate("MenuSound", "Output Frequency", 0));
        menuSound_Latency->setTitle(QApplication::translate("MenuSound", "Sound Latency", 0));
index 676176d..733f23b 100644 (file)
@@ -1113,7 +1113,7 @@ void OSD::set_features(void)
 extern std::string cpp_homedir;
 extern std::string my_procname;
 
-void OSD::initialize(int rate, int samples)
+void OSD::initialize(int rate, int samples, int* presented_rate, int* presented_samples)
 {
        // get module path
        QString tmp_path;
@@ -1138,7 +1138,7 @@ void OSD::initialize(int rate, int samples)
        initialize_input();
        initialize_printer();
        initialize_screen();
-       initialize_sound(rate, samples);
+       initialize_sound(rate, samples, presented_rate, presented_samples);
 #if defined(USE_SOUND_FILES)
        init_sound_files();
 #endif
index 779bcc8..fbea948 100644 (file)
@@ -73,7 +73,7 @@ protected:
 public:
        OSD(USING_FLAGS *p, CSP_Logger *logger);
        ~OSD();
-       void initialize(int rate, int samples);
+       void initialize(int rate, int samples, int* presented_rate, int* presented_samples);
        void release();
        void power_off();
 
index b53c471..34d338a 100644 (file)
@@ -108,7 +108,7 @@ void OSD_BASE::set_parent_thread(EmuThreadClass *parent)
        parent_thread = parent;
 }
 
-void OSD_BASE::initialize(int rate, int samples)
+void OSD_BASE::initialize(int rate, int samples, int* presented_rate, int* presented_samples)
 {
 }
 
index 3e8b14a..2426a1d 100644 (file)
@@ -14,6 +14,7 @@
 #include <QList>
 #include <QThread>
 #include <QString>
+#include <QStringList>
 #include <QImage>
 #include <SDL.h>
 //#include "simd_types.h"
@@ -191,12 +192,18 @@ protected:
        bool self_invalidate;
        
        // sound
-       void initialize_sound(int rate, int samples);
+#if defined(USE_SDL2)   
+       SDL_AudioDeviceID audio_dev_id;
+#else
+       int audio_dev_id;
+#endif
+       SDL_AudioSpec snd_spec_req, snd_spec_presented;
        void release_sound();
        static void audio_callback(void *udata, Uint8 *stream, int len);
        int sound_rate, sound_samples;
        bool sound_ok, sound_started, now_mute;
        bool sound_first_half;
+       QStringList sound_device_list;
        
        _TCHAR sound_file_name[_MAX_PATH];
        FILEIO* rec_sound_fio;
@@ -212,12 +219,6 @@ protected:
        bool sound_initialized;
        Sint16 *sound_buf_ptr;
        Uint8 snd_total_volume;
-#if defined(USE_SDL2)   
-       SDL_AudioDeviceID audio_dev_id;
-#else
-       int audio_dev_id;
-#endif
-       SDL_AudioSpec snd_spec_req, snd_spec_presented;
        
        // video device
        virtual void initialize_video();
@@ -287,7 +288,9 @@ public:
        int host_cpus;
        bool now_auto_key;
        
-       virtual void initialize(int rate, int samples);
+       virtual void initialize(int rate, int samples, int* presented_rate, int* presented_samples);
+       // sound
+       virtual void initialize_sound(int rate, int samples, int* presented_rate, int* presented_samples);
        virtual void release();
        virtual void power_off();
        void suspend();
@@ -373,6 +376,10 @@ public:
        void start_record_sound();
        void stop_record_sound();
        void restart_record_sound();
+
+       const _TCHAR *get_sound_device_name(int num);
+       int get_sound_device_num();
+       
        bool now_record_sound;
        int get_sound_rate();
        // Wrapper : Sound
index dd9f400..43b6f1a 100644 (file)
@@ -28,7 +28,7 @@ void OSD_BASE::audio_callback(void *udata, Uint8 *stream, int len)
        Uint8 *s;
        int writepos;
        int sndlen;
-       
+       //printf("Callback: udata=%08x stream=%08x len=%d\n", udata, stream, len);
        sdl_snddata_t *pData = (sdl_snddata_t *)udata;
        if(pData == NULL) return;
        
@@ -61,7 +61,11 @@ void OSD_BASE::audio_callback(void *udata, Uint8 *stream, int len)
                        p = (Uint8 *)(*pData->sound_buf_ptr);
                        p = &p[writepos * 2];
                        s = &stream[spos * 2];
+#if defined(USE_SDL2)
+                       SDL_MixAudioFormat(s, (Uint8*)p, pData->sound_format, len2 * 2, *(pData->snd_total_volume));
+#else
                        SDL_MixAudio(s, (Uint8 *)p, len2 * 2, *(pData->snd_total_volume));
+#endif
                        *(pData->sound_data_len) -= len2;
                        if(*(pData->sound_data_len) <= 0) *(pData->sound_data_len) = 0;
                        *pData->sound_write_pos += len2;
@@ -79,11 +83,28 @@ void OSD_BASE::audio_callback(void *udata, Uint8 *stream, int len)
        } while(spos < len); 
 }
 
-void OSD_BASE::initialize_sound(int rate, int samples)
+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.value(num);
+       sdev.truncate(64);
+       return (const _TCHAR*)(sdev.toUtf8().constData());
+}
+
+int OSD_BASE::get_sound_device_num()
+{
+       return sound_device_list.count();
+}
+
+void OSD_BASE::initialize_sound(int rate, int samples, int* presented_rate, int* presented_samples)
 {
        std::string devname;
        int i;
 
+       if(sound_initialized) {
+               release_sound();
+       }
        sound_rate = rate;
        sound_samples = samples;
        rec_sound_buffer_ptr = 0;
@@ -117,17 +138,59 @@ void OSD_BASE::initialize_sound(int rate, int samples)
        snd_spec_req.samples = samples;
        snd_spec_req.callback = &(this->audio_callback);
        snd_spec_req.userdata = (void *)&snddata;
-#if defined(USE_SDL2)      
+#if defined(USE_SDL2)
+       debug_log(CSP_LOG_INFO, CSP_LOG_TYPE_SOUND, "Using Sound Driver: %s\n", SDL_GetCurrentAudioDriver());
+       sound_device_list.clear();
        for(i = 0; i < SDL_GetNumAudioDevices(0); i++) {
-               //devname = SDL_GetAudioDeviceName(i, 0);
                QString tmps = QString::fromUtf8(SDL_GetAudioDeviceName(i, 0));
                debug_log(CSP_LOG_INFO, CSP_LOG_TYPE_SOUND,
-                                                         "Audio Device: %s", tmps.toLocal8Bit().constData());
+                                 "Audio Device #%d: %s", i, tmps.toLocal8Bit().constData());
+               sound_device_list.append(tmps);
        }
 #endif   
-       SDL_OpenAudio(&snd_spec_req, &snd_spec_presented);
+#if defined(USE_SDL2)
+       
+       //QString sdev = QString::fromUtf8("\"") + sound_device_list.at(audio_dev_id) + QString::fromUtf8("\"");
+       //audio_dev_id = SDL_OpenAudioDevice(NULL, 0, &snd_spec_req, &snd_spec_presented, SDL_AUDIO_ALLOW_ANY_CHANGE);
+       QString sdev;
+       sdev = sound_device_list.at(p_config->sound_device_num);
+    audio_dev_id = SDL_OpenAudioDevice(sdev.toUtf8().constData(), 0,
+                                                                          &snd_spec_req, &snd_spec_presented,
+                                                                          0);
+       debug_log(CSP_LOG_INFO, CSP_LOG_TYPE_SOUND, "Try to openDEVICE #%d: %s -> %s: DEVID=%d\n",
+                         p_config->sound_device_num, sdev.toUtf8().constData(), (audio_dev_id <= 0) ? "FAIL" : "SUCCESS", audio_dev_id);
+#else
        audio_dev_id = 1;
-   
+       SDL_OpenAudio(&snd_spec_req, &snd_spec_presented);
+#endif
+
+#if defined(USE_SDL2)
+       if(audio_dev_id <= 0) {
+               debug_log(CSP_LOG_INFO, CSP_LOG_TYPE_SOUND,"Failed to initialize sound\n");
+               if(presented_rate != NULL) {
+                       *presented_rate = sound_rate;
+               }
+               if(presented_samples != NULL) {
+                       *presented_samples = sound_samples;
+               }
+               sound_initialized = false;
+               sound_ok = sound_first_half = false;
+               return;
+       }
+#endif
+       snddata.sound_format = snd_spec_presented.format;
+       if((snd_spec_presented.freq != sound_rate) ||
+          (snd_spec_presented.samples != sound_samples)) { // DEINI
+               sound_rate = snd_spec_presented.freq;
+               sound_samples = snd_spec_presented.samples;
+       }
+       debug_log(CSP_LOG_INFO, CSP_LOG_TYPE_SOUND,"Sample rate=%d samples=%d\n", sound_rate, sound_samples);
+       if(presented_rate != NULL) {
+               *presented_rate = sound_rate;
+       }
+       if(presented_samples != NULL) {
+               *presented_samples = sound_samples;
+       }
        // secondary buffer
        sound_buffer_size = sound_samples * snd_spec_presented.channels * 2;
        sound_buf_ptr = (Sint16 *)malloc(sound_buffer_size * sizeof(Sint16)); 
@@ -143,11 +206,6 @@ void OSD_BASE::initialize_sound(int rate, int samples)
        debug_log(CSP_LOG_INFO, CSP_LOG_TYPE_SOUND,
                                                  "Sound OK: BufSize = %d", sound_buffer_size);
        memset(sound_buf_ptr, 0x00, sound_buffer_size * sizeof(Sint16));
-//#if defined(USE_SDL2)   
-//     SDL_PauseAudioDevice(audio_dev_id, 0);
-//#else   
-//     SDL_PauseAudio(0);
-//#endif   
        sound_initialized = true;
        sound_ok = sound_first_half = true;
 }
@@ -162,13 +220,12 @@ void OSD_BASE::release_sound()
        //SDL_PauseAudioDevice(audio_dev_id, 1);
        SDL_CloseAudioDevice(audio_dev_id);
 #else   
-       //SDL_PauseAudio(1);
        SDL_CloseAudio();
 #endif   
+       stop_record_sound();
        if(sound_buf_ptr != NULL) free(sound_buf_ptr);
        sound_buf_ptr = NULL;
        // stop recording
-       stop_record_sound();
 }
 
 void OSD_BASE::update_sound(int* extra_frames)
index 30772ae..694d08c 100644 (file)
@@ -43,6 +43,7 @@ typedef struct {
        Uint8 *snd_total_volume;
        bool *sound_exit;
        bool *sound_debug;
+       SDL_AudioFormat sound_format;
        config_t *p_config;
 } sdl_snddata_t;
 
index fa2883f..24939db 100644 (file)
@@ -409,6 +409,7 @@ double OSD::get_window_mode_power(int mode)
        return mode + WINDOW_MODE_BASE;
 }
 
+
 void OSD::initialize_video()
 {
        movie_loader = NULL;