Skip to content

Commit

Permalink
Merge branch 'bochs-emu:master' into telescope
Browse files Browse the repository at this point in the history
  • Loading branch information
therealdreg authored Apr 5, 2024
2 parents d935398 + c1f93f0 commit 27519fc
Show file tree
Hide file tree
Showing 12 changed files with 193 additions and 43 deletions.
8 changes: 4 additions & 4 deletions bochs/.bochsrc
Original file line number Diff line number Diff line change
Expand Up @@ -958,15 +958,15 @@ parport1: enabled=1, file="parport.out"
# waveoutdrv:
# This defines the driver to be used for the waveout feature.
# Possible values are 'file' (all wave data sent to file), 'dummy' (no
# output) and the platform-dependant drivers 'alsa', 'oss', 'osx', 'pulse',
# 'sdl' and 'win'.
# output), 'pulse', 'sdl' (both cross-platform) and the platform-dependant
# drivers 'alsa', 'oss', 'osx' and 'win'.
# waveout:
# This defines the device to be used for wave output (if necessary) or
# the output file for the 'file' driver.
# waveindrv:
# This defines the driver to be used for the wavein feature.
# Possible values are 'dummy' (recording silence) and platform-dependent
# drivers 'alsa', 'oss', 'sdl' and 'win'.
# Possible values are 'dummy' (recording silence), 'pulse', 'sdl' (both
# cross-platform) and platform-dependent drivers 'alsa', 'oss' and 'win'.
# wavein:
# This defines the device to be used for wave input (if necessary).
# midioutdrv:
Expand Down
2 changes: 1 addition & 1 deletion bochs/CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Detailed change log :
- USB
- Now includes the USB Debugger support for the xHCI and UHCI controllers
- Sound
- Added lowlevel sound output support using PulseAudio simple API
- Added PCM playback/recording support using PulseAudio simple API

-------------------------------------------------------------------------
Changes in 2.8 (March 10, 2024):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@
<ClCompile Include="..\cpu\softfloat3e\extF80_mul.c" />
<ClCompile Include="..\cpu\softfloat3e\extF80_rem.c" />
<ClCompile Include="..\cpu\softfloat3e\extF80_roundToInt.c" />
<ClCompile Include="..\cpu\softfloat3e\extF80_scale.c" />
<ClCompile Include="..\cpu\softfloat3e\extF80_sqrt.c" />
<ClCompile Include="..\cpu\softfloat3e\extF80_to_f128.c" />
<ClCompile Include="..\cpu\softfloat3e\extF80_to_f16.c" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@
<ClCompile Include="..\cpu\softfloat3e\extF80_mul.c" />
<ClCompile Include="..\cpu\softfloat3e\extF80_rem.c" />
<ClCompile Include="..\cpu\softfloat3e\extF80_roundToInt.c" />
<ClCompile Include="..\cpu\softfloat3e\extF80_scale.c" />
<ClCompile Include="..\cpu\softfloat3e\extF80_sqrt.c" />
<ClCompile Include="..\cpu\softfloat3e\extF80_to_f128.c" />
<ClCompile Include="..\cpu\softfloat3e\extF80_to_f16.c" />
Expand Down
30 changes: 16 additions & 14 deletions bochs/configure
Original file line number Diff line number Diff line change
Expand Up @@ -25296,20 +25296,6 @@ fi
DEVICE_LINK_OPTS="$DEVICE_LINK_OPTS -lasound"
fi
fi
if test "x$PKG_CONFIG" != x; then
$PKG_CONFIG --exists libpulse-simple
if test x$? = x0; then
SOUNDLOW_OBJS="$SOUNDLOW_OBJS soundpulse.o"
soundlow_drivers="$soundlow_drivers pulse"
printf "%s\n" "#define BX_HAVE_SOUND_PULSE 1" >>confdefs.h

if test "$bx_plugins" = 1; then
PULSE_SOUND_LINK_OPTS="$PULSE_SOUND_LINK_OPTS `$PKG_CONFIG --libs libpulse-simple`"
else
DEVICE_LINK_OPTS="$DEVICE_LINK_OPTS `$PKG_CONFIG --libs libpulse-simple`"
fi
fi
fi
;;
*-pc-windows*)
SOUNDLOW_OBJS='soundwin.o'
Expand Down Expand Up @@ -25377,6 +25363,22 @@ fi

