fmodaudio.c 16.9 KB
Newer Older
bellard's avatar
bellard committed
1
/*
2 3 4 5
 * QEMU FMOD audio driver
 *
 * Copyright (c) 2004-2005 Vassili Karpov (malc)
 *
bellard's avatar
bellard committed
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */
#include <fmod.h>
#include <fmod_errors.h>
pbrook's avatar
pbrook committed
26 27
#include "qemu-common.h"
#include "audio.h"
bellard's avatar
bellard committed
28

29 30
#define AUDIO_CAP "fmod"
#include "audio_int.h"
31

32 33
typedef struct FMODVoiceOut {
    HWVoiceOut hw;
34 35 36
    unsigned int old_pos;
    FSOUND_SAMPLE *fmod_sample;
    int channel;
37
} FMODVoiceOut;
bellard's avatar
bellard committed
38

39 40 41 42
typedef struct FMODVoiceIn {
    HWVoiceIn hw;
    FSOUND_SAMPLE *fmod_sample;
} FMODVoiceIn;
bellard's avatar
bellard committed
43 44

static struct {
45
    const char *drvname;
bellard's avatar
bellard committed
46 47 48 49
    int nb_samples;
    int freq;
    int nb_channels;
    int bufsize;
50
    int broken_adc;
bellard's avatar
bellard committed
51
} conf = {
52 53 54
    .nb_samples  = 2048 * 2,
    .freq        = 44100,
    .nb_channels = 2,
bellard's avatar
bellard committed
55 56
};

57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
static void GCC_FMT_ATTR (1, 2) fmod_logerr (const char *fmt, ...)
{
    va_list ap;

    va_start (ap, fmt);
    AUD_vlog (AUDIO_CAP, fmt, ap);
    va_end (ap);

    AUD_log (AUDIO_CAP, "Reason: %s\n",
             FMOD_ErrorString (FSOUND_GetError ()));
}

static void GCC_FMT_ATTR (2, 3) fmod_logerr2 (
    const char *typ,
    const char *fmt,
    ...
    )
{
    va_list ap;

bellard's avatar
bellard committed
77
    AUD_log (AUDIO_CAP, "Could not initialize %s\n", typ);
78 79 80 81 82 83 84 85

    va_start (ap, fmt);
    AUD_vlog (AUDIO_CAP, fmt, ap);
    va_end (ap);

    AUD_log (AUDIO_CAP, "Reason: %s\n",
             FMOD_ErrorString (FSOUND_GetError ()));
}
bellard's avatar
bellard committed
86

87
static int fmod_write (SWVoiceOut *sw, void *buf, int len)
bellard's avatar
bellard committed
88
{
89
    return audio_pcm_sw_write (sw, buf, len);
bellard's avatar
bellard committed
90 91
}

92
static void fmod_clear_sample (FMODVoiceOut *fmd)
bellard's avatar
bellard committed
93
{
94
    HWVoiceOut *hw = &fmd->hw;
bellard's avatar
bellard committed
95 96 97 98 99 100 101
    int status;
    void *p1 = 0, *p2 = 0;
    unsigned int len1 = 0, len2 = 0;

    status = FSOUND_Sample_Lock (
        fmd->fmod_sample,
        0,
102
        hw->samples << hw->info.shift,
bellard's avatar
bellard committed
103 104 105 106 107 108 109
        &p1,
        &p2,
        &len1,
        &len2
        );

    if (!status) {
110
        fmod_logerr ("Failed to lock sample\n");
bellard's avatar
bellard committed
111 112 113
        return;
    }

114 115 116
    if ((len1 & hw->info.align) || (len2 & hw->info.align)) {
        dolog ("Lock returned misaligned length %d, %d, alignment %d\n",
               len1, len2, hw->info.align + 1);
bellard's avatar
bellard committed
117 118 119
        goto fail;
    }

120 121 122
    if ((len1 + len2) - (hw->samples << hw->info.shift)) {
        dolog ("Lock returned incomplete length %d, %d\n",
               len1 + len2, hw->samples << hw->info.shift);
bellard's avatar
bellard committed
123 124
        goto fail;
    }
125 126

    audio_pcm_info_clear_buf (&hw->info, p1, hw->samples);
bellard's avatar
bellard committed
127 128 129 130

 fail:
    status = FSOUND_Sample_Unlock (fmd->fmod_sample, p1, p2, len1, len2);
    if (!status) {
131
        fmod_logerr ("Failed to unlock sample\n");
bellard's avatar
bellard committed
132 133 134
    }
}

