[OSD][Qt][SOUND][QT_MULTIMEDIA] Available to set master volume.Will implement better.
#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
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
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
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;
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
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
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];
+}
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);
};
}
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());
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
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
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);
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();
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);
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);
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);
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;
#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();
}
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);
}
}
}
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()));
}
}
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]);
}
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);
} else {
action_VolumeDialog->setIcon(VolumeHighIcon);
}
+ emit sig_update_master_volume(level);
}
void Ui_MainWindowBase::retranslateSoundMenu(void)
Ui_SndSliderObject::~Ui_SndSliderObject()
{
}
-
+#include "../osd_base.h"
#include <cstdint>
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();
}
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 {
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
m_audioInputSource = nullptr;
m_audioInputBuffer = nullptr;
m_audioInput = nullptr;
+ sound_initialized = false;
#if QT_VERSION >= 0x051400
vm_mutex = new QRecursiveMutex();
QAudioFormat m_audioOutputFormat;
QAudioDevice m_audioOutputDevice;
-
QAudioFormat m_audioInputFormat;
QAudioDevice m_audioInputDevice;
QAudioSource *m_audioInputSource;
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:
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();
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();
{
// ToDo: Sound Input
QAudioFormat desired;
-
if(m_audioOutputSink != nullptr) {
m_audioOutputSink->stop();
delete m_audioOutputSink;
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()) {
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);
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());
}
}
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);
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
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