Skip to content

Commit

Permalink
SB16: Fixes for wavemode 2 and 3.
Browse files Browse the repository at this point in the history
Fixed segfault in this case by moving audio buffers to the waveout class.
Redirect fmopl output to the file driver in wavemode 2.
  • Loading branch information
vruppert committed Dec 23, 2024
1 parent 0a828b5 commit 2d0daf5
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
6 changes: 4 additions & 2 deletions bochs/iodev/sound/sb16.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// $Id$
/////////////////////////////////////////////////////////////////////////
//
// 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 @@ -274,13 +274,15 @@ void bx_sb16_c::init(void)
if (BX_SB16_WAVEOUT1 == NULL) {
BX_PANIC(("Couldn't initialize waveout driver"));
BX_SB16_THIS wavemode &= ~1;
} else {
} else if (BX_SB16_THIS wavemode & 1) {
BX_SB16_THIS fmopl_callback_id = BX_SB16_WAVEOUT1->register_wave_callback(BX_SB16_THISP, fmopl_callback);
}
if (BX_SB16_THIS wavemode & 2) {
BX_SB16_WAVEOUT2 = DEV_sound_get_waveout(1);
if (BX_SB16_WAVEOUT2 == NULL) {
BX_PANIC(("Couldn't initialize wave file driver"));
} else if (BX_SB16_THIS wavemode == 2) {
BX_SB16_THIS fmopl_callback_id = BX_SB16_WAVEOUT2->register_wave_callback(BX_SB16_THISP, fmopl_callback);
}
}
BX_SB16_WAVEIN = DEV_sound_get_wavein();
Expand Down
12 changes: 5 additions & 7 deletions bochs/iodev/sound/soundlow.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@

// audio buffer support

bx_audio_buffer_c *audio_buffers[2];

bx_audio_buffer_c::bx_audio_buffer_c(Bit8u _format)
{
format = _format;
Expand Down Expand Up @@ -174,11 +172,11 @@ void convert_float_to_s16le(float *src, unsigned srcsize, Bit8u *dst)
Bit32u pcm_callback(void *dev, Bit16u rate, Bit8u *buffer, Bit32u len)
{
Bit32u copied = 0;
UNUSED(dev);
UNUSED(rate);
bx_soundlow_waveout_c *waveout = (bx_soundlow_waveout_c*)dev;

while (len > 0) {
audio_buffer_t *curbuffer = audio_buffers[1]->get_buffer();
audio_buffer_t *curbuffer = waveout->get_audio_buffer(1)->get_buffer();
if (curbuffer == NULL)
break;
Bit32u tmplen = curbuffer->size - curbuffer->pos;
Expand All @@ -192,7 +190,7 @@ Bit32u pcm_callback(void *dev, Bit16u rate, Bit8u *buffer, Bit32u len)
len -= tmplen;
}
if (curbuffer->pos >= curbuffer->size) {
audio_buffers[1]->delete_buffer();
waveout->get_audio_buffer(1)->delete_buffer();
}
}
return copied;
Expand All @@ -208,12 +206,12 @@ BX_THREAD_FUNC(resampler_thread, indata)
bx_soundlow_waveout_c *waveout = (bx_soundlow_waveout_c*)indata;
while (waveout->resampler_running()) {
BX_LOCK(resampler_mutex);
audio_buffer_t *curbuffer = audio_buffers[0]->get_buffer();
audio_buffer_t *curbuffer = waveout->get_audio_buffer(0)->get_buffer();
BX_UNLOCK(resampler_mutex);
if (curbuffer != NULL) {
waveout->resampler(curbuffer, NULL);
BX_LOCK(resampler_mutex);
audio_buffers[0]->delete_buffer();
waveout->get_audio_buffer(0)->delete_buffer();
BX_UNLOCK(resampler_mutex);
} else {
BX_MSLEEP(20);
Expand Down
3 changes: 3 additions & 0 deletions bochs/iodev/sound/soundlow.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ class BOCHSAPI_MSVCONLY bx_soundlow_waveout_c : public logfunctions {
bool resampler_running() {return res_thread_start;}
bool mixer_running() {return mix_thread_start;}

bx_audio_buffer_c *get_audio_buffer(int n) {return audio_buffers[n];}

protected:
void start_resampler_thread(void);
void start_mixer_thread(void);
Expand All @@ -127,6 +129,7 @@ class BOCHSAPI_MSVCONLY bx_soundlow_waveout_c : public logfunctions {
#if BX_HAVE_LIBSAMPLERATE || BX_HAVE_SOXR_LSR
SRC_STATE *src_state;
#endif
bx_audio_buffer_c *audio_buffers[2];

int cb_count;
struct {
Expand Down

0 comments on commit 2d0daf5

Please sign in to comment.