135
static void fmod_write_sample (HWVoiceOut *hw, uint8_t *dst, int dst_len)
bellard's avatar
bellard committed
136
{
137 138 139
    int src_len1 = dst_len;
    int src_len2 = 0;
    int pos = hw->rpos + dst_len;
malc's avatar
malc committed
140 141
    struct st_sample *src1 = hw->mix_buf + hw->rpos;
    struct st_sample *src2 = NULL;
142 143 144 145

    if (pos > hw->samples) {
        src_len1 = hw->samples - hw->rpos;
        src2 = hw->mix_buf;
bellard's avatar
bellard committed
146 147 148 149 150 151 152 153 154
        src_len2 = dst_len - src_len1;
        pos = src_len2;
    }

    if (src_len1) {
        hw->clip (dst, src1, src_len1);
    }

    if (src_len2) {
155
        dst = advance (dst, src_len1 << hw->info.shift);
bellard's avatar
bellard committed
156 157
        hw->clip (dst, src2, src_len2);
    }
158 159

    hw->rpos = pos % hw->samples;
bellard's avatar
bellard committed
160 161
}

162
static int fmod_unlock_sample (FSOUND_SAMPLE *sample, void *p1, void *p2,
bellard's avatar
bellard committed
163 164
                               unsigned int blen1, unsigned int blen2)
{
165
    int status = FSOUND_Sample_Unlock (sample, p1, p2, blen1, blen2);
bellard's avatar
bellard committed
166
    if (!status) {
167
        fmod_logerr ("Failed to unlock sample\n");
bellard's avatar
bellard committed
168 169 170 171 172
        return -1;
    }
    return 0;
}

173 174 175 176 177 178 179 180 181 182
static int fmod_lock_sample (
    FSOUND_SAMPLE *sample,
    struct audio_pcm_info *info,
    int pos,
    int len,
    void **p1,
    void **p2,
    unsigned int *blen1,
    unsigned int *blen2
    )
bellard's avatar
bellard committed
183 184 185 186
{
    int status;

    status = FSOUND_Sample_Lock (
187 188 189
        sample,
        pos << info->shift,
        len << info->shift,
bellard's avatar
bellard committed
190 191 192 193 194 195 196
        p1,
        p2,
        blen1,
        blen2
        );

    if (!status) {
197
        fmod_logerr ("Failed to lock sample\n");
bellard's avatar
bellard committed
198 199 200
        return -1;
    }

201 202 203 204 205 206 207 208 209 210
    if ((*blen1 & info->align) || (*blen2 & info->align)) {
        dolog ("Lock returned misaligned length %d, %d, alignment %d\n",
               *blen1, *blen2, info->align + 1);

        fmod_unlock_sample (sample, *p1, *p2, *blen1, *blen2);

        *p1 = NULL - 1;
        *p2 = NULL - 1;
        *blen1 = ~0U;
        *blen2 = ~0U;
bellard's avatar
bellard committed
211 212
        return -1;
    }
213 214 215 216 217 218 219 220 221 222 223

    if (!*p1 && *blen1) {
        dolog ("warning: !p1 && blen1=%d\n", *blen1);
        *blen1 = 0;
    }

    if (!p2 && *blen2) {
        dolog ("warning: !p2 && blen2=%d\n", *blen2);
        *blen2 = 0;
    }

bellard's avatar
bellard committed
224 225 226
    return 0;
}

