audio.c 40.8 KB
Newer Older
bellard's avatar
bellard committed
1 2
/*
 * QEMU Audio subsystem
3 4 5
 *
 * Copyright (c) 2003-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 "vl.h"

26 27
#define AUDIO_CAP "audio"
#include "audio_int.h"
bellard's avatar
bellard committed
28

29 30 31
/* #define DEBUG_PLIVE */
/* #define DEBUG_LIVE */
/* #define DEBUG_OUT */
bellard's avatar
bellard committed
32

bellard's avatar
bellard committed
33 34
#define SW_NAME(sw) (sw)->name ? (sw)->name : "unknown"

35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
static struct audio_driver *drvtab[] = {
#ifdef CONFIG_OSS
    &oss_audio_driver,
#endif
#ifdef CONFIG_ALSA
    &alsa_audio_driver,
#endif
#ifdef CONFIG_COREAUDIO
    &coreaudio_audio_driver,
#endif
#ifdef CONFIG_DSOUND
    &dsound_audio_driver,
#endif
#ifdef CONFIG_FMOD
    &fmod_audio_driver,
#endif
#ifdef CONFIG_SDL
    &sdl_audio_driver,
#endif
    &no_audio_driver,
    &wav_audio_driver
};
bellard's avatar
bellard committed
57

bellard's avatar
bellard committed
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
struct fixed_settings {
    int enabled;
    int nb_voices;
    int greedy;
    audsettings_t settings;
};

static struct {
    struct fixed_settings fixed_out;
    struct fixed_settings fixed_in;
    union {
        int hz;
        int64_t ticks;
    } period;
    int plive;
bellard's avatar
bellard committed
73
    int log_to_monitor;
bellard's avatar
bellard committed
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
} conf = {
    {                           /* DAC fixed settings */
        1,                      /* enabled */
        1,                      /* nb_voices */
        1,                      /* greedy */
        {
            44100,              /* freq */
            2,                  /* nchannels */
            AUD_FMT_S16         /* fmt */
        }
    },

    {                           /* ADC fixed settings */
        1,                      /* enabled */
        1,                      /* nb_voices */
        1,                      /* greedy */
        {
            44100,              /* freq */
            2,                  /* nchannels */
            AUD_FMT_S16         /* fmt */
        }
    },

97
    { 0 },                      /* period */
bellard's avatar
bellard committed
98 99
    0,                          /* plive */
    0
100 101
};

bellard's avatar
bellard committed
102 103
static AudioState glob_audio_state;

104 105 106 107 108 109 110 111 112
volume_t nominal_volume = {
    0,
#ifdef FLOAT_MIXENG
    1.0,
    1.0
#else
    UINT_MAX,
    UINT_MAX
#endif
bellard's avatar
bellard committed
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
};

/* http://www.df.lth.se/~john_e/gems/gem002d.html */
/* http://www.multi-platforms.com/Tips/PopCount.htm */
uint32_t popcount (uint32_t u)
{
    u = ((u&0x55555555) + ((u>>1)&0x55555555));
    u = ((u&0x33333333) + ((u>>2)&0x33333333));
    u = ((u&0x0f0f0f0f) + ((u>>4)&0x0f0f0f0f));
    u = ((u&0x00ff00ff) + ((u>>8)&0x00ff00ff));
    u = ( u&0x0000ffff) + (u>>16);
    return u;
}

inline uint32_t lsbindex (uint32_t u)
{
    return popcount ((u&-u)-1);
}

132 133 134 135
#ifdef AUDIO_IS_FLAWLESS_AND_NO_CHECKS_ARE_REQURIED
#error No its not
#else
int audio_bug (const char *funcname, int cond)
bellard's avatar
bellard committed
136
{
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
    if (cond) {
        static int shown;

        AUD_log (NULL, "Error a bug that was just triggered in %s\n", funcname);
        if (!shown) {
            shown = 1;
            AUD_log (NULL, "Save all your work and restart without audio\n");
            AUD_log (NULL, "Please send bug report to malc@pulsesoft.com\n");
            AUD_log (NULL, "I am sorry\n");
        }
        AUD_log (NULL, "Context:\n");

#if defined AUDIO_BREAKPOINT_ON_BUG
#  if defined HOST_I386
#    if defined __GNUC__
        __asm__ ("int3");
#    elif defined _MSC_VER
        _asm _emit 0xcc;
#    else
        abort ();
#    endif
#  else
        abort ();
#  endif
#endif
bellard's avatar
bellard committed
162 163
    }

164
    return cond;
bellard's avatar
bellard committed
165
}
166
#endif
bellard's avatar
bellard committed
167

bellard's avatar
bellard committed
168 169 170 171 172 173 174 175 176 177 178 179 180
void *audio_calloc (const char *funcname, int nmemb, size_t size)
{
    int cond;
    size_t len;

    len = nmemb * size;
    cond = !nmemb || !size;
    cond |= nmemb < 0;
    cond |= len < size;

    if (audio_bug ("audio_calloc", cond)) {
        AUD_log (NULL, "%s passed invalid arguments to audio_calloc\n",
                 funcname);
bellard's avatar
bellard committed
181
        AUD_log (NULL, "nmemb=%d size=%zu (len=%zu)\n", nmemb, size, len);
bellard's avatar
bellard committed
182 183 184 185 186 187
        return NULL;
    }

    return qemu_mallocz (len);
}

188
static char *audio_alloc_prefix (const char *s)
bellard's avatar
bellard committed
189
{
190 191 192
    const char qemu_prefix[] = "QEMU_";
    size_t len;
    char *r;
bellard's avatar
bellard committed
193

194 195 196
    if (!s) {
        return NULL;
    }
bellard's avatar
bellard committed
197

198 199
    len = strlen (s);
    r = qemu_malloc (len + sizeof (qemu_prefix));
bellard's avatar
bellard committed
200

201 202 203
    if (r) {
        size_t i;
        char *u = r + sizeof (qemu_prefix) - 1;
bellard's avatar
bellard committed
204

205 206 207 208 209 210
        strcpy (r, qemu_prefix);
        strcat (r, s);

        for (i = 0; i < len; ++i) {
            u[i] = toupper (u[i]);
        }
bellard's avatar
bellard committed
211
    }
212
    return r;
bellard's avatar
bellard committed
213 214
}

