FreeBSD kernel sound device code
channel.c
Go to the documentation of this file.
1/*-
2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3 *
4 * Copyright (c) 2005-2009 Ariff Abdullah <ariff@FreeBSD.org>
5 * Portions Copyright (c) Ryan Beasley <ryan.beasley@gmail.com> - GSoC 2006
6 * Copyright (c) 1999 Cameron Grant <cg@FreeBSD.org>
7 * Portions Copyright (c) Luigi Rizzo <luigi@FreeBSD.org> - 1997-99
8 * All rights reserved.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
30 */
31
32#include "opt_isa.h"
33
34#ifdef HAVE_KERNEL_OPTION_HEADERS
35#include "opt_snd.h"
36#endif
37
38#include <dev/sound/pcm/sound.h>
39#include <dev/sound/pcm/vchan.h>
40
41#include "feeder_if.h"
42
43SND_DECLARE_FILE("$FreeBSD$");
44
46SYSCTL_INT(_hw_snd, OID_AUTO, report_soft_formats, CTLFLAG_RW,
47 &report_soft_formats, 0, "report software-emulated formats");
48
50SYSCTL_INT(_hw_snd, OID_AUTO, report_soft_matrix, CTLFLAG_RW,
51 &report_soft_matrix, 0, "report software-emulated channel matrixing");
52
54
55static int
56sysctl_hw_snd_latency(SYSCTL_HANDLER_ARGS)
57{
58 int err, val;
59
61 err = sysctl_handle_int(oidp, &val, 0, req);
62 if (err != 0 || req->newptr == NULL)
63 return err;
64 if (val < CHN_LATENCY_MIN || val > CHN_LATENCY_MAX)
65 err = EINVAL;
66 else
68
69 return err;
70}
71SYSCTL_PROC(_hw_snd, OID_AUTO, latency,
72 CTLTYPE_INT | CTLFLAG_RWTUN | CTLFLAG_MPSAFE, 0, sizeof(int),
74 "buffering latency (0=low ... 10=high)");
75
77
78static int
80{
81 int err, val;
82
84 err = sysctl_handle_int(oidp, &val, 0, req);
85 if (err != 0 || req->newptr == NULL)
86 return err;
87 if (val < CHN_LATENCY_PROFILE_MIN || val > CHN_LATENCY_PROFILE_MAX)
88 err = EINVAL;
89 else
91
92 return err;
93}
94SYSCTL_PROC(_hw_snd, OID_AUTO, latency_profile,
95 CTLTYPE_INT | CTLFLAG_RWTUN | CTLFLAG_MPSAFE, 0, sizeof(int),
97 "buffering latency profile (0=aggressive 1=safe)");
98
100
101static int
102sysctl_hw_snd_timeout(SYSCTL_HANDLER_ARGS)
103{
104 int err, val;
105
107 err = sysctl_handle_int(oidp, &val, 0, req);
108 if (err != 0 || req->newptr == NULL)
109 return err;
110 if (val < CHN_TIMEOUT_MIN || val > CHN_TIMEOUT_MAX)
111 err = EINVAL;
112 else
114
115 return err;
116}
117SYSCTL_PROC(_hw_snd, OID_AUTO, timeout,
118 CTLTYPE_INT | CTLFLAG_RWTUN | CTLFLAG_MPSAFE, 0, sizeof(int),
120 "interrupt timeout (1 - 10) seconds");
121
122static int chn_vpc_autoreset = 1;
123SYSCTL_INT(_hw_snd, OID_AUTO, vpc_autoreset, CTLFLAG_RWTUN,
124 &chn_vpc_autoreset, 0, "automatically reset channels volume to 0db");
125
127
128static void
129chn_vpc_proc(int reset, int db)
130{
131 struct snddev_info *d;
132 struct pcm_channel *c;
133 int i;
134
135 for (i = 0; pcm_devclass != NULL &&
136 i < devclass_get_maxunit(pcm_devclass); i++) {
137 d = devclass_get_softc(pcm_devclass, i);
138 if (!PCM_REGISTERED(d))
139 continue;
140 PCM_LOCK(d);
141 PCM_WAIT(d);
142 PCM_ACQUIRE(d);
143 CHN_FOREACH(c, d, channels.pcm) {
144 CHN_LOCK(c);
146 if (reset != 0)
148 CHN_UNLOCK(c);
149 }
150 PCM_RELEASE(d);
151 PCM_UNLOCK(d);
152 }
153}
154
155static int
156sysctl_hw_snd_vpc_0db(SYSCTL_HANDLER_ARGS)
157{
158 int err, val;
159
161 err = sysctl_handle_int(oidp, &val, 0, req);
162 if (err != 0 || req->newptr == NULL)
163 return (err);
164 if (val < SND_VOL_0DB_MIN || val > SND_VOL_0DB_MAX)
165 return (EINVAL);
166
168 chn_vpc_proc(0, val);
169
170 return (0);
171}
172SYSCTL_PROC(_hw_snd, OID_AUTO, vpc_0db,
173 CTLTYPE_INT | CTLFLAG_RWTUN | CTLFLAG_NEEDGIANT, 0, sizeof(int),
175 "0db relative level");
176
177static int
178sysctl_hw_snd_vpc_reset(SYSCTL_HANDLER_ARGS)
179{
180 int err, val;
181
182 val = 0;
183 err = sysctl_handle_int(oidp, &val, 0, req);
184 if (err != 0 || req->newptr == NULL || val == 0)
185 return (err);
186
189
190 return (0);
191}
192SYSCTL_PROC(_hw_snd, OID_AUTO, vpc_reset,
193 CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_NEEDGIANT, 0, sizeof(int),
195 "reset volume on all channels");
196
197static int chn_usefrags = 0;
198static int chn_syncdelay = -1;
199
200SYSCTL_INT(_hw_snd, OID_AUTO, usefrags, CTLFLAG_RWTUN,
201 &chn_usefrags, 0, "prefer setfragments() over setblocksize()");
202SYSCTL_INT(_hw_snd, OID_AUTO, syncdelay, CTLFLAG_RWTUN,
203 &chn_syncdelay, 0,
204 "append (0-1000) millisecond trailing buffer delay on each sync");
205
213MTX_SYSINIT(pcm_syncgroup, &snd_pcm_syncgroups_mtx, "PCM channel sync group lock", MTX_DEF);
222struct pcm_synclist snd_pcm_syncgroups = SLIST_HEAD_INITIALIZER(snd_pcm_syncgroups);
223
224static void
226{
227 switch (dir) {
228 case PCMDIR_PLAY:
229 c->lock = snd_mtxcreate(c->name, "pcm play channel");
230 cv_init(&c->intr_cv, "pcmwr");
231 break;
233 c->lock = snd_mtxcreate(c->name, "pcm virtual play channel");
234 cv_init(&c->intr_cv, "pcmwrv");
235 break;
236 case PCMDIR_REC:
237 c->lock = snd_mtxcreate(c->name, "pcm record channel");
238 cv_init(&c->intr_cv, "pcmrd");
239 break;
241 c->lock = snd_mtxcreate(c->name, "pcm virtual record channel");
242 cv_init(&c->intr_cv, "pcmrdv");
243 break;
244 default:
245 panic("%s(): Invalid direction=%d", __func__, dir);
246 break;
247 }
248
249 cv_init(&c->cv, "pcmchn");
250}
251
252static void
254{
256
257 CHN_BROADCAST(&c->cv);
259
260 cv_destroy(&c->cv);
261 cv_destroy(&c->intr_cv);
262
264}
265
272static int
274{
275 struct snd_dbuf *bs = c->bufsoft;
276 u_int delta;
277
279
280 if (c->flags & CHN_F_MMAP) {
281 if (sndbuf_getprevtotal(bs) < c->lw)
282 delta = c->lw;
283 else
284 delta = sndbuf_gettotal(bs) - sndbuf_getprevtotal(bs);
285 } else {
286 if (c->direction == PCMDIR_PLAY)
287 delta = sndbuf_getfree(bs);
288 else
289 delta = sndbuf_getready(bs);
290 }
291
292 return ((delta < c->lw) ? 0 : 1);
293}
294
295static void
297{
298
301}
302
303static void
305{
306 struct snd_dbuf *bs;
307 struct pcm_channel *ch;
308
310
311 bs = c->bufsoft;
312
313 if (CHN_EMPTY(c, children.busy)) {
314 if (SEL_WAITING(sndbuf_getsel(bs)) && chn_polltrigger(c))
315 selwakeuppri(sndbuf_getsel(bs), PRIBIO);
316 if (c->flags & CHN_F_SLEEPING) {
317 /*
318 * Ok, I can just panic it right here since it is
319 * quite obvious that we never allow multiple waiters
320 * from userland. I'm too generous...
321 */
323 }
324 } else {
325 CHN_FOREACH(ch, c, children.busy) {
326 CHN_LOCK(ch);
327 chn_wakeup(ch);
328 CHN_UNLOCK(ch);
329 }
330 }
331}
332
333static int
335{
336 int ret;
337
339
340 if (c->flags & CHN_F_DEAD)
341 return (EINVAL);
342
344 ret = cv_timedwait_sig(&c->intr_cv, c->lock, timeout);
345 c->flags &= ~CHN_F_SLEEPING;
346
347 return ((c->flags & CHN_F_DEAD) ? EINVAL : ret);
348}
349
350/*
351 * chn_dmaupdate() tracks the status of a dma transfer,
352 * updating pointers.
353 */
354
355static unsigned int
357{
358 struct snd_dbuf *b = c->bufhard;
359 unsigned int delta, old, hwptr, amt;
360
361 KASSERT(sndbuf_getsize(b) > 0, ("bufsize == 0"));
363
364 old = sndbuf_gethwptr(b);
365 hwptr = chn_getptr(c);
366 delta = (sndbuf_getsize(b) + hwptr - old) % sndbuf_getsize(b);
367 sndbuf_sethwptr(b, hwptr);
368
369 if (c->direction == PCMDIR_PLAY) {
370 amt = min(delta, sndbuf_getready(b));
371 amt -= amt % sndbuf_getalign(b);
372 if (amt > 0)
373 sndbuf_dispose(b, NULL, amt);
374 } else {
375 amt = min(delta, sndbuf_getfree(b));
376 amt -= amt % sndbuf_getalign(b);
377 if (amt > 0)
378 sndbuf_acquire(b, NULL, amt);
379 }
380 if (snd_verbose > 3 && CHN_STARTED(c) && delta == 0) {
381 device_printf(c->dev, "WARNING: %s DMA completion "
382 "too fast/slow ! hwptr=%u, old=%u "
383 "delta=%u amt=%u ready=%u free=%u\n",
384 CHN_DIRSTR(c), hwptr, old, delta, amt,
386 }
387
388 return delta;
389}
390
391static void
393{
394 struct snd_dbuf *b = c->bufhard;
395 struct snd_dbuf *bs = c->bufsoft;
396 unsigned int amt, want, wasfree;
397
399
400 if ((c->flags & CHN_F_MMAP) && !(c->flags & CHN_F_CLOSING))
401 sndbuf_acquire(bs, NULL, sndbuf_getfree(bs));
402
403 wasfree = sndbuf_getfree(b);
404 want = min(sndbuf_getsize(b),
405 imax(0, sndbuf_xbytes(sndbuf_getsize(bs), bs, b) -
407 amt = min(wasfree, want);
408 if (amt > 0)
409 sndbuf_feed(bs, b, c, c->feeder, amt);
410
411 /*
412 * Possible xruns. There should be no empty space left in buffer.
413 */
414 if (sndbuf_getready(b) < want)
415 c->xruns++;
416
417 if (sndbuf_getfree(b) < wasfree)
418 chn_wakeup(c);
419}
420
421#if 0
422static void
423chn_wrupdate(struct pcm_channel *c)
424{
425
427 KASSERT(c->direction == PCMDIR_PLAY, ("%s(): bad channel", __func__));
428
429 if ((c->flags & (CHN_F_MMAP | CHN_F_VIRTUAL)) || CHN_STOPPED(c))
430 return;
432 chn_wrfeed(c);
433 /* tell the driver we've updated the primary buffer */
435}
436#endif
437
438static void
440{
441
443 /* update pointers in primary buffer */
445 /* ...and feed from secondary to primary */
446 chn_wrfeed(c);
447 /* tell the driver we've updated the primary buffer */
449}
450
451/*
452 * user write routine - uiomove data into secondary buffer, trigger if necessary
453 * if blocking, sleep, rinse and repeat.
454 *
455 * called externally, so must handle locking
456 */
457
458int
459chn_write(struct pcm_channel *c, struct uio *buf)
460{
461 struct snd_dbuf *bs = c->bufsoft;
462 void *off;
463 int ret, timeout, sz, t, p;
464
466
467 ret = 0;
468 timeout = chn_timeout * hz;
469
470 while (ret == 0 && buf->uio_resid > 0) {
471 sz = min(buf->uio_resid, sndbuf_getfree(bs));
472 if (sz > 0) {
473 /*
474 * The following assumes that the free space in
475 * the buffer can never be less around the
476 * unlock-uiomove-lock sequence.
477 */
478 while (ret == 0 && sz > 0) {
479 p = sndbuf_getfreeptr(bs);
480 t = min(sz, sndbuf_getsize(bs) - p);
481 off = sndbuf_getbufofs(bs, p);
482 CHN_UNLOCK(c);
483 ret = uiomove(off, t, buf);
484 CHN_LOCK(c);
485 sz -= t;
486 sndbuf_acquire(bs, NULL, t);
487 }
488 ret = 0;
489 if (CHN_STOPPED(c) && !(c->flags & CHN_F_NOTRIGGER)) {
490 ret = chn_start(c, 0);
491 if (ret != 0)
492 c->flags |= CHN_F_DEAD;
493 }
494 } else if (c->flags & (CHN_F_NBIO | CHN_F_NOTRIGGER)) {
505 ret = EAGAIN;
506 } else {
507 ret = chn_sleep(c, timeout);
508 if (ret == EAGAIN) {
509 ret = EINVAL;
510 c->flags |= CHN_F_DEAD;
511 device_printf(c->dev, "%s(): %s: "
512 "play interrupt timeout, channel dead\n",
513 __func__, c->name);
514 } else if (ret == ERESTART || ret == EINTR)
516 }
517 }
518
519 return (ret);
520}
521
522/*
523 * Feed new data from the read buffer. Can be called in the bottom half.
524 */
525static void
527{
528 struct snd_dbuf *b = c->bufhard;
529 struct snd_dbuf *bs = c->bufsoft;
530 unsigned int amt;
531
533
534 if (c->flags & CHN_F_MMAP)
535 sndbuf_dispose(bs, NULL, sndbuf_getready(bs));
536
537 amt = sndbuf_getfree(bs);
538 if (amt > 0)
539 sndbuf_feed(b, bs, c, c->feeder, amt);
540
542 if (amt > 0) {
543 c->xruns++;
544 sndbuf_dispose(b, NULL, amt);
545 }
546
547 if (sndbuf_getready(bs) > 0)
548 chn_wakeup(c);
549}
550
551#if 0
552static void
553chn_rdupdate(struct pcm_channel *c)
554{
555
557 KASSERT(c->direction == PCMDIR_REC, ("chn_rdupdate on bad channel"));
558
559 if ((c->flags & (CHN_F_MMAP | CHN_F_VIRTUAL)) || CHN_STOPPED(c))
560 return;
563 chn_rdfeed(c);
564}
565#endif
566
567/* read interrupt routine. Must be called with interrupts blocked. */
568static void
570{
571
573 /* tell the driver to update the primary buffer if non-dma */
575 /* update pointers in primary buffer */
577 /* ...and feed from primary to secondary */
578 chn_rdfeed(c);
579}
580
581/*
582 * user read routine - trigger if necessary, uiomove data from secondary buffer
583 * if blocking, sleep, rinse and repeat.
584 *
585 * called externally, so must handle locking
586 */
587
588int
589chn_read(struct pcm_channel *c, struct uio *buf)
590{
591 struct snd_dbuf *bs = c->bufsoft;
592 void *off;
593 int ret, timeout, sz, t, p;
594
596
597 if (CHN_STOPPED(c) && !(c->flags & CHN_F_NOTRIGGER)) {
598 ret = chn_start(c, 0);
599 if (ret != 0) {
600 c->flags |= CHN_F_DEAD;
601 return (ret);
602 }
603 }
604
605 ret = 0;
606 timeout = chn_timeout * hz;
607
608 while (ret == 0 && buf->uio_resid > 0) {
609 sz = min(buf->uio_resid, sndbuf_getready(bs));
610 if (sz > 0) {
611 /*
612 * The following assumes that the free space in
613 * the buffer can never be less around the
614 * unlock-uiomove-lock sequence.
615 */
616 while (ret == 0 && sz > 0) {
617 p = sndbuf_getreadyptr(bs);
618 t = min(sz, sndbuf_getsize(bs) - p);
619 off = sndbuf_getbufofs(bs, p);
620 CHN_UNLOCK(c);
621 ret = uiomove(off, t, buf);
622 CHN_LOCK(c);
623 sz -= t;
624 sndbuf_dispose(bs, NULL, t);
625 }
626 ret = 0;
627 } else if (c->flags & (CHN_F_NBIO | CHN_F_NOTRIGGER))
628 ret = EAGAIN;
629 else {
630 ret = chn_sleep(c, timeout);
631 if (ret == EAGAIN) {
632 ret = EINVAL;
633 c->flags |= CHN_F_DEAD;
634 device_printf(c->dev, "%s(): %s: "
635 "record interrupt timeout, channel dead\n",
636 __func__, c->name);
637 } else if (ret == ERESTART || ret == EINTR)
639 }
640 }
641
642 return (ret);
643}
644
645void
647{
648
650
651 c->interrupts++;
652
653 if (c->direction == PCMDIR_PLAY)
654 chn_wrintr(c);
655 else
656 chn_rdintr(c);
657}
658
659void
661{
662
663 if (CHN_LOCKOWNED(c)) {
665 return;
666 }
667
668 CHN_LOCK(c);
670 CHN_UNLOCK(c);
671}
672
673u_int32_t
674chn_start(struct pcm_channel *c, int force)
675{
676 u_int32_t i, j;
677 struct snd_dbuf *b = c->bufhard;
678 struct snd_dbuf *bs = c->bufsoft;
679 int err;
680
682 /* if we're running, or if we're prevented from triggering, bail */
683 if (CHN_STARTED(c) || ((c->flags & CHN_F_NOTRIGGER) && !force))
684 return (EINVAL);
685
686 err = 0;
687
688 if (force) {
689 i = 1;
690 j = 0;
691 } else {
692 if (c->direction == PCMDIR_REC) {
693 i = sndbuf_getfree(bs);
694 j = (i > 0) ? 1 : sndbuf_getready(b);
695 } else {
696 if (sndbuf_getfree(bs) == 0) {
697 i = 1;
698 j = 0;
699 } else {
700 struct snd_dbuf *pb;
701
702 pb = CHN_BUF_PARENT(c, b);
703 i = sndbuf_xbytes(sndbuf_getready(bs), bs, pb);
704 j = sndbuf_getalign(pb);
705 }
706 }
707 if (snd_verbose > 3 && CHN_EMPTY(c, children))
708 device_printf(c->dev, "%s(): %s (%s) threshold "
709 "i=%d j=%d\n", __func__, CHN_DIRSTR(c),
710 (c->flags & CHN_F_VIRTUAL) ? "virtual" :
711 "hardware", i, j);
712 }
713
714 if (i >= j) {
716 sndbuf_setrun(b, 1);
717 if (c->flags & CHN_F_CLOSING)
718 c->feedcount = 2;
719 else {
720 c->feedcount = 0;
721 c->interrupts = 0;
722 c->xruns = 0;
723 }
724 if (c->parentchannel == NULL) {
725 if (c->direction == PCMDIR_PLAY)
727 sndbuf_xbytes(sndbuf_getsize(bs), bs, b));
728 if (snd_verbose > 3)
729 device_printf(c->dev,
730 "%s(): %s starting! (%s/%s) "
731 "(ready=%d force=%d i=%d j=%d "
732 "intrtimeout=%u latency=%dms)\n",
733 __func__,
734 (c->flags & CHN_F_HAS_VCHAN) ?
735 "VCHAN PARENT" : "HW", CHN_DIRSTR(c),
736 (c->flags & CHN_F_CLOSING) ? "closing" :
737 "running",
739 force, i, j, c->timeout,
740 (sndbuf_getsize(b) * 1000) /
742 }
744 }
745
746 return (err);
747}
748
749void
751{
752 struct snd_dbuf *b = c->bufhard;
753 struct snd_dbuf *bs = c->bufsoft;
754
755 c->blocks = 0;
757 sndbuf_reset(bs);
758}
759
760/*
761 * chn_sync waits until the space in the given channel goes above
762 * a threshold. The threshold is checked against fl or rl respectively.
763 * Assume that the condition can become true, do not check here...
764 */
765int
766chn_sync(struct pcm_channel *c, int threshold)
767{
768 struct snd_dbuf *b, *bs;
769 int ret, count, hcount, minflush, resid, residp, syncdelay, blksz;
770 u_int32_t cflag;
771
773
774 if (c->direction != PCMDIR_PLAY)
775 return (EINVAL);
776
777 bs = c->bufsoft;
778
779 if ((c->flags & (CHN_F_DEAD | CHN_F_ABORTING)) ||
780 (threshold < 1 && sndbuf_getready(bs) < 1))
781 return (0);
782
783 /* if we haven't yet started and nothing is buffered, else start*/
784 if (CHN_STOPPED(c)) {
785 if (threshold > 0 || sndbuf_getready(bs) > 0) {
786 ret = chn_start(c, 1);
787 if (ret != 0)
788 return (ret);
789 } else
790 return (0);
791 }
792
794
795 minflush = threshold + sndbuf_xbytes(sndbuf_getready(b), b, bs);
796
797 syncdelay = chn_syncdelay;
798
799 if (syncdelay < 0 && (threshold > 0 || sndbuf_getready(bs) > 0))
800 minflush += sndbuf_xbytes(sndbuf_getsize(b), b, bs);
801
802 /*
803 * Append (0-1000) millisecond trailing buffer (if needed)
804 * for slower / high latency hardwares (notably USB audio)
805 * to avoid audible truncation.
806 */
807 if (syncdelay > 0)
808 minflush += (sndbuf_getalign(bs) * sndbuf_getspd(bs) *
809 ((syncdelay > 1000) ? 1000 : syncdelay)) / 1000;
810
811 minflush -= minflush % sndbuf_getalign(bs);
812
813 if (minflush > 0) {
814 threshold = min(minflush, sndbuf_getfree(bs));
815 sndbuf_clear(bs, threshold);
816 sndbuf_acquire(bs, NULL, threshold);
817 minflush -= threshold;
818 }
819
820 resid = sndbuf_getready(bs);
821 residp = resid;
823 if (blksz < 1) {
824 device_printf(c->dev,
825 "%s(): WARNING: blksz < 1 ! maxsize=%d [%d/%d/%d]\n",
826 __func__, sndbuf_getmaxsize(b), sndbuf_getsize(b),
828 if (sndbuf_getblkcnt(b) > 0)
830 if (blksz < 1)
831 blksz = 1;
832 }
833 count = sndbuf_xbytes(minflush + resid, bs, b) / blksz;
834 hcount = count;
835 ret = 0;
836
837 if (snd_verbose > 3)
838 device_printf(c->dev, "%s(): [begin] timeout=%d count=%d "
839 "minflush=%d resid=%d\n", __func__, c->timeout, count,
840 minflush, resid);
841
842 cflag = c->flags & CHN_F_CLOSING;
844 while (count > 0 && (resid > 0 || minflush > 0)) {
845 ret = chn_sleep(c, c->timeout);
846 if (ret == ERESTART || ret == EINTR) {
848 break;
849 } else if (ret == 0 || ret == EAGAIN) {
850 resid = sndbuf_getready(bs);
851 if (resid == residp) {
852 --count;
853 if (snd_verbose > 3)
854 device_printf(c->dev,
855 "%s(): [stalled] timeout=%d "
856 "count=%d hcount=%d "
857 "resid=%d minflush=%d\n",
858 __func__, c->timeout, count,
859 hcount, resid, minflush);
860 } else if (resid < residp && count < hcount) {
861 ++count;
862 if (snd_verbose > 3)
863 device_printf(c->dev,
864 "%s((): [resume] timeout=%d "
865 "count=%d hcount=%d "
866 "resid=%d minflush=%d\n",
867 __func__, c->timeout, count,
868 hcount, resid, minflush);
869 }
870 if (minflush > 0 && sndbuf_getfree(bs) > 0) {
871 threshold = min(minflush,
872 sndbuf_getfree(bs));
873 sndbuf_clear(bs, threshold);
874 sndbuf_acquire(bs, NULL, threshold);
875 resid = sndbuf_getready(bs);
876 minflush -= threshold;
877 }
878 residp = resid;
879 } else
880 break;
881 }
882 c->flags &= ~CHN_F_CLOSING;
883 c->flags |= cflag;
884
885 if (snd_verbose > 3)
886 device_printf(c->dev,
887 "%s(): timeout=%d count=%d hcount=%d resid=%d residp=%d "
888 "minflush=%d ret=%d\n",
889 __func__, c->timeout, count, hcount, resid, residp,
890 minflush, ret);
891
892 return (0);
893}
894
895/* called externally, handle locking */
896int
897chn_poll(struct pcm_channel *c, int ev, struct thread *td)
898{
899 struct snd_dbuf *bs = c->bufsoft;
900 int ret;
901
903
904 if (!(c->flags & (CHN_F_MMAP | CHN_F_TRIGGERED))) {
905 ret = chn_start(c, 1);
906 if (ret != 0)
907 return (0);
908 }
909
910 ret = 0;
911 if (chn_polltrigger(c)) {
913 ret = ev;
914 } else
915 selrecord(td, sndbuf_getsel(bs));
916
917 return (ret);
918}
919
920/*
921 * chn_abort terminates a running dma transfer. it may sleep up to 200ms.
922 * it returns the number of bytes that have not been transferred.
923 *
924 * called from: dsp_close, dsp_ioctl, with channel locked
925 */
926int
928{
929 int missing = 0;
930 struct snd_dbuf *b = c->bufhard;
931 struct snd_dbuf *bs = c->bufsoft;
932
934 if (CHN_STOPPED(c))
935 return 0;
937
938 c->flags &= ~CHN_F_TRIGGERED;
939 /* kill the channel */
941 sndbuf_setrun(b, 0);
942 if (!(c->flags & CHN_F_VIRTUAL))
944 missing = sndbuf_getready(bs);
945
946 c->flags &= ~CHN_F_ABORTING;
947 return missing;
948}
949
950/*
951 * this routine tries to flush the dma transfer. It is called
952 * on a close of a playback channel.
953 * first, if there is data in the buffer, but the dma has not yet
954 * begun, we need to start it.
955 * next, we wait for the play buffer to drain
956 * finally, we stop the dma.
957 *
958 * called from: dsp_close, not valid for record channels.
959 */
960
961int
963{
964 struct snd_dbuf *b = c->bufhard;
965
967 KASSERT(c->direction == PCMDIR_PLAY, ("chn_flush on bad channel"));
968 DEB(printf("chn_flush: c->flags 0x%08x\n", c->flags));
969
971 chn_sync(c, 0);
972 c->flags &= ~CHN_F_TRIGGERED;
973 /* kill the channel */
975 sndbuf_setrun(b, 0);
976
977 c->flags &= ~CHN_F_CLOSING;
978 return 0;
979}
980
981int
982snd_fmtvalid(uint32_t fmt, uint32_t *fmtlist)
983{
984 int i;
985
986 for (i = 0; fmtlist[i] != 0; i++) {
987 if (fmt == fmtlist[i] ||
988 ((fmt & AFMT_PASSTHROUGH) &&
989 (AFMT_ENCODING(fmt) & fmtlist[i])))
990 return (1);
991 }
992
993 return (0);
994}
995
996static const struct {
997 char *name, *alias1, *alias2;
998 uint32_t afmt;
999} afmt_tab[] = {
1000 { "alaw", NULL, NULL, AFMT_A_LAW },
1001 { "mulaw", NULL, NULL, AFMT_MU_LAW },
1002 { "u8", "8", NULL, AFMT_U8 },
1003 { "s8", NULL, NULL, AFMT_S8 },
1004#if BYTE_ORDER == LITTLE_ENDIAN
1005 { "s16le", "s16", "16", AFMT_S16_LE },
1006 { "s16be", NULL, NULL, AFMT_S16_BE },
1007#else
1008 { "s16le", NULL, NULL, AFMT_S16_LE },
1009 { "s16be", "s16", "16", AFMT_S16_BE },
1010#endif
1011 { "u16le", NULL, NULL, AFMT_U16_LE },
1012 { "u16be", NULL, NULL, AFMT_U16_BE },
1013 { "s24le", NULL, NULL, AFMT_S24_LE },
1014 { "s24be", NULL, NULL, AFMT_S24_BE },
1015 { "u24le", NULL, NULL, AFMT_U24_LE },
1016 { "u24be", NULL, NULL, AFMT_U24_BE },
1017#if BYTE_ORDER == LITTLE_ENDIAN
1018 { "s32le", "s32", "32", AFMT_S32_LE },
1019 { "s32be", NULL, NULL, AFMT_S32_BE },
1020#else
1021 { "s32le", NULL, NULL, AFMT_S32_LE },
1022 { "s32be", "s32", "32", AFMT_S32_BE },
1023#endif
1024 { "u32le", NULL, NULL, AFMT_U32_LE },
1025 { "u32be", NULL, NULL, AFMT_U32_BE },
1026 { "ac3", NULL, NULL, AFMT_AC3 },
1027 { NULL, NULL, NULL, 0 }
1029
1030uint32_t
1031snd_str2afmt(const char *req)
1032{
1033 int ext;
1034 int ch;
1035 int i;
1036 char b1[8];
1037 char b2[8];
1038
1039 memset(b1, 0, sizeof(b1));
1040 memset(b2, 0, sizeof(b2));
1041
1042 i = sscanf(req, "%5[^:]:%6s", b1, b2);
1043
1044 if (i == 1) {
1045 if (strlen(req) != strlen(b1))
1046 return (0);
1047 strlcpy(b2, "2.0", sizeof(b2));
1048 } else if (i == 2) {
1049 if (strlen(req) != (strlen(b1) + 1 + strlen(b2)))
1050 return (0);
1051 } else
1052 return (0);
1053
1054 i = sscanf(b2, "%d.%d", &ch, &ext);
1055
1056 if (i == 0) {
1057 if (strcasecmp(b2, "mono") == 0) {
1058 ch = 1;
1059 ext = 0;
1060 } else if (strcasecmp(b2, "stereo") == 0) {
1061 ch = 2;
1062 ext = 0;
1063 } else if (strcasecmp(b2, "quad") == 0) {
1064 ch = 4;
1065 ext = 0;
1066 } else
1067 return (0);
1068 } else if (i == 1) {
1069 if (ch < 1 || ch > AFMT_CHANNEL_MAX)
1070 return (0);
1071 ext = 0;
1072 } else if (i == 2) {
1073 if (ext < 0 || ext > AFMT_EXTCHANNEL_MAX)
1074 return (0);
1075 if (ch < 1 || (ch + ext) > AFMT_CHANNEL_MAX)
1076 return (0);
1077 } else
1078 return (0);
1079
1080 for (i = 0; afmt_tab[i].name != NULL; i++) {
1081 if (strcasecmp(afmt_tab[i].name, b1) != 0) {
1082 if (afmt_tab[i].alias1 == NULL)
1083 continue;
1084 if (strcasecmp(afmt_tab[i].alias1, b1) != 0) {
1085 if (afmt_tab[i].alias2 == NULL)
1086 continue;
1087 if (strcasecmp(afmt_tab[i].alias2, b1) != 0)
1088 continue;
1089 }
1090 }
1091 /* found a match */
1092 return (SND_FORMAT(afmt_tab[i].afmt, ch + ext, ext));
1093 }
1094 /* not a valid format */
1095 return (0);
1096}
1097
1098uint32_t
1099snd_afmt2str(uint32_t afmt, char *buf, size_t len)
1100{
1101 uint32_t enc;
1102 uint32_t ext;
1103 uint32_t ch;
1104 int i;
1105
1106 if (buf == NULL || len < AFMTSTR_LEN)
1107 return (0);
1108
1109 memset(buf, 0, len);
1110
1111 enc = AFMT_ENCODING(afmt);
1112 ch = AFMT_CHANNEL(afmt);
1113 ext = AFMT_EXTCHANNEL(afmt);
1114 /* check there is at least one channel */
1115 if (ch <= ext)
1116 return (0);
1117 for (i = 0; afmt_tab[i].name != NULL; i++) {
1118 if (enc != afmt_tab[i].afmt)
1119 continue;
1120 /* found a match */
1121 snprintf(buf, len, "%s:%d.%d",
1122 afmt_tab[i].name, ch - ext, ext);
1123 return (SND_FORMAT(enc, ch, ext));
1124 }
1125 return (0);
1126}
1127
1128int
1129chn_reset(struct pcm_channel *c, uint32_t fmt, uint32_t spd)
1130{
1131 int r;
1132
1134 c->feedcount = 0;
1135 c->flags &= CHN_F_RESET;
1136 c->interrupts = 0;
1137 c->timeout = 1;
1138 c->xruns = 0;
1139
1141 CHN_F_BITPERFECT : 0;
1142
1143 r = CHANNEL_RESET(c->methods, c->devinfo);
1144 if (r == 0 && fmt != 0 && spd != 0) {
1145 r = chn_setparam(c, fmt, spd);
1146 fmt = 0;
1147 spd = 0;
1148 }
1149 if (r == 0 && fmt != 0)
1150 r = chn_setformat(c, fmt);
1151 if (r == 0 && spd != 0)
1152 r = chn_setspeed(c, spd);
1153 if (r == 0)
1155 if (r == 0) {
1156 chn_resetbuf(c);
1157 r = CHANNEL_RESETDONE(c->methods, c->devinfo);
1158 }
1159 return r;
1160}
1161
1162int
1163chn_init(struct pcm_channel *c, void *devinfo, int dir, int direction)
1164{
1165 struct feeder_class *fc;
1166 struct snd_dbuf *b, *bs;
1167 int i, ret;
1168
1169 if (chn_timeout < CHN_TIMEOUT_MIN || chn_timeout > CHN_TIMEOUT_MAX)
1171
1172 chn_lockinit(c, dir);
1173
1174 b = NULL;
1175 bs = NULL;
1176 CHN_INIT(c, children);
1177 CHN_INIT(c, children.busy);
1178 c->devinfo = NULL;
1179 c->feeder = NULL;
1180 c->latency = -1;
1181 c->timeout = 1;
1182
1183 ret = ENOMEM;
1184 b = sndbuf_create(c->dev, c->name, "primary", c);
1185 if (b == NULL)
1186 goto out;
1187 bs = sndbuf_create(c->dev, c->name, "secondary", c);
1188 if (bs == NULL)
1189 goto out;
1190
1191 CHN_LOCK(c);
1192
1193 ret = EINVAL;
1194 fc = feeder_getclass(NULL);
1195 if (fc == NULL)
1196 goto out;
1197 if (chn_addfeeder(c, fc, NULL))
1198 goto out;
1199
1200 /*
1201 * XXX - sndbuf_setup() & sndbuf_resize() expect to be called
1202 * with the channel unlocked because they are also called
1203 * from driver methods that don't know about locking
1204 */
1205 CHN_UNLOCK(c);
1206 sndbuf_setup(bs, NULL, 0);
1207 CHN_LOCK(c);
1208 c->bufhard = b;
1209 c->bufsoft = bs;
1210 c->flags = 0;
1211 c->feederflags = 0;
1212 c->sm = NULL;
1213 c->format = SND_FORMAT(AFMT_U8, 1, 0);
1215
1218
1219 for (i = 0; i < SND_CHN_T_MAX; i++) {
1221 }
1222
1225
1226 memset(c->muted, 0, sizeof(c->muted));
1227
1229
1230 ret = ENODEV;
1231 CHN_UNLOCK(c); /* XXX - Unlock for CHANNEL_INIT() malloc() call */
1232 c->devinfo = CHANNEL_INIT(c->methods, devinfo, b, c, direction);
1233 CHN_LOCK(c);
1234 if (c->devinfo == NULL)
1235 goto out;
1236
1237 ret = ENOMEM;
1238 if ((sndbuf_getsize(b) == 0) && ((c->flags & CHN_F_VIRTUAL) == 0))
1239 goto out;
1240
1241 ret = 0;
1242 c->direction = direction;
1243
1246 sndbuf_setfmt(bs, c->format);
1247 sndbuf_setspd(bs, c->speed);
1248
1254 if (c->direction == PCMDIR_PLAY) {
1255 bs->sl = sndbuf_getmaxsize(bs);
1256 bs->shadbuf = malloc(bs->sl, M_DEVBUF, M_NOWAIT);
1257 if (bs->shadbuf == NULL) {
1258 ret = ENOMEM;
1259 goto out;
1260 }
1261 }
1262
1263out:
1264 CHN_UNLOCK(c);
1265 if (ret) {
1266 if (c->devinfo) {
1267 if (CHANNEL_FREE(c->methods, c->devinfo))
1268 sndbuf_free(b);
1269 }
1270 if (bs)
1271 sndbuf_destroy(bs);
1272 if (b)
1274 CHN_LOCK(c);
1275 c->flags |= CHN_F_DEAD;
1277
1278 return ret;
1279 }
1280
1281 return 0;
1282}
1283
1284int
1286{
1287 struct snd_dbuf *b = c->bufhard;
1288 struct snd_dbuf *bs = c->bufsoft;
1289
1290 if (CHN_STARTED(c)) {
1291 CHN_LOCK(c);
1293 CHN_UNLOCK(c);
1294 }
1295 while (chn_removefeeder(c) == 0)
1296 ;
1297 if (CHANNEL_FREE(c->methods, c->devinfo))
1298 sndbuf_free(b);
1299 sndbuf_destroy(bs);
1301 CHN_LOCK(c);
1302 c->flags |= CHN_F_DEAD;
1304
1305 return (0);
1306}
1307
1308/* XXX Obsolete. Use *_matrix() variant instead. */
1309int
1311{
1312 int ret;
1313
1316 right) << 8;
1317
1318 return (ret);
1319}
1320
1321int
1322chn_setvolume_multi(struct pcm_channel *c, int vc, int left, int right,
1323 int center)
1324{
1325 int i, ret;
1326
1327 ret = 0;
1328
1329 for (i = 0; i < SND_CHN_T_MAX; i++) {
1330 if ((1 << i) & SND_CHN_LEFT_MASK)
1331 ret |= chn_setvolume_matrix(c, vc, i, left);
1332 else if ((1 << i) & SND_CHN_RIGHT_MASK)
1333 ret |= chn_setvolume_matrix(c, vc, i, right) << 8;
1334 else
1335 ret |= chn_setvolume_matrix(c, vc, i, center) << 16;
1336 }
1337
1338 return (ret);
1339}
1340
1341int
1342chn_setvolume_matrix(struct pcm_channel *c, int vc, int vt, int val)
1343{
1344 int i;
1345
1346 KASSERT(c != NULL && vc >= SND_VOL_C_MASTER && vc < SND_VOL_C_MAX &&
1347 (vc == SND_VOL_C_MASTER || (vc & 1)) &&
1348 (vt == SND_CHN_T_VOL_0DB || (vt >= SND_CHN_T_BEGIN &&
1349 vt <= SND_CHN_T_END)) && (vt != SND_CHN_T_VOL_0DB ||
1351 ("%s(): invalid volume matrix c=%p vc=%d vt=%d val=%d",
1352 __func__, c, vc, vt, val));
1354
1355 if (val < 0)
1356 val = 0;
1357 if (val > 100)
1358 val = 100;
1359
1360 c->volume[vc][vt] = val;
1361
1362 /*
1363 * Do relative calculation here and store it into class + 1
1364 * to ease the job of feeder_volume.
1365 */
1366 if (vc == SND_VOL_C_MASTER) {
1367 for (vc = SND_VOL_C_BEGIN; vc <= SND_VOL_C_END;
1368 vc += SND_VOL_C_STEP)
1369 c->volume[SND_VOL_C_VAL(vc)][vt] =
1370 SND_VOL_CALC_VAL(c->volume, vc, vt);
1371 } else if (vc & 1) {
1372 if (vt == SND_CHN_T_VOL_0DB)
1373 for (i = SND_CHN_T_BEGIN; i <= SND_CHN_T_END;
1374 i += SND_CHN_T_STEP) {
1375 c->volume[SND_VOL_C_VAL(vc)][i] =
1376 SND_VOL_CALC_VAL(c->volume, vc, i);
1377 }
1378 else
1379 c->volume[SND_VOL_C_VAL(vc)][vt] =
1380 SND_VOL_CALC_VAL(c->volume, vc, vt);
1381 }
1382
1383 return (val);
1384}
1385
1386int
1387chn_getvolume_matrix(struct pcm_channel *c, int vc, int vt)
1388{
1389 KASSERT(c != NULL && vc >= SND_VOL_C_MASTER && vc < SND_VOL_C_MAX &&
1390 (vt == SND_CHN_T_VOL_0DB ||
1391 (vt >= SND_CHN_T_BEGIN && vt <= SND_CHN_T_END)),
1392 ("%s(): invalid volume matrix c=%p vc=%d vt=%d",
1393 __func__, c, vc, vt));
1395
1396 return (c->volume[vc][vt]);
1397}
1398
1399int
1400chn_setmute_multi(struct pcm_channel *c, int vc, int mute)
1401{
1402 int i, ret;
1403
1404 ret = 0;
1405
1406 for (i = 0; i < SND_CHN_T_MAX; i++) {
1407 if ((1 << i) & SND_CHN_LEFT_MASK)
1408 ret |= chn_setmute_matrix(c, vc, i, mute);
1409 else if ((1 << i) & SND_CHN_RIGHT_MASK)
1410 ret |= chn_setmute_matrix(c, vc, i, mute) << 8;
1411 else
1412 ret |= chn_setmute_matrix(c, vc, i, mute) << 16;
1413 }
1414 return (ret);
1415}
1416
1417int
1418chn_setmute_matrix(struct pcm_channel *c, int vc, int vt, int mute)
1419{
1420 int i;
1421
1422 KASSERT(c != NULL && vc >= SND_VOL_C_MASTER && vc < SND_VOL_C_MAX &&
1423 (vc == SND_VOL_C_MASTER || (vc & 1)) &&
1424 (vt == SND_CHN_T_VOL_0DB || (vt >= SND_CHN_T_BEGIN && vt <= SND_CHN_T_END)),
1425 ("%s(): invalid mute matrix c=%p vc=%d vt=%d mute=%d",
1426 __func__, c, vc, vt, mute));
1427
1429
1430 mute = (mute != 0);
1431
1432 c->muted[vc][vt] = mute;
1433
1434 /*
1435 * Do relative calculation here and store it into class + 1
1436 * to ease the job of feeder_volume.
1437 */
1438 if (vc == SND_VOL_C_MASTER) {
1439 for (vc = SND_VOL_C_BEGIN; vc <= SND_VOL_C_END;
1440 vc += SND_VOL_C_STEP)
1441 c->muted[SND_VOL_C_VAL(vc)][vt] = mute;
1442 } else if (vc & 1) {
1443 if (vt == SND_CHN_T_VOL_0DB) {
1444 for (i = SND_CHN_T_BEGIN; i <= SND_CHN_T_END;
1445 i += SND_CHN_T_STEP) {
1446 c->muted[SND_VOL_C_VAL(vc)][i] = mute;
1447 }
1448 } else {
1449 c->muted[SND_VOL_C_VAL(vc)][vt] = mute;
1450 }
1451 }
1452 return (mute);
1453}
1454
1455int
1456chn_getmute_matrix(struct pcm_channel *c, int vc, int vt)
1457{
1458 KASSERT(c != NULL && vc >= SND_VOL_C_MASTER && vc < SND_VOL_C_MAX &&
1459 (vt == SND_CHN_T_VOL_0DB ||
1460 (vt >= SND_CHN_T_BEGIN && vt <= SND_CHN_T_END)),
1461 ("%s(): invalid mute matrix c=%p vc=%d vt=%d",
1462 __func__, c, vc, vt));
1464
1465 return (c->muted[vc][vt]);
1466}
1467
1468struct pcmchan_matrix *
1470{
1471
1472 KASSERT(c != NULL, ("%s(): NULL channel", __func__));
1474
1475 if (!(c->format & AFMT_CONVERTIBLE))
1476 return (NULL);
1477
1478 return (&c->matrix);
1479}
1480
1481int
1483{
1484
1485 KASSERT(c != NULL && m != NULL,
1486 ("%s(): NULL channel or matrix", __func__));
1488
1489 if (!(c->format & AFMT_CONVERTIBLE))
1490 return (EINVAL);
1491
1492 c->matrix = *m;
1494
1495 return (chn_setformat(c, SND_FORMAT(c->format, m->channels, m->ext)));
1496}
1497
1498/*
1499 * XXX chn_oss_* exists for the sake of compatibility.
1500 */
1501int
1502chn_oss_getorder(struct pcm_channel *c, unsigned long long *map)
1503{
1504
1505 KASSERT(c != NULL && map != NULL,
1506 ("%s(): NULL channel or map", __func__));
1508
1509 if (!(c->format & AFMT_CONVERTIBLE))
1510 return (EINVAL);
1511
1513}
1514
1515int
1516chn_oss_setorder(struct pcm_channel *c, unsigned long long *map)
1517{
1518 struct pcmchan_matrix m;
1519 int ret;
1520
1521 KASSERT(c != NULL && map != NULL,
1522 ("%s(): NULL channel or map", __func__));
1524
1525 if (!(c->format & AFMT_CONVERTIBLE))
1526 return (EINVAL);
1527
1528 m = c->matrix;
1530 if (ret != 0)
1531 return (ret);
1532
1533 return (chn_setmatrix(c, &m));
1534}
1535
1536#define SND_CHN_OSS_FRONT (SND_CHN_T_MASK_FL | SND_CHN_T_MASK_FR)
1537#define SND_CHN_OSS_SURR (SND_CHN_T_MASK_SL | SND_CHN_T_MASK_SR)
1538#define SND_CHN_OSS_CENTER_LFE (SND_CHN_T_MASK_FC | SND_CHN_T_MASK_LF)
1539#define SND_CHN_OSS_REAR (SND_CHN_T_MASK_BL | SND_CHN_T_MASK_BR)
1540
1541int
1542chn_oss_getmask(struct pcm_channel *c, uint32_t *retmask)
1543{
1544 struct pcmchan_matrix *m;
1545 struct pcmchan_caps *caps;
1546 uint32_t i, format;
1547
1548 KASSERT(c != NULL && retmask != NULL,
1549 ("%s(): NULL channel or retmask", __func__));
1551
1552 caps = chn_getcaps(c);
1553 if (caps == NULL || caps->fmtlist == NULL)
1554 return (ENODEV);
1555
1556 for (i = 0; caps->fmtlist[i] != 0; i++) {
1557 format = caps->fmtlist[i];
1558 if (!(format & AFMT_CONVERTIBLE)) {
1559 *retmask |= DSP_BIND_SPDIF;
1560 continue;
1561 }
1562 m = CHANNEL_GETMATRIX(c->methods, c->devinfo, format);
1563 if (m == NULL)
1564 continue;
1565 if (m->mask & SND_CHN_OSS_FRONT)
1566 *retmask |= DSP_BIND_FRONT;
1567 if (m->mask & SND_CHN_OSS_SURR)
1568 *retmask |= DSP_BIND_SURR;
1570 *retmask |= DSP_BIND_CENTER_LFE;
1571 if (m->mask & SND_CHN_OSS_REAR)
1572 *retmask |= DSP_BIND_REAR;
1573 }
1574
1575 /* report software-supported binding mask */
1577 *retmask |= DSP_BIND_FRONT | DSP_BIND_SURR |
1578 DSP_BIND_CENTER_LFE | DSP_BIND_REAR;
1579
1580 return (0);
1581}
1582
1583void
1584chn_vpc_reset(struct pcm_channel *c, int vc, int force)
1585{
1586 int i;
1587
1588 KASSERT(c != NULL && vc >= SND_VOL_C_BEGIN && vc <= SND_VOL_C_END,
1589 ("%s(): invalid reset c=%p vc=%d", __func__, c, vc));
1591
1592 if (force == 0 && chn_vpc_autoreset == 0)
1593 return;
1594
1595 for (i = SND_CHN_T_BEGIN; i <= SND_CHN_T_END; i += SND_CHN_T_STEP)
1596 CHN_SETVOLUME(c, vc, i, c->volume[vc][SND_CHN_T_VOL_0DB]);
1597}
1598
1599static u_int32_t
1600round_pow2(u_int32_t v)
1601{
1602 u_int32_t ret;
1603
1604 if (v < 2)
1605 v = 2;
1606 ret = 0;
1607 while (v >> ret)
1608 ret++;
1609 ret = 1 << (ret - 1);
1610 while (ret < v)
1611 ret <<= 1;
1612 return ret;
1613}
1614
1615static u_int32_t
1616round_blksz(u_int32_t v, int round)
1617{
1618 u_int32_t ret, tmp;
1619
1620 if (round < 1)
1621 round = 1;
1622
1623 ret = min(round_pow2(v), CHN_2NDBUFMAXSIZE >> 1);
1624
1625 if (ret > v && (ret >> 1) > 0 && (ret >> 1) >= ((v * 3) >> 2))
1626 ret >>= 1;
1627
1628 tmp = ret - (ret % round);
1629 while (tmp < 16 || tmp < round) {
1630 ret <<= 1;
1631 tmp = ret - (ret % round);
1632 }
1633
1634 return ret;
1635}
1636
1637/*
1638 * 4Front call it DSP Policy, while we call it "Latency Profile". The idea
1639 * is to keep 2nd buffer short so that it doesn't cause long queue during
1640 * buffer transfer.
1641 *
1642 * Latency reference table for 48khz stereo 16bit: (PLAY)
1643 *
1644 * +---------+------------+-----------+------------+
1645 * | Latency | Blockcount | Blocksize | Buffersize |
1646 * +---------+------------+-----------+------------+
1647 * | 0 | 2 | 64 | 128 |
1648 * +---------+------------+-----------+------------+
1649 * | 1 | 4 | 128 | 512 |
1650 * +---------+------------+-----------+------------+
1651 * | 2 | 8 | 512 | 4096 |
1652 * +---------+------------+-----------+------------+
1653 * | 3 | 16 | 512 | 8192 |
1654 * +---------+------------+-----------+------------+
1655 * | 4 | 32 | 512 | 16384 |
1656 * +---------+------------+-----------+------------+
1657 * | 5 | 32 | 1024 | 32768 |
1658 * +---------+------------+-----------+------------+
1659 * | 6 | 16 | 2048 | 32768 |
1660 * +---------+------------+-----------+------------+
1661 * | 7 | 8 | 4096 | 32768 |
1662 * +---------+------------+-----------+------------+
1663 * | 8 | 4 | 8192 | 32768 |
1664 * +---------+------------+-----------+------------+
1665 * | 9 | 2 | 16384 | 32768 |
1666 * +---------+------------+-----------+------------+
1667 * | 10 | 2 | 32768 | 65536 |
1668 * +---------+------------+-----------+------------+
1669 *
1670 * Recording need a different reference table. All we care is
1671 * gobbling up everything within reasonable buffering threshold.
1672 *
1673 * Latency reference table for 48khz stereo 16bit: (REC)
1674 *
1675 * +---------+------------+-----------+------------+
1676 * | Latency | Blockcount | Blocksize | Buffersize |
1677 * +---------+------------+-----------+------------+
1678 * | 0 | 512 | 32 | 16384 |
1679 * +---------+------------+-----------+------------+
1680 * | 1 | 256 | 64 | 16384 |
1681 * +---------+------------+-----------+------------+
1682 * | 2 | 128 | 128 | 16384 |
1683 * +---------+------------+-----------+------------+
1684 * | 3 | 64 | 256 | 16384 |
1685 * +---------+------------+-----------+------------+
1686 * | 4 | 32 | 512 | 16384 |
1687 * +---------+------------+-----------+------------+
1688 * | 5 | 32 | 1024 | 32768 |
1689 * +---------+------------+-----------+------------+
1690 * | 6 | 16 | 2048 | 32768 |
1691 * +---------+------------+-----------+------------+
1692 * | 7 | 8 | 4096 | 32768 |
1693 * +---------+------------+-----------+------------+
1694 * | 8 | 4 | 8192 | 32768 |
1695 * +---------+------------+-----------+------------+
1696 * | 9 | 2 | 16384 | 32768 |
1697 * +---------+------------+-----------+------------+
1698 * | 10 | 2 | 32768 | 65536 |
1699 * +---------+------------+-----------+------------+
1700 *
1701 * Calculations for other data rate are entirely based on these reference
1702 * tables. For normal operation, Latency 5 seems give the best, well
1703 * balanced performance for typical workload. Anything below 5 will
1704 * eat up CPU to keep up with increasing context switches because of
1705 * shorter buffer space and usually require the application to handle it
1706 * aggressively through possibly real time programming technique.
1707 *
1708 */
1709#define CHN_LATENCY_PBLKCNT_REF \
1710 {{1, 2, 3, 4, 5, 5, 4, 3, 2, 1, 1}, \
1711 {1, 2, 3, 4, 5, 5, 4, 3, 2, 1, 1}}
1712#define CHN_LATENCY_PBUFSZ_REF \
1713 {{7, 9, 12, 13, 14, 15, 15, 15, 15, 15, 16}, \
1714 {11, 12, 13, 14, 15, 16, 16, 16, 16, 16, 17}}
1715
1716#define CHN_LATENCY_RBLKCNT_REF \
1717 {{9, 8, 7, 6, 5, 5, 4, 3, 2, 1, 1}, \
1718 {9, 8, 7, 6, 5, 5, 4, 3, 2, 1, 1}}
1719#define CHN_LATENCY_RBUFSZ_REF \
1720 {{14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 16}, \
1721 {15, 15, 15, 15, 15, 16, 16, 16, 16, 16, 17}}
1722
1723#define CHN_LATENCY_DATA_REF 192000 /* 48khz stereo 16bit ~ 48000 x 2 x 2 */
1724
1725static int
1726chn_calclatency(int dir, int latency, int bps, u_int32_t datarate,
1727 u_int32_t max, int *rblksz, int *rblkcnt)
1728{
1729 static int pblkcnts[CHN_LATENCY_PROFILE_MAX + 1][CHN_LATENCY_MAX + 1] =
1731 static int pbufszs[CHN_LATENCY_PROFILE_MAX + 1][CHN_LATENCY_MAX + 1] =
1733 static int rblkcnts[CHN_LATENCY_PROFILE_MAX + 1][CHN_LATENCY_MAX + 1] =
1735 static int rbufszs[CHN_LATENCY_PROFILE_MAX + 1][CHN_LATENCY_MAX + 1] =
1737 u_int32_t bufsz;
1738 int lprofile, blksz, blkcnt;
1739
1740 if (latency < CHN_LATENCY_MIN || latency > CHN_LATENCY_MAX ||
1741 bps < 1 || datarate < 1 ||
1742 !(dir == PCMDIR_PLAY || dir == PCMDIR_REC)) {
1743 if (rblksz != NULL)
1744 *rblksz = CHN_2NDBUFMAXSIZE >> 1;
1745 if (rblkcnt != NULL)
1746 *rblkcnt = 2;
1747 printf("%s(): FAILED dir=%d latency=%d bps=%d "
1748 "datarate=%u max=%u\n",
1749 __func__, dir, latency, bps, datarate, max);
1750 return CHN_2NDBUFMAXSIZE;
1751 }
1752
1753 lprofile = chn_latency_profile;
1754
1755 if (dir == PCMDIR_PLAY) {
1756 blkcnt = pblkcnts[lprofile][latency];
1757 bufsz = pbufszs[lprofile][latency];
1758 } else {
1759 blkcnt = rblkcnts[lprofile][latency];
1760 bufsz = rbufszs[lprofile][latency];
1761 }
1762
1763 bufsz = round_pow2(snd_xbytes(1 << bufsz, CHN_LATENCY_DATA_REF,
1764 datarate));
1765 if (bufsz > max)
1766 bufsz = max;
1767 blksz = round_blksz(bufsz >> blkcnt, bps);
1768
1769 if (rblksz != NULL)
1770 *rblksz = blksz;
1771 if (rblkcnt != NULL)
1772 *rblkcnt = 1 << blkcnt;
1773
1774 return blksz << blkcnt;
1775}
1776
1777static int
1778chn_resizebuf(struct pcm_channel *c, int latency,
1779 int blkcnt, int blksz)
1780{
1781 struct snd_dbuf *b, *bs, *pb;
1782 int sblksz, sblkcnt, hblksz, hblkcnt, limit = 0, nsblksz, nsblkcnt;
1783 int ret;
1784
1786
1787 if ((c->flags & (CHN_F_MMAP | CHN_F_TRIGGERED)) ||
1789 return EINVAL;
1790
1791 if (latency == -1) {
1792 c->latency = -1;
1793 latency = chn_latency;
1794 } else if (latency == -2) {
1795 latency = c->latency;
1796 if (latency < CHN_LATENCY_MIN || latency > CHN_LATENCY_MAX)
1797 latency = chn_latency;
1798 } else if (latency < CHN_LATENCY_MIN || latency > CHN_LATENCY_MAX)
1799 return EINVAL;
1800 else {
1801 c->latency = latency;
1802 }
1803
1804 bs = c->bufsoft;
1805 b = c->bufhard;
1806
1807 if (!(blksz == 0 || blkcnt == -1) &&
1808 (blksz < 16 || blksz < sndbuf_getalign(bs) || blkcnt < 2 ||
1810 return EINVAL;
1811
1814 &sblksz, &sblkcnt);
1815
1816 if (blksz == 0 || blkcnt == -1) {
1817 if (blkcnt == -1)
1818 c->flags &= ~CHN_F_HAS_SIZE;
1819 if (c->flags & CHN_F_HAS_SIZE) {
1820 blksz = sndbuf_getblksz(bs);
1822 }
1823 } else
1825
1826 if (c->flags & CHN_F_HAS_SIZE) {
1827 /*
1828 * The application has requested their own blksz/blkcnt.
1829 * Just obey with it, and let them toast alone. We can
1830 * clamp it to the nearest latency profile, but that would
1831 * defeat the purpose of having custom control. The least
1832 * we can do is round it to the nearest ^2 and align it.
1833 */
1834 sblksz = round_blksz(blksz, sndbuf_getalign(bs));
1835 sblkcnt = round_pow2(blkcnt);
1836 }
1837
1838 if (c->parentchannel != NULL) {
1839 pb = c->parentchannel->bufsoft;
1840 CHN_UNLOCK(c);
1844 CHN_LOCK(c);
1845 if (c->direction == PCMDIR_PLAY) {
1846 limit = (pb != NULL) ?
1847 sndbuf_xbytes(sndbuf_getsize(pb), pb, bs) : 0;
1848 } else {
1849 limit = (pb != NULL) ?
1850 sndbuf_xbytes(sndbuf_getblksz(pb), pb, bs) * 2 : 0;
1851 }
1852 } else {
1853 hblkcnt = 2;
1854 if (c->flags & CHN_F_HAS_SIZE) {
1855 hblksz = round_blksz(sndbuf_xbytes(sblksz, bs, b),
1857 hblkcnt = round_pow2(sndbuf_getblkcnt(bs));
1858 } else
1859 chn_calclatency(c->direction, latency,
1862 CHN_2NDBUFMAXSIZE, &hblksz, &hblkcnt);
1863
1864 if ((hblksz << 1) > sndbuf_getmaxsize(b))
1865 hblksz = round_blksz(sndbuf_getmaxsize(b) >> 1,
1867
1868 while ((hblksz * hblkcnt) > sndbuf_getmaxsize(b)) {
1869 if (hblkcnt < 4)
1870 hblksz >>= 1;
1871 else
1872 hblkcnt >>= 1;
1873 }
1874
1875 hblksz -= hblksz % sndbuf_getalign(b);
1876
1877#if 0
1878 hblksz = sndbuf_getmaxsize(b) >> 1;
1879 hblksz -= hblksz % sndbuf_getalign(b);
1880 hblkcnt = 2;
1881#endif
1882
1883 CHN_UNLOCK(c);
1884 if (chn_usefrags == 0 ||
1885 CHANNEL_SETFRAGMENTS(c->methods, c->devinfo,
1886 hblksz, hblkcnt) != 0)
1887 sndbuf_setblksz(b, CHANNEL_SETBLOCKSIZE(c->methods,
1888 c->devinfo, hblksz));
1889 CHN_LOCK(c);
1890
1891 if (!CHN_EMPTY(c, children)) {
1892 nsblksz = round_blksz(
1894 sndbuf_getalign(bs));
1895 nsblkcnt = sndbuf_getblkcnt(b);
1896 if (c->direction == PCMDIR_PLAY) {
1897 do {
1898 nsblkcnt--;
1899 } while (nsblkcnt >= 2 &&
1900 nsblksz * nsblkcnt >= sblksz * sblkcnt);
1901 nsblkcnt++;
1902 }
1903 sblksz = nsblksz;
1904 sblkcnt = nsblkcnt;
1905 limit = 0;
1906 } else
1907 limit = sndbuf_xbytes(sndbuf_getblksz(b), b, bs) * 2;
1908 }
1909
1912
1913#if 0
1914 while (limit > 0 && (sblksz * sblkcnt) > limit) {
1915 if (sblkcnt < 4)
1916 break;
1917 sblkcnt >>= 1;
1918 }
1919#endif
1920
1921 while ((sblksz * sblkcnt) < limit)
1922 sblkcnt <<= 1;
1923
1924 while ((sblksz * sblkcnt) > CHN_2NDBUFMAXSIZE) {
1925 if (sblkcnt < 4)
1926 sblksz >>= 1;
1927 else
1928 sblkcnt >>= 1;
1929 }
1930
1931 sblksz -= sblksz % sndbuf_getalign(bs);
1932
1933 if (sndbuf_getblkcnt(bs) != sblkcnt || sndbuf_getblksz(bs) != sblksz ||
1934 sndbuf_getsize(bs) != (sblkcnt * sblksz)) {
1935 ret = sndbuf_remalloc(bs, sblkcnt, sblksz);
1936 if (ret != 0) {
1937 device_printf(c->dev, "%s(): Failed: %d %d\n",
1938 __func__, sblkcnt, sblksz);
1939 return ret;
1940 }
1941 }
1942
1943 /*
1944 * Interrupt timeout
1945 */
1946 c->timeout = ((u_int64_t)hz * sndbuf_getsize(bs)) /
1947 ((u_int64_t)sndbuf_getspd(bs) * sndbuf_getalign(bs));
1948 if (c->parentchannel != NULL)
1949 c->timeout = min(c->timeout, c->parentchannel->timeout);
1950 if (c->timeout < 1)
1951 c->timeout = 1;
1952
1953 /*
1954 * OSSv4 docs: "By default OSS will set the low water level equal
1955 * to the fragment size which is optimal in most cases."
1956 */
1957 c->lw = sndbuf_getblksz(bs);
1958 chn_resetbuf(c);
1959
1960 if (snd_verbose > 3)
1961 device_printf(c->dev, "%s(): %s (%s) timeout=%u "
1962 "b[%d/%d/%d] bs[%d/%d/%d] limit=%d\n",
1963 __func__, CHN_DIRSTR(c),
1964 (c->flags & CHN_F_VIRTUAL) ? "virtual" : "hardware",
1965 c->timeout,
1969 sndbuf_getblkcnt(bs), limit);
1970
1971 return 0;
1972}
1973
1974int
1975chn_setlatency(struct pcm_channel *c, int latency)
1976{
1978 /* Destroy blksz/blkcnt, enforce latency profile. */
1979 return chn_resizebuf(c, latency, -1, 0);
1980}
1981
1982int
1984{
1986 /* Destroy latency profile, enforce blksz/blkcnt */
1987 return chn_resizebuf(c, -1, blkcnt, blksz);
1988}
1989
1990int
1991chn_setparam(struct pcm_channel *c, uint32_t format, uint32_t speed)
1992{
1993 struct pcmchan_caps *caps;
1994 uint32_t hwspeed, delta;
1995 int ret;
1996
1998
1999 if (speed < 1 || format == 0 || CHN_STARTED(c))
2000 return (EINVAL);
2001
2002 c->format = format;
2003 c->speed = speed;
2004
2005 caps = chn_getcaps(c);
2006
2007 hwspeed = speed;
2008 RANGE(hwspeed, caps->minspeed, caps->maxspeed);
2009
2010 sndbuf_setspd(c->bufhard, CHANNEL_SETSPEED(c->methods, c->devinfo,
2011 hwspeed));
2012 hwspeed = sndbuf_getspd(c->bufhard);
2013
2014 delta = (hwspeed > speed) ? (hwspeed - speed) : (speed - hwspeed);
2015
2016 if (delta <= feeder_rate_round)
2017 c->speed = hwspeed;
2018
2019 ret = feeder_chain(c);
2020
2021 if (ret == 0)
2022 ret = CHANNEL_SETFORMAT(c->methods, c->devinfo,
2024
2025 if (ret == 0)
2026 ret = chn_resizebuf(c, -2, 0, 0);
2027
2028 return (ret);
2029}
2030
2031int
2033{
2034 uint32_t oldformat, oldspeed, format;
2035 int ret;
2036
2037#if 0
2038 /* XXX force 48k */
2039 if (c->format & AFMT_PASSTHROUGH)
2041#endif
2042
2043 oldformat = c->format;
2044 oldspeed = c->speed;
2045 format = oldformat;
2046
2047 ret = chn_setparam(c, format, speed);
2048 if (ret != 0) {
2049 if (snd_verbose > 3)
2050 device_printf(c->dev,
2051 "%s(): Setting speed %d failed, "
2052 "falling back to %d\n",
2053 __func__, speed, oldspeed);
2054 chn_setparam(c, c->format, oldspeed);
2055 }
2056
2057 return (ret);
2058}
2059
2060int
2062{
2063 uint32_t oldformat, oldspeed, speed;
2064 int ret;
2065
2066 /* XXX force stereo */
2067 if ((format & AFMT_PASSTHROUGH) && AFMT_CHANNEL(format) < 2) {
2070 }
2071
2072 oldformat = c->format;
2073 oldspeed = c->speed;
2074 speed = oldspeed;
2075
2076 ret = chn_setparam(c, format, speed);
2077 if (ret != 0) {
2078 if (snd_verbose > 3)
2079 device_printf(c->dev,
2080 "%s(): Format change 0x%08x failed, "
2081 "falling back to 0x%08x\n",
2082 __func__, format, oldformat);
2083 chn_setparam(c, oldformat, oldspeed);
2084 }
2085
2086 return (ret);
2087}
2088
2089void
2091{
2092 struct snddev_info *d;
2093 struct snd_mixer *m;
2094
2095 d = (c != NULL) ? c->parentsnddev : NULL;
2096 m = (d != NULL && d->mixer_dev != NULL) ? d->mixer_dev->si_drv1 :
2097 NULL;
2098
2099 if (d == NULL || m == NULL)
2100 return;
2101
2103
2104 if (c->feederflags & (1 << FEEDER_VOLUME)) {
2105 uint32_t parent;
2106 int vol, pvol, left, right, center;
2107
2108 if (c->direction == PCMDIR_PLAY &&
2109 (d->flags & SD_F_SOFTPCMVOL)) {
2110 /* CHN_UNLOCK(c); */
2111 vol = mix_get(m, SOUND_MIXER_PCM);
2112 parent = mix_getparent(m, SOUND_MIXER_PCM);
2113 if (parent != SOUND_MIXER_NONE)
2114 pvol = mix_get(m, parent);
2115 else
2116 pvol = 100 | (100 << 8);
2117 /* CHN_LOCK(c); */
2118 } else {
2119 vol = 100 | (100 << 8);
2120 pvol = vol;
2121 }
2122
2123 if (vol == -1) {
2124 device_printf(c->dev,
2125 "Soft PCM Volume: Failed to read pcm "
2126 "default value\n");
2127 vol = 100 | (100 << 8);
2128 }
2129
2130 if (pvol == -1) {
2131 device_printf(c->dev,
2132 "Soft PCM Volume: Failed to read parent "
2133 "default value\n");
2134 pvol = 100 | (100 << 8);
2135 }
2136
2137 left = ((vol & 0x7f) * (pvol & 0x7f)) / 100;
2138 right = (((vol >> 8) & 0x7f) * ((pvol >> 8) & 0x7f)) / 100;
2139 center = (left + right) >> 1;
2140
2142 }
2143
2144 if (c->feederflags & (1 << FEEDER_EQ)) {
2145 struct pcm_feeder *f;
2146 int treble, bass, state;
2147
2148 /* CHN_UNLOCK(c); */
2149 treble = mix_get(m, SOUND_MIXER_TREBLE);
2150 bass = mix_get(m, SOUND_MIXER_BASS);
2151 /* CHN_LOCK(c); */
2152
2153 if (treble == -1)
2154 treble = 50;
2155 else
2156 treble = ((treble & 0x7f) +
2157 ((treble >> 8) & 0x7f)) >> 1;
2158
2159 if (bass == -1)
2160 bass = 50;
2161 else
2162 bass = ((bass & 0x7f) + ((bass >> 8) & 0x7f)) >> 1;
2163
2165 if (f != NULL) {
2166 if (FEEDER_SET(f, FEEDEQ_TREBLE, treble) != 0)
2167 device_printf(c->dev,
2168 "EQ: Failed to set treble -- %d\n",
2169 treble);
2170 if (FEEDER_SET(f, FEEDEQ_BASS, bass) != 0)
2171 device_printf(c->dev,
2172 "EQ: Failed to set bass -- %d\n",
2173 bass);
2174 if (FEEDER_SET(f, FEEDEQ_PREAMP, d->eqpreamp) != 0)
2175 device_printf(c->dev,
2176 "EQ: Failed to set preamp -- %d\n",
2177 d->eqpreamp);
2178 if (d->flags & SD_F_EQ_BYPASSED)
2180 else if (d->flags & SD_F_EQ_ENABLED)
2182 else
2184 if (FEEDER_SET(f, FEEDEQ_STATE, state) != 0)
2185 device_printf(c->dev,
2186 "EQ: Failed to set state -- %d\n", state);
2187 }
2188 }
2189}
2190
2191int
2193{
2194#ifdef DEV_ISA
2195 struct snd_dbuf *b = c->bufhard;
2196#endif
2197 struct snddev_info *d = c->parentsnddev;
2198 int ret;
2199
2201#ifdef DEV_ISA
2202 if (SND_DMA(b) && (go == PCMTRIG_EMLDMAWR || go == PCMTRIG_EMLDMARD))
2204#endif
2205 if (!PCMTRIG_COMMON(go))
2206 return (CHANNEL_TRIGGER(c->methods, c->devinfo, go));
2207
2208 if (go == c->trigger)
2209 return (0);
2210
2211 ret = CHANNEL_TRIGGER(c->methods, c->devinfo, go);
2212 if (ret != 0)
2213 return (ret);
2214
2215 switch (go) {
2216 case PCMTRIG_START:
2217 if (snd_verbose > 3)
2218 device_printf(c->dev,
2219 "%s() %s: calling go=0x%08x , "
2220 "prev=0x%08x\n", __func__, c->name, go,
2221 c->trigger);
2222 if (c->trigger != PCMTRIG_START) {
2223 c->trigger = go;
2224 CHN_UNLOCK(c);
2225 PCM_LOCK(d);
2226 CHN_INSERT_HEAD(d, c, channels.pcm.busy);
2227 PCM_UNLOCK(d);
2228 CHN_LOCK(c);
2230 }
2231 break;
2232 case PCMTRIG_STOP:
2233 case PCMTRIG_ABORT:
2234 if (snd_verbose > 3)
2235 device_printf(c->dev,
2236 "%s() %s: calling go=0x%08x , "
2237 "prev=0x%08x\n", __func__, c->name, go,
2238 c->trigger);
2239 if (c->trigger == PCMTRIG_START) {
2240 c->trigger = go;
2241 CHN_UNLOCK(c);
2242 PCM_LOCK(d);
2243 CHN_REMOVE(d, c, channels.pcm.busy);
2244 PCM_UNLOCK(d);
2245 CHN_LOCK(c);
2246 }
2247 break;
2248 default:
2249 break;
2250 }
2251
2252 return (0);
2253}
2254
2266int
2268{
2269 int hwptr;
2270
2272 hwptr = (CHN_STARTED(c)) ? CHANNEL_GETPTR(c->methods, c->devinfo) : 0;
2273 return (hwptr - (hwptr % sndbuf_getalign(c->bufhard)));
2274}
2275
2276struct pcmchan_caps *
2278{
2280 return CHANNEL_GETCAPS(c->methods, c->devinfo);
2281}
2282
2283u_int32_t
2285{
2286 u_int32_t *fmtlist, fmts;
2287 int i;
2288
2290 fmts = 0;
2291 for (i = 0; fmtlist[i]; i++)
2292 fmts |= fmtlist[i];
2293
2294 /* report software-supported formats */
2297
2298 return (AFMT_ENCODING(fmts));
2299}
2300
2301int
2302chn_notify(struct pcm_channel *c, u_int32_t flags)
2303{
2304 struct pcm_channel *ch;
2305 struct pcmchan_caps *caps;
2306 uint32_t bestformat, bestspeed, besthwformat, *vchanformat, *vchanrate;
2307 uint32_t vpflags;
2308 int dirty, err, run, nrun;
2309
2311
2312 if (CHN_EMPTY(c, children))
2313 return (ENODEV);
2314
2315 err = 0;
2316
2317 /*
2318 * If the hwchan is running, we can't change its rate, format or
2319 * blocksize
2320 */
2321 run = (CHN_STARTED(c)) ? 1 : 0;
2322 if (run)
2323 flags &= CHN_N_VOLUME | CHN_N_TRIGGER;
2324
2325 if (flags & CHN_N_RATE) {
2326 /*
2327 * XXX I'll make good use of this someday.
2328 * However this is currently being superseded by
2329 * the availability of CHN_F_VCHAN_DYNAMIC.
2330 */
2331 }
2332
2333 if (flags & CHN_N_FORMAT) {
2334 /*
2335 * XXX I'll make good use of this someday.
2336 * However this is currently being superseded by
2337 * the availability of CHN_F_VCHAN_DYNAMIC.
2338 */
2339 }
2340
2341 if (flags & CHN_N_VOLUME) {
2342 /*
2343 * XXX I'll make good use of this someday, though
2344 * soft volume control is currently pretty much
2345 * integrated.
2346 */
2347 }
2348
2349 if (flags & CHN_N_BLOCKSIZE) {
2350 /*
2351 * Set to default latency profile
2352 */
2354 }
2355
2356 if ((flags & CHN_N_TRIGGER) && !(c->flags & CHN_F_VCHAN_DYNAMIC)) {
2357 nrun = CHN_EMPTY(c, children.busy) ? 0 : 1;
2358 if (nrun && !run)
2359 err = chn_start(c, 1);
2360 if (!nrun && run)
2361 chn_abort(c);
2362 flags &= ~CHN_N_TRIGGER;
2363 }
2364
2365 if (flags & CHN_N_TRIGGER) {
2366 if (c->direction == PCMDIR_PLAY) {
2367 vchanformat = &c->parentsnddev->pvchanformat;
2368 vchanrate = &c->parentsnddev->pvchanrate;
2369 } else {
2370 vchanformat = &c->parentsnddev->rvchanformat;
2371 vchanrate = &c->parentsnddev->rvchanrate;
2372 }
2373
2374 /* Dynamic Virtual Channel */
2375 if (!(c->flags & CHN_F_VCHAN_ADAPTIVE)) {
2376 bestformat = *vchanformat;
2377 bestspeed = *vchanrate;
2378 } else {
2379 bestformat = 0;
2380 bestspeed = 0;
2381 }
2382
2383 besthwformat = 0;
2384 nrun = 0;
2385 caps = chn_getcaps(c);
2386 dirty = 0;
2387 vpflags = 0;
2388
2389 CHN_FOREACH(ch, c, children.busy) {
2390 CHN_LOCK(ch);
2391 if ((ch->format & AFMT_PASSTHROUGH) &&
2392 snd_fmtvalid(ch->format, caps->fmtlist)) {
2393 bestformat = ch->format;
2394 bestspeed = ch->speed;
2395 CHN_UNLOCK(ch);
2396 vpflags = CHN_F_PASSTHROUGH;
2397 nrun++;
2398 break;
2399 }
2400 if ((ch->flags & CHN_F_EXCLUSIVE) && vpflags == 0) {
2401 if (c->flags & CHN_F_VCHAN_ADAPTIVE) {
2402 bestspeed = ch->speed;
2403 RANGE(bestspeed, caps->minspeed,
2404 caps->maxspeed);
2405 besthwformat = snd_fmtbest(ch->format,
2406 caps->fmtlist);
2407 if (besthwformat != 0)
2408 bestformat = besthwformat;
2409 }
2410 CHN_UNLOCK(ch);
2411 vpflags = CHN_F_EXCLUSIVE;
2412 nrun++;
2413 continue;
2414 }
2415 if (!(c->flags & CHN_F_VCHAN_ADAPTIVE) ||
2416 vpflags != 0) {
2417 CHN_UNLOCK(ch);
2418 nrun++;
2419 continue;
2420 }
2421 if (ch->speed > bestspeed) {
2422 bestspeed = ch->speed;
2423 RANGE(bestspeed, caps->minspeed,
2424 caps->maxspeed);
2425 }
2426 besthwformat = snd_fmtbest(ch->format, caps->fmtlist);
2427 if (!(besthwformat & AFMT_VCHAN)) {
2428 CHN_UNLOCK(ch);
2429 nrun++;
2430 continue;
2431 }
2432 if (AFMT_CHANNEL(besthwformat) >
2433 AFMT_CHANNEL(bestformat))
2434 bestformat = besthwformat;
2435 else if (AFMT_CHANNEL(besthwformat) ==
2436 AFMT_CHANNEL(bestformat) &&
2437 AFMT_BIT(besthwformat) > AFMT_BIT(bestformat))
2438 bestformat = besthwformat;
2439 CHN_UNLOCK(ch);
2440 nrun++;
2441 }
2442
2443 if (bestformat == 0)
2444 bestformat = c->format;
2445 if (bestspeed == 0)
2446 bestspeed = c->speed;
2447
2448 if (bestformat != c->format || bestspeed != c->speed)
2449 dirty = 1;
2450
2452 c->flags |= vpflags;
2453
2454 if (nrun && !run) {
2455 if (dirty) {
2456 bestspeed = CHANNEL_SETSPEED(c->methods,
2457 c->devinfo, bestspeed);
2458 err = chn_reset(c, bestformat, bestspeed);
2459 }
2460 if (err == 0 && dirty) {
2461 CHN_FOREACH(ch, c, children.busy) {
2462 CHN_LOCK(ch);
2463 if (VCHAN_SYNC_REQUIRED(ch))
2464 vchan_sync(ch);
2465 CHN_UNLOCK(ch);
2466 }
2467 }
2468 if (err == 0) {
2469 if (dirty)
2470 c->flags |= CHN_F_DIRTY;
2471 err = chn_start(c, 1);
2472 }
2473 }
2474
2475 if (nrun && run && dirty) {
2476 chn_abort(c);
2477 bestspeed = CHANNEL_SETSPEED(c->methods, c->devinfo,
2478 bestspeed);
2479 err = chn_reset(c, bestformat, bestspeed);
2480 if (err == 0) {
2481 CHN_FOREACH(ch, c, children.busy) {
2482 CHN_LOCK(ch);
2483 if (VCHAN_SYNC_REQUIRED(ch))
2484 vchan_sync(ch);
2485 CHN_UNLOCK(ch);
2486 }
2487 }
2488 if (err == 0) {
2489 c->flags |= CHN_F_DIRTY;
2490 err = chn_start(c, 1);
2491 }
2492 }
2493
2494 if (err == 0 && !(bestformat & AFMT_PASSTHROUGH) &&
2495 (bestformat & AFMT_VCHAN)) {
2496 *vchanformat = bestformat;
2497 *vchanrate = bestspeed;
2498 }
2499
2500 if (!nrun && run) {
2502 bestformat = *vchanformat;
2503 bestspeed = *vchanrate;
2504 chn_abort(c);
2505 if (c->format != bestformat || c->speed != bestspeed)
2506 chn_reset(c, bestformat, bestspeed);
2507 }
2508 }
2509
2510 return (err);
2511}
2512
2528int
2530{
2531 KASSERT(rates != NULL, ("rates is null"));
2533 return CHANNEL_GETRATES(c->methods, c->devinfo, rates);
2534}
2535
2553int
2555{
2556 struct pcmchan_syncmember *sm;
2557 struct pcmchan_syncgroup *sg;
2558 int sg_id;
2559
2560 sg_id = 0;
2561
2562 PCM_SG_LOCKASSERT(MA_OWNED);
2563
2564 if (c->sm != NULL) {
2565 sm = c->sm;
2566 sg = sm->parent;
2567 c->sm = NULL;
2568
2569 KASSERT(sg != NULL, ("syncmember has null parent"));
2570
2571 SLIST_REMOVE(&sg->members, sm, pcmchan_syncmember, link);
2572 free(sm, M_DEVBUF);
2573
2574 if (SLIST_EMPTY(&sg->members)) {
2575 SLIST_REMOVE(&snd_pcm_syncgroups, sg, pcmchan_syncgroup, link);
2576 sg_id = sg->id;
2577 free(sg, M_DEVBUF);
2578 }
2579 }
2580
2581 return sg_id;
2582}
2583
2584#ifdef OSSV4_EXPERIMENT
2585int
2586chn_getpeaks(struct pcm_channel *c, int *lpeak, int *rpeak)
2587{
2589 return CHANNEL_GETPEAKS(c->methods, c->devinfo, lpeak, rpeak);
2590}
2591#endif
void * devinfo
Definition: ac97_if.m:47
struct sb16props amt[SOUND_MIXER_NRDEVICES]
#define DEB(x)
Definition: als4000.c:56
uint32_t format
Definition: audio_dai_if.m:39
uint32_t speed
Definition: audio_dai_if.m:86
int go
Definition: audio_dai_if.m:64
unsigned int fmt
Definition: audio_soc.c:91
int sndbuf_setup(struct snd_dbuf *b, void *buf, unsigned int size)
Definition: buffer.c:123
u_int64_t sndbuf_gettotal(struct snd_dbuf *b)
Definition: buffer.c:557
void sndbuf_clear(struct snd_dbuf *b, unsigned int length)
Zero out space in buffer free area.
Definition: buffer.c:270
unsigned int sndbuf_getspd(struct snd_dbuf *b)
Definition: buffer.c:373
int sndbuf_acquire(struct snd_dbuf *b, u_int8_t *from, unsigned int count)
Acquire buffer space to extend ready area.
Definition: buffer.c:618
unsigned int sndbuf_getblkcnt(struct snd_dbuf *b)
Definition: buffer.c:391
unsigned int sndbuf_getalign(struct snd_dbuf *b)
Definition: buffer.c:385
void sndbuf_reset(struct snd_dbuf *b)
Definition: buffer.c:334
void sndbuf_setblksz(struct snd_dbuf *b, unsigned int blksz)
Definition: buffer.c:409
unsigned int sndbuf_getblksz(struct snd_dbuf *b)
Definition: buffer.c:403
void sndbuf_setspd(struct snd_dbuf *b, unsigned int spd)
Definition: buffer.c:379
int sndbuf_remalloc(struct snd_dbuf *b, unsigned int blkcnt, unsigned int blksz)
Definition: buffer.c:214
unsigned int sndbuf_getfreeptr(struct snd_dbuf *b)
Definition: buffer.c:531
int sndbuf_setfmt(struct snd_dbuf *b, u_int32_t fmt)
Definition: buffer.c:355
void sndbuf_updateprevtotal(struct snd_dbuf *b)
Definition: buffer.c:573
unsigned int sndbuf_getfree(struct snd_dbuf *b)
Definition: buffer.c:522
unsigned int sndbuf_getmaxsize(struct snd_dbuf *b)
Definition: buffer.c:441
void sndbuf_destroy(struct snd_dbuf *b)
Definition: buffer.c:59
u_int32_t sndbuf_getfmt(struct snd_dbuf *b)
Definition: buffer.c:349
unsigned int sndbuf_xbytes(unsigned int v, struct snd_dbuf *from, struct snd_dbuf *to)
Definition: buffer.c:581
unsigned int sndbuf_getready(struct snd_dbuf *b)
Definition: buffer.c:504
unsigned int sndbuf_getsize(struct snd_dbuf *b)
Definition: buffer.c:435
void sndbuf_free(struct snd_dbuf *b)
Definition: buffer.c:135
struct snd_dbuf * sndbuf_create(device_t dev, char *drv, char *desc, struct pcm_channel *channel)
Definition: buffer.c:46
void sndbuf_setrun(struct snd_dbuf *b, int go)
Definition: buffer.c:459
void sndbuf_fillsilence_rl(struct snd_dbuf *b, u_int rl)
Definition: buffer.c:308
struct selinfo * sndbuf_getsel(struct snd_dbuf *b)
Definition: buffer.c:465
unsigned int sndbuf_gethwptr(struct snd_dbuf *b)
Definition: buffer.c:488
void * sndbuf_getbufofs(struct snd_dbuf *b, unsigned int ofs)
Definition: buffer.c:427
u_int64_t sndbuf_getprevtotal(struct snd_dbuf *b)
Definition: buffer.c:565
int sndbuf_feed(struct snd_dbuf *from, struct snd_dbuf *to, struct pcm_channel *channel, struct pcm_feeder *feeder, unsigned int count)
Definition: buffer.c:691
int sndbuf_dispose(struct snd_dbuf *b, u_int8_t *to, unsigned int count)
Dispose samples from channel buffer, increasing size of ready area.
Definition: buffer.c:655
unsigned int sndbuf_getreadyptr(struct snd_dbuf *b)
Definition: buffer.c:513
void sndbuf_sethwptr(struct snd_dbuf *b, unsigned int ptr)
Definition: buffer.c:496
static u_int32_t snd_xbytes(u_int32_t v, u_int32_t from, u_int32_t to)
Definition: buffer.h:139
#define SND_DMA(b)
Definition: buffer.h:31
int chn_reset(struct pcm_channel *c, uint32_t fmt, uint32_t spd)
Definition: channel.c:1129
void chn_vpc_reset(struct pcm_channel *c, int vc, int force)
Definition: channel.c:1584
int chn_setvolume(struct pcm_channel *c, int left, int right)
Definition: channel.c:1310
int chn_syncdestroy(struct pcm_channel *c)
Remove channel from a sync group, if there is one.
Definition: channel.c:2554
char * alias1
Definition: channel.c:997
MTX_SYSINIT(pcm_syncgroup, &snd_pcm_syncgroups_mtx, "PCM channel sync group lock", MTX_DEF)
static u_int32_t round_blksz(u_int32_t v, int round)
Definition: channel.c:1616
int chn_flush(struct pcm_channel *c)
Definition: channel.c:962
static void chn_wrintr(struct pcm_channel *c)
Definition: channel.c:439
int chn_kill(struct pcm_channel *c)
Definition: channel.c:1285
#define CHN_LATENCY_RBUFSZ_REF
Definition: channel.c:1719
int report_soft_formats
Definition: channel.c:45
static u_int32_t round_pow2(u_int32_t v)
Definition: channel.c:1600
int chn_trigger(struct pcm_channel *c, int go)
Definition: channel.c:2192
int chn_read(struct pcm_channel *c, struct uio *buf)
Definition: channel.c:589
int chn_setmute_matrix(struct pcm_channel *c, int vc, int vt, int mute)
Definition: channel.c:1418
int chn_setspeed(struct pcm_channel *c, uint32_t speed)
Definition: channel.c:2032
int chn_setmatrix(struct pcm_channel *c, struct pcmchan_matrix *m)
Definition: channel.c:1482
uint32_t snd_str2afmt(const char *req)
Definition: channel.c:1031
static void chn_pollreset(struct pcm_channel *c)
Definition: channel.c:296
static void chn_vpc_proc(int reset, int db)
Definition: channel.c:129
int chn_setvolume_multi(struct pcm_channel *c, int vc, int left, int right, int center)
Definition: channel.c:1322
static void chn_rdintr(struct pcm_channel *c)
Definition: channel.c:569
int chn_oss_setorder(struct pcm_channel *c, unsigned long long *map)
Definition: channel.c:1516
static int chn_usefrags
Definition: channel.c:197
static int chn_resizebuf(struct pcm_channel *c, int latency, int blkcnt, int blksz)
Definition: channel.c:1778
static int chn_vpc_autoreset
Definition: channel.c:122
int chn_poll(struct pcm_channel *c, int ev, struct thread *td)
Definition: channel.c:897
static int chn_sleep(struct pcm_channel *c, int timeout)
Definition: channel.c:334
int chn_setlatency(struct pcm_channel *c, int latency)
Definition: channel.c:1975
uint32_t snd_afmt2str(uint32_t afmt, char *buf, size_t len)
Definition: channel.c:1099
struct pcmchan_matrix * chn_getmatrix(struct pcm_channel *c)
Definition: channel.c:1469
struct pcmchan_caps * chn_getcaps(struct pcm_channel *c)
Definition: channel.c:2277
char * name
Definition: channel.c:997
int chn_notify(struct pcm_channel *c, u_int32_t flags)
Definition: channel.c:2302
static int chn_polltrigger(struct pcm_channel *c)
Determine channel is ready for I/O.
Definition: channel.c:273
#define CHN_LATENCY_PBLKCNT_REF
Definition: channel.c:1709
int chn_abort(struct pcm_channel *c)
Definition: channel.c:927
static void chn_wrfeed(struct pcm_channel *c)
Definition: channel.c:392
SND_DECLARE_FILE("$FreeBSD$")
#define SND_CHN_OSS_REAR
Definition: channel.c:1539
void chn_intr_locked(struct pcm_channel *c)
Definition: channel.c:646
#define SND_CHN_OSS_FRONT
Definition: channel.c:1536
int chn_setformat(struct pcm_channel *c, uint32_t format)
Definition: channel.c:2061
static void chn_lockdestroy(struct pcm_channel *c)
Definition: channel.c:253
static int chn_calclatency(int dir, int latency, int bps, u_int32_t datarate, u_int32_t max, int *rblksz, int *rblkcnt)
Definition: channel.c:1726
#define CHN_LATENCY_DATA_REF
Definition: channel.c:1723
int chn_getvolume_matrix(struct pcm_channel *c, int vc, int vt)
Definition: channel.c:1387
#define CHN_LATENCY_PBUFSZ_REF
Definition: channel.c:1712
static void chn_rdfeed(struct pcm_channel *c)
Definition: channel.c:526
int chn_oss_getorder(struct pcm_channel *c, unsigned long long *map)
Definition: channel.c:1502
static const struct @25 afmt_tab[]
int chn_init(struct pcm_channel *c, void *devinfo, int dir, int direction)
Definition: channel.c:1163
int snd_fmtvalid(uint32_t fmt, uint32_t *fmtlist)
Definition: channel.c:982
static int sysctl_hw_snd_latency(SYSCTL_HANDLER_ARGS)
Definition: channel.c:56
uint32_t afmt
Definition: channel.c:998
int chn_setblocksize(struct pcm_channel *c, int blkcnt, int blksz)
Definition: channel.c:1983
int chn_getrates(struct pcm_channel *c, int **rates)
Fetch array of supported discrete sample rates.
Definition: channel.c:2529
static int chn_timeout
Definition: channel.c:99
int chn_oss_getmask(struct pcm_channel *c, uint32_t *retmask)
Definition: channel.c:1542
static void chn_wakeup(struct pcm_channel *c)
Definition: channel.c:304
void chn_resetbuf(struct pcm_channel *c)
Definition: channel.c:750
static void chn_lockinit(struct pcm_channel *c, int dir)
Definition: channel.c:225
int chn_sync(struct pcm_channel *c, int threshold)
Definition: channel.c:766
static int sysctl_hw_snd_timeout(SYSCTL_HANDLER_ARGS)
Definition: channel.c:102
int chn_getmute_matrix(struct pcm_channel *c, int vc, int vt)
Definition: channel.c:1456
struct pcm_synclist snd_pcm_syncgroups
syncgroups' master list
Definition: channel.c:222
int chn_latency_profile
Definition: channel.c:76
int report_soft_matrix
Definition: channel.c:49
void chn_intr(struct pcm_channel *c)
Definition: channel.c:660
int chn_write(struct pcm_channel *c, struct uio *buf)
Definition: channel.c:459
u_int32_t chn_getformats(struct pcm_channel *c)
Definition: channel.c:2284
#define CHN_LATENCY_RBLKCNT_REF
Definition: channel.c:1716
int chn_setparam(struct pcm_channel *c, uint32_t format, uint32_t speed)
Definition: channel.c:1991
int chn_setvolume_matrix(struct pcm_channel *c, int vc, int vt, int val)
Definition: channel.c:1342
SYSCTL_PROC(_hw_snd, OID_AUTO, latency, CTLTYPE_INT|CTLFLAG_RWTUN|CTLFLAG_MPSAFE, 0, sizeof(int), sysctl_hw_snd_latency, "I", "buffering latency (0=low ... 10=high)")
static int sysctl_hw_snd_latency_profile(SYSCTL_HANDLER_ARGS)
Definition: channel.c:79
#define SND_CHN_OSS_CENTER_LFE
Definition: channel.c:1538
char * alias2
Definition: channel.c:997
static int chn_syncdelay
Definition: channel.c:198
void chn_syncstate(struct pcm_channel *c)
Definition: channel.c:2090
u_int32_t chn_start(struct pcm_channel *c, int force)
Definition: channel.c:674
int chn_getptr(struct pcm_channel *c)
Queries sound driver for sample-aligned hardware buffer pointer index.
Definition: channel.c:2267
static int sysctl_hw_snd_vpc_0db(SYSCTL_HANDLER_ARGS)
Definition: channel.c:156
static int sysctl_hw_snd_vpc_reset(SYSCTL_HANDLER_ARGS)
Definition: channel.c:178
int chn_latency
Definition: channel.c:53
static int chn_vol_0db_pcm
Definition: channel.c:126
#define SND_CHN_OSS_SURR
Definition: channel.c:1537
struct mtx snd_pcm_syncgroups_mtx
Channel sync group lock.
Definition: channel.c:212
static unsigned int chn_dmaupdate(struct pcm_channel *c)
Definition: channel.c:356
int chn_setmute_multi(struct pcm_channel *c, int vc, int mute)
Definition: channel.c:1400
SYSCTL_INT(_hw_snd, OID_AUTO, report_soft_formats, CTLFLAG_RW, &report_soft_formats, 0, "report software-emulated formats")
#define CHN_TIMEOUT
Definition: channel.h:436
#define CHN_UNLOCK(c)
Definition: channel.h:322
#define PCM_SG_LOCKASSERT(arg)
Definition: channel.h:61
#define CHN_F_MMAP
Definition: channel.h:362
#define CHN_F_TRIGGERED
Definition: channel.h:357
#define CHN_LATENCY_PROFILE_MAX
Definition: channel.h:426
#define PCMDIR_PLAY_VIRTUAL
Definition: channel.h:340
#define CHN_F_DIRTY
Definition: channel.h:365
#define CHN_LOCK(c)
Definition: channel.h:321
#define CHN_F_HAS_VCHAN
Definition: channel.h:370
#define CHN_STOPPED(c)
Definition: channel.h:430
#define CHN_F_PASSTHROUGH
Definition: channel.h:378
#define PCMDIR_PLAY
Definition: channel.h:339
#define CHN_F_ABORTING
Definition: channel.h:355
#define CHN_F_VCHAN_ADAPTIVE
Definition: channel.h:373
#define CHN_LATENCY_DEFAULT
Definition: channel.h:420
#define PCMTRIG_START
Definition: channel.h:344
#define CHN_F_NBIO
Definition: channel.h:361
#define CHN_BITPERFECT(c)
Definition: channel.h:433
#define CHN_LOCKOWNED(c)
Definition: channel.h:320
#define CHN_F_RESET
Definition: channel.h:403
#define CHN_F_HAS_SIZE
Definition: channel.h:369
#define CHN_F_DEAD
Definition: channel.h:366
#define CHN_LATENCY_PROFILE_DEFAULT
Definition: channel.h:427
#define CHN_EMPTY(x, y)
Definition: channel.h:178
#define CHN_N_TRIGGER
Definition: channel.h:416
#define CHN_INSERT_HEAD(x, y, z)
Definition: channel.h:187
#define CHN_INIT(x, y)
Definition: channel.h:176
#define CHN_FOREACH(x, y, z)
Definition: channel.h:181
#define PCMTRIG_EMLDMARD
Definition: channel.h:346
#define CHN_LOCKASSERT(c)
Definition: channel.h:324
#define CHN_F_SLEEPING
Definition: channel.h:359
#define PCMDIR_REC_VIRTUAL
Definition: channel.h:342
#define CHN_DIRSTR(c)
Definition: channel.h:431
#define CHN_N_VOLUME
Definition: channel.h:414
#define CHN_TIMEOUT_MAX
Definition: channel.h:438
#define CHN_BROADCAST(x)
Definition: channel.h:252
#define CHN_REMOVE(x, y, z)
Definition: channel.h:193
#define CHN_F_CLOSING
Definition: channel.h:354
#define CHN_F_NOTRIGGER
Definition: channel.h:358
#define CHN_SETVOLUME(...)
Definition: channel.h:307
#define PCMTRIG_STOP
Definition: channel.h:347
#define CHN_F_BITPERFECT
Definition: channel.h:377
#define CHN_F_VCHAN_DYNAMIC
Definition: channel.h:374
#define CHN_2NDBUFMAXSIZE
Definition: channel.h:449
#define PCMTRIG_EMLDMAWR
Definition: channel.h:345
#define CHN_LATENCY_MAX
Definition: channel.h:419
#define CHN_N_FORMAT
Definition: channel.h:413
#define CHN_BUF_PARENT(x, y)
Definition: channel.h:247
#define CHN_F_EXCLUSIVE
Definition: channel.h:379
#define PCMDIR_REC
Definition: channel.h:341
#define CHN_STARTED(c)
Definition: channel.h:429
#define CHN_N_RATE
Definition: channel.h:412
#define CHN_F_VIRTUAL
Definition: channel.h:376
#define AFMTSTR_LEN
Definition: channel.h:332
#define PCMTRIG_COMMON(x)
Definition: channel.h:350
#define PCMTRIG_ABORT
Definition: channel.h:348
#define CHN_N_BLOCKSIZE
Definition: channel.h:415
struct pcm_channel * c
Definition: channel_if.m:106
METHOD int free
Definition: channel_if.m:110
int ** rates
Definition: channel_if.m:220
int * lpeak
Definition: channel_if.m:195
int * rpeak
Definition: channel_if.m:196
struct pcmchan_matrix * m
Definition: channel_if.m:232
struct snd_dbuf * b
Definition: channel_if.m:105
uint32_t spd
Definition: dsp.c:394
int max
Definition: dsp.c:392
uint16_t len
unsigned right
Definition: es137x.c:261
unsigned left
Definition: es137x.c:260
struct feeder_class * feeder_getclass(struct pcm_feederdesc *desc)
Definition: feeder.c:224
struct pcm_feeder * chn_findfeeder(struct pcm_channel *c, u_int32_t type)
Definition: feeder.c:270
u_int32_t snd_fmtbest(u_int32_t fmt, u_int32_t *fmts)
Definition: feeder.c:408
int chn_addfeeder(struct pcm_channel *c, struct feeder_class *fc, struct pcm_feederdesc *desc)
Definition: feeder.c:238
int chn_removefeeder(struct pcm_channel *c)
Definition: feeder.c:256
@ FEEDEQ_BYPASS
Definition: feeder.h:133
@ FEEDEQ_BASS
Definition: feeder.h:128
@ FEEDEQ_DISABLE
Definition: feeder.h:131
@ FEEDEQ_PREAMP
Definition: feeder.h:129
@ FEEDEQ_TREBLE
Definition: feeder.h:127
@ FEEDEQ_ENABLE
Definition: feeder.h:132
@ FEEDEQ_STATE
Definition: feeder.h:130
@ FEEDER_VOLUME
Definition: feeder.h:87
@ FEEDER_EQ
Definition: feeder.h:86
struct pcmchan_matrix * feeder_matrix_id_map(int)
int feeder_rate_round
Definition: feeder_rate.c:158
int feeder_matrix_oss_get_channel_order(struct pcmchan_matrix *, unsigned long long *)
int feeder_matrix_oss_set_channel_order(struct pcmchan_matrix *, unsigned long long *)
int feeder_chain(struct pcm_channel *)
Definition: feeder_chain.c:581
u_int32_t count
Definition: feeder_if.m:86
static u_int32_t fmts[]
Definition: fm801.c:112
u_int32_t limit
Definition: fm801.c:375
int blksz
Definition: hdac_if.m:64
int dir
Definition: hdac_if.m:45
bus_addr_t buf
Definition: hdac_if.m:63
int blkcnt
Definition: hdac_if.m:65
uint8_t r
#define SND_VOL_0DB_PCM
Definition: matrix.h:209
#define SND_CHN_T_END
Definition: matrix.h:178
#define SND_VOL_C_BEGIN
Definition: matrix.h:199
#define SND_VOL_C_STEP
Definition: matrix.h:201
#define SND_CHN_T_FL
Definition: matrix.h:42
#define SND_CHN_T_MAX
Definition: matrix.h:60
#define SND_CHN_T_STEP
Definition: matrix.h:179
#define SND_VOL_C_VAL(x)
Definition: matrix.h:203
#define SND_CHN_T_FR
Definition: matrix.h:43
#define SND_VOL_C_MAX
Definition: matrix.h:197
#define SND_CHN_MATRIX_1_0
Definition: matrix.h:127
#define SND_CHN_RIGHT_MASK
Definition: matrix.h:108
#define SND_VOL_CALC_VAL(x, y, z)
Definition: matrix.h:216
#define SND_VOL_0DB_MIN
Definition: matrix.h:205
#define SND_CHN_T_VOL_0DB
Definition: matrix.h:174
#define SND_VOL_C_END
Definition: matrix.h:200
#define SND_CHN_MATRIX_PCMCHANNEL
Definition: matrix.h:170
#define SND_VOL_0DB_MASTER
Definition: matrix.h:208
#define SND_CHN_LEFT_MASK
Definition: matrix.h:101
#define SND_VOL_C_PCM
Definition: matrix.h:195
#define SND_CHN_T_BEGIN
Definition: matrix.h:177
#define SND_VOL_0DB_MAX
Definition: matrix.h:206
#define SND_VOL_C_MASTER
Definition: matrix.h:194
u_int32_t mix_getparent(struct snd_mixer *m, u_int32_t dev)
Definition: mixer.c:611
int mix_get(struct snd_mixer *m, u_int dev)
Definition: mixer.c:1016
int state
u_int32_t val
#define RANGE(var, low, high)
Definition: sequencer.h:45
void sndbuf_dmabounce(struct snd_dbuf *b)
Definition: sndbuf_dma.c:103
void * snd_mtxcreate(const char *desc, const char *type)
Definition: sound.c:88
uint32_t pcm_getflags(device_t dev)
Definition: sound.c:816
devclass_t pcm_devclass
Definition: sound.c:49
void snd_mtxfree(void *m)
Definition: sound.c:98
#define AFMT_EXTCHANNEL_MAX
Definition: sound.h:220
#define AFMT_ENCODING(v)
Definition: sound.h:222
#define SD_F_EQ_ENABLED
Definition: sound.h:143
#define AFMT_PASSTHROUGH_EXTCHANNEL
Definition: sound.h:208
#define AFMT_PASSTHROUGH_RATE
Definition: sound.h:206
#define AFMT_PASSTHROUGH_CHANNEL
Definition: sound.h:207
#define SND_FORMAT(f, c, e)
Definition: sound.h:238
#define AFMT_BIT(v)
Definition: sound.h:230
#define AFMT_VCHAN
Definition: sound.h:203
#define PCM_RELEASE(x)
Definition: sound.h:554
#define PCM_ACQUIRE(x)
Definition: sound.h:546
#define SD_F_SOFTPCMVOL
Definition: sound.h:134
#define DSP_DEFAULT_SPEED
Definition: sound.h:295
#define AFMT_PASSTHROUGH
Definition: sound.h:205
#define PCM_WAIT(x)
Definition: sound.h:540
#define SD_F_BITPERFECT
Definition: sound.h:140
#define PCM_UNLOCK(d)
Definition: sound.h:421
#define AFMT_CHANNEL(v)
Definition: sound.h:227
#define PCM_LOCK(d)
Definition: sound.h:420
#define SD_F_EQ_BYPASSED
Definition: sound.h:144
#define AFMT_CONVERTIBLE
Definition: sound.h:199
int snd_verbose
#define AFMT_CHANNEL_MAX
Definition: sound.h:217
#define AFMT_EXTCHANNEL(v)
Definition: sound.h:224
#define PCM_REGISTERED(x)
Definition: sound.h:178
struct pcmchan_syncmember * sm
Definition: channel.h:140
char name[CHN_NAMELEN]
Definition: channel.h:109
u_int32_t flags
Definition: channel.h:96
kobj_t methods
Definition: channel.h:86
int trigger
Definition: channel.h:112
struct pcm_channel::@28 channels
u_int64_t blocks
Definition: channel.h:98
struct pcm_channel::@27 children
u_int32_t feederflags
Definition: channel.h:97
struct pcm_channel::@27::@29 busy
u_int32_t speed
Definition: channel.h:94
unsigned int lw
Definition: channel.h:135
void * devinfo
Definition: channel.h:106
struct snd_dbuf * bufhard
Definition: channel.h:103
int direction
Definition: channel.h:100
unsigned int xruns
Definition: channel.h:101
u_int32_t format
Definition: channel.h:95
struct mtx * lock
Definition: channel.h:111
struct snd_dbuf * bufsoft
Definition: channel.h:103
struct pcm_channel * parentchannel
Definition: channel.h:105
struct pcm_feeder * feeder
Definition: channel.h:90
int8_t muted[SND_VOL_C_MAX][SND_CHN_T_VOL_MAX]
Definition: channel.h:170
int16_t volume[SND_VOL_C_MAX][SND_CHN_T_VOL_MAX]
Definition: channel.h:169
struct cv cv
Definition: channel.h:127
struct pcmchan_matrix matrix
Definition: channel.h:166
struct cv intr_cv
Definition: channel.h:116
unsigned int interrupts
Definition: channel.h:101
struct snddev_info * parentsnddev
Definition: channel.h:104
unsigned int feedcount
Definition: channel.h:101
int latency
Definition: channel.h:93
device_t dev
Definition: channel.h:107
unsigned int timeout
Definition: channel.h:102
u_int32_t * fmtlist
Definition: channel.h:35
u_int32_t caps
Definition: channel.h:36
struct pcmchan_matrix::@26 map[SND_CHN_T_MAX+1]
uint32_t mask
Definition: channel.h:46
uint8_t channels
Definition: channel.h:41
uint8_t ext
Definition: channel.h:41
Specifies an audio device sync group.
Definition: channel.h:66
Specifies a container for members of a sync group.
Definition: channel.h:75
struct pcmchan_syncgroup * parent
Definition: channel.h:77
char name[SNDBUF_NAMELEN]
Definition: buffer.h:63
u_int8_t * shadbuf
Definition: buffer.h:44
volatile int sl
Definition: buffer.h:45
u_int8_t parent[32]
Definition: mixer.c:64
struct cdev * mixer_dev
Definition: sound.h:403
unsigned flags
Definition: sound.h:396
uint32_t pvchanformat
Definition: sound.h:404
uint32_t rvchanformat
Definition: sound.h:405
uint32_t rvchanrate
Definition: sound.h:405
struct snddev_info::@49 channels
int32_t eqpreamp
Definition: sound.h:406
uint32_t pvchanrate
Definition: sound.h:404
METHOD int reset
Definition: synth_if.m:283
const void * req
int vchan_sync(struct pcm_channel *c)
Definition: vchan.c:906
#define VCHAN_SYNC_REQUIRED(c)
Definition: vchan.h:45