malc's avatar
malc committed
227
static int fmod_run_out (HWVoiceOut *hw, int live)
bellard's avatar
bellard committed
228
{
229
    FMODVoiceOut *fmd = (FMODVoiceOut *) hw;
malc's avatar
malc committed
230
    int decr;
bellard's avatar
bellard committed
231 232 233 234
    void *p1 = 0, *p2 = 0;
    unsigned int blen1 = 0, blen2 = 0;
    unsigned int len1 = 0, len2 = 0;

malc's avatar
malc committed
235
    if (!hw->pending_disable) {
236
        return 0;
bellard's avatar
bellard committed
237 238 239 240 241
    }

    decr = live;

    if (fmd->channel >= 0) {
242 243 244
        int len = decr;
        int old_pos = fmd->old_pos;
        int ppos = FSOUND_GetCurrentPosition (fmd->channel);
bellard's avatar
bellard committed
245

246 247
        if (ppos == old_pos || !ppos) {
            return 0;
bellard's avatar
bellard committed
248
        }
249 250 251 252 253 254 255 256 257 258 259 260 261 262 263

        if ((old_pos < ppos) && ((old_pos + len) > ppos)) {
            len = ppos - old_pos;
        }
        else {
            if ((old_pos > ppos) && ((old_pos + len) > (ppos + hw->samples))) {
                len = hw->samples - old_pos + ppos;
            }
        }
        decr = len;

        if (audio_bug (AUDIO_FUNC, decr < 0)) {
            dolog ("decr=%d live=%d ppos=%d old_pos=%d len=%d\n",
                   decr, live, ppos, old_pos, len);
            return 0;
bellard's avatar
bellard committed
264 265 266
        }
    }

267 268 269

    if (!decr) {
        return 0;
bellard's avatar
bellard committed
270 271
    }

272 273 274 275 276
    if (fmod_lock_sample (fmd->fmod_sample, &fmd->hw.info,
                          fmd->old_pos, decr,
                          &p1, &p2,
                          &blen1, &blen2)) {
        return 0;
bellard's avatar
bellard committed
277 278
    }

279 280
    len1 = blen1 >> hw->info.shift;
    len2 = blen2 >> hw->info.shift;
bellard's avatar
bellard committed
281 282 283
    ldebug ("%p %p %d %d %d %d\n", p1, p2, len1, len2, blen1, blen2);
    decr = len1 + len2;

284 285
    if (p1 && len1) {
        fmod_write_sample (hw, p1, len1);
bellard's avatar
bellard committed
286 287
    }

288 289
    if (p2 && len2) {
        fmod_write_sample (hw, p2, len2);
bellard's avatar
bellard committed
290 291
    }

292
    fmod_unlock_sample (fmd->fmod_sample, p1, p2, blen1, blen2);
bellard's avatar
bellard committed
293 294

    fmd->old_pos = (fmd->old_pos + decr) % hw->samples;
295
    return decr;
bellard's avatar
bellard committed
296 297
}

298
static int aud_to_fmodfmt (audfmt_e fmt, int stereo)
bellard's avatar
bellard committed
299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319
{
    int mode = FSOUND_LOOP_NORMAL;

    switch (fmt) {
    case AUD_FMT_S8:
        mode |= FSOUND_SIGNED | FSOUND_8BITS;
        break;

    case AUD_FMT_U8:
        mode |= FSOUND_UNSIGNED | FSOUND_8BITS;
        break;

    case AUD_FMT_S16:
        mode |= FSOUND_SIGNED | FSOUND_16BITS;
        break;

    case AUD_FMT_U16:
        mode |= FSOUND_UNSIGNED | FSOUND_16BITS;
        break;

    default:
320 321 322 323 324
        dolog ("Internal logic error: Bad audio format %d\n", fmt);
#ifdef DEBUG_FMOD
        abort ();
#endif
        mode |= FSOUND_8BITS;
bellard's avatar
bellard committed
325 326 327 328 329
    }
    mode |= stereo ? FSOUND_STEREO : FSOUND_MONO;
    return mode;
}

330
static void fmod_fini_out (HWVoiceOut *hw)
bellard's avatar
bellard committed
331
{
332
    FMODVoiceOut *fmd = (FMODVoiceOut *) hw;
bellard's avatar
bellard committed
333 334 335 336 337 338 339 340 341 342 343

    if (fmd->fmod_sample) {
        FSOUND_Sample_Free (fmd->fmod_sample);
        fmd->fmod_sample = 0;

        if (fmd->channel >= 0) {
            FSOUND_StopSound (fmd->channel);
        }
    }
}