215
const char *audio_audfmt_to_string (audfmt_e fmt)
bellard's avatar
bellard committed
216
{
217 218 219
    switch (fmt) {
    case AUD_FMT_U8:
        return "U8";
bellard's avatar
bellard committed
220

221 222
    case AUD_FMT_U16:
        return "U16";
bellard's avatar
bellard committed
223 224

    case AUD_FMT_S8:
225
        return "S8";
bellard's avatar
bellard committed
226 227

    case AUD_FMT_S16:
228
        return "S16";
bellard's avatar
bellard committed
229 230
    }

231 232
    dolog ("Bogus audfmt %d returning S16\n", fmt);
    return "S16";
bellard's avatar
bellard committed
233 234
}

235
audfmt_e audio_string_to_audfmt (const char *s, audfmt_e defval, int *defaultp)
bellard's avatar
bellard committed
236
{
237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258
    if (!strcasecmp (s, "u8")) {
        *defaultp = 0;
        return AUD_FMT_U8;
    }
    else if (!strcasecmp (s, "u16")) {
        *defaultp = 0;
        return AUD_FMT_U16;
    }
    else if (!strcasecmp (s, "s8")) {
        *defaultp = 0;
        return AUD_FMT_S8;
    }
    else if (!strcasecmp (s, "s16")) {
        *defaultp = 0;
        return AUD_FMT_S16;
    }
    else {
        dolog ("Bogus audio format `%s' using %s\n",
               s, audio_audfmt_to_string (defval));
        *defaultp = 1;
        return defval;
    }
bellard's avatar
bellard committed
259 260
}

261 262 263
static audfmt_e audio_get_conf_fmt (const char *envname,
                                    audfmt_e defval,
                                    int *defaultp)
bellard's avatar
bellard committed
264
{
265 266 267 268
    const char *var = getenv (envname);
    if (!var) {
        *defaultp = 1;
        return defval;
bellard's avatar
bellard committed
269
    }
270
    return audio_string_to_audfmt (var, defval, defaultp);
bellard's avatar
bellard committed
271 272
}

273
static int audio_get_conf_int (const char *key, int defval, int *defaultp)
bellard's avatar
bellard committed
274
{
275 276
    int val;
    char *strval;
bellard's avatar
bellard committed
277

278 279 280 281 282 283 284 285 286 287
    strval = getenv (key);
    if (strval) {
        *defaultp = 0;
        val = atoi (strval);
        return val;
    }
    else {
        *defaultp = 1;
        return defval;
    }
bellard's avatar
bellard committed
288 289
}

290 291 292
static const char *audio_get_conf_str (const char *key,
                                       const char *defval,
                                       int *defaultp)
bellard's avatar
bellard committed
293
{
294 295 296 297 298 299 300 301
    const char *val = getenv (key);
    if (!val) {
        *defaultp = 1;
        return defval;
    }
    else {
        *defaultp = 0;
        return val;
bellard's avatar
bellard committed
302 303 304
    }
}

bellard's avatar
bellard committed
305
void AUD_vlog (const char *cap, const char *fmt, va_list ap)
bellard's avatar
bellard committed
306
{
bellard's avatar
bellard committed
307 308 309 310 311 312 313 314 315 316 317 318 319
    if (conf.log_to_monitor) {
        if (cap) {
            term_printf ("%s: ", cap);
        }

        term_vprintf (fmt, ap);
    }
    else {
        if (cap) {
            fprintf (stderr, "%s: ", cap);
        }

        vfprintf (stderr, fmt, ap);
bellard's avatar
bellard committed
320 321 322
    }
}

bellard's avatar
bellard committed
323
void AUD_log (const char *cap, const char *fmt, ...)
bellard's avatar
bellard committed
324
{
bellard's avatar
bellard committed
325 326 327 328 329
    va_list ap;

    va_start (ap, fmt);
    AUD_vlog (cap, fmt, ap);
    va_end (ap);
bellard's avatar
bellard committed
330 331
}

332 333
static void audio_print_options (const char *prefix,
                                 struct audio_option *opt)
bellard's avatar
bellard committed
334
{
335 336 337 338 339 340 341 342 343
    char *uprefix;

    if (!prefix) {
        dolog ("No prefix specified\n");
        return;
    }

    if (!opt) {
        dolog ("No options\n");
bellard's avatar
bellard committed
344
        return;
345
    }
bellard's avatar
bellard committed
346

347
    uprefix = audio_alloc_prefix (prefix);
bellard's avatar
bellard committed
348

349 350 351
    for (; opt->name; opt++) {
        const char *state = "default";
        printf ("  %s_%s: ", uprefix, opt->name);
bellard's avatar
bellard committed
352

353 354 355
        if (opt->overridenp && *opt->overridenp) {
            state = "current";
        }
bellard's avatar
bellard committed
356

357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388
        switch (opt->tag) {
        case AUD_OPT_BOOL:
            {
                int *intp = opt->valp;
                printf ("boolean, %s = %d\n", state, *intp ? 1 : 0);
            }
            break;

        case AUD_OPT_INT:
            {
                int *intp = opt->valp;
                printf ("integer, %s = %d\n", state, *intp);
            }
            break;

        case AUD_OPT_FMT:
            {
                audfmt_e *fmtp = opt->valp;
                printf (
                    "format, %s = %s, (one of: U8 S8 U16 S16)\n",
                    state,
                    audio_audfmt_to_string (*fmtp)
                    );
            }
            break;

        case AUD_OPT_STR:
            {
                const char **strp = opt->valp;
                printf ("string, %s = %s\n",
                        state,
                        *strp ? *strp : "(not set)");
bellard's avatar
bellard committed
389
            }
390 391 392 393 394 395 396
            break;

        default:
            printf ("???\n");
            dolog ("Bad value tag for option %s_%s %d\n",
                   uprefix, opt->name, opt->tag);
            break;
bellard's avatar
bellard committed
397
        }
398
        printf ("    %s\n", opt->descr);
bellard's avatar
bellard committed
399
    }
400 401

    qemu_free (uprefix);
bellard's avatar
bellard committed
402 403
}