fi
fi
if test "$cross_configure" = 0 -a "$DEFAULT_GUI" != win32; then
if test "x$PKG_CONFIG" != x; then
$PKG_CONFIG --exists libpulse-simple
if test x$? = x0; then
SOUNDLOW_OBJS="$SOUNDLOW_OBJS soundpulse.o"
soundlow_drivers="$soundlow_drivers pulse"
printf "%s\n" "#define BX_HAVE_SOUND_PULSE 1" >>confdefs.h

if test "$bx_plugins" = 1; then
PULSE_SOUND_LINK_OPTS="$PULSE_SOUND_LINK_OPTS `$PKG_CONFIG --libs libpulse-simple`"
else
DEVICE_LINK_OPTS="$DEVICE_LINK_OPTS `$PKG_CONFIG --libs libpulse-simple`"
fi
fi
fi
fi
if test "$MSVC_TARGET" = 0; then
ac_fn_c_check_header_compile "$LINENO" "samplerate.h" "ac_cv_header_samplerate_h" "$ac_includes_default"
if test "x$ac_cv_header_samplerate_h" = xyes
Expand Down
28 changes: 15 additions & 13 deletions bochs/configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -2071,19 +2071,6 @@ if test "$soundcard_present" = 1; then
DEVICE_LINK_OPTS="$DEVICE_LINK_OPTS -lasound"
fi
fi
if test "x$PKG_CONFIG" != x; then
$PKG_CONFIG --exists libpulse-simple
if test x$? = x0; then
SOUNDLOW_OBJS="$SOUNDLOW_OBJS soundpulse.o"
soundlow_drivers="$soundlow_drivers pulse"
AC_DEFINE(BX_HAVE_SOUND_PULSE, 1)
if test "$bx_plugins" = 1; then
PULSE_SOUND_LINK_OPTS="$PULSE_SOUND_LINK_OPTS `$PKG_CONFIG --libs libpulse-simple`"
else
DEVICE_LINK_OPTS="$DEVICE_LINK_OPTS `$PKG_CONFIG --libs libpulse-simple`"
fi
fi
fi
;;
*-pc-windows*)
SOUNDLOW_OBJS='soundwin.o'
Expand Down Expand Up @@ -2145,6 +2132,21 @@ if test "$soundcard_present" = 1; then
AC_DEFINE(BX_HAVE_SDL2_AUDIO_CAPTURE, 1)
fi
fi
if test "$cross_configure" = 0 -a "$DEFAULT_GUI" != win32; then
if test "x$PKG_CONFIG" != x; then
$PKG_CONFIG --exists libpulse-simple
if test x$? = x0; then
SOUNDLOW_OBJS="$SOUNDLOW_OBJS soundpulse.o"
soundlow_drivers="$soundlow_drivers pulse"
AC_DEFINE(BX_HAVE_SOUND_PULSE, 1)
if test "$bx_plugins" = 1; then
PULSE_SOUND_LINK_OPTS="$PULSE_SOUND_LINK_OPTS `$PKG_CONFIG --libs libpulse-simple`"
else
DEVICE_LINK_OPTS="$DEVICE_LINK_OPTS `$PKG_CONFIG --libs libpulse-simple`"
fi
fi
fi
fi
if test "$MSVC_TARGET" = 0; then
AC_CHECK_HEADER([samplerate.h], [bx_have_libsamplerate=1])
if test "$bx_have_libsamplerate" = 1; then
Expand Down
6 changes: 5 additions & 1 deletion bochs/gui/vncsrv.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// Donald Becker
// http://www.psyon.org
//
// Copyright (C) 2001-2023 The Bochs Project
// Copyright (C) 2001-2024 The Bochs Project
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
Expand Down Expand Up @@ -44,6 +44,10 @@
// is used to know when we are exporting symbols and when we are importing.
#define BX_PLUGGABLE