malc's avatar
malc committed
344
static int fmod_init_out (HWVoiceOut *hw, struct audsettings *as)
bellard's avatar
bellard committed
345
{
346
    int mode, channel;
347
    FMODVoiceOut *fmd = (FMODVoiceOut *) hw;
malc's avatar
malc committed
348
    struct audsettings obt_as = *as;
bellard's avatar
bellard committed
349

bellard's avatar
bellard committed
350
    mode = aud_to_fmodfmt (as->fmt, as->nchannels == 2 ? 1 : 0);
bellard's avatar
bellard committed
351 352 353 354
    fmd->fmod_sample = FSOUND_Sample_Alloc (
        FSOUND_FREE,            /* index */
        conf.nb_samples,        /* length */
        mode,                   /* mode */
bellard's avatar
bellard committed
355
        as->freq,               /* freq */
bellard's avatar
bellard committed
356 357 358 359 360 361
        255,                    /* volume */
        128,                    /* pan */
        255                     /* priority */
        );

    if (!fmd->fmod_sample) {
362
        fmod_logerr2 ("DAC", "Failed to allocate FMOD sample\n");
bellard's avatar
bellard committed
363 364 365 366 367
        return -1;
    }

    channel = FSOUND_PlaySoundEx (FSOUND_FREE, fmd->fmod_sample, 0, 1);
    if (channel < 0) {
368
        fmod_logerr2 ("DAC", "Failed to start playing sound\n");
bellard's avatar
bellard committed
369 370 371 372 373
        FSOUND_Sample_Free (fmd->fmod_sample);
        return -1;
    }
    fmd->channel = channel;

374
    /* FMOD always operates on little endian frames? */
375 376
    obt_as.endianness = 0;
    audio_pcm_init_info (&hw->info, &obt_as);
bellard's avatar
bellard committed
377
    hw->samples = conf.nb_samples;
bellard's avatar
bellard committed
378 379 380
    return 0;
}

381
static int fmod_ctl_out (HWVoiceOut *hw, int cmd, ...)
bellard's avatar
bellard committed
382 383
{
    int status;
384
    FMODVoiceOut *fmd = (FMODVoiceOut *) hw;
bellard's avatar
bellard committed
385 386 387 388 389 390

    switch (cmd) {
    case VOICE_ENABLE:
        fmod_clear_sample (fmd);
        status = FSOUND_SetPaused (fmd->channel, 0);
        if (!status) {
391
            fmod_logerr ("Failed to resume channel %d\n", fmd->channel);
bellard's avatar
bellard committed
392 393 394 395 396 397
        }
        break;

    case VOICE_DISABLE:
        status = FSOUND_SetPaused (fmd->channel, 1);
        if (!status) {
398
            fmod_logerr ("Failed to pause channel %d\n", fmd->channel);
bellard's avatar
bellard committed
399 400 401 402 403 404
        }
        break;
    }
    return 0;
}

malc's avatar
malc committed
405
static int fmod_init_in (HWVoiceIn *hw, struct audsettings *as)
406
{
407
    int mode;
408
    FMODVoiceIn *fmd = (FMODVoiceIn *) hw;
malc's avatar
malc committed
409
    struct audsettings obt_as = *as;
410 411 412 413 414

    if (conf.broken_adc) {
        return -1;
    }

bellard's avatar
bellard committed
415
    mode = aud_to_fmodfmt (as->fmt, as->nchannels == 2 ? 1 : 0);
416 417 418 419
    fmd->fmod_sample = FSOUND_Sample_Alloc (
        FSOUND_FREE,            /* index */
        conf.nb_samples,        /* length */
        mode,                   /* mode */
bellard's avatar
bellard committed
420
        as->freq,               /* freq */
421 422 423 424 425 426 427 428 429 430 431
        255,                    /* volume */
        128,                    /* pan */
        255                     /* priority */
        );

    if (!fmd->fmod_sample) {
        fmod_logerr2 ("ADC", "Failed to allocate FMOD sample\n");
        return -1;
    }

    /* FMOD always operates on little endian frames? */
432 433
    obt_as.endianness = 0;
    audio_pcm_init_info (&hw->info, &obt_as);
bellard's avatar
bellard committed
434
    hw->samples = conf.nb_samples;
435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466
    return 0;
}

static void fmod_fini_in (HWVoiceIn *hw)
{
    FMODVoiceIn *fmd = (FMODVoiceIn *) hw;

    if (fmd->fmod_sample) {
        FSOUND_Record_Stop ();
        FSOUND_Sample_Free (fmd->fmod_sample);
        fmd->fmod_sample = 0;
    }
}