404 405
static void audio_process_options (const char *prefix,
                                   struct audio_option *opt)
bellard's avatar
bellard committed
406
{
407 408 409
    char *optname;
    const char qemu_prefix[] = "QEMU_";
    size_t preflen;
bellard's avatar
bellard committed
410

411 412 413 414
    if (audio_bug (AUDIO_FUNC, !prefix)) {
        dolog ("prefix = NULL\n");
        return;
    }
bellard's avatar
bellard committed
415

416 417 418
    if (audio_bug (AUDIO_FUNC, !opt)) {
        dolog ("opt = NULL\n");
        return;
bellard's avatar
bellard committed
419 420
    }

421
    preflen = strlen (prefix);
bellard's avatar
bellard committed
422

423 424 425 426 427 428 429 430 431 432 433
    for (; opt->name; opt++) {
        size_t len, i;
        int def;

        if (!opt->valp) {
            dolog ("Option value pointer for `%s' is not set\n",
                   opt->name);
            continue;
        }

        len = strlen (opt->name);
bellard's avatar
bellard committed
434 435 436
        /* len of opt->name + len of prefix + size of qemu_prefix
         * (includes trailing zero) + zero + underscore (on behalf of
         * sizeof) */
437 438
        optname = qemu_malloc (len + preflen + sizeof (qemu_prefix) + 1);
        if (!optname) {
bellard's avatar
bellard committed
439
            dolog ("Could not allocate memory for option name `%s'\n",
440 441 442 443 444
                   opt->name);
            continue;
        }

        strcpy (optname, qemu_prefix);
bellard's avatar
bellard committed
445 446

        /* copy while upper-casing, including trailing zero */
447 448 449 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
        for (i = 0; i <= preflen; ++i) {
            optname[i + sizeof (qemu_prefix) - 1] = toupper (prefix[i]);
        }
        strcat (optname, "_");
        strcat (optname, opt->name);

        def = 1;
        switch (opt->tag) {
        case AUD_OPT_BOOL:
        case AUD_OPT_INT:
            {
                int *intp = opt->valp;
                *intp = audio_get_conf_int (optname, *intp, &def);
            }
            break;

        case AUD_OPT_FMT:
            {
                audfmt_e *fmtp = opt->valp;
                *fmtp = audio_get_conf_fmt (optname, *fmtp, &def);
            }
            break;

        case AUD_OPT_STR:
            {
                const char **strp = opt->valp;
                *strp = audio_get_conf_str (optname, *strp, &def);
            }
            break;

        default:
            dolog ("Bad value tag for option `%s' - %d\n",
                   optname, opt->tag);
bellard's avatar
bellard committed
480 481 482
            break;
        }

483 484 485 486 487 488
        if (!opt->overridenp) {
            opt->overridenp = &opt->overriden;
        }
        *opt->overridenp = !def;
        qemu_free (optname);
    }
bellard's avatar
bellard committed
489 490
}

bellard's avatar
bellard committed
491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540
static void audio_print_settings (audsettings_t *as)
{
    dolog ("frequency=%d nchannels=%d fmt=", as->freq, as->nchannels);

    switch (as->fmt) {
    case AUD_FMT_S8:
        AUD_log (NULL, "S8");
        break;
    case AUD_FMT_U8:
        AUD_log (NULL, "U8");
        break;
    case AUD_FMT_S16:
        AUD_log (NULL, "S16");
        break;
    case AUD_FMT_U16:
        AUD_log (NULL, "U16");
        break;
    default:
        AUD_log (NULL, "invalid(%d)", as->fmt);
        break;
    }
    AUD_log (NULL, "\n");
}

static int audio_validate_settigs (audsettings_t *as)
{
    int invalid;

    invalid = as->nchannels != 1 && as->nchannels != 2;

    switch (as->fmt) {
    case AUD_FMT_S8:
    case AUD_FMT_U8:
    case AUD_FMT_S16:
    case AUD_FMT_U16:
        break;
    default:
        invalid = 1;
        break;
    }

    invalid |= as->freq <= 0;

    if (invalid) {
        return -1;
    }
    return 0;
}

static int audio_pcm_info_eq (struct audio_pcm_info *info, audsettings_t *as)
bellard's avatar
bellard committed
541
{
542
    int bits = 8, sign = 0;
bellard's avatar
bellard committed
543

bellard's avatar
bellard committed
544
    switch (as->fmt) {
545 546 547 548 549 550 551 552 553 554
    case AUD_FMT_S8:
        sign = 1;
    case AUD_FMT_U8:
        break;

    case AUD_FMT_S16:
        sign = 1;
    case AUD_FMT_U16:
        bits = 16;
        break;
bellard's avatar
bellard committed
555
    }
bellard's avatar
bellard committed
556 557
    return info->freq == as->freq
        && info->nchannels == as->nchannels
558 559 560
        && info->sign == sign
        && info->bits == bits;
}
bellard's avatar
bellard committed
561

bellard's avatar
bellard committed
562 563 564 565 566
void audio_pcm_init_info (
    struct audio_pcm_info *info,
    audsettings_t *as,
    int swap_endian
    )
567 568 569
{
    int bits = 8, sign = 0;

bellard's avatar
bellard committed
570
    switch (as->fmt) {
bellard's avatar
bellard committed
571 572 573 574 575 576 577 578 579 580 581 582
    case AUD_FMT_S8:
        sign = 1;
    case AUD_FMT_U8:
        break;

    case AUD_FMT_S16:
        sign = 1;
    case AUD_FMT_U16:
        bits = 16;
        break;
    }

bellard's avatar
bellard committed
583
    info->freq = as->freq;
584 585
    info->bits = bits;
    info->sign = sign;
bellard's avatar
bellard committed
586 587
    info->nchannels = as->nchannels;
    info->shift = (as->nchannels == 2) + (bits == 16);
588 589 590
    info->align = (1 << info->shift) - 1;
    info->bytes_per_second = info->freq << info->shift;
    info->swap_endian = swap_endian;
bellard's avatar
bellard committed
591 592
}