#ifdef __CYGWIN__
#define __USE_W32_SOCKETS
#endif

#include "param_names.h"
#include "iodev.h"
#include "keymap.h"
Expand Down
10 changes: 9 additions & 1 deletion bochs/iodev/sound/soundlow.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// $Id$
/////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2011-2021 The Bochs Project
// Copyright (C) 2011-2024 The Bochs Project
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
Expand Down Expand Up @@ -91,6 +91,13 @@ void bx_audio_buffer_c::delete_buffer()
delete tmpbuffer;
}

void bx_audio_buffer_c::flush()
{
while (root != NULL) {
BX_MSLEEP(1);
}
}

// convert to float format for resampler

static void convert_to_float(Bit8u *src, unsigned srcsize, audio_buffer_t *audiobuf)
Expand Down Expand Up @@ -468,6 +475,7 @@ Bit32u bx_soundlow_waveout_c::resampler_common(audio_buffer_t *inbuffer, float *
#else
if (param.samplerate != real_pcm_param.samplerate) {
real_pcm_param.samplerate = param.samplerate;
audio_buffers[1]->flush();
set_pcm_params(&real_pcm_param);
}
*fbuffer = new float[inbuffer->size];
Expand Down
3 changes: 2 additions & 1 deletion bochs/iodev/sound/soundlow.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// $Id$
/////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2011-2021 The Bochs Project
// Copyright (C) 2011-2024 The Bochs Project
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
Expand Down Expand Up @@ -75,6 +75,7 @@ class bx_audio_buffer_c {
audio_buffer_t *new_buffer(Bit32u size);
audio_buffer_t *get_buffer();
void delete_buffer();
void flush();
private:
Bit8u format;
audio_buffer_t *root;
Expand Down
117 changes: 115 additions & 2 deletions bochs/iodev/sound/soundpulse.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@
// is used to know when we are exporting symbols and when we are importing.
#define BX_PLUGGABLE

// Lowlevel sound output support using PulseAudio simple API
// PCM playback/recording support using PulseAudio simple API

#include "bochs.h"
#include "plugin.h"

#if BX_SUPPORT_SOUNDLOW
#if BX_HAVE_SOUND_PULSE && BX_SUPPORT_SOUNDLOW

#include "pc_system.h"
#include "soundlow.h"
#include "soundpulse.h"

Expand All @@ -51,6 +52,14 @@ bx_soundlow_waveout_c* bx_sound_pulse_c::get_waveout()
return waveout;
}

bx_soundlow_wavein_c* bx_sound_pulse_c::get_wavein()
{
if (wavein == NULL) {
wavein = new bx_soundlow_wavein_pulse_c();
}
return wavein;
}

// bx_sound_waveout_pulse_c class implementation

int bx_soundlow_waveout_pulse_c::openwaveoutput(const char *wavedev)
Expand Down Expand Up @@ -114,4 +123,108 @@ int bx_soundlow_waveout_pulse_c::closewaveoutput()
return BX_SOUNDLOW_OK;
}

// bx_sound_wavein_pulse_c class implementation

bx_soundlow_wavein_pulse_c::bx_soundlow_wavein_pulse_c()
:bx_soundlow_wavein_c()
{
s = NULL;
}

bx_soundlow_wavein_pulse_c::~bx_soundlow_wavein_pulse_c()
{
if (s) {
pa_simple_free(s);
s = NULL;
}
}

int bx_soundlow_wavein_pulse_c::openwaveinput(const char *wavedev, sound_record_handler_t rh)
{
UNUSED(wavedev);
record_handler = rh;
if (rh != NULL) {
record_timer_index = DEV_register_timer(this, record_timer_handler, 1, 1, 0, "wavein");
// record timer: inactive, continuous, frequency variable
}
return BX_SOUNDLOW_OK;
}

