fmodaudio.c 16.8 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 26 27
 * 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>
#include "vl.h"

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

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

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

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

61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
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
81
    AUD_log (AUDIO_CAP, "Could not initialize %s\n", typ);
82 83 84 85 86 87 88 89

    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
90

91
static int fmod_write (SWVoiceOut *sw, void *buf, int len)
bellard's avatar
bellard committed
92
{
93
    return audio_pcm_sw_write (sw, buf, len);
bellard's avatar
bellard committed
94 95
}

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

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

    if (!status) {
114
        fmod_logerr ("Failed to lock sample\n");
bellard's avatar
bellard committed
115 116 117
        return;
    }

118 119 120
    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
121 122 123
        goto fail;
    }

124 125 126
    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
127 128
        goto fail;
    }
129 130

    audio_pcm_info_clear_buf (&hw->info, p1, hw->samples);
bellard's avatar
bellard committed
131 132 133 134

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

139
static void fmod_write_sample (HWVoiceOut *hw, uint8_t *dst, int dst_len)
bellard's avatar
bellard committed
140
{
141 142 143 144 145 146 147 148 149
    int src_len1 = dst_len;
    int src_len2 = 0;
    int pos = hw->rpos + dst_len;
    st_sample_t *src1 = hw->mix_buf + hw->rpos;
    st_sample_t *src2 = NULL;

    if (pos > hw->samples) {
        src_len1 = hw->samples - hw->rpos;
        src2 = hw->mix_buf;
bellard's avatar
bellard committed
150 151 152 153 154 155 156 157 158
        src_len2 = dst_len - src_len1;
        pos = src_len2;
    }

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

    if (src_len2) {
159
        dst = advance (dst, src_len1 << hw->info.shift);
bellard's avatar
bellard committed
160 161
        hw->clip (dst, src2, src_len2);
    }
162 163

    hw->rpos = pos % hw->samples;
bellard's avatar
bellard committed
164 165
}

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

177 178 179 180 181 182 183 184 185 186
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
187 188 189 190
{
    int status;

    status = FSOUND_Sample_Lock (
191 192 193
        sample,
        pos << info->shift,
        len << info->shift,
bellard's avatar
bellard committed
194 195 196 197 198 199 200
        p1,
        p2,
        blen1,
        blen2
        );

    if (!status) {
201
        fmod_logerr ("Failed to lock sample\n");
bellard's avatar
bellard committed
202 203 204
        return -1;
    }

205 206 207 208 209 210 211 212 213 214
    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
215 216
        return -1;
    }
217 218 219 220 221 222 223 224 225 226 227

    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
228 229 230
    return 0;
}

231
static int fmod_run_out (HWVoiceOut *hw)
bellard's avatar
bellard committed
232
{
233 234
    FMODVoiceOut *fmd = (FMODVoiceOut *) hw;
    int live, decr;
bellard's avatar
bellard committed
235 236 237
    void *p1 = 0, *p2 = 0;
    unsigned int blen1 = 0, blen2 = 0;
    unsigned int len1 = 0, len2 = 0;
238
    int nb_live;
bellard's avatar
bellard committed
239

240 241 242
    live = audio_pcm_hw_get_live_out2 (hw, &nb_live);
    if (!live) {
        return 0;
bellard's avatar
bellard committed
243 244 245
    }

    if (!hw->pending_disable
246 247 248 249
        && nb_live
        && (conf.threshold && live <= conf.threshold)) {
        ldebug ("live=%d nb_live=%d\n", live, nb_live);
        return 0;
bellard's avatar
bellard committed
250 251 252 253 254
    }

    decr = live;

    if (fmd->channel >= 0) {
255 256 257
        int len = decr;
        int old_pos = fmd->old_pos;
        int ppos = FSOUND_GetCurrentPosition (fmd->channel);
bellard's avatar
bellard committed
258

259 260
        if (ppos == old_pos || !ppos) {
            return 0;
bellard's avatar
bellard committed
261
        }
262 263 264 265 266 267 268 269 270 271 272 273 274 275 276

        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
277 278 279
        }
    }

280 281 282

    if (!decr) {
        return 0;
bellard's avatar
bellard committed
283 284
    }

285 286 287 288 289
    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
290 291
    }

292 293
    len1 = blen1 >> hw->info.shift;
    len2 = blen2 >> hw->info.shift;
bellard's avatar
bellard committed
294 295 296
    ldebug ("%p %p %d %d %d %d\n", p1, p2, len1, len2, blen1, blen2);
    decr = len1 + len2;

297 298
    if (p1 && len1) {
        fmod_write_sample (hw, p1, len1);
bellard's avatar
bellard committed
299 300
    }

301 302
    if (p2 && len2) {
        fmod_write_sample (hw, p2, len2);
bellard's avatar
bellard committed
303 304
    }

305
    fmod_unlock_sample (fmd->fmod_sample, p1, p2, blen1, blen2);
