static bool audio_state_sndboard_qemu(int streamid, void *params)
{
- SWVoiceOut *out = qemu_voice_out;
+ SWVoiceOut *out = (SWVoiceOut*)params;
if (!out || !out->active)
return false;
return true;
}
-static void calculate_volume_qemu(void)
+static void calculate_volume_qemu(SWVoiceOut *out)
{
- SWVoiceOut *out = qemu_voice_out;
if (!out)
return;
out->left_volume = (100 - currprefs.sound_volume_board) * 32768 / 100;
out->right_volume = (100 - currprefs.sound_volume_board) * 32768 / 100;
}
+static void calculate_volume_qemu_all(void)
+{
+ for (SWVoiceOut *out = qemu_voice_out; out; out = out->next) {
+ calculate_volume_qemu(out);
+ }
+}
+
+static bool qemu_voice_out_active(void)
+{
+ for (SWVoiceOut *out = qemu_voice_out; out; out = out->next) {
+ if (out->active)
+ return true;
+ }
+ return false;
+}
+
void AUD_close_in(QEMUSoundCard *card, SWVoiceIn *sw)
{
}
int AUD_read(SWVoiceIn *sw, void *pcm_buf, int size)
{
- return size;
+ return 0;
}
int AUD_write(SWVoiceOut *sw, void *pcm_buf, int size)
{
+ if (!sw || !pcm_buf || size <= 0)
+ return 0;
+ if (size > (int)sizeof(sw->samplebuf))
+ size = sizeof(sw->samplebuf);
memcpy(sw->samplebuf, pcm_buf, size);
sw->samplebuf_total = size;
return sw->samplebuf_total;
}
void AUD_set_active_out(SWVoiceOut *sw, int on)
{
+ if (!sw)
+ return;
sw->active = on != 0;
sw->event_time = (int)(base_event_clock * CYCLE_UNIT / sw->freq);
sw->samplebuf_index = 0;
sw->samplebuf_total = 0;
- calculate_volume_qemu();
+ calculate_volume_qemu(sw);
audio_enable_stream(false, sw->streamid, 2, NULL, NULL);
sw->streamid = 0;
if (on) {
- sw->streamid = audio_enable_stream(true, -1, 2, audio_state_sndboard_qemu, NULL);
+ sw->streamid = audio_enable_stream(true, -1, 2, audio_state_sndboard_qemu, sw);
}
}
void AUD_set_active_in(SWVoiceIn *sw, int on)
}
void AUD_close_out(QEMUSoundCard *card, SWVoiceOut *sw)
{
- qemu_voice_out = NULL;
if (sw) {
+ SWVoiceOut **outp = &qemu_voice_out;
+ while (*outp) {
+ if (*outp == sw) {
+ *outp = sw->next;
+ break;
+ }
+ outp = &(*outp)->next;
+ }
audio_enable_stream(false, sw->streamid, 0, NULL, NULL);
sw->streamid = 0;
xfree(sw);
struct audsettings *settings)
{
SWVoiceOut *out = sw;
- if (!sw)
+ if (!sw) {
out = xcalloc(SWVoiceOut, 1);
+ out->next = qemu_voice_out;
+ qemu_voice_out = out;
+ }
int bits = 8;
if (settings->fmt >= AUD_FMT_U16)
write_log(_T("QEMU AUDIO: freq=%d ch=%d bits=%d (fmt=%d) '%s'\n"), out->freq, out->ch, bits, settings->fmt, name2);
xfree(name2);
- qemu_voice_out = out;
-
return out;
}
sndboard_vsync_toccata(&snddev[0]);
if (fm801_active)
sndboard_vsync_fm801();
- if (qemu_voice_out && qemu_voice_out->active)
+ if (qemu_voice_out_active())
sndboard_vsync_qemu();
}
calculate_volume_toccata(&snddev[0]);
if (fm801_active)
calculate_volume_fm801();
- if (qemu_voice_out && qemu_voice_out->active)
- calculate_volume_qemu();
+ calculate_volume_qemu_all();
}
static void snd_init(void)