| 91 |
{ |
{ |
| 92 |
va_list ap; |
va_list ap; |
| 93 |
|
|
| 94 |
AUD_log (AUDIO_CAP, "Can not initialize %s\n", typ); |
AUD_log (AUDIO_CAP, "Could not initialize %s\n", typ); |
| 95 |
|
|
| 96 |
va_start (ap, fmt); |
va_start (ap, fmt); |
| 97 |
AUD_vlog (AUDIO_CAP, fmt, ap); |
AUD_vlog (AUDIO_CAP, fmt, ap); |
| 179 |
return 0; |
return 0; |
| 180 |
} |
} |
| 181 |
|
|
| 182 |
#ifdef DEBUG_MISMATCHES |
#if defined DEBUG_MISMATCHES || defined DEBUG |
| 183 |
static void oss_dump_info (struct oss_params *req, struct oss_params *obt) |
static void oss_dump_info (struct oss_params *req, struct oss_params *obt) |
| 184 |
{ |
{ |
| 185 |
dolog ("parameter | requested value | obtained value\n"); |
dolog ("parameter | requested value | obtained value\n"); |
| 253 |
obt->fragsize = abinfo.fragsize; |
obt->fragsize = abinfo.fragsize; |
| 254 |
*pfd = fd; |
*pfd = fd; |
| 255 |
|
|
| 256 |
|
#ifdef DEBUG_MISMATCHES |
| 257 |
if ((req->fmt != obt->fmt) || |
if ((req->fmt != obt->fmt) || |
| 258 |
(req->nchannels != obt->nchannels) || |
(req->nchannels != obt->nchannels) || |
| 259 |
(req->freq != obt->freq) || |
(req->freq != obt->freq) || |
| 260 |
(req->fragsize != obt->fragsize) || |
(req->fragsize != obt->fragsize) || |
| 261 |
(req->nfrags != obt->nfrags)) { |
(req->nfrags != obt->nfrags)) { |
|
#ifdef DEBUG_MISMATCHES |
|
| 262 |
dolog ("Audio parameters mismatch\n"); |
dolog ("Audio parameters mismatch\n"); |
| 263 |
oss_dump_info (req, obt); |
oss_dump_info (req, obt); |
|
#endif |
|
| 264 |
} |
} |
| 265 |
|
#endif |
| 266 |
|
|
| 267 |
#ifdef DEBUG |
#ifdef DEBUG |
| 268 |
oss_dump_info (req, obt); |
oss_dump_info (req, obt); |
| 283 |
st_sample_t *src; |
st_sample_t *src; |
| 284 |
struct audio_buf_info abinfo; |
struct audio_buf_info abinfo; |
| 285 |
struct count_info cntinfo; |
struct count_info cntinfo; |
| 286 |
|
int bufsize; |
| 287 |
|
|
| 288 |
live = audio_pcm_hw_get_live_out (hw); |
live = audio_pcm_hw_get_live_out (hw); |
| 289 |
if (!live) { |
if (!live) { |
| 290 |
return 0; |
return 0; |
| 291 |
} |
} |
| 292 |
|
|
| 293 |
|
bufsize = hw->samples << hw->info.shift; |
| 294 |
|
|
| 295 |
if (oss->mmapped) { |
if (oss->mmapped) { |
| 296 |
int bytes; |
int bytes; |
| 297 |
|
|
| 303 |
|
|
| 304 |
if (cntinfo.ptr == oss->old_optr) { |
if (cntinfo.ptr == oss->old_optr) { |
| 305 |
if (abs (hw->samples - live) < 64) { |
if (abs (hw->samples - live) < 64) { |
| 306 |
dolog ("warning: overrun\n"); |
dolog ("warning: Overrun\n"); |
| 307 |
} |
} |
| 308 |
return 0; |
return 0; |
| 309 |
} |
} |
| 312 |
bytes = cntinfo.ptr - oss->old_optr; |
bytes = cntinfo.ptr - oss->old_optr; |
| 313 |
} |
} |
| 314 |
else { |
else { |
| 315 |
bytes = hw->bufsize + cntinfo.ptr - oss->old_optr; |
bytes = bufsize + cntinfo.ptr - oss->old_optr; |
| 316 |
} |
} |
| 317 |
|
|
| 318 |
decr = audio_MIN (bytes >> hw->info.shift, live); |
decr = audio_MIN (bytes >> hw->info.shift, live); |
| 324 |
return 0; |
return 0; |
| 325 |
} |
} |
| 326 |
|
|
| 327 |
if (abinfo.bytes < 0 || abinfo.bytes > hw->bufsize) { |
if (abinfo.bytes < 0 || abinfo.bytes > bufsize) { |
| 328 |
ldebug ("warning: invalid available size, size=%d bufsize=%d\n", |
ldebug ("warning: Invalid available size, size=%d bufsize=%d\n", |
| 329 |
abinfo.bytes, hw->bufsize); |
abinfo.bytes, bufsize); |
| 330 |
return 0; |
return 0; |
| 331 |
} |
} |
| 332 |
|
|
| 365 |
int wsamples = written >> hw->info.shift; |
int wsamples = written >> hw->info.shift; |
| 366 |
int wbytes = wsamples << hw->info.shift; |
int wbytes = wsamples << hw->info.shift; |
| 367 |
if (wbytes != written) { |
if (wbytes != written) { |
| 368 |
dolog ("warning: misaligned write %d (requested %d), " |
dolog ("warning: Misaligned write %d (requested %d), " |
| 369 |
"alignment %d\n", |
"alignment %d\n", |
| 370 |
wbytes, written, hw->info.align + 1); |
wbytes, written, hw->info.align + 1); |
| 371 |
} |
} |
| 399 |
|
|
| 400 |
if (oss->pcm_buf) { |
if (oss->pcm_buf) { |
| 401 |
if (oss->mmapped) { |
if (oss->mmapped) { |
| 402 |
err = munmap (oss->pcm_buf, hw->bufsize); |
err = munmap (oss->pcm_buf, hw->samples << hw->info.shift); |
| 403 |
if (err) { |
if (err) { |
| 404 |
oss_logerr (errno, "Failed to unmap buffer %p, size %d\n", |
oss_logerr (errno, "Failed to unmap buffer %p, size %d\n", |
| 405 |
oss->pcm_buf, hw->bufsize); |
oss->pcm_buf, hw->samples << hw->info.shift); |
| 406 |
} |
} |
| 407 |
} |
} |
| 408 |
else { |
else { |
| 412 |
} |
} |
| 413 |
} |
} |
| 414 |
|
|
| 415 |
static int oss_init_out (HWVoiceOut *hw, int freq, int nchannels, audfmt_e fmt) |
static int oss_init_out (HWVoiceOut *hw, audsettings_t *as) |
| 416 |
{ |
{ |
| 417 |
OSSVoiceOut *oss = (OSSVoiceOut *) hw; |
OSSVoiceOut *oss = (OSSVoiceOut *) hw; |
| 418 |
struct oss_params req, obt; |
struct oss_params req, obt; |
| 420 |
int err; |
int err; |
| 421 |
int fd; |
int fd; |
| 422 |
audfmt_e effective_fmt; |
audfmt_e effective_fmt; |
| 423 |
|
audsettings_t obt_as; |
| 424 |
|
|
| 425 |
req.fmt = aud_to_ossfmt (fmt); |
req.fmt = aud_to_ossfmt (as->fmt); |
| 426 |
req.freq = freq; |
req.freq = as->freq; |
| 427 |
req.nchannels = nchannels; |
req.nchannels = as->nchannels; |
| 428 |
req.fragsize = conf.fragsize; |
req.fragsize = conf.fragsize; |
| 429 |
req.nfrags = conf.nfrags; |
req.nfrags = conf.nfrags; |
| 430 |
|
|
| 438 |
return -1; |
return -1; |
| 439 |
} |
} |
| 440 |
|
|
| 441 |
|
obt_as.freq = obt.freq; |
| 442 |
|
obt_as.nchannels = obt.nchannels; |
| 443 |
|
obt_as.fmt = effective_fmt; |
| 444 |
|
|
| 445 |
audio_pcm_init_info ( |
audio_pcm_init_info ( |
| 446 |
&hw->info, |
&hw->info, |
| 447 |
obt.freq, |
&obt_as, |
|
obt.nchannels, |
|
|
effective_fmt, |
|
| 448 |
audio_need_to_swap_endian (endianness) |
audio_need_to_swap_endian (endianness) |
| 449 |
); |
); |
| 450 |
oss->nfrags = obt.nfrags; |
oss->nfrags = obt.nfrags; |
| 451 |
oss->fragsize = obt.fragsize; |
oss->fragsize = obt.fragsize; |
| 452 |
hw->bufsize = obt.nfrags * obt.fragsize; |
|
| 453 |
|
if (obt.nfrags * obt.fragsize & hw->info.align) { |
| 454 |
|
dolog ("warning: Misaligned DAC buffer, size %d, alignment %d\n", |
| 455 |
|
obt.nfrags * obt.fragsize, hw->info.align + 1); |
| 456 |
|
} |
| 457 |
|
|
| 458 |
|
hw->samples = (obt.nfrags * obt.fragsize) >> hw->info.shift; |
| 459 |
|
|
| 460 |
oss->mmapped = 0; |
oss->mmapped = 0; |
| 461 |
if (conf.try_mmap) { |
if (conf.try_mmap) { |
| 462 |
oss->pcm_buf = mmap (0, hw->bufsize, PROT_READ | PROT_WRITE, |
oss->pcm_buf = mmap ( |
| 463 |
MAP_SHARED, fd, 0); |
0, |
| 464 |
|
hw->samples << hw->info.shift, |
| 465 |
|
PROT_READ | PROT_WRITE, |
| 466 |
|
MAP_SHARED, |
| 467 |
|
fd, |
| 468 |
|
0 |
| 469 |
|
); |
| 470 |
if (oss->pcm_buf == MAP_FAILED) { |
if (oss->pcm_buf == MAP_FAILED) { |
| 471 |
oss_logerr (errno, "Failed to map %d bytes of DAC\n", |
oss_logerr (errno, "Failed to map %d bytes of DAC\n", |
| 472 |
hw->bufsize); |
hw->samples << hw->info.shift); |
| 473 |
} else { |
} else { |
| 474 |
int err; |
int err; |
| 475 |
int trig = 0; |
int trig = 0; |
| 490 |
} |
} |
| 491 |
|
|
| 492 |
if (!oss->mmapped) { |
if (!oss->mmapped) { |
| 493 |
err = munmap (oss->pcm_buf, hw->bufsize); |
err = munmap (oss->pcm_buf, hw->samples << hw->info.shift); |
| 494 |
if (err) { |
if (err) { |
| 495 |
oss_logerr (errno, "Failed to unmap buffer %p size %d\n", |
oss_logerr (errno, "Failed to unmap buffer %p size %d\n", |
| 496 |
oss->pcm_buf, hw->bufsize); |
oss->pcm_buf, hw->samples << hw->info.shift); |
| 497 |
} |
} |
| 498 |
} |
} |
| 499 |
} |
} |
| 500 |
} |
} |
| 501 |
|
|
| 502 |
if (!oss->mmapped) { |
if (!oss->mmapped) { |
| 503 |
oss->pcm_buf = qemu_mallocz (hw->bufsize); |
oss->pcm_buf = audio_calloc ( |
| 504 |
|
AUDIO_FUNC, |
| 505 |
|
hw->samples, |
| 506 |
|
1 << hw->info.shift |
| 507 |
|
); |
| 508 |
if (!oss->pcm_buf) { |
if (!oss->pcm_buf) { |
| 509 |
|
dolog ("Could not allocate DAC buffer (%d bytes)\n", |
| 510 |
|
hw->samples << hw->info.shift); |
| 511 |
oss_anal_close (&fd); |
oss_anal_close (&fd); |
| 512 |
return -1; |
return -1; |
| 513 |
} |
} |
| 552 |
return 0; |
return 0; |
| 553 |
} |
} |
| 554 |
|
|
| 555 |
static int oss_init_in (HWVoiceIn *hw, |
static int oss_init_in (HWVoiceIn *hw, audsettings_t *as) |
|
int freq, int nchannels, audfmt_e fmt) |
|
| 556 |
{ |
{ |
| 557 |
OSSVoiceIn *oss = (OSSVoiceIn *) hw; |
OSSVoiceIn *oss = (OSSVoiceIn *) hw; |
| 558 |
struct oss_params req, obt; |
struct oss_params req, obt; |
| 560 |
int err; |
int err; |
| 561 |
int fd; |
int fd; |
| 562 |
audfmt_e effective_fmt; |
audfmt_e effective_fmt; |
| 563 |
|
audsettings_t obt_as; |
| 564 |
|
|
| 565 |
req.fmt = aud_to_ossfmt (fmt); |
req.fmt = aud_to_ossfmt (as->fmt); |
| 566 |
req.freq = freq; |
req.freq = as->freq; |
| 567 |
req.nchannels = nchannels; |
req.nchannels = as->nchannels; |
| 568 |
req.fragsize = conf.fragsize; |
req.fragsize = conf.fragsize; |
| 569 |
req.nfrags = conf.nfrags; |
req.nfrags = conf.nfrags; |
| 570 |
if (oss_open (1, &req, &obt, &fd)) { |
if (oss_open (1, &req, &obt, &fd)) { |
| 577 |
return -1; |
return -1; |
| 578 |
} |
} |
| 579 |
|
|
| 580 |
|
obt_as.freq = obt.freq; |
| 581 |
|
obt_as.nchannels = obt.nchannels; |
| 582 |
|
obt_as.fmt = effective_fmt; |
| 583 |
|
|
| 584 |
audio_pcm_init_info ( |
audio_pcm_init_info ( |
| 585 |
&hw->info, |
&hw->info, |
| 586 |
obt.freq, |
&obt_as, |
|
obt.nchannels, |
|
|
effective_fmt, |
|
| 587 |
audio_need_to_swap_endian (endianness) |
audio_need_to_swap_endian (endianness) |
| 588 |
); |
); |
| 589 |
oss->nfrags = obt.nfrags; |
oss->nfrags = obt.nfrags; |
| 590 |
oss->fragsize = obt.fragsize; |
oss->fragsize = obt.fragsize; |
| 591 |
hw->bufsize = obt.nfrags * obt.fragsize; |
|
| 592 |
oss->pcm_buf = qemu_mallocz (hw->bufsize); |
if (obt.nfrags * obt.fragsize & hw->info.align) { |
| 593 |
|
dolog ("warning: Misaligned ADC buffer, size %d, alignment %d\n", |
| 594 |
|
obt.nfrags * obt.fragsize, hw->info.align + 1); |
| 595 |
|
} |
| 596 |
|
|
| 597 |
|
hw->samples = (obt.nfrags * obt.fragsize) >> hw->info.shift; |
| 598 |
|
oss->pcm_buf = audio_calloc (AUDIO_FUNC, hw->samples, 1 << hw->info.shift); |
| 599 |
if (!oss->pcm_buf) { |
if (!oss->pcm_buf) { |
| 600 |
|
dolog ("Could not allocate ADC buffer (%d bytes)\n", |
| 601 |
|
hw->samples << hw->info.shift); |
| 602 |
oss_anal_close (&fd); |
oss_anal_close (&fd); |
| 603 |
return -1; |
return -1; |
| 604 |
} |
} |
| 657 |
|
|
| 658 |
if (nread > 0) { |
if (nread > 0) { |
| 659 |
if (nread & hw->info.align) { |
if (nread & hw->info.align) { |
| 660 |
dolog ("warning: misaligned read %d (requested %d), " |
dolog ("warning: Misaligned read %d (requested %d), " |
| 661 |
"alignment %d\n", nread, bufs[i].add << hwshift, |
"alignment %d\n", nread, bufs[i].add << hwshift, |
| 662 |
hw->info.align + 1); |
hw->info.align + 1); |
| 663 |
} |
} |