Some work on the lowlevel sound support

- ALSA driver is now default on Linux (if present)
- SDL sound driver is now default if no platform-specific driver is available
  and the SDL gui is enabled
- soundlnx.cc: sendwavepacket() now exits with error if device is not opened
- soundmod.cc: exit beep loop if sendwavepacket() returns error
This commit is contained in:
Volker Ruppert 2013-08-04 14:35:06 +00:00
parent 73875eebad
commit 51688143aa
4 changed files with 32 additions and 15 deletions

View File

@ -850,12 +850,13 @@ typedef
#define BX_SUPPORT_SOUNDLOW 0
#if BX_SUPPORT_SOUNDLOW
// Determines which sound lowlevel class is to be used.
// Determines which sound lowlevel class is to be used as the default.
// Currently the following are available:
// bx_sound_alsa_c Output for Linux with ALSA PCM and sequencer interface
// bx_sound_linux_c Output for Linux, to /dev/dsp and /dev/midi00
// or ALSA PCM and sequencer interface
// bx_sound_windows_c Output for Windows midi and wave mappers
// bx_sound_osx_c Output for MacOSX midi and wave device
// bx_sound_sdl_c Wave output with SDL
// bx_sound_lowlevel_c Dummy functions, no output
#define BX_SOUND_LOWLEVEL_C bx_sound_lowlevel_c
// Use ALSA sound interface on Linux

View File

@ -1767,6 +1767,8 @@ AC_SUBST(CDROM_OBJS)
SOUNDCARD_OBJS=''
SOUNDLOW_OBJS=''
GAME_OBJS=''
soundlow_drivers=''
soundlow_default=''
soundcard_present=0
gameport_present=0
AC_MSG_CHECKING(for Sound Blaster 16 support)
@ -1814,17 +1816,20 @@ AC_ARG_ENABLE(es1370,
)
if test "$soundcard_present" = 1; then
AC_MSG_CHECKING(for sound lowlevel module)
AC_DEFINE(BX_SUPPORT_SOUNDLOW, 1)
case "$target" in
*-linux* | *-freebsd*)
SOUNDLOW_OBJS='soundlnx.o'
AC_DEFINE(BX_SOUND_LOWLEVEL_C, bx_sound_linux_c)
AC_MSG_RESULT(linux)
soundlow_drivers="oss"
soundlow_default="oss"
bx_have_alsa=0
AC_CHECK_HEADER([alsa/asoundlib.h], [bx_have_alsa=1])
if test "$bx_have_alsa" = 1; then
SOUNDLOW_OBJS="$SOUNDLOW_OBJS soundalsa.o"
AC_DEFINE(BX_SOUND_LOWLEVEL_C, bx_sound_alsa_c)
soundlow_default="alsa"
soundlow_drivers="alsa $soundlow_drivers"
AC_DEFINE(BX_HAVE_ALSASOUND, 1)
if test "$bx_plugins" = 1; then
SOUND_LINK_OPTS="$SOUND_LINK_OPTS -lasound"
@ -1837,40 +1842,47 @@ if test "$soundcard_present" = 1; then
SOUNDLOW_OBJS='soundwin.o'
AC_DEFINE(BX_SOUND_LOWLEVEL_C, bx_sound_windows_c)
DEVICE_LINK_OPTS="$DEVICE_LINK_OPTS winmm.lib"
AC_MSG_RESULT(win)
soundlow_drivers="win"
soundlow_default="win"
;;
*-cygwin* | *-mingw32*)
SOUNDLOW_OBJS='soundwin.o'
AC_DEFINE(BX_SOUND_LOWLEVEL_C, bx_sound_windows_c)
DEVICE_LINK_OPTS="$DEVICE_LINK_OPTS -lwinmm"
AC_MSG_RESULT(win)
soundlow_drivers="win"
soundlow_default="win"
;;
*-macosx* | *-macos* | *-apple-darwin*)
SOUNDLOW_OBJS='soundosx.o'
AC_DEFINE(BX_SOUND_LOWLEVEL_C, bx_sound_osx_c)
DEVICE_LINK_OPTS="$DEVICE_LINK_OPTS -framework CoreServices -framework AudioUnit -framework AudioToolbox"
AC_MSG_RESULT(osx)
soundlow_drivers="osx"
soundlow_default="osx"
;;
*)
SOUNDLOW_OBJS=''
AC_DEFINE(BX_SOUND_LOWLEVEL_C, bx_sound_lowlevel_c)
AC_MSG_RESULT(dummy)
soundlow_default="dummy"
;;
esac
AC_MSG_CHECKING(for additional sound lowlevel modules)
if test "$with_sdl" = yes; then
SOUNDLOW_OBJS="$SOUNDLOW_OBJS soundsdl.o"
if test "$bx_plugins" = 1; then
SOUND_LINK_OPTS="$SOUND_LINK_OPTS `sdl-config --libs`"
fi
AC_MSG_RESULT(sdl)
else
AC_MSG_RESULT(none)
soundlow_drivers="$soundlow_drivers sdl"
if test "$soundlow_default" = "dummy"; then
soundlow_default="sdl"
fi
fi
if test "$bx_plugins" = 0; then
SOUND_LIB_VAR='iodev/sound/libsound.a'
AC_SUBST(SOUND_LIB_VAR)
fi
AC_MSG_CHECKING(for sound lowlevel modules)
AC_MSG_RESULT($soundlow_drivers)
AC_MSG_CHECKING(for default sound lowlevel module)
AC_MSG_RESULT($soundlow_default)
else
AC_DEFINE(BX_SUPPORT_SOUNDLOW, 0)
fi

View File

@ -193,8 +193,11 @@ int bx_sound_linux_c::startwaveplayback(int frequency, int bits, bx_bool stereo,
int bx_sound_linux_c::sendwavepacket(int length, Bit8u data[])
{
int ret = write(wave_fd[0], data, length);
if (wave_fd[0] == -1) {
return BX_SOUNDLOW_ERR;
}
int ret = write(wave_fd[0], data, length);
if (ret == length) {
return BX_SOUNDLOW_OK;
} else {

View File

@ -138,7 +138,7 @@ void beep_thread(void *indata)
#endif
{
Bit8u level;
int i, j;
int i, j, ret;
bx_sound_lowlevel_c *soundmod = (bx_sound_lowlevel_c*)indata;
level = 0x40;
@ -149,7 +149,8 @@ void beep_thread(void *indata)
beep_buffer[j++] = level;
if ((++i % beep_bytes) == 0) level ^= 0x40;
} while (j < beep_bufsize);
soundmod->sendwavepacket(beep_bufsize, beep_buffer);
ret = soundmod->sendwavepacket(beep_bufsize, beep_buffer);
if (ret == BX_SOUNDLOW_ERR) break;
if (soundmod->get_type() == BX_SOUNDLOW_WIN) {
#ifdef WIN32
Sleep(100);