int bx_soundlow_wavein_pulse_c::startwaverecord(bx_pcm_param_t *param)
{
pa_sample_spec spec;
int signeddata = param->format & 1;
int pa_error;
Bit64u timer_val;
Bit8u shift = 0;

if (record_timer_index != BX_NULL_TIMER_HANDLE) {
if (param->bits == 16) shift++;
if (param->channels == 2) shift++;
record_packet_size = (param->samplerate / 10) << shift; // 0.1 sec
if (record_packet_size > BX_SOUNDLOW_WAVEPACKETSIZE) {
record_packet_size = BX_SOUNDLOW_WAVEPACKETSIZE;
}
timer_val = (Bit64u)record_packet_size * 1000000 / (param->samplerate << shift);
bx_pc_system.activate_timer(record_timer_index, (Bit32u)timer_val, 1);
}
if (memcmp(param, &wavein_param, sizeof(bx_pcm_param_t)) != 0) {
wavein_param = *param;

if (s) {
pa_simple_free(s);
s = NULL;
}
if ((param->bits == 16) && (signeddata == 1)) {
spec.format = PA_SAMPLE_S16LE;
} else if ((param->bits == 8) && (signeddata == 0)) {
spec.format = PA_SAMPLE_U8;
} else {
return BX_SOUNDLOW_ERR;
}
spec.channels = param->channels;
spec.rate = param->samplerate;
if (!(s = pa_simple_new(NULL, "bochs", PA_STREAM_RECORD, NULL, "record", &spec, NULL, NULL, &pa_error))) {
BX_ERROR(("pa_simple_new() failed: %s", pa_strerror(pa_error)));
return BX_SOUNDLOW_ERR;
}
}
return BX_SOUNDLOW_OK;
}

int bx_soundlow_wavein_pulse_c::getwavepacket(int length, Bit8u data[])
{
int pa_error;

if (s) {
if (pa_simple_read(s, data, length, &pa_error) < 0) {
BX_ERROR(("pa_simple_read() failed: %s", pa_strerror(pa_error)));
return BX_SOUNDLOW_ERR;
}
} else {
memset(data, 0, length);
}
return BX_SOUNDLOW_OK;
}

int bx_soundlow_wavein_pulse_c::stopwaverecord()
{
if (record_timer_index != BX_NULL_TIMER_HANDLE) {
bx_pc_system.deactivate_timer(record_timer_index);
}
return BX_SOUNDLOW_OK;
}

void bx_soundlow_wavein_pulse_c::record_timer_handler(void *this_ptr)
{
bx_soundlow_wavein_pulse_c *class_ptr = (bx_soundlow_wavein_pulse_c *) this_ptr;

class_ptr->record_timer();
}

void bx_soundlow_wavein_pulse_c::record_timer(void)
{
record_handler(this, record_packet_size);
}

#endif // BX_HAVE_SOUND_PULSE
22 changes: 21 additions & 1 deletion bochs/iodev/sound/soundpulse.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA

// Lowlevel sound output support using PulseAudio simple API
// PCM playback/recording support using PulseAudio simple API

#if BX_HAVE_SOUND_PULSE

Expand All @@ -31,6 +31,7 @@ class bx_sound_pulse_c : public bx_sound_lowlevel_c {
virtual ~bx_sound_pulse_c() {}

virtual bx_soundlow_waveout_c* get_waveout();
virtual bx_soundlow_wavein_c* get_wavein();
} bx_sound_pulse;

// the pulse waveout class
Expand All @@ -49,4 +50,23 @@ class bx_soundlow_waveout_pulse_c : public bx_soundlow_waveout_c {
pa_simple *s;
};

// the pulse waveoin class

class bx_soundlow_wavein_pulse_c : public bx_soundlow_wavein_c {
public:
bx_soundlow_wavein_pulse_c();
virtual ~bx_soundlow_wavein_pulse_c();

virtual int openwaveinput(const char *wavedev, sound_record_handler_t rh);
virtual int startwaverecord(bx_pcm_param_t *param);
virtual int getwavepacket(int length, Bit8u data[]);
virtual int stopwaverecord();

static void record_timer_handler(void *);
void record_timer(void);
private:
bx_pcm_param_t wavein_param;
pa_simple *s;
};

#endif // BX_HAVE_SOUND_PULSE
Loading

0 comments on commit 27519fc

Please sign in to comment.