593
void audio_pcm_info_clear_buf (struct audio_pcm_info *info, void *buf, int len)
bellard's avatar
bellard committed
594
{
595 596 597 598 599 600
    if (!len) {
        return;
    }

    if (info->sign) {
        memset (buf, len << info->shift, 0x00);
bellard's avatar
bellard committed
601 602
    }
    else {
603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619
        if (info->bits == 8) {
            memset (buf, len << info->shift, 0x80);
        }
        else {
            int i;
            uint16_t *p = buf;
            int shift = info->nchannels - 1;
            short s = INT16_MAX;

            if (info->swap_endian) {
                s = bswap16 (s);
            }

            for (i = 0; i < len << shift; i++) {
                p[i] = s;
            }
        }
bellard's avatar
bellard committed
620 621 622
    }
}

623 624 625 626
/*
 * Hard voice (capture)
 */
static void audio_pcm_hw_free_resources_in (HWVoiceIn *hw)
bellard's avatar
bellard committed
627
{
628 629
    if (hw->conv_buf) {
        qemu_free (hw->conv_buf);
bellard's avatar
bellard committed
630
    }
631
    hw->conv_buf = NULL;
bellard's avatar
bellard committed
632 633
}

634
static int audio_pcm_hw_alloc_resources_in (HWVoiceIn *hw)
bellard's avatar
bellard committed
635
{
bellard's avatar
bellard committed
636
    hw->conv_buf = audio_calloc (AUDIO_FUNC, hw->samples, sizeof (st_sample_t));
637
    if (!hw->conv_buf) {
bellard's avatar
bellard committed
638 639
        dolog ("Could not allocate ADC conversion buffer (%d samples)\n",
               hw->samples);
640
        return -1;
bellard's avatar
bellard committed
641
    }
642
    return 0;
bellard's avatar
bellard committed
643 644
}

bellard's avatar
bellard committed
645
static int audio_pcm_hw_find_min_in (HWVoiceIn *hw)
bellard's avatar
bellard committed
646
{
647 648 649 650 651 652 653
    SWVoiceIn *sw;
    int m = hw->total_samples_captured;

    for (sw = hw->sw_head.lh_first; sw; sw = sw->entries.le_next) {
        if (sw->active) {
            m = audio_MIN (m, sw->total_hw_samples_acquired);
        }
bellard's avatar
bellard committed
654
    }
655
    return m;
bellard's avatar
bellard committed
656 657
}

658
int audio_pcm_hw_get_live_in (HWVoiceIn *hw)
bellard's avatar
bellard committed
659
{
660 661 662 663
    int live = hw->total_samples_captured - audio_pcm_hw_find_min_in (hw);
    if (audio_bug (AUDIO_FUNC, live < 0 || live > hw->samples)) {
        dolog ("live=%d hw->samples=%d\n", live, hw->samples);
        return 0;
bellard's avatar
bellard committed
664
    }
665
    return live;
bellard's avatar
bellard committed
666 667
}

668 669 670 671
/*
 * Soft voice (capture)
 */
static void audio_pcm_sw_free_resources_in (SWVoiceIn *sw)
bellard's avatar
bellard committed
672
{
673 674
    if (sw->conv_buf) {
        qemu_free (sw->conv_buf);
bellard's avatar
bellard committed
675 676
    }

677 678
    if (sw->rate) {
        st_rate_stop (sw->rate);
bellard's avatar
bellard committed
679 680
    }

681 682
    sw->conv_buf = NULL;
    sw->rate = NULL;
bellard's avatar
bellard committed
683 684
}

685
static int audio_pcm_sw_alloc_resources_in (SWVoiceIn *sw)
bellard's avatar
bellard committed
686
{
687
    int samples = ((int64_t) sw->hw->samples << 32) / sw->ratio;
bellard's avatar
bellard committed
688
    sw->conv_buf = audio_calloc (AUDIO_FUNC, samples, sizeof (st_sample_t));
689
    if (!sw->conv_buf) {
bellard's avatar
bellard committed
690 691
        dolog ("Could not allocate buffer for `%s' (%d samples)\n",
               SW_NAME (sw), samples);
bellard's avatar
bellard committed
692
        return -1;
693
    }
bellard's avatar
bellard committed
694

695 696 697 698 699 700
    sw->rate = st_rate_start (sw->hw->info.freq, sw->info.freq);
    if (!sw->rate) {
        qemu_free (sw->conv_buf);
        sw->conv_buf = NULL;
        return -1;
    }
bellard's avatar
bellard committed
701 702 703
    return 0;
}

bellard's avatar
bellard committed
704 705 706 707 708 709
static int audio_pcm_sw_init_in (
    SWVoiceIn *sw,
    HWVoiceIn *hw,
    const char *name,
    audsettings_t *as
    )
bellard's avatar
bellard committed
710
{
bellard's avatar
bellard committed
711 712 713
    /* None of the cards emulated by QEMU are big-endian
       hence following shortcut */
    audio_pcm_init_info (&sw->info, as, audio_need_to_swap_endian (0));
714 715
    sw->hw = hw;
    sw->ratio = ((int64_t) sw->info.freq << 32) / sw->hw->info.freq;
bellard's avatar
bellard committed
716

717 718
    sw->clip =
        mixeng_clip
bellard's avatar
bellard committed
719
        [sw->info.nchannels == 2]
720 721 722
        [sw->info.sign]
        [sw->info.swap_endian]
        [sw->info.bits == 16];
bellard's avatar
bellard committed
723

724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742
    sw->name = qemu_strdup (name);
    audio_pcm_sw_free_resources_in (sw);
    return audio_pcm_sw_alloc_resources_in (sw);
}