static int fmod_run_in (HWVoiceIn *hw)
{
    FMODVoiceIn *fmd = (FMODVoiceIn *) hw;
    int hwshift = hw->info.shift;
    int live, dead, new_pos, len;
    unsigned int blen1 = 0, blen2 = 0;
    unsigned int len1, len2;
    unsigned int decr;
    void *p1, *p2;

    live = audio_pcm_hw_get_live_in (hw);
    dead = hw->samples - live;
    if (!dead) {
        return 0;
    }

    new_pos = FSOUND_Record_GetPosition ();
    if (new_pos < 0) {
bellard's avatar
bellard committed
467
        fmod_logerr ("Could not get recording position\n");
468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488
        return 0;
    }

    len = audio_ring_dist (new_pos,  hw->wpos, hw->samples);
    if (!len) {
        return 0;
    }
    len = audio_MIN (len, dead);

    if (fmod_lock_sample (fmd->fmod_sample, &fmd->hw.info,
                          hw->wpos, len,
                          &p1, &p2,
                          &blen1, &blen2)) {
        return 0;
    }

    len1 = blen1 >> hwshift;
    len2 = blen2 >> hwshift;
    decr = len1 + len2;

    if (p1 && blen1) {
489
        hw->conv (hw->conv_buf + hw->wpos, p1, len1);
490 491
    }
    if (p2 && len2) {
492
        hw->conv (hw->conv_buf, p2, len2);
493 494 495 496 497 498 499
    }

    fmod_unlock_sample (fmd->fmod_sample, p1, p2, blen1, blen2);
    hw->wpos = (hw->wpos + decr) % hw->samples;
    return decr;
}

bellard's avatar
bellard committed
500 501 502 503
static struct {
    const char *name;
    int type;
} drvtab[] = {
malc's avatar
malc committed
504
    { .name = "none",   .type = FSOUND_OUTPUT_NOSOUND },
bellard's avatar
bellard committed
505
#ifdef _WIN32
malc's avatar
malc committed
506 507 508 509
    { .name = "winmm",  .type = FSOUND_OUTPUT_WINMM   },
    { .name = "dsound", .type = FSOUND_OUTPUT_DSOUND  },
    { .name = "a3d",    .type = FSOUND_OUTPUT_A3D     },
    { .name = "asio",   .type = FSOUND_OUTPUT_ASIO    },
bellard's avatar
bellard committed
510 511
#endif
#ifdef __linux__
malc's avatar
malc committed
512 513 514
    { .name = "oss",    .type = FSOUND_OUTPUT_OSS     },
    { .name = "alsa",   .type = FSOUND_OUTPUT_ALSA    },
    { .name = "esd",    .type = FSOUND_OUTPUT_ESD     },
bellard's avatar
bellard committed
515 516
#endif
#ifdef __APPLE__
malc's avatar
malc committed
517
    { .name = "mac",    .type = FSOUND_OUTPUT_MAC     },
bellard's avatar
bellard committed
518 519
#endif
#if 0
malc's avatar
malc committed
520 521 522
    { .name = "xbox",   .type = FSOUND_OUTPUT_XBOX    },
    { .name = "ps2",    .type = FSOUND_OUTPUT_PS2     },
    { .name = "gcube",  .type = FSOUND_OUTPUT_GC      },
bellard's avatar
bellard committed
523
#endif
malc's avatar
malc committed
524
    { .name = "none-realtime", .type = FSOUND_OUTPUT_NOSOUND_NONREALTIME }
bellard's avatar
bellard committed
525 526 527 528
};

static void *fmod_audio_init (void)
{
529
    size_t i;
bellard's avatar
bellard committed
530 531 532
    double ver;
    int status;
    int output_type = -1;
533
    const char *drv = conf.drvname;
bellard's avatar
bellard committed
534 535 536 537 538 539 540

    ver = FSOUND_GetVersion ();
    if (ver < FMOD_VERSION) {
        dolog ("Wrong FMOD version %f, need at least %f\n", ver, FMOD_VERSION);
        return NULL;
    }

541 542 543 544 545 546 547 548
#ifdef __linux__
    if (ver < 3.75) {
        dolog ("FMOD before 3.75 has bug preventing ADC from working\n"
               "ADC will be disabled.\n");
        conf.broken_adc = 1;
    }
#endif

bellard's avatar
bellard committed
549 550
    if (drv) {
        int found = 0;
551
        for (i = 0; i < ARRAY_SIZE (drvtab); i++) {
bellard's avatar
bellard committed
552 553 554 555 556 557 558
            if (!strcmp (drv, drvtab[i].name)) {
                output_type = drvtab[i].type;
                found = 1;
                break;
            }
        }
        if (!found) {
559 560
            dolog ("Unknown FMOD driver `%s'\n", drv);
            dolog ("Valid drivers:\n");
561
            for (i = 0; i < ARRAY_SIZE (drvtab); i++) {
562 563
                dolog ("  %s\n", drvtab[i].name);
            }
bellard's avatar
bellard committed
564 565 566 567 568 569
        }
    }

    if (output_type != -1) {
        status = FSOUND_SetOutput (output_type);
        if (!status) {
570
            fmod_logerr ("FSOUND_SetOutput(%d) failed\n", output_type);
bellard's avatar
bellard committed
571 572 573 574 575 576 577
            return NULL;
        }
    }

    if (conf.bufsize) {
        status = FSOUND_SetBufferSize (conf.bufsize);
        if (!status) {
578
            fmod_logerr ("FSOUND_SetBufferSize (%d) failed\n", conf.bufsize);
bellard's avatar
bellard committed
579 580 581 582 583
        }
    }

    status = FSOUND_Init (conf.freq, conf.nb_channels, 0);
    if (!status) {
584
        fmod_logerr ("FSOUND_Init failed\n");
bellard's avatar
bellard committed
585 586 587 588 589 590
        return NULL;
    }

    return &conf;
}

