2004-01-16 21:18:38 +03:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
2011-02-25 01:05:47 +03:00
|
|
|
// $Id$
|
2004-01-16 21:18:38 +03:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
2013-06-14 23:08:51 +04:00
|
|
|
// Copyright (C) 2003 David N. Welton <davidw@dedasys.com>.
|
2021-01-23 15:06:11 +03:00
|
|
|
// Copyright (C) 2003-2021 The Bochs Project
|
2004-01-16 21:18:38 +03:00
|
|
|
//
|
|
|
|
// This library is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU Lesser General Public
|
|
|
|
// License as published by the Free Software Foundation; either
|
|
|
|
// version 2 of the License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This library is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
// Lesser General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Lesser General Public
|
|
|
|
// License along with this library; if not, write to the Free Software
|
2009-02-08 12:05:52 +03:00
|
|
|
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
2004-01-16 19:30:46 +03:00
|
|
|
|
2004-02-02 02:42:04 +03:00
|
|
|
#define BX_PLUGGABLE
|
|
|
|
|
2004-06-19 19:20:15 +04:00
|
|
|
#include "iodev.h"
|
2004-09-05 14:30:19 +04:00
|
|
|
#include "speaker.h"
|
2012-05-20 22:58:08 +04:00
|
|
|
|
|
|
|
#if BX_SUPPORT_SOUNDLOW
|
2015-02-16 11:48:11 +03:00
|
|
|
#include "sound/soundlow.h"
|
2012-05-20 18:19:49 +04:00
|
|
|
#include "sound/soundmod.h"
|
2012-05-20 22:58:08 +04:00
|
|
|
#endif
|
2004-06-19 19:20:15 +04:00
|
|
|
|
2004-01-16 21:18:38 +03:00
|
|
|
#ifdef __linux__
|
2004-01-16 19:30:46 +03:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <linux/kd.h>
|
2004-01-16 21:18:38 +03:00
|
|
|
#endif
|
2004-01-16 19:30:46 +03:00
|
|
|
|
2004-02-02 02:42:04 +03:00
|
|
|
#define LOG_THIS theSpeaker->
|
|
|
|
|
|
|
|
bx_speaker_c *theSpeaker= NULL;
|
|
|
|
|
2015-03-15 09:58:59 +03:00
|
|
|
#if defined(__linux__) || defined(WIN32)
|
|
|
|
#define BX_SYSTEM_SPEAKER
|
|
|
|
#endif
|
|
|
|
|
|
|
|
enum {
|
|
|
|
BX_SPK_MODE_NONE,
|
|
|
|
#if BX_SUPPORT_SOUNDLOW
|
|
|
|
BX_SPK_MODE_SOUND,
|
|
|
|
#endif
|
|
|
|
#ifdef BX_SYSTEM_SPEAKER
|
|
|
|
BX_SPK_MODE_SYSTEM,
|
|
|
|
#endif
|
|
|
|
BX_SPK_MODE_GUI
|
|
|
|
};
|
|
|
|
|
|
|
|
static const char *speaker_mode_list[] = {
|
|
|
|
"none",
|
|
|
|
#if BX_SUPPORT_SOUNDLOW
|
|
|
|
"sound",
|
|
|
|
#endif
|
|
|
|
#ifdef BX_SYSTEM_SPEAKER
|
|
|
|
"system",
|
|
|
|
#endif
|
|
|
|
"gui",
|
|
|
|
NULL
|
|
|
|
};
|
2013-06-16 22:52:34 +04:00
|
|
|
|
2015-02-16 11:48:11 +03:00
|
|
|
#if BX_SUPPORT_SOUNDLOW
|
|
|
|
BX_MUTEX(beep_mutex);
|
|
|
|
|
|
|
|
Bit32u beep_callback(void *dev, Bit16u rate, Bit8u *buffer, Bit32u len);
|
|
|
|
#endif
|
|
|
|
|
2013-06-16 22:52:34 +04:00
|
|
|
// builtin configuration handling functions
|
|
|
|
|
|
|
|
void speaker_init_options(void)
|
|
|
|
{
|
2020-06-21 12:08:05 +03:00
|
|
|
bx_list_c *deplist;
|
|
|
|
|
2013-06-16 22:52:34 +04:00
|
|
|
bx_list_c *sound = (bx_list_c*)SIM->get_param("sound");
|
|
|
|
bx_list_c *menu = new bx_list_c(sound, "speaker", "PC speaker output configuration");
|
|
|
|
menu->set_options(menu->SERIES_ASK);
|
|
|
|
bx_param_bool_c *enabled = new bx_param_bool_c(menu, "enabled", "Enable speaker output",
|
|
|
|
"Enables the PC speaker output", 1);
|
|
|
|
bx_param_enum_c *mode = new bx_param_enum_c(menu, "mode", "Speaker output mode",
|
2015-03-15 09:58:59 +03:00
|
|
|
"The mode can be one these: 'none', 'sound', 'system' or 'gui'",
|
|
|
|
speaker_mode_list, 1, BX_SPK_MODE_NONE);
|
2013-06-16 22:52:34 +04:00
|
|
|
mode->set_ask_format("Select speker output mode [%s] ");
|
2020-07-09 00:31:49 +03:00
|
|
|
#if BX_SUPPORT_SOUNDLOW
|
2020-06-21 12:08:05 +03:00
|
|
|
bx_param_num_c *volume = new bx_param_num_c(menu, "volume", "Speaker volume",
|
|
|
|
"Set the PC speaker volume", 0, 15, 15);
|
2020-07-09 00:31:49 +03:00
|
|
|
#endif
|
2020-06-21 12:08:05 +03:00
|
|
|
deplist = new bx_list_c(NULL);
|
2013-06-16 22:52:34 +04:00
|
|
|
deplist->add(mode);
|
|
|
|
enabled->set_dependent_list(deplist);
|
2020-07-09 00:31:49 +03:00
|
|
|
#if BX_SUPPORT_SOUNDLOW
|
2020-06-21 12:08:05 +03:00
|
|
|
deplist = new bx_list_c(NULL);
|
|
|
|
deplist->add(volume);
|
|
|
|
mode->set_dependent_list(deplist, 0);
|
|
|
|
mode->set_dependent_bitmap(BX_SPK_MODE_SOUND, 1);
|
2020-07-09 00:31:49 +03:00
|
|
|
#endif
|
2013-06-16 22:52:34 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
Bit32s speaker_options_parser(const char *context, int num_params, char *params[])
|
|
|
|
{
|
|
|
|
if (!strcmp(params[0], "speaker")) {
|
|
|
|
bx_list_c *base = (bx_list_c*) SIM->get_param(BXPN_SOUND_SPEAKER);
|
|
|
|
for (int i=1; i<num_params; i++) {
|
|
|
|
if (SIM->parse_param_from_list(context, params[i], base) < 0) {
|
|
|
|
BX_ERROR(("%s: unknown parameter for speaker ignored.", context));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
BX_PANIC(("%s: unknown directive '%s'", context, params[0]));
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
Bit32s speaker_options_save(FILE *fp)
|
|
|
|
{
|
|
|
|
return SIM->write_param_list(fp, (bx_list_c*) SIM->get_param(BXPN_SOUND_SPEAKER), NULL, 0);
|
|
|
|
}
|
|
|
|
|
2021-01-23 15:06:11 +03:00
|
|
|
// device plugin entry point
|
2013-06-16 22:52:34 +04:00
|
|
|
|
2021-01-23 15:06:11 +03:00
|
|
|
PLUGIN_ENTRY_FOR_MODULE(speaker)
|
2004-02-02 02:42:04 +03:00
|
|
|
{
|
2021-02-07 19:16:06 +03:00
|
|
|
if (mode == PLUGIN_INIT) {
|
2021-01-23 15:06:11 +03:00
|
|
|
theSpeaker = new bx_speaker_c();
|
|
|
|
bx_devices.pluginSpeaker = theSpeaker;
|
|
|
|
BX_REGISTER_DEVICE_DEVMODEL(plugin, type, theSpeaker, BX_PLUGIN_SPEAKER);
|
|
|
|
// add new configuration parameters for the config interface
|
|
|
|
speaker_init_options();
|
|
|
|
// register add-on options for bochsrc and command line
|
|
|
|
SIM->register_addon_option("speaker", speaker_options_parser, speaker_options_save);
|
2021-02-06 19:51:55 +03:00
|
|
|
bx_devices.add_sound_device();
|
2021-02-07 19:16:06 +03:00
|
|
|
} else if (mode == PLUGIN_FINI) {
|
2021-01-23 15:06:11 +03:00
|
|
|
bx_devices.pluginSpeaker = &bx_devices.stubSpeaker;
|
|
|
|
delete theSpeaker;
|
|
|
|
SIM->unregister_addon_option("speaker");
|
|
|
|
((bx_list_c*)SIM->get_param("sound"))->remove("speaker");
|
2021-02-06 19:51:55 +03:00
|
|
|
bx_devices.remove_sound_device();
|
2021-02-07 19:16:06 +03:00
|
|
|
} else {
|
|
|
|
return (int)PLUGTYPE_OPTIONAL;
|
2021-01-23 15:06:11 +03:00
|
|
|
}
|
2004-02-02 02:42:04 +03:00
|
|
|
return(0); // Success
|
|
|
|
}
|
|
|
|
|
2013-06-16 22:52:34 +04:00
|
|
|
// the device object
|
|
|
|
|
2006-09-10 21:18:44 +04:00
|
|
|
bx_speaker_c::bx_speaker_c()
|
|
|
|
{
|
2013-12-29 16:56:52 +04:00
|
|
|
put("speaker", "PCSPK");
|
2004-02-02 02:42:04 +03:00
|
|
|
|
|
|
|
beep_frequency = 0.0; // Off
|
|
|
|
#ifdef __linux__
|
2012-05-24 22:06:40 +04:00
|
|
|
consolefd = -1;
|
2004-02-02 02:42:04 +03:00
|
|
|
#endif
|
2015-02-16 11:48:11 +03:00
|
|
|
#if BX_SUPPORT_SOUNDLOW
|
|
|
|
waveout = NULL;
|
|
|
|
#endif
|
2004-01-16 19:30:46 +03:00
|
|
|
}
|
|
|
|
|
2006-09-10 21:18:44 +04:00
|
|
|
bx_speaker_c::~bx_speaker_c()
|
|
|
|
{
|
2013-06-14 23:08:51 +04:00
|
|
|
beep_off();
|
2015-03-15 09:58:59 +03:00
|
|
|
switch (output_mode) {
|
2015-02-16 11:48:11 +03:00
|
|
|
#if BX_SUPPORT_SOUNDLOW
|
2015-03-15 09:58:59 +03:00
|
|
|
case BX_SPK_MODE_SOUND:
|
|
|
|
beep_active = 0;
|
|
|
|
if (waveout != NULL) {
|
|
|
|
if (beep_callback_id >= 0) {
|
|
|
|
waveout->unregister_wave_callback(beep_callback_id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
#ifdef __linux__
|
|
|
|
case BX_SPK_MODE_SYSTEM:
|
|
|
|
if (consolefd >= 0) {
|
|
|
|
close(consolefd);
|
|
|
|
}
|
|
|
|
break;
|
2004-01-16 21:18:38 +03:00
|
|
|
#endif
|
2015-03-16 21:28:29 +03:00
|
|
|
}
|
2006-09-10 21:18:44 +04:00
|
|
|
BX_DEBUG(("Exit"));
|
2004-02-02 02:42:04 +03:00
|
|
|
}
|
|
|
|
|
2008-01-27 01:24:03 +03:00
|
|
|
void bx_speaker_c::init(void)
|
2004-02-02 02:42:04 +03:00
|
|
|
{
|
2013-06-16 22:52:34 +04:00
|
|
|
// Read in values from config interface
|
|
|
|
bx_list_c *base = (bx_list_c*) SIM->get_param(BXPN_SOUND_SPEAKER);
|
|
|
|
// Check if the device is disabled or not configured
|
|
|
|
if (!SIM->get_param_bool("enabled", base)->get()) {
|
|
|
|
BX_INFO(("PC speaker output disabled"));
|
|
|
|
// mark unused plugin for removal
|
2018-01-16 19:55:39 +03:00
|
|
|
((bx_param_bool_c*)((bx_list_c*)SIM->get_param(BXPN_PLUGIN_CTRL))->get_by_name("speaker"))->set(0);
|
2013-06-16 22:52:34 +04:00
|
|
|
return;
|
|
|
|
}
|
2015-03-15 09:58:59 +03:00
|
|
|
output_mode = SIM->get_param_enum("mode", base)->get();
|
|
|
|
switch (output_mode) {
|
2013-06-24 23:19:12 +04:00
|
|
|
#if BX_SUPPORT_SOUNDLOW
|
2015-03-15 09:58:59 +03:00
|
|
|
case BX_SPK_MODE_SOUND:
|
|
|
|
waveout = DEV_sound_get_waveout(0);
|
|
|
|
if (waveout != NULL) {
|
|
|
|
beep_active = 0;
|
2020-06-21 12:08:05 +03:00
|
|
|
beep_volume = SIM->get_param_num("volume", base)->get();
|
2018-05-10 13:50:42 +03:00
|
|
|
#if BX_HAVE_REALTIME_USEC
|
|
|
|
dsp_active = 0;
|
|
|
|
dsp_start_usec = bx_get_realtime64_usec();
|
|
|
|
dsp_cb_usec = 0;
|
|
|
|
dsp_count = 0;
|
|
|
|
#endif
|
2015-03-15 09:58:59 +03:00
|
|
|
BX_INIT_MUTEX(beep_mutex);
|
|
|
|
beep_callback_id = waveout->register_wave_callback(theSpeaker, beep_callback);
|
|
|
|
BX_INFO(("Using lowlevel sound support for output"));
|
|
|
|
} else {
|
|
|
|
BX_ERROR(("Failed to use lowlevel sound support for output"));
|
|
|
|
output_mode = BX_SPK_MODE_NONE;
|
|
|
|
}
|
|
|
|
break;
|
2013-06-24 23:19:12 +04:00
|
|
|
#endif
|
2015-03-15 09:58:59 +03:00
|
|
|
#ifdef BX_SYSTEM_SPEAKER
|
|
|
|
case BX_SPK_MODE_SYSTEM:
|
2012-05-24 22:06:40 +04:00
|
|
|
#ifdef __linux__
|
2015-03-15 09:58:59 +03:00
|
|
|
consolefd = open("/dev/console", O_WRONLY);
|
|
|
|
if (consolefd != -1) {
|
|
|
|
BX_INFO(("Using /dev/console for output"));
|
|
|
|
} else {
|
|
|
|
BX_ERROR(("Failed to open /dev/console: %s", strerror(errno)));
|
|
|
|
BX_ERROR(("Deactivating beep on console"));
|
|
|
|
output_mode = BX_SPK_MODE_NONE;
|
|
|
|
}
|
2012-05-24 22:06:40 +04:00
|
|
|
#elif defined(WIN32)
|
2015-03-15 09:58:59 +03:00
|
|
|
BX_INFO(("Using system beep for output"));
|
2013-06-16 22:52:34 +04:00
|
|
|
#endif
|
2015-03-15 09:58:59 +03:00
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
case BX_SPK_MODE_GUI:
|
|
|
|
BX_INFO(("Forwarding beep to gui"));
|
|
|
|
break;
|
2013-06-16 22:52:34 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void bx_speaker_c::reset(unsigned type)
|
|
|
|
{
|
2004-02-02 02:42:04 +03:00
|
|
|
beep_off();
|
|
|
|
}
|
|
|
|
|
2015-02-16 11:48:11 +03:00
|
|
|
#if BX_SUPPORT_SOUNDLOW
|
|
|
|
Bit32u bx_speaker_c::beep_generator(Bit16u rate, Bit8u *buffer, Bit32u len)
|
|
|
|
{
|
2018-05-10 13:50:42 +03:00
|
|
|
Bit32u j = 0, ret = 0;
|
2015-02-16 11:48:11 +03:00
|
|
|
Bit16u beep_samples;
|
|
|
|
static Bit16u beep_pos = 0;
|
|
|
|
|
|
|
|
BX_LOCK(beep_mutex);
|
|
|
|
if (!beep_active) {
|
2018-01-18 22:00:57 +03:00
|
|
|
beep_samples = 0;
|
|
|
|
} else {
|
|
|
|
beep_samples = (Bit32u)((float)rate / beep_frequency / 2);
|
|
|
|
}
|
|
|
|
if (beep_samples == 0) {
|
2018-05-10 13:50:42 +03:00
|
|
|
#if BX_SUPPORT_SOUNDLOW && BX_HAVE_REALTIME_USEC
|
|
|
|
if (dsp_active) {
|
|
|
|
ret = dsp_generator(rate, buffer, len);
|
|
|
|
}
|
|
|
|
#endif
|
2015-02-16 11:48:11 +03:00
|
|
|
BX_UNLOCK(beep_mutex);
|
2018-05-10 13:50:42 +03:00
|
|
|
return ret;
|
2015-02-16 11:48:11 +03:00
|
|
|
}
|
|
|
|
do {
|
2020-06-21 12:08:05 +03:00
|
|
|
buffer[j++] = (Bit8u)beep_level;
|
|
|
|
buffer[j++] = (Bit8u)(beep_level >> 8);
|
|
|
|
buffer[j++] = (Bit8u)beep_level;
|
|
|
|
buffer[j++] = (Bit8u)(beep_level >> 8);
|
2015-02-16 11:48:11 +03:00
|
|
|
if ((++beep_pos % beep_samples) == 0) {
|
2020-06-21 12:08:05 +03:00
|
|
|
beep_level *= -1;
|
2015-02-16 11:48:11 +03:00
|
|
|
beep_pos = 0;
|
|
|
|
beep_samples = (Bit32u)((float)rate / beep_frequency / 2);
|
2018-01-18 22:00:57 +03:00
|
|
|
if (beep_samples == 0) break;
|
2015-02-16 11:48:11 +03:00
|
|
|
}
|
|
|
|
} while (j < len);
|
|
|
|
BX_UNLOCK(beep_mutex);
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
2018-05-10 13:50:42 +03:00
|
|
|
#if BX_SUPPORT_SOUNDLOW && BX_HAVE_REALTIME_USEC
|
|
|
|
Bit32u bx_speaker_c::dsp_generator(Bit16u rate, Bit8u *buffer, Bit32u len)
|
|
|
|
{
|
|
|
|
Bit32u i = 0, j = 0;
|
|
|
|
double tmp_dsp_usec, step_usec;
|
|
|
|
|
|
|
|
Bit64u new_dsp_cb_usec = bx_get_realtime64_usec() - dsp_start_usec;
|
|
|
|
if (dsp_cb_usec == 0) {
|
|
|
|
dsp_cb_usec = new_dsp_cb_usec - 25000;
|
|
|
|
}
|
|
|
|
tmp_dsp_usec = (double)dsp_cb_usec;
|
|
|
|
step_usec = 1000000.0 / (double)rate;
|
|
|
|
do {
|
|
|
|
if ((i < dsp_count) && (dsp_event_buffer[i] < (Bit64u)tmp_dsp_usec)) {
|
2020-06-21 12:08:05 +03:00
|
|
|
beep_level *= -1;
|
2018-05-10 13:50:42 +03:00
|
|
|
i++;
|
|
|
|
}
|
2020-06-21 12:08:05 +03:00
|
|
|
buffer[j++] = (Bit8u)beep_level;
|
|
|
|
buffer[j++] = (Bit8u)(beep_level >> 8);
|
|
|
|
buffer[j++] = (Bit8u)beep_level;
|
|
|
|
buffer[j++] = (Bit8u)(beep_level >> 8);
|
2018-05-10 13:50:42 +03:00
|
|
|
tmp_dsp_usec += step_usec;
|
|
|
|
} while (j < len);
|
|
|
|
dsp_active = 0;
|
|
|
|
dsp_count = 0;
|
|
|
|
dsp_cb_usec = new_dsp_cb_usec;
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-02-16 11:48:11 +03:00
|
|
|
Bit32u beep_callback(void *dev, Bit16u rate, Bit8u *buffer, Bit32u len)
|
|
|
|
{
|
|
|
|
return ((bx_speaker_c*)dev)->beep_generator(rate, buffer, len);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2004-02-02 02:42:04 +03:00
|
|
|
void bx_speaker_c::beep_on(float frequency)
|
|
|
|
{
|
2013-06-12 01:04:07 +04:00
|
|
|
#if defined(WIN32)
|
2013-06-16 22:52:34 +04:00
|
|
|
if ((output_mode == BX_SPK_MODE_SYSTEM) && (beep_frequency != 0.0)) {
|
2013-06-12 01:04:07 +04:00
|
|
|
beep_off();
|
|
|
|
}
|
|
|
|
#endif
|
2004-02-02 02:42:04 +03:00
|
|
|
|
2015-03-15 09:58:59 +03:00
|
|
|
switch (output_mode) {
|
2012-05-20 18:19:49 +04:00
|
|
|
#if BX_SUPPORT_SOUNDLOW
|
2015-03-15 09:58:59 +03:00
|
|
|
case BX_SPK_MODE_SOUND:
|
|
|
|
if ((waveout != NULL) && (frequency != beep_frequency)) {
|
|
|
|
BX_LOCK(beep_mutex);
|
|
|
|
beep_frequency = frequency;
|
2020-06-21 12:08:05 +03:00
|
|
|
if (!beep_active) {
|
|
|
|
beep_level = (Bit16s)(0x4000 * (beep_volume / 15.0f));
|
|
|
|
}
|
2015-03-15 09:58:59 +03:00
|
|
|
beep_active = 1;
|
|
|
|
BX_UNLOCK(beep_mutex);
|
|
|
|
}
|
|
|
|
break;
|
2012-05-20 18:19:49 +04:00
|
|
|
#endif
|
2015-03-15 09:58:59 +03:00
|
|
|
#ifdef BX_SYSTEM_SPEAKER
|
|
|
|
case BX_SPK_MODE_SYSTEM:
|
2004-01-16 21:18:38 +03:00
|
|
|
#ifdef __linux__
|
2015-03-15 09:58:59 +03:00
|
|
|
if (consolefd != -1) {
|
|
|
|
BX_DEBUG(("PC speaker on with frequency %f", frequency));
|
|
|
|
ioctl(consolefd, KIOCSOUND, (int)(clock_tick_rate/frequency));
|
|
|
|
}
|
2005-01-29 15:08:31 +03:00
|
|
|
#elif defined(WIN32)
|
2015-03-15 09:58:59 +03:00
|
|
|
usec_start = bx_pc_system.time_usec();
|
|
|
|
#endif
|
|
|
|
break;
|
2004-02-02 02:42:04 +03:00
|
|
|
#endif
|
2015-03-15 09:58:59 +03:00
|
|
|
case BX_SPK_MODE_GUI:
|
|
|
|
// give the gui a chance to signal beep on
|
|
|
|
bx_gui->beep_on(frequency);
|
|
|
|
break;
|
2013-06-16 22:52:34 +04:00
|
|
|
}
|
2015-02-16 11:48:11 +03:00
|
|
|
beep_frequency = frequency;
|
2004-01-16 19:30:46 +03:00
|
|
|
}
|
|
|
|
|
2005-02-09 21:25:57 +03:00
|
|
|
#if defined(WIN32)
|
|
|
|
|
2010-02-08 17:53:31 +03:00
|
|
|
static struct {
|
2005-02-09 21:25:57 +03:00
|
|
|
DWORD frequency;
|
|
|
|
DWORD msec;
|
|
|
|
} beep_info;
|
|
|
|
|
|
|
|
DWORD WINAPI BeepThread(LPVOID)
|
|
|
|
{
|
|
|
|
static BOOL threadActive = FALSE;
|
|
|
|
|
|
|
|
while (threadActive) Sleep(10);
|
|
|
|
threadActive = TRUE;
|
|
|
|
Beep(beep_info.frequency, beep_info.msec);
|
|
|
|
threadActive = FALSE;
|
2005-02-12 11:59:47 +03:00
|
|
|
return 0;
|
2005-02-09 21:25:57 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2004-02-02 02:42:04 +03:00
|
|
|
void bx_speaker_c::beep_off()
|
2004-01-16 19:30:46 +03:00
|
|
|
{
|
2015-03-15 09:58:59 +03:00
|
|
|
switch (output_mode) {
|
2012-05-20 18:19:49 +04:00
|
|
|
#if BX_SUPPORT_SOUNDLOW
|
2015-03-15 09:58:59 +03:00
|
|
|
case BX_SPK_MODE_SOUND:
|
|
|
|
if (waveout != NULL) {
|
|
|
|
BX_LOCK(beep_mutex);
|
|
|
|
beep_active = 0;
|
|
|
|
beep_frequency = 0.0;
|
|
|
|
BX_UNLOCK(beep_mutex);
|
|
|
|
}
|
|
|
|
break;
|
2012-05-20 18:19:49 +04:00
|
|
|
#endif
|
2015-03-15 09:58:59 +03:00
|
|
|
#ifdef BX_SYSTEM_SPEAKER
|
|
|
|
case BX_SPK_MODE_SYSTEM:
|
|
|
|
if (beep_frequency != 0.0) {
|
2004-01-16 21:18:38 +03:00
|
|
|
#ifdef __linux__
|
2015-03-15 09:58:59 +03:00
|
|
|
if (consolefd != -1) {
|
|
|
|
ioctl(consolefd, KIOCSOUND, 0);
|
|
|
|
}
|
2005-01-29 15:08:31 +03:00
|
|
|
#elif defined(WIN32)
|
2015-03-15 09:58:59 +03:00
|
|
|
// FIXME: sound should start at beep_on() and end here
|
|
|
|
DWORD threadID;
|
|
|
|
beep_info.msec = (DWORD)((bx_pc_system.time_usec() - usec_start) / 1000);
|
|
|
|
beep_info.frequency = (DWORD)beep_frequency;
|
|
|
|
CloseHandle(CreateThread(NULL, 0, BeepThread, NULL, 0, &threadID));
|
2004-01-16 21:18:38 +03:00
|
|
|
#endif
|
2015-03-15 09:58:59 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
case BX_SPK_MODE_GUI:
|
|
|
|
// give the gui a chance to signal beep off
|
|
|
|
bx_gui->beep_off();
|
|
|
|
break;
|
2004-01-16 21:18:38 +03:00
|
|
|
}
|
2013-06-16 22:52:34 +04:00
|
|
|
beep_frequency = 0.0;
|
2004-01-16 19:30:46 +03:00
|
|
|
}
|
2018-05-10 13:50:42 +03:00
|
|
|
|
2021-01-31 11:22:55 +03:00
|
|
|
void bx_speaker_c::set_line(bool level)
|
2018-05-10 13:50:42 +03:00
|
|
|
{
|
|
|
|
#if BX_SUPPORT_SOUNDLOW && BX_HAVE_REALTIME_USEC
|
2018-05-19 11:07:20 +03:00
|
|
|
if (output_mode == BX_SPK_MODE_SOUND) {
|
2018-05-10 13:50:42 +03:00
|
|
|
BX_LOCK(beep_mutex);
|
|
|
|
Bit64u timestamp = bx_get_realtime64_usec() - dsp_start_usec;
|
|
|
|
dsp_active = 1;
|
|
|
|
if (dsp_count < 500) {
|
|
|
|
dsp_event_buffer[dsp_count++] = timestamp;
|
|
|
|
} else {
|
|
|
|
BX_ERROR(("DSP event buffer full"));
|
|
|
|
}
|
|
|
|
BX_UNLOCK(beep_mutex);
|
|
|
|
}
|
2018-05-19 11:07:20 +03:00
|
|
|
#else
|
|
|
|
BX_DEBUG(("setting speaker line to %d", level));
|
|
|
|
#endif
|
2018-05-10 13:50:42 +03:00
|
|
|
}
|