static int audio_pcm_sw_get_rpos_in (SWVoiceIn *sw)
{
    HWVoiceIn *hw = sw->hw;
    int live = hw->total_samples_captured - sw->total_hw_samples_acquired;
    int rpos;

    if (audio_bug (AUDIO_FUNC, live < 0 || live > hw->samples)) {
        dolog ("live=%d hw->samples=%d\n", live, hw->samples);
        return 0;
    }

    rpos = hw->wpos - live;
    if (rpos >= 0) {
        return rpos;
bellard's avatar
bellard committed
743 744
    }
    else {
745
        return hw->samples + rpos;
bellard's avatar
bellard committed
746 747 748
    }
}

749
int audio_pcm_sw_read (SWVoiceIn *sw, void *buf, int size)
bellard's avatar
bellard committed
750
{
751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766
    HWVoiceIn *hw = sw->hw;
    int samples, live, ret = 0, swlim, isamp, osamp, rpos, total = 0;
    st_sample_t *src, *dst = sw->conv_buf;

    rpos = audio_pcm_sw_get_rpos_in (sw) % hw->samples;

    live = hw->total_samples_captured - sw->total_hw_samples_acquired;
    if (audio_bug (AUDIO_FUNC, live < 0 || live > hw->samples)) {
        dolog ("live_in=%d hw->samples=%d\n", live, hw->samples);
        return 0;
    }

    samples = size >> sw->info.shift;
    if (!live) {
        return 0;
    }
bellard's avatar
bellard committed
767

768 769
    swlim = (live * sw->ratio) >> 32;
    swlim = audio_MIN (swlim, samples);
bellard's avatar
bellard committed
770

771 772 773 774 775 776 777
    while (swlim) {
        src = hw->conv_buf + rpos;
        isamp = hw->wpos - rpos;
        /* XXX: <= ? */
        if (isamp <= 0) {
            isamp = hw->samples - rpos;
        }
bellard's avatar
bellard committed
778

779 780 781 782
        if (!isamp) {
            break;
        }
        osamp = swlim;
bellard's avatar
bellard committed
783

784 785
        if (audio_bug (AUDIO_FUNC, osamp < 0)) {
            dolog ("osamp=%d\n", osamp);
bellard's avatar
bellard committed
786
            return 0;
787
        }
bellard's avatar
bellard committed
788

789 790 791 792 793 794 795
        st_rate_flow (sw->rate, src, dst, &isamp, &osamp);
        swlim -= osamp;
        rpos = (rpos + isamp) % hw->samples;
        dst += osamp;
        ret += osamp;
        total += isamp;
    }
bellard's avatar
bellard committed
796

797 798 799
    sw->clip (buf, sw->conv_buf, ret);
    sw->total_hw_samples_acquired += total;
    return ret << sw->info.shift;
bellard's avatar
bellard committed
800 801
}

802 803 804 805 806 807 808
/*
 * Hard voice (playback)
 */
static void audio_pcm_hw_free_resources_out (HWVoiceOut *hw)
{
    if (hw->mix_buf) {
        qemu_free (hw->mix_buf);
bellard's avatar
bellard committed
809 810
    }

811 812 813 814 815
    hw->mix_buf = NULL;
}

static int audio_pcm_hw_alloc_resources_out (HWVoiceOut *hw)
{
bellard's avatar
bellard committed
816
    hw->mix_buf = audio_calloc (AUDIO_FUNC, hw->samples, sizeof (st_sample_t));
817
    if (!hw->mix_buf) {
bellard's avatar
bellard committed
818 819
        dolog ("Could not allocate DAC mixing buffer (%d samples)\n",
               hw->samples);
820
        return -1;
bellard's avatar
bellard committed
821 822
    }

823 824 825
    return 0;
}

bellard's avatar
bellard committed
826
static int audio_pcm_hw_find_min_out (HWVoiceOut *hw, int *nb_livep)
827
{
bellard's avatar
bellard committed
828 829 830
    SWVoiceOut *sw;
    int m = INT_MAX;
    int nb_live = 0;
bellard's avatar
bellard committed
831

bellard's avatar
bellard committed
832 833 834 835 836
    for (sw = hw->sw_head.lh_first; sw; sw = sw->entries.le_next) {
        if (sw->active || !sw->empty) {
            m = audio_MIN (m, sw->total_hw_samples_mixed);
            nb_live += 1;
        }
bellard's avatar
bellard committed
837
    }
bellard's avatar
bellard committed
838 839 840

    *nb_livep = nb_live;
    return m;
841
}
bellard's avatar
bellard committed
842

843 844 845
int audio_pcm_hw_get_live_out2 (HWVoiceOut *hw, int *nb_live)
{
    int smin;
bellard's avatar
bellard committed
846

847 848 849 850
    smin = audio_pcm_hw_find_min_out (hw, nb_live);

    if (!*nb_live) {
        return 0;
bellard's avatar
bellard committed
851 852
    }
    else {
853 854 855 856 857
        int live = smin;

        if (audio_bug (AUDIO_FUNC, live < 0 || live > hw->samples)) {
            dolog ("live=%d hw->samples=%d\n", live, hw->samples);
            return 0;
bellard's avatar
bellard committed
858
        }
859
        return live;
bellard's avatar
bellard committed
860
    }
861 862 863 864 865 866
}

int audio_pcm_hw_get_live_out (HWVoiceOut *hw)
{
    int nb_live;
    int live;
bellard's avatar
bellard committed
867

868 869 870 871
    live = audio_pcm_hw_get_live_out2 (hw, &nb_live);
    if (audio_bug (AUDIO_FUNC, live < 0 || live > hw->samples)) {
        dolog ("live=%d hw->samples=%d\n", live, hw->samples);
        return 0;
bellard's avatar
bellard committed
872
    }
873
    return live;
bellard's avatar
bellard committed
874 875
}

876 877 878 879
/*
 * Soft voice (playback)
 */
static void audio_pcm_sw_free_resources_out (SWVoiceOut *sw)
880
{
881 882 883
    if (sw->buf) {
        qemu_free (sw->buf);
    }
884

885 886
    if (sw->rate) {
        st_rate_stop (sw->rate);
887
    }
888 889 890

    sw->buf = NULL;
    sw->rate = NULL;
891 892
}