bellard's avatar
bellard committed
306 307

    fmd->old_pos = (fmd->old_pos + decr) % hw->samples;
308
    return decr;
bellard's avatar
bellard committed
309 310
}

311
static int aud_to_fmodfmt (audfmt_e fmt, int stereo)
bellard's avatar
bellard committed
312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332
{
    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:
333 334 335 336 337
        dolog ("Internal logic error: Bad audio format %d\n", fmt);
#ifdef DEBUG_FMOD
        abort ();
#endif
        mode |= FSOUND_8BITS;
bellard's avatar
bellard committed
338 339 340 341 342
    }
    mode |= stereo ? FSOUND_STEREO : FSOUND_MONO;
    return mode;
}

343
static void fmod_fini_out (HWVoiceOut *hw)
bellard's avatar
bellard committed
344
{
345
    FMODVoiceOut *fmd = (FMODVoiceOut *) hw;
bellard's avatar
bellard committed
346 347 348 349 350 351 352 353 354 355 356

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

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

bellard's avatar
bellard committed
357
static int fmod_init_out (HWVoiceOut *hw, audsettings_t *as)
bellard's avatar
bellard committed
358 359
{
    int bits16, mode, channel;
360
    FMODVoiceOut *fmd = (FMODVoiceOut *) hw;
361
    audsettings_t obt_as = *as;
bellard's avatar
bellard committed
362

bellard's avatar
bellard committed
363
    mode = aud_to_fmodfmt (as->fmt, as->nchannels == 2 ? 1 : 0);
bellard's avatar
bellard committed
364 365 366 367
    fmd->fmod_sample = FSOUND_Sample_Alloc (
        FSOUND_FREE,            /* index */
        conf.nb_samples,        /* length */
        mode,                   /* mode */
bellard's avatar
bellard committed
368
        as->freq,               /* freq */
bellard's avatar
bellard committed
369 370 371 372 373 374
        255,                    /* volume */
        128,                    /* pan */
        255                     /* priority */
        );

    if (!fmd->fmod_sample) {
375
        fmod_logerr2 ("DAC", "Failed to allocate FMOD sample\n");
bellard's avatar
bellard committed
376 377 378 379 380
        return -1;
    }

    channel = FSOUND_PlaySoundEx (FSOUND_FREE, fmd->fmod_sample, 0, 1);
    if (channel < 0) {
381
        fmod_logerr2 ("DAC", "Failed to start playing sound\n");
bellard's avatar
bellard committed
382 383 384 385 386
        FSOUND_Sample_Free (fmd->fmod_sample);
        return -1;
    }
    fmd->channel = channel;

387
    /* FMOD always operates on little endian frames? */
388 389
    obt_as.endianness = 0;
    audio_pcm_init_info (&hw->info, &obt_as);
390
    bits16 = (mode & FSOUND_16BITS) != 0;
bellard's avatar
bellard committed
391
    hw->samples = conf.nb_samples;
bellard's avatar
bellard committed
392 393 394
    return 0;
}

395
static int fmod_ctl_out (HWVoiceOut *hw, int cmd, ...)
bellard's avatar
bellard committed
396 397
{
    int status;
398
    FMODVoiceOut *fmd = (FMODVoiceOut *) hw;
bellard's avatar
bellard committed
399 400 401 402 403 404

    switch (cmd) {
    case VOICE_ENABLE:
        fmod_clear_sample (fmd);
        status = FSOUND_SetPaused (fmd->channel, 0);
        if (!status) {
405
            fmod_logerr ("Failed to resume channel %d\n", fmd->channel);
bellard's avatar
bellard committed
406 407 408 409 410 411
        }
        break;

    case VOICE_DISABLE:
        status = FSOUND_SetPaused (fmd->channel, 1);
        if (!status) {
412
            fmod_logerr ("Failed to pause channel %d\n", fmd->channel);
bellard's avatar
bellard committed
413 414 415 416 417 418
        }
        break;
    }
    return 0;
}

bellard's avatar
bellard committed
419
static int fmod_init_in (HWVoiceIn *hw, audsettings_t *as)
420 421 422
{
    int bits16, mode;
    FMODVoiceIn *fmd = (FMODVoiceIn *) hw;
423
    audsettings_t obt_as = *as;
424 425 426 427 428

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

bellard's avatar
bellard committed
429
    mode = aud_to_fmodfmt (as->fmt, as->nchannels == 2 ? 1 : 0);
430 431 432 433
    fmd->fmod_sample = FSOUND_Sample_Alloc (
        FSOUND_FREE,            /* index */
        conf.nb_samples,        /* length */
        mode,                   /* mode */
bellard's avatar
bellard committed
434
        as->freq,               /* freq */
435 436 437 438 439 440 441 442 443 444 445
        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? */
446 447
    obt_as.endianness = 0;
    audio_pcm_init_info (&hw->info, &obt_as);
448
    bits16 = (mode & FSOUND_16BITS) != 0;
bellard's avatar
bellard committed
449
    hw->samples = conf.nb_samples;
450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481
    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
482
        fmod_logerr ("Could not get recording position\n");
483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514
        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) {
        hw->conv (hw->conv_buf + hw->wpos, p1, len1, &nominal_volume);
    }
    if (p2 && len2) {
        hw->conv (hw->conv_buf, p2, len2, &nominal_volume);
    }

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

bellard's avatar
bellard committed
515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538
static struct {
    const char *name;
    int type;
} drvtab[] = {
    {"none", FSOUND_OUTPUT_NOSOUND},
#ifdef _WIN32
    {"winmm", FSOUND_OUTPUT_WINMM},
    {"dsound", FSOUND_OUTPUT_DSOUND},
    {"a3d", FSOUND_OUTPUT_A3D},
    {"asio", FSOUND_OUTPUT_ASIO},
#endif
#ifdef __linux__
    {"oss", FSOUND_OUTPUT_OSS},
    {"alsa", FSOUND_OUTPUT_ALSA},
    {"esd", FSOUND_OUTPUT_ESD},
#endif
#ifdef __APPLE__
    {"mac", FSOUND_OUTPUT_MAC},
#endif
#if 0
    {"xbox", FSOUND_OUTPUT_XBOX},
    {"ps2", FSOUND_OUTPUT_PS2},
    {"gcube", FSOUND_OUTPUT_GC},
#endif
539
    {"none-realtime", FSOUND_OUTPUT_NOSOUND_NONREALTIME}
bellard's avatar
bellard committed
540 541 542 543
};

static void *fmod_audio_init (void)
{
544
    size_t i;
bellard's avatar
bellard committed
545 546 547
    double ver;
    int status;
    int output_type = -1;
548
    const char *drv = conf.drvname;
bellard's avatar
bellard committed
549 550 551 552 553 554 555

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

556 557 558 559 560 561 562 563
#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
564 565 566 567 568 569 570 571 572 573
    if (drv) {
        int found = 0;
        for (i = 0; i < sizeof (drvtab) / sizeof (drvtab[0]); i++) {
            if (!strcmp (drv, drvtab[i].name)) {
                output_type = drvtab[i].type;
                found = 1;
                break;
            }
        }
        if (!found) {
574 575 576 577 578
            dolog ("Unknown FMOD driver `%s'\n", drv);
            dolog ("Valid drivers:\n");
            for (i = 0; i < sizeof (drvtab) / sizeof (drvtab[0]); i++) {
                dolog ("  %s\n", drvtab[i].name);
            }
bellard's avatar
bellard committed
579 580 581 582 583 584
        }
    }

    if (output_type != -1) {
        status = FSOUND_SetOutput (output_type);
        if (!status) {
585
            fmod_logerr ("FSOUND_SetOutput(%d) failed\n", output_type);
bellard's avatar
bellard committed
586 587 588 589 590 591 592
            return NULL;
        }
    }

    if (conf.bufsize) {
        status = FSOUND_SetBufferSize (conf.bufsize);
        if (!status) {
593
            fmod_logerr ("FSOUND_SetBufferSize (%d) failed\n", conf.bufsize);
bellard's avatar
bellard committed
594 595 596 597 598
        }
    }

    status = FSOUND_Init (conf.freq, conf.nb_channels, 0);
    if (!status) {
599
        fmod_logerr ("FSOUND_Init failed\n");
bellard's avatar
bellard committed
600 601 602 603 604 605
        return NULL;
    }

    return &conf;
}

606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633
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
634 635
static void fmod_audio_fini (void *opaque)
{
636
    (void) opaque;
bellard's avatar
bellard committed
637 638 639
    FSOUND_Close ();
}

640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670
static struct audio_option fmod_options[] = {
    {"DRV", AUD_OPT_STR, &conf.drvname,
     "FMOD driver", NULL, 0},
    {"FREQ", AUD_OPT_INT, &conf.freq,
     "Default frequency", NULL, 0},
    {"SAMPLES", AUD_OPT_INT, &conf.nb_samples,
     "Buffer size in samples", NULL, 0},
    {"CHANNELS", AUD_OPT_INT, &conf.nb_channels,
     "Number of default channels (1 - mono, 2 - stereo)", NULL, 0},
    {"BUFSIZE", AUD_OPT_INT, &conf.bufsize,
     "(undocumented)", NULL, 0},
#if 0
    {"THRESHOLD", AUD_OPT_INT, &conf.threshold,
     "(undocumented)"},
#endif

    {NULL, 0, NULL, NULL, NULL, 0}
};

static struct audio_pcm_ops fmod_pcm_ops = {
    fmod_init_out,
    fmod_fini_out,
    fmod_run_out,
    fmod_write,
    fmod_ctl_out,

    fmod_init_in,
    fmod_fini_in,
    fmod_run_in,
    fmod_read,
    fmod_ctl_in
bellard's avatar
bellard committed
671 672
};

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