diff --git a/bochs/iodev/iodev.h b/bochs/iodev/iodev.h index 503dc97aa..536c853a5 100644 --- a/bochs/iodev/iodev.h +++ b/bochs/iodev/iodev.h @@ -379,6 +379,12 @@ public: virtual void* init_module(const char *type, logfunctions *dev) { STUBFUNC(soundmod_ctl, init_module); return NULL; } + virtual bx_bool beep_on(float frequency) { + return 0; + } + virtual bx_bool beep_off() { + return 0; + } }; #endif diff --git a/bochs/iodev/sound/es1370.cc b/bochs/iodev/sound/es1370.cc index 51e729357..e4b49a8c1 100644 --- a/bochs/iodev/sound/es1370.cc +++ b/bochs/iodev/sound/es1370.cc @@ -207,7 +207,13 @@ void bx_es1370_c::init(void) BX_ES1370_THIS pci_base_address[0] = 0; BX_ES1370_THIS soundmod = DEV_sound_init_module("default", BX_ES1370_THIS_PTR); - BX_ES1370_THIS s.dac_outputinit = 0; + int ret = BX_ES1370_THIS soundmod->openwaveoutput(SIM->get_param_string(BXPN_ES1370_WAVEDEV)->getptr()); + if (ret != BX_SOUNDLOW_OK) { + BX_ERROR(("could not open wave output device")); + BX_ES1370_THIS s.dac_outputinit = 0; + } else { + BX_ES1370_THIS s.dac_outputinit = 1; + } BX_ES1370_THIS s.adc_inputinit = 0; BX_ES1370_THIS s.dac_nr_active = -1; @@ -306,7 +312,6 @@ void bx_es1370_c::after_restore_state(void) BX_INFO(("new base address: 0x%04x", BX_ES1370_THIS pci_base_address[0])); } BX_ES1370_THIS check_lower_irq(BX_ES1370_THIS s.sctl); - BX_ES1370_THIS s.dac_outputinit = 0; BX_ES1370_THIS s.adc_inputinit = 0; BX_ES1370_THIS s.dac_nr_active = -1; BX_ES1370_THIS update_voices(BX_ES1370_THIS s.ctl, BX_ES1370_THIS s.sctl, 1); @@ -659,15 +664,6 @@ void bx_es1370_c::update_voices(Bit32u ctl, Bit32u sctl, bx_bool force) BX_ES1370_THIS s.adc_inputinit = 1; } } - } else { - if (!BX_ES1370_THIS s.dac_outputinit) { - ret = BX_ES1370_THIS soundmod->openwaveoutput(SIM->get_param_string(BXPN_ES1370_WAVEDEV)->getptr()); - if (ret != BX_SOUNDLOW_OK) { - BX_ERROR(("could not open wave output device")); - } else { - BX_ES1370_THIS s.dac_outputinit = 1; - } - } } } } diff --git a/bochs/iodev/sound/sb16.cc b/bochs/iodev/sound/sb16.cc index 45a0d37f9..2b1886c8b 100644 --- a/bochs/iodev/sound/sb16.cc +++ b/bochs/iodev/sound/sb16.cc @@ -302,19 +302,29 @@ void bx_sb16_c::init(void) BX_SB16_THIS dmatimer = SIM->get_param_num("dmatimer", base)->get(); BX_SB16_THIS loglevel = SIM->get_param_num("loglevel", base)->get(); - // let the output functions initialize - BX_SB16_OUTPUT = DEV_sound_init_module("default", BX_SB16_THISP); + if ((BX_SB16_THIS wavemode == 1) || (BX_SB16_THIS midimode == 1)) { + // let the output functions initialize + BX_SB16_OUTPUT = DEV_sound_init_module("default", BX_SB16_THISP); - if (BX_SB16_OUTPUT == NULL) - { - writelog(MIDILOG(2), "Couldn't initialize output devices. Output disabled."); - BX_SB16_THIS midimode = 0; - BX_SB16_THIS wavemode = 0; + if (BX_SB16_OUTPUT == NULL) { + writelog(MIDILOG(2), "Couldn't initialize output devices. Output disabled."); + BX_SB16_THIS midimode = 0; + BX_SB16_THIS wavemode = 0; + } } DSP.dma.chunk = new Bit8u[BX_SOUNDLOW_WAVEPACKETSIZE]; DSP.dma.chunkindex = 0; - DSP.outputinit = 0; + if (BX_SB16_THIS wavemode == 1) { + int ret = BX_SB16_OUTPUT->openwaveoutput(SIM->get_param_string(BXPN_SB16_WAVEFILE)->getptr()); + if (ret != BX_SOUNDLOW_OK) { + writelog(WAVELOG(2), "Error: Could not open wave output device."); + BX_SB16_THIS wavemode = 0; + DSP.outputinit = 0; + } else { + DSP.outputinit = 1; + } + } DSP.inputinit = 0; MPU.outputinit = 0; @@ -1287,15 +1297,6 @@ void bx_sb16_c::dsp_dma(Bit8u command, Bit8u mode, Bit16u length, Bit8u comp) // write the output to the device/file if (DSP.dma.output == 1) { if (BX_SB16_THIS wavemode == 1) { - if (DSP.outputinit == 0) { - ret = BX_SB16_OUTPUT->openwaveoutput(SIM->get_param_string(BXPN_SB16_WAVEFILE)->getptr()); - if (ret != BX_SOUNDLOW_OK) { - BX_SB16_THIS wavemode = 0; - writelog(WAVELOG(2), "Error: Could not open wave output device."); - } else { - DSP.outputinit = 1; - } - } if (DSP.outputinit == 1) { ret = BX_SB16_OUTPUT->startwaveplayback(DSP.dma.samplerate, DSP.dma.bits, DSP.dma.stereo, DSP.dma.format); if (ret != BX_SOUNDLOW_OK) { diff --git a/bochs/iodev/sound/soundmod.cc b/bochs/iodev/sound/soundmod.cc index a59c889ed..454465be6 100644 --- a/bochs/iodev/sound/soundmod.cc +++ b/bochs/iodev/sound/soundmod.cc @@ -34,7 +34,7 @@ #include "soundosx.h" #include "soundwin.h" -#define LOG_THIS device-> +#define LOG_THIS theSoundModCtl-> bx_soundmod_ctl_c* theSoundModCtl = NULL; @@ -54,21 +54,44 @@ void libsoundmod_LTX_plugin_fini(void) delete theSoundModCtl; } +bx_soundmod_ctl_c::bx_soundmod_ctl_c() +{ + put("sound", "SOUND"); + soundmod = NULL; +} + void* bx_soundmod_ctl_c::init_module(const char *type, logfunctions *device) { - bx_sound_lowlevel_c *soundmod; - if (!strcmp(type, "default")) { soundmod = new BX_SOUND_LOWLEVEL_C(device); } else if (!strcmp(type, "dummy")) { soundmod = new bx_sound_lowlevel_c(device); } else { BX_PANIC(("unknown sound module type '%s'", type)); - soundmod = NULL; } return soundmod; } +bx_bool bx_soundmod_ctl_c::beep_on(float frequency) +{ + if (soundmod != NULL) { + BX_INFO(("Beep ON (frequency=%.2f)",frequency)); + // TODO + return 1; + } + return 0; +} + +bx_bool bx_soundmod_ctl_c::beep_off() +{ + if (soundmod != NULL) { + BX_INFO(("Beep OFF")); + // TODO + return 1; + } + return 0; +} + // The dummy sound lowlevel functions. They don't do anything. bx_sound_lowlevel_c::bx_sound_lowlevel_c(logfunctions *dev) { diff --git a/bochs/iodev/sound/soundmod.h b/bochs/iodev/sound/soundmod.h index 1d7ef6c48..8ec005049 100644 --- a/bochs/iodev/sound/soundmod.h +++ b/bochs/iodev/sound/soundmod.h @@ -31,12 +31,18 @@ typedef Bit32u (*sound_record_handler_t)(void *arg, Bit32u len); +class bx_sound_lowlevel_c; + // Pseudo device that loads the lowlevel sound module class bx_soundmod_ctl_c : public bx_soundmod_ctl_stub_c { public: - bx_soundmod_ctl_c() {} + bx_soundmod_ctl_c(); virtual ~bx_soundmod_ctl_c() {} virtual void* init_module(const char *type, logfunctions *device); + virtual bx_bool beep_on(float frequency); + virtual bx_bool beep_off(); +private: + bx_sound_lowlevel_c *soundmod; }; // The class with the input/output functions diff --git a/bochs/iodev/speaker.cc b/bochs/iodev/speaker.cc index b01a8a2ab..6b38d5acc 100644 --- a/bochs/iodev/speaker.cc +++ b/bochs/iodev/speaker.cc @@ -22,6 +22,7 @@ #include "iodev.h" #include "speaker.h" +#include "sound/soundmod.h" #ifdef __linux__ #include @@ -97,6 +98,10 @@ void bx_speaker_c::beep_on(float frequency) { beep_frequency = frequency; +#if BX_SUPPORT_SOUNDLOW + if (DEV_soundmod_beep_on(frequency)) + return; +#endif #ifdef __linux__ if (consolefd != -1) { this->info("pc speaker on with frequency %f", frequency); @@ -106,7 +111,7 @@ void bx_speaker_c::beep_on(float frequency) usec_start = bx_pc_system.time_usec(); #endif - // give the gui a chance to signal beep off + // give the gui a chance to signal beep on bx_gui->beep_on(frequency); } @@ -132,6 +137,10 @@ DWORD WINAPI BeepThread(LPVOID) void bx_speaker_c::beep_off() { +#if BX_SUPPORT_SOUNDLOW + if (DEV_soundmod_beep_off()) + return; +#endif if (beep_frequency != 0.0) { #ifdef __linux__ if (consolefd != -1) { diff --git a/bochs/plugin.h b/bochs/plugin.h index 4dc1c0128..1146a4830 100644 --- a/bochs/plugin.h +++ b/bochs/plugin.h @@ -255,6 +255,8 @@ extern "C" { ///////// Sound module macro #define DEV_sound_init_module(a,b) \ ((bx_sound_lowlevel_c*)bx_devices.pluginSoundModCtl->init_module(a,b)) +#define DEV_soundmod_beep_on(a) bx_devices.pluginSoundModCtl->beep_on(a) +#define DEV_soundmod_beep_off() bx_devices.pluginSoundModCtl->beep_off() ///////// Networking module macro #define DEV_net_init_module(a,b,c,d) \