}
static CaptureVoiceOut *audio_pcm_capture_find_specific (
- AudioState *s,
struct audsettings *as
)
{
CaptureVoiceOut *cap;
+ AudioState *s = &glob_audio_state;
for (cap = s->cap_head.lh_first; cap; cap = cap->entries.le_next) {
if (audio_pcm_info_eq (&cap->hw.info, as)) {
}
}
-static int audio_attach_capture (AudioState *s, HWVoiceOut *hw)
+static int audio_attach_capture (HWVoiceOut *hw)
{
+ AudioState *s = &glob_audio_state;
CaptureVoiceOut *cap;
audio_detach_capture (hw);
HWVoiceOut *hw = NULL;
SWVoiceOut *sw;
- while ((hw = audio_pcm_hw_find_any_enabled_out (s, hw))) {
+ while ((hw = audio_pcm_hw_find_any_enabled_out (hw))) {
int played;
int live, free, nb_live, cleanup_required, prev_rpos;
#ifdef DEBUG_PLIVE
dolog ("Finishing with old voice\n");
#endif
- audio_close_out (s, sw);
+ audio_close_out (sw);
}
sw = sw1;
}
{
HWVoiceIn *hw = NULL;
- while ((hw = audio_pcm_hw_find_any_enabled_in (s, hw))) {
+ while ((hw = audio_pcm_hw_find_any_enabled_in (hw))) {
SWVoiceIn *sw;
int captured, min;
s->drv_opaque = drv->init ();
if (s->drv_opaque) {
- audio_init_nb_voices_out (s, drv);
- audio_init_nb_voices_in (s, drv);
+ audio_init_nb_voices_out (drv);
+ audio_init_nb_voices_in (drv);
s->drv = drv;
return 0;
}
int op = running ? VOICE_ENABLE : VOICE_DISABLE;
s->vm_running = running;
- while ((hwo = audio_pcm_hw_find_any_enabled_out (s, hwo))) {
+ while ((hwo = audio_pcm_hw_find_any_enabled_out (hwo))) {
hwo->pcm_ops->ctl_out (hwo, op);
}
- while ((hwi = audio_pcm_hw_find_any_enabled_in (s, hwi))) {
+ while ((hwi = audio_pcm_hw_find_any_enabled_in (hwi))) {
hwi->pcm_ops->ctl_in (hwi, op);
}
}
HWVoiceOut *hwo = NULL;
HWVoiceIn *hwi = NULL;
- while ((hwo = audio_pcm_hw_find_any_enabled_out (s, hwo))) {
+ while ((hwo = audio_pcm_hw_find_any_enabled_out (hwo))) {
SWVoiceCap *sc;
hwo->pcm_ops->ctl_out (hwo, VOICE_DISABLE);
}
}
- while ((hwi = audio_pcm_hw_find_any_enabled_in (s, hwi))) {
+ while ((hwi = audio_pcm_hw_find_any_enabled_in (hwi))) {
hwi->pcm_ops->ctl_in (hwi, VOICE_DISABLE);
hwi->pcm_ops->fini_in (hwi);
}
return 0;
}
-void AUD_register_card (AudioState *s, const char *name, QEMUSoundCard *card)
-{
- card->audio = s;
- card->name = qemu_strdup (name);
- memset (&card->entries, 0, sizeof (card->entries));
- LIST_INSERT_HEAD (&s->card_head, card, entries);
-}
-
-void AUD_remove_card (QEMUSoundCard *card)
-{
- LIST_REMOVE (card, entries);
- card->audio = NULL;
- qemu_free (card->name);
-}
-
-AudioState *AUD_init (void)
+static void audio_init (void)
{
size_t i;
int done = 0;
const char *drvname;
AudioState *s = &glob_audio_state;
+ if (s->drv) {
+ return;
+ }
+
LIST_INIT (&s->hw_head_out);
LIST_INIT (&s->hw_head_in);
LIST_INIT (&s->cap_head);
s->ts = qemu_new_timer (vm_clock, audio_timer, s);
if (!s->ts) {
- dolog ("Could not create audio timer\n");
- return NULL;
+ hw_error("Could not create audio timer\n");
}
audio_process_options ("AUDIO", audio_options);
if (!done) {
done = !audio_driver_init (s, &no_audio_driver);
if (!done) {
- dolog ("Could not initialize audio subsystem\n");
+ hw_error("Could not initialize audio subsystem\n");
}
else {
dolog ("warning: Using timer based audio emulation\n");
}
}
- if (done) {
- VMChangeStateEntry *e;
-
- if (conf.period.hertz <= 0) {
- if (conf.period.hertz < 0) {
- dolog ("warning: Timer period is negative - %d "
- "treating as zero\n",
- conf.period.hertz);
- }
- conf.period.ticks = 1;
- }
- else {
- conf.period.ticks = ticks_per_sec / conf.period.hertz;
- }
+ VMChangeStateEntry *e;
- e = qemu_add_vm_change_state_handler (audio_vm_change_state_handler, s);
- if (!e) {
- dolog ("warning: Could not register change state handler\n"
- "(Audio can continue looping even after stopping the VM)\n");
+ if (conf.period.hertz <= 0) {
+ if (conf.period.hertz < 0) {
+ dolog ("warning: Timer period is negative - %d "
+ "treating as zero\n",
+ conf.period.hertz);
}
+ conf.period.ticks = 1;
+ } else {
+ conf.period.ticks = ticks_per_sec / conf.period.hertz;
}
- else {
- qemu_del_timer (s->ts);
- return NULL;
+
+ e = qemu_add_vm_change_state_handler (audio_vm_change_state_handler, s);
+ if (!e) {
+ dolog ("warning: Could not register change state handler\n"
+ "(Audio can continue looping even after stopping the VM)\n");
}
LIST_INIT (&s->card_head);
register_savevm ("audio", 0, 1, audio_save, audio_load, s);
qemu_mod_timer (s->ts, qemu_get_clock (vm_clock) + conf.period.ticks);
- return s;
}
+void AUD_register_card (const char *name, QEMUSoundCard *card)
+{
+ audio_init ();
+ card->name = qemu_strdup (name);
+ memset (&card->entries, 0, sizeof (card->entries));
+ LIST_INSERT_HEAD (&glob_audio_state.card_head, card, entries);
+}
+
+void AUD_remove_card (QEMUSoundCard *card)
+{
+ LIST_REMOVE (card, entries);
+ qemu_free (card->name);
+}
+
+
CaptureVoiceOut *AUD_add_capture (
- AudioState *s,
struct audsettings *as,
struct audio_capture_ops *ops,
void *cb_opaque
)
{
+ AudioState *s = &glob_audio_state;
CaptureVoiceOut *cap;
struct capture_callback *cb;
- if (!s) {
- /* XXX suppress */
- s = &glob_audio_state;
- }
-
if (audio_validate_settings (as)) {
dolog ("Invalid settings were passed when trying to add capture\n");
audio_print_settings (as);
cb->ops = *ops;
cb->opaque = cb_opaque;
- cap = audio_pcm_capture_find_specific (s, as);
+ cap = audio_pcm_capture_find_specific (as);
if (cap) {
LIST_INSERT_HEAD (&cap->cb_head, cb, entries);
return cap;
LIST_INSERT_HEAD (&cap->cb_head, cb, entries);
hw = NULL;
- while ((hw = audio_pcm_hw_find_any_out (s, hw))) {
- audio_attach_capture (s, hw);
+ while ((hw = audio_pcm_hw_find_any_out (hw))) {
+ audio_attach_capture (hw);
}
return cap;