893
static int audio_pcm_sw_alloc_resources_out (SWVoiceOut *sw)
bellard's avatar
bellard committed
894
{
bellard's avatar
bellard committed
895
    sw->buf = audio_calloc (AUDIO_FUNC, sw->hw->samples, sizeof (st_sample_t));
896
    if (!sw->buf) {
bellard's avatar
bellard committed
897 898
        dolog ("Could not allocate buffer for `%s' (%d samples)\n",
               SW_NAME (sw), sw->hw->samples);
899 900
        return -1;
    }
bellard's avatar
bellard committed
901

902 903 904 905 906 907 908
    sw->rate = st_rate_start (sw->info.freq, sw->hw->info.freq);
    if (!sw->rate) {
        qemu_free (sw->buf);
        sw->buf = NULL;
        return -1;
    }
    return 0;
bellard's avatar
bellard committed
909 910
}

bellard's avatar
bellard committed
911 912 913 914 915 916
static int audio_pcm_sw_init_out (
    SWVoiceOut *sw,
    HWVoiceOut *hw,
    const char *name,
    audsettings_t *as
    )
bellard's avatar
bellard committed
917
{
bellard's avatar
bellard committed
918 919 920
    /* None of the cards emulated by QEMU are big-endian
       hence following shortcut */
    audio_pcm_init_info (&sw->info, as, audio_need_to_swap_endian (0));
921 922 923 924 925 926 927 928
    sw->hw = hw;
    sw->empty = 1;
    sw->active = 0;
    sw->ratio = ((int64_t) sw->hw->info.freq << 32) / sw->info.freq;
    sw->total_hw_samples_mixed = 0;

    sw->conv =
        mixeng_conv
bellard's avatar
bellard committed
929
        [sw->info.nchannels == 2]
930 931 932 933
        [sw->info.sign]
        [sw->info.swap_endian]
        [sw->info.bits == 16];
    sw->name = qemu_strdup (name);
bellard's avatar
bellard committed
934

935 936
    audio_pcm_sw_free_resources_out (sw);
    return audio_pcm_sw_alloc_resources_out (sw);
bellard's avatar
bellard committed
937 938
}

939
int audio_pcm_sw_write (SWVoiceOut *sw, void *buf, int size)
bellard's avatar
bellard committed
940
{
941 942
    int hwsamples, samples, isamp, osamp, wpos, live, dead, left, swlim, blck;
    int ret = 0, pos = 0, total = 0;
bellard's avatar
bellard committed
943

944 945 946
    if (!sw) {
        return size;
    }
bellard's avatar
bellard committed
947

948
    hwsamples = sw->hw->samples;
bellard's avatar
bellard committed
949

950 951 952 953 954
    live = sw->total_hw_samples_mixed;
    if (audio_bug (AUDIO_FUNC, live < 0 || live > hwsamples)){
        dolog ("live=%d hw->samples=%d\n", live, hwsamples);
        return 0;
    }
bellard's avatar
bellard committed
955

956 957 958
    if (live == hwsamples) {
        return 0;
    }
bellard's avatar
bellard committed
959

960 961
    wpos = (sw->hw->rpos + live) % hwsamples;
    samples = size >> sw->info.shift;
bellard's avatar
bellard committed
962

963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998
    dead = hwsamples - live;
    swlim = ((int64_t) dead << 32) / sw->ratio;
    swlim = audio_MIN (swlim, samples);
    if (swlim) {
        sw->conv (sw->buf, buf, swlim, &sw->vol);
    }

    while (swlim) {
        dead = hwsamples - live;
        left = hwsamples - wpos;
        blck = audio_MIN (dead, left);
        if (!blck) {
            break;
        }
        isamp = swlim;
        osamp = blck;
        st_rate_flow_mix (
            sw->rate,
            sw->buf + pos,
            sw->hw->mix_buf + wpos,
            &isamp,
            &osamp
            );
        ret += isamp;
        swlim -= isamp;
        pos += isamp;
        live += osamp;
        wpos = (wpos + osamp) % hwsamples;
        total += osamp;
    }

    sw->total_hw_samples_mixed += total;
    sw->empty = sw->total_hw_samples_mixed == 0;

#ifdef DEBUG_OUT
    dolog (
bellard's avatar
bellard committed
999 1000
        "%s: write size %d ret %d total sw %d\n",
        SW_NAME (sw),
1001 1002
        size >> sw->info.shift,
        ret,
bellard's avatar
bellard committed
1003
        sw->total_hw_samples_mixed
1004 1005 1006 1007
        );
#endif

    return ret << sw->info.shift;
bellard's avatar
bellard committed
1008 1009
}

1010 1011
#ifdef DEBUG_AUDIO
static void audio_pcm_print_info (const char *cap, struct audio_pcm_info *info)
bellard's avatar
bellard committed
1012
{
1013 1014
    dolog ("%s: bits %d, sign %d, freq %d, nchan %d\n",
           cap, info->bits, info->sign, info->freq, info->nchannels);
bellard's avatar
bellard committed
1015
}
1016
#endif
bellard's avatar
bellard committed
1017

1018 1019 1020 1021 1022 1023
#define DAC
#include "audio_template.h"
#undef DAC
#include "audio_template.h"

int AUD_write (SWVoiceOut *sw, void *buf, int size)
bellard's avatar
bellard committed
1024
{
1025
    int bytes;
bellard's avatar
bellard committed
1026

1027 1028 1029 1030
    if (!sw) {
        /* XXX: Consider options */
        return size;
    }
bellard's avatar
bellard committed
1031

1032
    if (!sw->hw->enabled) {
bellard's avatar
bellard committed
1033
        dolog ("Writing to disabled voice %s\n", SW_NAME (sw));
bellard's avatar
bellard committed
1034 1035 1036
        return 0;
    }

1037 1038 1039 1040 1041 1042 1043
    bytes = sw->hw->pcm_ops->write (sw, buf, size);
    return bytes;
}

