} conf = {0x220, 44100};
typedef struct {
+ QEMUSoundCard card;
int ticking[2];
int enabled;
int active;
#endif
} AdlibState;
-static AdlibState adlib;
+static AdlibState glob_adlib;
static void adlib_stop_opl_timer (AdlibState *s, size_t n)
{
if (s->ticking[i]) {
uint64_t delta;
- delta = AUD_time_stamp_get_elapsed_usec_out (s->voice, &s->ats);
+ delta = AUD_get_elapsed_usec_out (s->voice, &s->ats);
ldebug (
"delta = %f dexp = %f expired => %d\n",
delta / 1000000.0,
static void timer_handler (int c, double interval_Sec)
{
- AdlibState *s = &adlib;
+ AdlibState *s = &glob_adlib;
unsigned n = c & 1;
#ifdef DEBUG
double interval;
+ int64_t exp;
#endif
if (interval_Sec == 0.0) {
s->active = 0;
s->enabled = 0;
+ AUD_remove_card (&s->card);
}
-void Adlib_init (void)
+int Adlib_init (AudioState *audio, qemu_irq *pic)
{
- AdlibState *s = &adlib;
+ AdlibState *s = &glob_adlib;
+ audsettings_t as;
+
+ if (!audio) {
+ dolog ("No audio state\n");
+ return -1;
+ }
#ifdef HAS_YMF262
if (YMF262Init (1, 14318180, conf.freq)) {
dolog ("YMF262Init %d failed\n", conf.freq);
- return;
+ return -1;
}
else {
YMF262SetTimerHandler (0, timer_handler, 0);
s->opl = OPLCreate (OPL_TYPE_YM3812, 3579545, conf.freq);
if (!s->opl) {
dolog ("OPLCreate %d failed\n", conf.freq);
- return;
+ return -1;
}
else {
OPLSetTimerHandler (s->opl, timer_handler, 0);
}
#endif
+ as.freq = conf.freq;
+ as.nchannels = SHIFT;
+ as.fmt = AUD_FMT_S16;
+ as.endianness = AUDIO_HOST_ENDIANNESS;
+
+ AUD_register_card (audio, "adlib", &s->card);
+
s->voice = AUD_open_out (
+ &s->card,
s->voice,
"adlib",
s,
adlib_callback,
- conf.freq,
- SHIFT,
- AUD_FMT_S16
+ &as
);
if (!s->voice) {
Adlib_fini (s);
- return;
+ return -1;
}
s->samples = AUD_get_buffer_size_out (s->voice) >> SHIFT;
s->mixbuf = qemu_mallocz (s->samples << SHIFT);
if (!s->mixbuf) {
- dolog ("not enough memory for adlib mixing buffer (%d)\n",
- s->samples << SHIFT);
+ dolog ("Could not allocate mixing buffer, %d samples (each %d bytes)\n",
+ s->samples, 1 << SHIFT);
Adlib_fini (s);
- return;
+ return -1;
}
register_ioport_read (0x388, 4, 1, adlib_read, s);
register_ioport_read (conf.port + 8, 2, 1, adlib_read, s);
register_ioport_write (conf.port + 8, 2, 1, adlib_write, s);
+
+ return 0;
}