2011-02-13 20:26:52 +03:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
2011-02-25 01:05:47 +03:00
|
|
|
// $Id$
|
2011-02-13 20:26:52 +03:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
2017-01-28 12:52:09 +03:00
|
|
|
// Copyright (C) 2011-2017 The Bochs Project
|
2011-02-13 20:26:52 +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
|
|
|
|
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
|
2011-03-20 21:02:12 +03:00
|
|
|
// Common sound module code and dummy sound lowlevel functions
|
2011-02-13 20:26:52 +03:00
|
|
|
|
|
|
|
// Define BX_PLUGGABLE in files that can be compiled into plugins. For
|
|
|
|
// platforms that require a special tag on exported symbols, BX_PLUGGABLE
|
|
|
|
// is used to know when we are exporting symbols and when we are importing.
|
|
|
|
#define BX_PLUGGABLE
|
|
|
|
|
2011-02-15 00:14:20 +03:00
|
|
|
#include "iodev.h"
|
|
|
|
|
2011-03-20 21:02:12 +03:00
|
|
|
#if BX_SUPPORT_SOUNDLOW
|
2011-02-15 00:14:20 +03:00
|
|
|
|
2011-02-13 20:26:52 +03:00
|
|
|
#include "soundmod.h"
|
2014-11-24 21:25:14 +03:00
|
|
|
#include "soundlow.h"
|
2011-02-15 00:14:20 +03:00
|
|
|
#include "soundlnx.h"
|
|
|
|
#include "soundosx.h"
|
|
|
|
#include "soundwin.h"
|
2012-06-09 14:12:05 +04:00
|
|
|
#include "soundsdl.h"
|
2013-07-14 19:14:53 +04:00
|
|
|
#include "soundalsa.h"
|
2015-02-16 18:47:17 +03:00
|
|
|
#include "soundfile.h"
|
2011-02-15 00:14:20 +03:00
|
|
|
|
2014-11-14 21:25:37 +03:00
|
|
|
#if BX_WITH_SDL || BX_WITH_SDL2
|
2012-06-09 00:49:39 +04:00
|
|
|
#include <SDL.h>
|
|
|
|
#endif
|
2012-05-20 21:22:50 +04:00
|
|
|
|
2012-05-20 18:19:49 +04:00
|
|
|
#define LOG_THIS theSoundModCtl->
|
2011-02-15 00:14:20 +03:00
|
|
|
|
|
|
|
bx_soundmod_ctl_c* theSoundModCtl = NULL;
|
2011-02-13 20:26:52 +03:00
|
|
|
|
2017-01-28 12:52:09 +03:00
|
|
|
int CDECL libsoundmod_LTX_plugin_init(plugin_t *plugin, plugintype_t type)
|
2011-02-15 00:14:20 +03:00
|
|
|
{
|
2011-12-25 12:52:34 +04:00
|
|
|
if (type == PLUGTYPE_CORE) {
|
|
|
|
theSoundModCtl = new bx_soundmod_ctl_c;
|
|
|
|
bx_devices.pluginSoundModCtl = theSoundModCtl;
|
|
|
|
return 0; // Success
|
|
|
|
} else {
|
|
|
|
return -1;
|
|
|
|
}
|
2011-02-15 00:14:20 +03:00
|
|
|
}
|
|
|
|
|
2014-06-08 12:40:08 +04:00
|
|
|
void CDECL libsoundmod_LTX_plugin_fini(void)
|
2011-02-15 00:14:20 +03:00
|
|
|
{
|
|
|
|
delete theSoundModCtl;
|
|
|
|
}
|
|
|
|
|
2012-05-20 18:19:49 +04:00
|
|
|
bx_soundmod_ctl_c::bx_soundmod_ctl_c()
|
2011-02-15 00:14:20 +03:00
|
|
|
{
|
2013-12-29 16:56:52 +04:00
|
|
|
put("soundctl", "SNDCTL");
|
2015-02-17 21:28:25 +03:00
|
|
|
n_sound_drivers = 0;
|
2015-02-20 19:36:26 +03:00
|
|
|
soundmod[0].module = NULL;
|
2015-02-13 14:30:46 +03:00
|
|
|
waveout = NULL;
|
2012-05-20 18:19:49 +04:00
|
|
|
}
|
2011-02-15 00:14:20 +03:00
|
|
|
|
2013-06-24 23:19:12 +04:00
|
|
|
bx_soundmod_ctl_c::~bx_soundmod_ctl_c()
|
2012-05-20 18:19:49 +04:00
|
|
|
{
|
2015-02-17 21:28:25 +03:00
|
|
|
for (unsigned i = 0; i < n_sound_drivers; i++) {
|
|
|
|
delete soundmod[i].module;
|
|
|
|
}
|
2013-06-24 23:19:12 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void bx_soundmod_ctl_c::init()
|
|
|
|
{
|
2015-02-13 14:30:46 +03:00
|
|
|
const char *pwaveout = SIM->get_param_string(BXPN_SOUND_WAVEOUT)->getptr();
|
2015-02-22 23:29:58 +03:00
|
|
|
const char *pwavein = SIM->get_param_string(BXPN_SOUND_WAVEIN)->getptr();
|
2015-03-07 01:54:30 +03:00
|
|
|
int ret;
|
2014-11-22 14:43:40 +03:00
|
|
|
|
2015-03-07 01:54:30 +03:00
|
|
|
waveout = get_waveout(0);
|
|
|
|
if (waveout != NULL) {
|
2015-02-22 23:29:58 +03:00
|
|
|
if (!strlen(pwavein)) {
|
2015-02-17 21:28:25 +03:00
|
|
|
SIM->get_param_string(BXPN_SOUND_WAVEIN)->set(pwaveout);
|
|
|
|
}
|
2015-03-07 01:54:30 +03:00
|
|
|
ret = waveout->openwaveoutput(pwaveout);
|
|
|
|
if (ret != BX_SOUNDLOW_OK) {
|
|
|
|
BX_PANIC(("Could not open wave output device"));
|
2015-02-17 21:28:25 +03:00
|
|
|
}
|
2015-03-07 01:54:30 +03:00
|
|
|
} else {
|
|
|
|
BX_PANIC(("no waveout support present"));
|
2014-11-22 14:43:40 +03:00
|
|
|
}
|
2015-02-17 21:28:25 +03:00
|
|
|
}
|
|
|
|
|
2015-02-22 23:29:58 +03:00
|
|
|
bx_sound_lowlevel_c* bx_soundmod_ctl_c::get_driver(int driver_id)
|
2015-02-17 21:28:25 +03:00
|
|
|
{
|
|
|
|
bx_sound_lowlevel_c *driver = NULL;
|
|
|
|
unsigned i;
|
2014-11-22 14:43:40 +03:00
|
|
|
|
2015-02-17 21:28:25 +03:00
|
|
|
for (i = 0; i < n_sound_drivers; i++) {
|
2015-03-07 01:54:30 +03:00
|
|
|
if (driver_id == soundmod[i].drv_id) {
|
2015-02-17 21:28:25 +03:00
|
|
|
return soundmod[i].module;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (i == BX_MAX_SOUND_DRIVERS) {
|
|
|
|
BX_PANIC(("Too many sound drivers!"));
|
|
|
|
return NULL;
|
|
|
|
}
|
2015-02-22 23:29:58 +03:00
|
|
|
if (driver_id == BX_SOUNDDRV_DUMMY) {
|
2015-03-10 23:56:44 +03:00
|
|
|
driver = new bx_sound_dummy_c();
|
2015-02-22 23:29:58 +03:00
|
|
|
} else if (driver_id == BX_SOUNDDRV_FILE) {
|
2015-02-17 21:28:25 +03:00
|
|
|
driver = new bx_sound_file_c();
|
2015-02-24 00:32:34 +03:00
|
|
|
#if BX_HAVE_SOUND_ALSA
|
2015-02-22 23:29:58 +03:00
|
|
|
} else if (driver_id == BX_SOUNDDRV_ALSA) {
|
2015-02-17 21:28:25 +03:00
|
|
|
driver = new bx_sound_alsa_c();
|
2013-06-24 23:19:12 +04:00
|
|
|
#endif
|
2015-02-24 00:32:34 +03:00
|
|
|
#if BX_HAVE_SOUND_SDL
|
2015-02-22 23:29:58 +03:00
|
|
|
} else if (driver_id == BX_SOUNDDRV_SDL) {
|
2015-02-17 21:28:25 +03:00
|
|
|
driver = new bx_sound_sdl_c();
|
2013-07-25 22:47:11 +04:00
|
|
|
#endif
|
2015-02-24 00:32:34 +03:00
|
|
|
#if BX_HAVE_SOUND_OSS
|
2015-02-22 23:29:58 +03:00
|
|
|
} else if (driver_id == BX_SOUNDDRV_OSS) {
|
2015-02-17 21:28:25 +03:00
|
|
|
driver = new bx_sound_oss_c();
|
2013-07-25 22:47:11 +04:00
|
|
|
#endif
|
2015-02-24 00:32:34 +03:00
|
|
|
#if BX_HAVE_SOUND_OSX
|
2015-02-22 23:29:58 +03:00
|
|
|
} else if (driver_id == BX_SOUNDDRV_OSX) {
|
2015-02-17 21:28:25 +03:00
|
|
|
driver = new bx_sound_osx_c();
|
2013-07-25 22:47:11 +04:00
|
|
|
#endif
|
2015-02-24 00:32:34 +03:00
|
|
|
#if BX_HAVE_SOUND_WIN
|
2015-02-22 23:29:58 +03:00
|
|
|
} else if (driver_id == BX_SOUNDDRV_WIN) {
|
2015-02-17 21:28:25 +03:00
|
|
|
driver = new bx_sound_windows_c();
|
2012-06-09 00:49:39 +04:00
|
|
|
#endif
|
2011-02-15 00:14:20 +03:00
|
|
|
} else {
|
2015-02-22 23:29:58 +03:00
|
|
|
BX_PANIC(("unknown lowlevel sound driver id %d", driver_id));
|
2011-02-15 00:14:20 +03:00
|
|
|
}
|
2015-02-17 21:28:25 +03:00
|
|
|
if (driver != NULL) {
|
2015-02-22 23:29:58 +03:00
|
|
|
BX_INFO(("Installed sound driver '%s' at index #%d",
|
|
|
|
sound_driver_names[driver_id], i));
|
|
|
|
soundmod[i].drv_id = driver_id;
|
2015-02-17 21:28:25 +03:00
|
|
|
soundmod[i].module = driver;
|
|
|
|
n_sound_drivers++;
|
2013-07-06 19:12:04 +04:00
|
|
|
}
|
2015-02-17 21:28:25 +03:00
|
|
|
return driver;
|
|
|
|
}
|
|
|
|
|
2015-03-07 01:54:30 +03:00
|
|
|
bx_soundlow_waveout_c* bx_soundmod_ctl_c::get_waveout(bx_bool using_file)
|
2015-02-17 21:28:25 +03:00
|
|
|
{
|
|
|
|
bx_sound_lowlevel_c *module = NULL;
|
|
|
|
|
2015-03-07 01:54:30 +03:00
|
|
|
if (!using_file) {
|
|
|
|
int driver_id = SIM->get_param_enum(BXPN_SOUND_WAVEOUT_DRV)->get();
|
|
|
|
module = get_driver(driver_id);
|
|
|
|
} else {
|
2015-02-22 23:29:58 +03:00
|
|
|
module = get_driver(BX_SOUNDDRV_FILE);
|
2015-02-17 21:28:25 +03:00
|
|
|
}
|
|
|
|
if (module != NULL) {
|
|
|
|
return module->get_waveout();
|
|
|
|
} else {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-07 01:54:30 +03:00
|
|
|
bx_soundlow_wavein_c* bx_soundmod_ctl_c::get_wavein()
|
2015-02-17 21:28:25 +03:00
|
|
|
{
|
|
|
|
bx_sound_lowlevel_c *module = NULL;
|
2015-03-10 23:56:44 +03:00
|
|
|
bx_soundlow_wavein_c *wavein = NULL;
|
2015-02-17 21:28:25 +03:00
|
|
|
|
2015-03-07 01:54:30 +03:00
|
|
|
int driver_id = SIM->get_param_enum(BXPN_SOUND_WAVEIN_DRV)->get();
|
|
|
|
module = get_driver(driver_id);
|
2015-02-17 21:28:25 +03:00
|
|
|
if (module != NULL) {
|
2015-03-10 23:56:44 +03:00
|
|
|
wavein = module->get_wavein();
|
|
|
|
if (wavein == NULL) {
|
|
|
|
BX_ERROR(("sound service 'wavein' not available - using dummy driver"));
|
|
|
|
module = get_driver(BX_SOUNDDRV_DUMMY);
|
|
|
|
if (module != NULL) {
|
|
|
|
wavein = module->get_wavein();
|
|
|
|
}
|
|
|
|
}
|
2013-06-24 23:19:12 +04:00
|
|
|
}
|
2015-03-10 23:56:44 +03:00
|
|
|
return wavein;
|
2013-06-24 23:19:12 +04:00
|
|
|
}
|
|
|
|
|
2015-03-07 01:54:30 +03:00
|
|
|
bx_soundlow_midiout_c* bx_soundmod_ctl_c::get_midiout(bx_bool using_file)
|
2013-06-24 23:19:12 +04:00
|
|
|
{
|
2015-02-17 21:28:25 +03:00
|
|
|
bx_sound_lowlevel_c *module = NULL;
|
2015-03-10 23:56:44 +03:00
|
|
|
bx_soundlow_midiout_c *midiout = NULL;
|
2015-02-17 21:28:25 +03:00
|
|
|
|
2015-03-07 01:54:30 +03:00
|
|
|
if (!using_file) {
|
|
|
|
int driver_id = SIM->get_param_enum(BXPN_SOUND_MIDIOUT_DRV)->get();
|
|
|
|
module = get_driver(driver_id);
|
|
|
|
} else {
|
2015-02-22 23:29:58 +03:00
|
|
|
module = get_driver(BX_SOUNDDRV_FILE);
|
2015-02-17 21:28:25 +03:00
|
|
|
}
|
|
|
|
if (module != NULL) {
|
2015-03-10 23:56:44 +03:00
|
|
|
midiout = module->get_midiout();
|
|
|
|
if (midiout == NULL) {
|
|
|
|
BX_ERROR(("sound service 'midiout' not available - using dummy driver"));
|
|
|
|
module = get_driver(BX_SOUNDDRV_DUMMY);
|
|
|
|
if (module != NULL) {
|
|
|
|
midiout = module->get_midiout();
|
|
|
|
}
|
|
|
|
}
|
2015-02-17 21:28:25 +03:00
|
|
|
}
|
2015-03-10 23:56:44 +03:00
|
|
|
return midiout;
|
2011-02-15 00:14:20 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|