591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618
static int fmod_read (SWVoiceIn *sw, void *buf, int size)
{
    return audio_pcm_sw_read (sw, buf, size);
}

static int fmod_ctl_in (HWVoiceIn *hw, int cmd, ...)
{
    int status;
    FMODVoiceIn *fmd = (FMODVoiceIn *) hw;

    switch (cmd) {
    case VOICE_ENABLE:
        status = FSOUND_Record_StartSample (fmd->fmod_sample, 1);
        if (!status) {
            fmod_logerr ("Failed to start recording\n");
        }
        break;

    case VOICE_DISABLE:
        status = FSOUND_Record_Stop ();
        if (!status) {
            fmod_logerr ("Failed to stop recording\n");
        }
        break;
    }
    return 0;
}

bellard's avatar
bellard committed
619 620
static void fmod_audio_fini (void *opaque)
{
621
    (void) opaque;
bellard's avatar
bellard committed
622 623 624
    FSOUND_Close ();
}

625
static struct audio_option fmod_options[] = {
malc's avatar
malc committed
626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654
    {
        .name  = "DRV",
        .tag   = AUD_OPT_STR,
        .valp  = &conf.drvname,
        .descr = "FMOD driver"
    },
    {
        .name  = "FREQ",
        .tag   = AUD_OPT_INT,
        .valp  = &conf.freq,
        .descr = "Default frequency"
    },
    {
        .name  = "SAMPLES",
        .tag   = AUD_OPT_INT,
        .valp  = &conf.nb_samples,
        .descr = "Buffer size in samples"
    },
    {
        .name  = "CHANNELS",
        .tag   = AUD_OPT_INT,
        .valp  = &conf.nb_channels,
        .descr = "Number of default channels (1 - mono, 2 - stereo)"
    },
    {
        .name  = "BUFSIZE",
        .tag   = AUD_OPT_INT,
        .valp  = &conf.bufsize,
        .descr = "(undocumented)"
655
    },
656
    { /* End of list */ }
657 658
};

659
static struct audio_pcm_ops fmod_pcm_ops = {
660 661 662 663 664 665
    .init_out = fmod_init_out,
    .fini_out = fmod_fini_out,
    .run_out  = fmod_run_out,
    .write    = fmod_write,
    .ctl_out  = fmod_ctl_out,

malc's avatar
malc committed
666 667 668 669 670
    .init_in  = fmod_init_in,
    .fini_in  = fmod_fini_in,
    .run_in   = fmod_run_in,
    .read     = fmod_read,
    .ctl_in   = fmod_ctl_in
bellard's avatar
bellard committed
671 672
};

673
struct audio_driver fmod_audio_driver = {
674 675 676 677 678 679 680 681 682 683 684
    .name           = "fmod",
    .descr          = "FMOD 3.xx http://www.fmod.org",
    .options        = fmod_options,
    .init           = fmod_audio_init,
    .fini           = fmod_audio_fini,
    .pcm_ops        = &fmod_pcm_ops,
    .can_be_default = 1,
    .max_voices_out = INT_MAX,
    .max_voices_in  = INT_MAX,
    .voice_size_out = sizeof (FMODVoiceOut),
    .voice_size_in  = sizeof (FMODVoiceIn)
bellard's avatar
bellard committed
685
};