int AUD_read (SWVoiceIn *sw, void *buf, int size)
{
    int bytes;
bellard's avatar
bellard committed
1044

1045 1046 1047
    if (!sw) {
        /* XXX: Consider options */
        return size;
bellard's avatar
bellard committed
1048
    }
1049 1050

    if (!sw->hw->enabled) {
bellard's avatar
bellard committed
1051
        dolog ("Reading from disabled voice %s\n", SW_NAME (sw));
1052
        return 0;
bellard's avatar
bellard committed
1053
    }
1054 1055 1056

    bytes = sw->hw->pcm_ops->read (sw, buf, size);
    return bytes;
bellard's avatar
bellard committed
1057 1058
}

1059
int AUD_get_buffer_size_out (SWVoiceOut *sw)
bellard's avatar
bellard committed
1060
{
bellard's avatar
bellard committed
1061
    return sw->hw->samples << sw->hw->info.shift;
1062 1063 1064 1065 1066
}

void AUD_set_active_out (SWVoiceOut *sw, int on)
{
    HWVoiceOut *hw;
bellard's avatar
bellard committed
1067

1068
    if (!sw) {
bellard's avatar
bellard committed
1069
        return;
1070
    }
bellard's avatar
bellard committed
1071 1072

    hw = sw->hw;
1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099
    if (sw->active != on) {
        SWVoiceOut *temp_sw;

        if (on) {
            int total;

            hw->pending_disable = 0;
            if (!hw->enabled) {
                hw->enabled = 1;
                hw->pcm_ops->ctl_out (hw, VOICE_ENABLE);
            }

            if (sw->empty) {
                total = 0;
            }
        }
        else {
            if (hw->enabled) {
                int nb_active = 0;

                for (temp_sw = hw->sw_head.lh_first; temp_sw;
                     temp_sw = temp_sw->entries.le_next) {
                    nb_active += temp_sw->active != 0;
                }

                hw->pending_disable = nb_active == 1;
            }
bellard's avatar
bellard committed
1100
        }
1101 1102 1103 1104 1105 1106 1107 1108 1109 1110
        sw->active = on;
    }
}

void AUD_set_active_in (SWVoiceIn *sw, int on)
{
    HWVoiceIn *hw;

    if (!sw) {
        return;
bellard's avatar
bellard committed
1111 1112
    }

1113
    hw = sw->hw;
bellard's avatar
bellard committed
1114
    if (sw->active != on) {
1115 1116
        SWVoiceIn *temp_sw;

bellard's avatar
bellard committed
1117 1118 1119
        if (on) {
            if (!hw->enabled) {
                hw->enabled = 1;
1120
                hw->pcm_ops->ctl_in (hw, VOICE_ENABLE);
bellard's avatar
bellard committed
1121
            }
1122
            sw->total_hw_samples_acquired = hw->total_samples_captured;
bellard's avatar
bellard committed
1123 1124
        }
        else {
1125
            if (hw->enabled) {
bellard's avatar
bellard committed
1126
                int nb_active = 0;
1127 1128 1129 1130

                for (temp_sw = hw->sw_head.lh_first; temp_sw;
                     temp_sw = temp_sw->entries.le_next) {
                    nb_active += temp_sw->active != 0;
bellard's avatar
bellard committed
1131 1132 1133
                }

                if (nb_active == 1) {
1134 1135
                    hw->enabled = 0;
                    hw->pcm_ops->ctl_in (hw, VOICE_DISABLE);
bellard's avatar
bellard committed
1136 1137 1138 1139 1140 1141 1142
                }
            }
        }
        sw->active = on;
    }
}

1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158
static int audio_get_avail (SWVoiceIn *sw)
{
    int live;

    if (!sw) {
        return 0;
    }

    live = sw->hw->total_samples_captured - sw->total_hw_samples_acquired;
    if (audio_bug (AUDIO_FUNC, live < 0 || live > sw->hw->samples)) {
        dolog ("live=%d sw->hw->samples=%d\n", live, sw->hw->samples);
        return 0;
    }

    ldebug (
        "%s: get_avail live %d ret %lld\n",
bellard's avatar
bellard committed
1159
        SW_NAME (sw),
1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177
        live, (((int64_t) live << 32) / sw->ratio) << sw->info.shift
        );

    return (((int64_t) live << 32) / sw->ratio) << sw->info.shift;
}

static int audio_get_free (SWVoiceOut *sw)
{
    int live, dead;

    if (!sw) {
        return 0;
    }

    live = sw->total_hw_samples_mixed;

    if (audio_bug (AUDIO_FUNC, live < 0 || live > sw->hw->samples)) {
        dolog ("live=%d sw->hw->samples=%d\n", live, sw->hw->samples);
bellard's avatar
bellard committed
1178
        return 0;
1179 1180 1181 1182 1183 1184
    }

    dead = sw->hw->samples - live;

#ifdef DEBUG_OUT
    dolog ("%s: get_free live %d dead %d ret %lld\n",
bellard's avatar
bellard committed
1185
           SW_NAME (sw),
1186
           live, dead, (((int64_t) dead << 32) / sw->ratio) << sw->info.shift);
bellard's avatar
bellard committed
1187
#endif
1188 1189 1190 1191

    return (((int64_t) dead << 32) / sw->ratio) << sw->info.shift;
}

