Revision c0fe3827 audio/alsaaudio.c

b/audio/alsaaudio.c
98 98
    audfmt_e fmt;
99 99
    int nchannels;
100 100
    int can_pause;
101
    snd_pcm_uframes_t buffer_size;
101
    snd_pcm_uframes_t samples;
102 102
};
103 103

  
104 104
static void GCC_FMT_ATTR (2, 3) alsa_logerr (int err, const char *fmt, ...)
......
121 121
{
122 122
    va_list ap;
123 123

  
124
    AUD_log (AUDIO_CAP, "Can not initialize %s\n", typ);
124
    AUD_log (AUDIO_CAP, "Could not initialize %s\n", typ);
125 125

  
126 126
    va_start (ap, fmt);
127 127
    AUD_vlog (AUDIO_CAP, fmt, ap);
......
209 209
    return 0;
210 210
}
211 211

  
212
#ifdef DEBUG_MISMATCHES
212
#if defined DEBUG_MISMATCHES || defined DEBUG
213 213
static void alsa_dump_info (struct alsa_params_req *req,
214 214
                            struct alsa_params_obt *obt)
215 215
{
......
221 221
    dolog ("============================================\n");
222 222
    dolog ("requested: buffer size %d period size %d\n",
223 223
           req->buffer_size, req->period_size);
224
    dolog ("obtained: buffer size %ld\n", obt->buffer_size);
224
    dolog ("obtained: samples %ld\n", obt->samples);
225 225
}
226 226
#endif
227 227

  
......
234 234

  
235 235
    err = snd_pcm_sw_params_current (handle, sw_params);
236 236
    if (err < 0) {
237
        dolog ("Can not fully initialize DAC\n");
237
        dolog ("Could not fully initialize DAC\n");
238 238
        alsa_logerr (err, "Failed to get current software parameters\n");
239 239
        return;
240 240
    }
241 241

  
242 242
    err = snd_pcm_sw_params_set_start_threshold (handle, sw_params, threshold);
243 243
    if (err < 0) {
244
        dolog ("Can not fully initialize DAC\n");
244
        dolog ("Could not fully initialize DAC\n");
245 245
        alsa_logerr (err, "Failed to set software threshold to %ld\n",
246 246
                     threshold);
247 247
        return;
......
249 249

  
250 250
    err = snd_pcm_sw_params (handle, sw_params);
251 251
    if (err < 0) {
252
        dolog ("Can not fully initialize DAC\n");
252
        dolog ("Could not fully initialize DAC\n");
253 253
        alsa_logerr (err, "Failed to set software parameters\n");
254 254
        return;
255 255
    }
......
344 344
                    handle,
345 345
                    hw_params,
346 346
                    &period_size,
347
                    0);
347
                    0
348
                    );
348 349
                if (err < 0) {
349 350
                    alsa_logerr2 (err, typ,
350 351
                                  "Failed to set period time %d\n",
......
357 358
                handle,
358 359
                hw_params,
359 360
                &buffer_size,
360
                0);
361
                0
362
                );
361 363

  
362 364
            if (err < 0) {
363 365
                alsa_logerr2 (err, typ,
......
382 384
                if (err < 0) {
383 385
                    alsa_logerr (
384 386
                        err,
385
                        "Can not get minmal period size for %s\n",
387
                        "Could not get minmal period size for %s\n",
386 388
                        typ
387 389
                        );
388 390
                }
......
419 421
                &minval
420 422
                );
421 423
            if (err < 0) {
422
                alsa_logerr (err, "Can not get minmal buffer size for %s\n",
424
                alsa_logerr (err, "Could not get minmal buffer size for %s\n",
423 425
                             typ);
424 426
            }
425 427
            else {
......
451 453
        }
452 454
    }
453 455
    else {
454
        dolog ("warning: buffer size is not set\n");
456
        dolog ("warning: Buffer size is not set\n");
455 457
    }
456 458

  
457 459
    err = snd_pcm_hw_params (handle, hw_params);
......
468 470

  
469 471
    err = snd_pcm_prepare (handle);
470 472
    if (err < 0) {
471
        alsa_logerr2 (err, typ, "Can not prepare handle %p\n", handle);
473
        alsa_logerr2 (err, typ, "Could not prepare handle %p\n", handle);
472 474
        goto err;
473 475
    }
474 476

  
475 477
    obt->can_pause = snd_pcm_hw_params_can_pause (hw_params);
476 478
    if (obt->can_pause < 0) {
477
        alsa_logerr (err, "Can not get pause capability for %s\n", typ);
479
        alsa_logerr (err, "Could not get pause capability for %s\n", typ);
478 480
        obt->can_pause = 0;
479 481
    }
480 482

  
......
493 495
    obt->fmt = req->fmt;
494 496
    obt->nchannels = nchannels;
495 497
    obt->freq = freq;
496
    obt->buffer_size = snd_pcm_frames_to_bytes (handle, obt_buffer_size);
498
    obt->samples = obt_buffer_size;
497 499
    *handlep = handle;
498 500

  
501
#if defined DEBUG_MISMATCHES || defined DEBUG
499 502
    if (obt->fmt != req->fmt ||
500 503
        obt->nchannels != req->nchannels ||
501 504
        obt->freq != req->freq) {
502
#ifdef DEBUG_MISMATCHES
503 505
        dolog ("Audio paramters mismatch for %s\n", typ);
504 506
        alsa_dump_info (req, obt);
505
#endif
506 507
    }
508
#endif
507 509

  
508 510
#ifdef DEBUG
509 511
    alsa_dump_info (req, obt);
......
550 552
            }
