Implemented support for the new mixer thread in the lowlevel sound module 'osx'

(untested). Started code cleanup in the Bochs sound code.
This commit is contained in:
Volker Ruppert 2015-02-07 22:15:22 +00:00
parent 9c1070cbed
commit fafc153a30
15 changed files with 28 additions and 159 deletions

View File

@ -790,9 +790,6 @@ void bx_es1370_c::update_voices(Bit32u ctl, Bit32u sctl, bx_bool force)
}
} else {
if (((int)i == BX_ES1370_THIS s.dac_nr_active) && BX_ES1370_THIS s.dac_outputinit) {
if (BX_ES1370_THIS wavemode == 1) {
BX_ES1370_THIS soundmod->stopwaveplayback();
}
BX_ES1370_THIS s.dac_nr_active = -1;
}
bx_pc_system.deactivate_timer(timer_id);

View File

@ -1458,9 +1458,7 @@ void bx_sb16_c::dsp_dmadone()
if ((DSP.dma.output == 1) && (DSP.dma.mode != 2)) {
dsp_sendwavepacket(); // flush the output
if (BX_SB16_THIS wavemode == 1) {
BX_SB16_OUTPUT->stopwaveplayback();
} else if (BX_SB16_THIS wavemode != 0) {
if (BX_SB16_THIS wavemode > 1) {
fflush(WAVEDATA);
}
} else if ((DSP.dma.output == 0) && (DSP.dma.mode != 2)) {

View File

@ -423,14 +423,4 @@ void bx_sound_alsa_c::record_timer(void)
record_handler(this, record_packet_size);
}
int bx_sound_alsa_c::register_wave_callback(void *arg, get_wave_cb_t wd_cb)
{
if (cb_count < BX_MAX_WAVE_CALLBACKS) {
get_wave[cb_count].device = arg;
get_wave[cb_count].cb = wd_cb;
return cb_count++;
}
return -1;
}
#endif

View File

@ -54,8 +54,6 @@ public:
static void record_timer_handler(void *);
void record_timer(void);
virtual int register_wave_callback(void *, get_wave_cb_t wd_cb);
private:
int alsa_seq_open(const char *alsadev);
int alsa_seq_output(int delta, int command, int length, Bit8u data[]);

View File

@ -336,14 +336,4 @@ void bx_sound_oss_c::record_timer(void)
record_handler(this, record_packet_size);
}
int bx_sound_oss_c::register_wave_callback(void *arg, get_wave_cb_t wd_cb)
{
if (cb_count < BX_MAX_WAVE_CALLBACKS) {
get_wave[cb_count].device = arg;
get_wave[cb_count].cb = wd_cb;
return cb_count++;
}
return -1;
}
#endif

View File

@ -50,8 +50,6 @@ public:
static void record_timer_handler(void *);
void record_timer(void);
virtual int register_wave_callback(void *, get_wave_cb_t wd_cb);
private:
FILE *midi;
int wave_fd[2];

View File

@ -188,11 +188,6 @@ int bx_sound_lowlevel_c::openwaveoutput(const char *wavedev)
return BX_SOUNDLOW_OK;
}
int bx_sound_lowlevel_c::waveready()
{
return BX_SOUNDLOW_OK;
}
int bx_sound_lowlevel_c::set_pcm_params(bx_pcm_param_t param)
{
UNUSED(param);
@ -288,11 +283,6 @@ int bx_sound_lowlevel_c::waveout(int length, Bit8u data[])
return BX_SOUNDLOW_OK;
}
int bx_sound_lowlevel_c::stopwaveplayback()
{
return BX_SOUNDLOW_OK;
}
int bx_sound_lowlevel_c::closewaveoutput()
{
return BX_SOUNDLOW_OK;
@ -348,6 +338,16 @@ bx_bool bx_sound_lowlevel_c::mixer_common(Bit8u *buffer, int len)
return (len3 > 0);
}
int bx_sound_lowlevel_c::register_wave_callback(void *arg, get_wave_cb_t wd_cb)
{
if (cb_count < BX_MAX_WAVE_CALLBACKS) {
get_wave[cb_count].device = arg;
get_wave[cb_count].cb = wd_cb;
return cb_count++;
}
return -1;
}
void bx_sound_lowlevel_c::unregister_wave_callback(int callback_id)
{
BX_LOCK(mixer_mutex);

View File

@ -90,12 +90,10 @@ public:
virtual int closemidioutput();
virtual int openwaveoutput(const char *wavedev);
virtual int waveready();
virtual int set_pcm_params(bx_pcm_param_t param);
virtual int sendwavepacket(int length, Bit8u data[], bx_pcm_param_t *src_param);
virtual int get_waveout_packetsize();
virtual int waveout(int length, Bit8u data[]);
virtual int stopwaveplayback();
virtual int closewaveoutput();
virtual int openwaveinput(const char *wavedev, sound_record_handler_t rh);
@ -107,7 +105,7 @@ public:
static void record_timer_handler(void *);
void record_timer(void);
virtual int register_wave_callback(void *, get_wave_cb_t wd_cb) {return -1;}
virtual int register_wave_callback(void *, get_wave_cb_t wd_cb);
virtual void unregister_wave_callback(int callback_id);
virtual bx_bool mixer_common(Bit8u *buffer, int len);

View File

@ -48,15 +48,9 @@
bx_soundmod_ctl_c* theSoundModCtl = NULL;
BX_THREAD_ID(threadID);
BX_MUTEX(beep_mutex);
static int beep_control;
Bit8u *beep_buffer;
unsigned int beep_bufsize;
bx_pcm_param_t beep_param;
Bit32u beep_callback(void *dev, Bit16u rate, Bit8u *buffer, Bit32u len);
BX_THREAD_FUNC(beep_thread, indata);
int CDECL libsoundmod_LTX_plugin_init(plugin_t *plugin, plugintype_t type, int argc, char *argv[])
{
@ -83,13 +77,7 @@ bx_soundmod_ctl_c::bx_soundmod_ctl_c()
bx_soundmod_ctl_c::~bx_soundmod_ctl_c()
{
beep_active = 0;
if (beep_callback_id < 0) {
beep_control = 0;
while (beep_control >= 0) {
BX_MSLEEP(1);
}
free(beep_buffer);
} else {
if (beep_callback_id >= 0) {
soundmod->unregister_wave_callback(beep_callback_id);
}
if (soundmod != NULL) {
@ -146,15 +134,6 @@ void bx_soundmod_ctl_c::init()
beep_cur_freq = 0.0;
BX_INIT_MUTEX(beep_mutex);
beep_callback_id = soundmod->register_wave_callback(theSoundModCtl, beep_callback);
if (beep_callback_id < 0) {
beep_bufsize = 4410;
beep_buffer = (Bit8u*)malloc(beep_bufsize);
beep_param.samplerate = 44100;
beep_param.bits = 16;
beep_param.channels = 2;
beep_param.format = 1;
BX_THREAD_CREATE(beep_thread, soundmod, threadID);
}
}
}
@ -196,29 +175,6 @@ Bit32u beep_callback(void *dev, Bit16u rate, Bit8u *buffer, Bit32u len)
return ((bx_soundmod_ctl_c*)dev)->beep_generator(rate, buffer, len);
}
BX_THREAD_FUNC(beep_thread, indata)
{
Bit32u len = 0;
bx_sound_lowlevel_c *soundmod = (bx_sound_lowlevel_c*)indata;
beep_control = 1;
while (beep_control > 0) {
len = theSoundModCtl->beep_generator(44100, beep_buffer, beep_bufsize);
if (len > 0) {
soundmod->sendwavepacket(beep_bufsize, beep_buffer, &beep_param);
if (soundmod->get_type() == BX_SOUNDLOW_WIN) {
BX_MSLEEP(25);
} else {
BX_MSLEEP(1);
}
} else {
BX_MSLEEP(25);
}
}
beep_control = -1;
BX_THREAD_EXIT;
}
bx_bool bx_soundmod_ctl_c::beep_on(float frequency)
{
if (soundmod != NULL) {

View File

@ -245,12 +245,17 @@ int bx_sound_osx_c::openwaveoutput(const char *wavedev)
}
#endif
WaveOpen = 1;
return BX_SOUNDLOW_OK;
set_pcm_params(real_pcm_param);
pcm_callback_id = register_wave_callback(this, pcm_callback);
BX_INIT_MUTEX(mixer_mutex);
start_mixer_thread();
WaveOpen = 1;
return BX_SOUNDLOW_OK;
}
#ifdef BX_SOUND_OSX_use_converter
OSStatus bx_sound_osx_c::core_audio_pause() {
OSStatus bx_sound_osx_c::core_audio_pause()
{
OSStatus err = noErr;
if (WaveOutputUnit) {
@ -264,7 +269,8 @@ OSStatus bx_sound_osx_c::core_audio_pause() {
return err;
}
OSStatus bx_sound_osx_c::core_audio_resume() {
OSStatus bx_sound_osx_c::core_audio_resume()
{
OSStatus err = noErr;
if (WaveConverter) {
@ -386,45 +392,13 @@ int bx_sound_osx_c::set_pcm_params(bx_pcm_param_t param)
return BX_SOUNDLOW_OK;
}
int bx_sound_osx_c::waveready()
int bx_sound_osx_c::waveout(int length, Bit8u data[])
{
// HACK: the -4 is to keep from overwriting buffers that
// have been sent, but possibly not yet played. There
// should be a better way of doing this.
if (WaveOpen && (head - tail < BX_SOUND_OSX_NBUF-4)) {
return BX_SOUNDLOW_OK;
}
else {
#ifdef BX_SOUND_OSX_use_converter
// If buffer is full, make sure sound is playing
if (!WavePlaying) {
if (core_audio_resume() != noErr)
return BX_SOUNDLOW_ERR;
}
#endif
return BX_SOUNDLOW_ERR;
}
}
int bx_sound_osx_c::sendwavepacket(int length, Bit8u data[], bx_pcm_param_t *src_param)
{
int len2;
#ifdef BX_SOUND_OSX_use_quicktime
SndCommand mySndCommand;
#endif
BX_DEBUG(("sendwavepacket(%d, %p), head=%u", length, data, head));
if (memcmp(src_param, &emu_pcm_param, sizeof(bx_pcm_param_t)) != 0) {
emu_pcm_param = *src_param;
cvt_mult = (src_param->bits == 8) ? 2 : 1;
if (src_param->channels == 1) cvt_mult <<= 1;
if (src_param->samplerate != real_pcm_param.samplerate) {
real_pcm_param.samplerate = src_param->samplerate;
set_pcm_params(real_pcm_param);
}
}
len2 = length * cvt_mult;
BX_DEBUG(("waveout(%d, %p), head=%u", length, data, head));
// sanity check
if ((!WaveOpen) || (head - tail >= BX_SOUND_OSX_NBUF))
@ -434,8 +408,8 @@ int bx_sound_osx_c::sendwavepacket(int length, Bit8u data[], bx_pcm_param_t *src
int n = head++ % BX_SOUND_OSX_NBUF;
// put data in buffer
convert_pcm_data(data, length, (Bit8u*)WaveData[n], len2, src_param);
WaveLength[n] = len2;
memcpy(WaveData[n], data, length);
WaveLength[n] = length;
#ifdef BX_SOUND_OSX_use_quicktime
memcpy(&WaveHeader[n], &WaveInfo, sizeof(WaveInfo));
@ -467,11 +441,6 @@ int bx_sound_osx_c::sendwavepacket(int length, Bit8u data[], bx_pcm_param_t *src
return BX_SOUNDLOW_OK;
}
int bx_sound_osx_c::stopwaveplayback()
{
return BX_SOUNDLOW_OK;
}
int bx_sound_osx_c::closewaveoutput()
{
#ifdef BX_SOUND_OSX_use_converter

View File

@ -49,10 +49,8 @@ public:
virtual int closemidioutput();
virtual int openwaveoutput(const char *wavedev);
virtual int waveready();
virtual int set_pcm_params(bx_pcm_param_t param);
virtual int sendwavepacket(int length, Bit8u data[], bx_pcm_param_t *src_param);
virtual int stopwaveplayback();
virtual int waveout(int length, Bit8u data[]);
virtual int closewaveoutput();
#ifdef BX_SOUND_OSX_use_converter
void nextbuffer(int *outDataSize, void **outData);

View File

@ -155,16 +155,6 @@ bx_bool bx_sound_sdl_c::mixer_common(Bit8u *buffer, int len)
return 1;
}
int bx_sound_sdl_c::register_wave_callback(void *arg, get_wave_cb_t wd_cb)
{
if (cb_count < BX_MAX_WAVE_CALLBACKS) {
get_wave[cb_count].device = arg;
get_wave[cb_count].cb = wd_cb;
return cb_count++;
}
return -1;
}
void bx_sound_sdl_c::unregister_wave_callback(int callback_id)
{
SDL_LockAudio();

View File

@ -38,7 +38,6 @@ public:
virtual int sendwavepacket(int length, Bit8u data[], bx_pcm_param_t *src_param);
virtual int closewaveoutput();
virtual int register_wave_callback(void *, get_wave_cb_t wd_cb);
virtual void unregister_wave_callback(int callback_id);
virtual bx_bool mixer_common(Bit8u *buffer, int len);
private:

View File

@ -453,14 +453,4 @@ void bx_sound_windows_c::record_timer(void)
record_handler(this, record_packet_size);
}
int bx_sound_windows_c::register_wave_callback(void *arg, get_wave_cb_t wd_cb)
{
if (cb_count < BX_MAX_WAVE_CALLBACKS) {
get_wave[cb_count].device = arg;
get_wave[cb_count].cb = wd_cb;
return cb_count++;
}
return -1;
}
#endif // defined(WIN32)

View File

@ -185,8 +185,6 @@ public:
static void record_timer_handler(void *);
void record_timer(void);
virtual int register_wave_callback(void *, get_wave_cb_t wd_cb);
private:
struct bx_sound_waveinfo_struct {
int frequency;