bellard's avatar
bellard committed
1192
static void audio_run_out (AudioState *s)
1193 1194 1195 1196
{
    HWVoiceOut *hw = NULL;
    SWVoiceOut *sw;

bellard's avatar
bellard committed
1197
    while ((hw = audio_pcm_hw_find_any_enabled_out (s, hw))) {
1198
        int played;
bellard's avatar
bellard committed
1199
        int live, free, nb_live, cleanup_required;
1200 1201 1202 1203 1204

        live = audio_pcm_hw_get_live_out2 (hw, &nb_live);
        if (!nb_live) {
            live = 0;
        }
bellard's avatar
bellard committed
1205

1206 1207
        if (audio_bug (AUDIO_FUNC, live < 0 || live > hw->samples)) {
            dolog ("live=%d hw->samples=%d\n", live, hw->samples);
bellard's avatar
bellard committed
1208
            continue;
1209 1210 1211 1212 1213
        }

        if (hw->pending_disable && !nb_live) {
#ifdef DEBUG_OUT
            dolog ("Disabling voice\n");
bellard's avatar
bellard committed
1214
#endif
1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240
            hw->enabled = 0;
            hw->pending_disable = 0;
            hw->pcm_ops->ctl_out (hw, VOICE_DISABLE);
            continue;
        }

        if (!live) {
            for (sw = hw->sw_head.lh_first; sw; sw = sw->entries.le_next) {
                if (sw->active) {
                    free = audio_get_free (sw);
                    if (free > 0) {
                        sw->callback.fn (sw->callback.opaque, free);
                    }
                }
            }
            continue;
        }

        played = hw->pcm_ops->run_out (hw);
        if (audio_bug (AUDIO_FUNC, hw->rpos >= hw->samples)) {
            dolog ("hw->rpos=%d hw->samples=%d played=%d\n",
                   hw->rpos, hw->samples, played);
            hw->rpos = 0;
        }

#ifdef DEBUG_OUT
bellard's avatar
bellard committed
1241
        dolog ("played=%d\n", played);
bellard's avatar
bellard committed
1242
#endif
1243 1244 1245 1246 1247

        if (played) {
            hw->ts_helper += played;
        }

bellard's avatar
bellard committed
1248
        cleanup_required = 0;
1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263
        for (sw = hw->sw_head.lh_first; sw; sw = sw->entries.le_next) {
            if (!sw->active && sw->empty) {
                continue;
            }

            if (audio_bug (AUDIO_FUNC, played > sw->total_hw_samples_mixed)) {
                dolog ("played=%d sw->total_hw_samples_mixed=%d\n",
                       played, sw->total_hw_samples_mixed);
                played = sw->total_hw_samples_mixed;
            }

            sw->total_hw_samples_mixed -= played;

            if (!sw->total_hw_samples_mixed) {
                sw->empty = 1;
bellard's avatar
bellard committed
1264
                cleanup_required |= !sw->active && !sw->callback.fn;
1265 1266 1267 1268 1269 1270 1271 1272 1273
            }

            if (sw->active) {
                free = audio_get_free (sw);
                if (free > 0) {
                    sw->callback.fn (sw->callback.opaque, free);
                }
            }
        }
bellard's avatar
bellard committed
1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286

        if (cleanup_required) {
        restart:
            for (sw = hw->sw_head.lh_first; sw; sw = sw->entries.le_next) {
                if (!sw->active && !sw->callback.fn) {
#ifdef DEBUG_PLIVE
                    dolog ("Finishing with old voice\n");
#endif
                    audio_close_out (s, sw);
                    goto restart; /* play it safe */
                }
            }
        }
1287 1288 1289
    }
}

bellard's avatar
bellard committed
1290
static void audio_run_in (AudioState *s)
1291 1292 1293
{
    HWVoiceIn *hw = NULL;

bellard's avatar
bellard committed
1294
    while ((hw = audio_pcm_hw_find_any_enabled_in (s, hw))) {
1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320
        SWVoiceIn *sw;
        int captured, min;

        captured = hw->pcm_ops->run_in (hw);

        min = audio_pcm_hw_find_min_in (hw);
        hw->total_samples_captured += captured - min;
        hw->ts_helper += captured;

        for (sw = hw->sw_head.lh_first; sw; sw = sw->entries.le_next) {
            sw->total_hw_samples_acquired -= min;

            if (sw->active) {
                int avail;

                avail = audio_get_avail (sw);
                if (avail > 0) {
                    sw->callback.fn (sw->callback.opaque, avail);
                }
            }
        }
    }
}

static struct audio_option audio_options[] = {
    /* DAC */
bellard's avatar
bellard committed
1321
    {"DAC_FIXED_SETTINGS", AUD_OPT_BOOL, &conf.fixed_out.enabled,
1322 1323
     "Use fixed settings for host DAC", NULL, 0},

bellard's avatar
bellard committed
1324
    {"DAC_FIXED_FREQ", AUD_OPT_INT, &conf.fixed_out.settings.freq,
1325 1326
     "Frequency for fixed host DAC", NULL, 0},

bellard's avatar
bellard committed
1327
    {"DAC_FIXED_FMT", AUD_OPT_FMT, &conf.fixed_out.settings.fmt,
1328 1329
     "Format for fixed host DAC", NULL, 0},

bellard's avatar
bellard committed
1330
    {"DAC_FIXED_CHANNELS", AUD_OPT_INT, &conf.fixed_out.settings.nchannels,
1331 1332
     "Number of channels for fixed DAC (1 - mono, 2 - stereo)", NULL, 0},

bellard's avatar
bellard committed
1333
    {"DAC_VOICES", AUD_OPT_INT, &conf.fixed_out.nb_voices,
1334 1335 1336
     "Number of voices for DAC", NULL, 0},

    /* ADC */
bellard's avatar
bellard committed
1337
    {"ADC_FIXED_SETTINGS", AUD_OPT_BOOL, &conf.fixed_in.enabled,
1338 1339
     "Use fixed settings for host ADC", NULL, 0},

bellard's avatar
bellard committed
1340 1341
    {"ADC_FIXED_FREQ", AUD_OPT_INT, &conf.fixed_in.settings.freq,
     "Frequency for fixed host ADC", NULL, 0},
1342

bellard's avatar
bellard committed
1343 1344
    {"ADC_FIXED_FMT", AUD_OPT_FMT, &conf.fixed_in.settings.fmt,
     "Format for fixed host ADC", NULL, 0},
1345

bellard's avatar
bellard committed
1346
    {"ADC_FIXED_CHANNELS", AUD_OPT_INT, &conf.fixed_in.settings.nchannels,
1347 1348
     "Number of channels for fixed ADC (1 - mono, 2 - stereo)", NULL, 0},

bellard's avatar
bellard committed
1349
    {"ADC_VOICES", AUD_OPT_INT, &conf.fixed_in.nb_voices,