551 553
        }
552 554

  
553
        alsa_logerr (avail, "Can not get amount free space\n");
555
        alsa_logerr (avail, "Could not get amount free space\n");
554 556
        return 0;
555 557
    }
556 558

  
......
618 620
    }
619 621
}
620 622

  
621
static int alsa_init_out (HWVoiceOut *hw, int freq, int nchannels, audfmt_e fmt)
623
static int alsa_init_out (HWVoiceOut *hw, audsettings_t *as)
622 624
{
623 625
    ALSAVoiceOut *alsa = (ALSAVoiceOut *) hw;
624 626
    struct alsa_params_req req;
......
627 629
    int endianness;
628 630
    int err;
629 631
    snd_pcm_t *handle;
632
    audsettings_t obt_as;
630 633

  
631
    req.fmt = aud_to_alsafmt (fmt);
632
    req.freq = freq;
633
    req.nchannels = nchannels;
634
    req.fmt = aud_to_alsafmt (as->fmt);
635
    req.freq = as->freq;
636
    req.nchannels = as->nchannels;
634 637
    req.period_size = conf.period_size_out;
635 638
    req.buffer_size = conf.buffer_size_out;
636 639

  
......
644 647
        return -1;
645 648
    }
646 649

  
650
    obt_as.freq = obt.freq;
651
    obt_as.nchannels = obt.nchannels;
652
    obt_as.fmt = effective_fmt;
653

  
647 654
    audio_pcm_init_info (
648 655
        &hw->info,
649
        obt.freq,
650
        obt.nchannels,
651
        effective_fmt,
656
        &obt_as,
652 657
        audio_need_to_swap_endian (endianness)
653 658
        );
654 659
    alsa->can_pause = obt.can_pause;
655
    hw->bufsize = obt.buffer_size;
660
    hw->samples = obt.samples;
656 661

  
657
    alsa->pcm_buf = qemu_mallocz (hw->bufsize);
662
    alsa->pcm_buf = audio_calloc (AUDIO_FUNC, obt.samples, 1 << hw->info.shift);
658 663
    if (!alsa->pcm_buf) {
664
        dolog ("Could not allocate DAC buffer (%d bytes)\n",
665
               hw->samples << hw->info.shift);
659 666
        alsa_anal_close (&handle);
660 667
        return -1;
661 668
    }
......
703 710
    return 0;
704 711
}
705 712

  
706
static int alsa_init_in (HWVoiceIn *hw,
707
                        int freq, int nchannels, audfmt_e fmt)
713
static int alsa_init_in (HWVoiceIn *hw, audsettings_t *as)
708 714
{
709 715
    ALSAVoiceIn *alsa = (ALSAVoiceIn *) hw;
710 716
    struct alsa_params_req req;
......
713 719
    int err;
714 720
    audfmt_e effective_fmt;
715 721
    snd_pcm_t *handle;
722
    audsettings_t obt_as;
716 723

  
717
    req.fmt = aud_to_alsafmt (fmt);
718
    req.freq = freq;
719
    req.nchannels = nchannels;
724
    req.fmt = aud_to_alsafmt (as->fmt);
725
    req.freq = as->freq;
726
    req.nchannels = as->nchannels;
720 727
    req.period_size = conf.period_size_in;
721 728
    req.buffer_size = conf.buffer_size_in;
722 729

  
......
730 737
        return -1;
731 738
    }
732 739

  
740
    obt_as.freq = obt.freq;
741
    obt_as.nchannels = obt.nchannels;
742
    obt_as.fmt = effective_fmt;
743

  
733 744
    audio_pcm_init_info (
734 745
        &hw->info,
735
        obt.freq,
736
        obt.nchannels,
737
        effective_fmt,
746
        &obt_as,
738 747
        audio_need_to_swap_endian (endianness)
739 748
        );
740 749
    alsa->can_pause = obt.can_pause;
741
    hw->bufsize = obt.buffer_size;
742
    alsa->pcm_buf = qemu_mallocz (hw->bufsize);
750
    hw->samples = obt.samples;
751

  
752
    alsa->pcm_buf = audio_calloc (AUDIO_FUNC, hw->samples, 1 << hw->info.shift);
743 753
    if (!alsa->pcm_buf) {
754
        dolog ("Could not allocate ADC buffer (%d bytes)\n",
755
               hw->samples << hw->info.shift);
744 756
        alsa_anal_close (&handle);
745 757
        return -1;
746 758
    }

Also available in: Unified diff