xref: /freebsd/sys/dev/sound/pcm/feeder_mixer.c (revision b6420b5ea5bcdeb859a2b3357e5dbaafe7aaff88)
190da2b28SAriff Abdullah /*-
24d846d26SWarner Losh  * SPDX-License-Identifier: BSD-2-Clause
3718cf2ccSPedro F. Giffuni  *
490da2b28SAriff Abdullah  * Copyright (c) 2008-2009 Ariff Abdullah <ariff@FreeBSD.org>
590da2b28SAriff Abdullah  * All rights reserved.
6c824383bSChristos Margiolis  * Copyright (c) 2024-2025 The FreeBSD Foundation
7c824383bSChristos Margiolis  *
8c824383bSChristos Margiolis  * Portions of this software were developed by Christos Margiolis
9c824383bSChristos Margiolis  * <christos@FreeBSD.org> under sponsorship from the FreeBSD Foundation.
1090da2b28SAriff Abdullah  *
1190da2b28SAriff Abdullah  * Redistribution and use in source and binary forms, with or without
1290da2b28SAriff Abdullah  * modification, are permitted provided that the following conditions
1390da2b28SAriff Abdullah  * are met:
1490da2b28SAriff Abdullah  * 1. Redistributions of source code must retain the above copyright
1590da2b28SAriff Abdullah  *    notice, this list of conditions and the following disclaimer.
1690da2b28SAriff Abdullah  * 2. Redistributions in binary form must reproduce the above copyright
1790da2b28SAriff Abdullah  *    notice, this list of conditions and the following disclaimer in the
1890da2b28SAriff Abdullah  *    documentation and/or other materials provided with the distribution.
1990da2b28SAriff Abdullah  *
2090da2b28SAriff Abdullah  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
2190da2b28SAriff Abdullah  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2290da2b28SAriff Abdullah  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2390da2b28SAriff Abdullah  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
2490da2b28SAriff Abdullah  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2590da2b28SAriff Abdullah  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2690da2b28SAriff Abdullah  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2790da2b28SAriff Abdullah  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2890da2b28SAriff Abdullah  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2990da2b28SAriff Abdullah  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3090da2b28SAriff Abdullah  * SUCH DAMAGE.
3190da2b28SAriff Abdullah  */
3290da2b28SAriff Abdullah 
3390da2b28SAriff Abdullah #ifdef _KERNEL
3490da2b28SAriff Abdullah #ifdef HAVE_KERNEL_OPTION_HEADERS
3590da2b28SAriff Abdullah #include "opt_snd.h"
3690da2b28SAriff Abdullah #endif
3790da2b28SAriff Abdullah #include <dev/sound/pcm/sound.h>
3890da2b28SAriff Abdullah #include <dev/sound/pcm/pcm.h>
3990da2b28SAriff Abdullah #include <dev/sound/pcm/vchan.h>
4090da2b28SAriff Abdullah #include "feeder_if.h"
4190da2b28SAriff Abdullah 
4290da2b28SAriff Abdullah #define SND_USE_FXDIV
4390da2b28SAriff Abdullah #include "snd_fxdiv_gen.h"
4490da2b28SAriff Abdullah #endif
4590da2b28SAriff Abdullah 
4690da2b28SAriff Abdullah #undef SND_FEEDER_MULTIFORMAT
4790da2b28SAriff Abdullah #define SND_FEEDER_MULTIFORMAT	1
4890da2b28SAriff Abdullah 
4990da2b28SAriff Abdullah struct feed_mixer_info {
5090da2b28SAriff Abdullah 	uint32_t format;
514021fa32SChristos Margiolis 	uint32_t channels;
5290da2b28SAriff Abdullah 	int bps;
5390da2b28SAriff Abdullah };
5490da2b28SAriff Abdullah 
55717adecbSChristos Margiolis __always_inline static void
feed_mixer_apply(uint8_t * src,uint8_t * dst,uint32_t count,const uint32_t fmt)564021fa32SChristos Margiolis feed_mixer_apply(uint8_t *src, uint8_t *dst, uint32_t count, const uint32_t fmt)
574021fa32SChristos Margiolis {
584021fa32SChristos Margiolis 	intpcm32_t z;
594021fa32SChristos Margiolis 	intpcm_t x, y;
604021fa32SChristos Margiolis 
614021fa32SChristos Margiolis 	src += count;
624021fa32SChristos Margiolis 	dst += count;
634021fa32SChristos Margiolis 
644021fa32SChristos Margiolis 	do {
654021fa32SChristos Margiolis 		src -= AFMT_BPS(fmt);
664021fa32SChristos Margiolis 		dst -= AFMT_BPS(fmt);
674021fa32SChristos Margiolis 		count -= AFMT_BPS(fmt);
684021fa32SChristos Margiolis 		x = pcm_sample_read_calc(src, fmt);
694021fa32SChristos Margiolis 		y = pcm_sample_read_calc(dst, fmt);
704021fa32SChristos Margiolis 		z = INTPCM_T(x) + y;
714021fa32SChristos Margiolis 		x = pcm_clamp_calc(z, fmt);
724021fa32SChristos Margiolis 		pcm_sample_write(dst, x, fmt);
734021fa32SChristos Margiolis 	} while (count != 0);
7490da2b28SAriff Abdullah }
7590da2b28SAriff Abdullah 
7690da2b28SAriff Abdullah static int
feed_mixer_init(struct pcm_feeder * f)7790da2b28SAriff Abdullah feed_mixer_init(struct pcm_feeder *f)
7890da2b28SAriff Abdullah {
794021fa32SChristos Margiolis 	struct feed_mixer_info *info;
8090da2b28SAriff Abdullah 
8190da2b28SAriff Abdullah 	if (f->desc->in != f->desc->out)
8290da2b28SAriff Abdullah 		return (EINVAL);
8390da2b28SAriff Abdullah 
844021fa32SChristos Margiolis 	info = malloc(sizeof(*info), M_DEVBUF, M_NOWAIT | M_ZERO);
854021fa32SChristos Margiolis 	if (info == NULL)
864021fa32SChristos Margiolis 		return (ENOMEM);
874021fa32SChristos Margiolis 
884021fa32SChristos Margiolis 	info->format = AFMT_ENCODING(f->desc->in);
894021fa32SChristos Margiolis 	info->channels = AFMT_CHANNEL(f->desc->in);
904021fa32SChristos Margiolis 	info->bps = AFMT_BPS(f->desc->in);
914021fa32SChristos Margiolis 
924021fa32SChristos Margiolis 	f->data = info;
934021fa32SChristos Margiolis 
9490da2b28SAriff Abdullah 	return (0);
9590da2b28SAriff Abdullah }
9690da2b28SAriff Abdullah 
974021fa32SChristos Margiolis static int
feed_mixer_free(struct pcm_feeder * f)984021fa32SChristos Margiolis feed_mixer_free(struct pcm_feeder *f)
994021fa32SChristos Margiolis {
1004021fa32SChristos Margiolis 	struct feed_mixer_info *info;
1014021fa32SChristos Margiolis 
1024021fa32SChristos Margiolis 	info = f->data;
1034021fa32SChristos Margiolis 	if (info != NULL)
1044021fa32SChristos Margiolis 		free(info, M_DEVBUF);
1054021fa32SChristos Margiolis 
1064021fa32SChristos Margiolis 	f->data = NULL;
1074021fa32SChristos Margiolis 
1084021fa32SChristos Margiolis 	return (0);
10990da2b28SAriff Abdullah }
11090da2b28SAriff Abdullah 
11190da2b28SAriff Abdullah static int
feed_mixer_set(struct pcm_feeder * f,int what,int value)11290da2b28SAriff Abdullah feed_mixer_set(struct pcm_feeder *f, int what, int value)
11390da2b28SAriff Abdullah {
1144021fa32SChristos Margiolis 	struct feed_mixer_info *info;
1154021fa32SChristos Margiolis 
1164021fa32SChristos Margiolis 	info = f->data;
11790da2b28SAriff Abdullah 
11890da2b28SAriff Abdullah 	switch (what) {
11990da2b28SAriff Abdullah 	case FEEDMIXER_CHANNELS:
12090da2b28SAriff Abdullah 		if (value < SND_CHN_MIN || value > SND_CHN_MAX)
12190da2b28SAriff Abdullah 			return (EINVAL);
1224021fa32SChristos Margiolis 		info->channels = (uint32_t)value;
12390da2b28SAriff Abdullah 		break;
12490da2b28SAriff Abdullah 	default:
12590da2b28SAriff Abdullah 		return (EINVAL);
12690da2b28SAriff Abdullah 	}
12790da2b28SAriff Abdullah 
12890da2b28SAriff Abdullah 	return (0);
12990da2b28SAriff Abdullah }
13090da2b28SAriff Abdullah 
13190da2b28SAriff Abdullah static __inline int
feed_mixer_rec(struct pcm_channel * c)13290da2b28SAriff Abdullah feed_mixer_rec(struct pcm_channel *c)
13390da2b28SAriff Abdullah {
13490da2b28SAriff Abdullah 	struct pcm_channel *ch;
13590da2b28SAriff Abdullah 	struct snd_dbuf *b, *bs;
13690da2b28SAriff Abdullah 	uint32_t cnt, maxfeed;
13790da2b28SAriff Abdullah 	int rdy;
13890da2b28SAriff Abdullah 
13990da2b28SAriff Abdullah 	/*
14090da2b28SAriff Abdullah 	 * Reset ready and moving pointer. We're not using bufsoft
14190da2b28SAriff Abdullah 	 * anywhere since its sole purpose is to become the primary
14290da2b28SAriff Abdullah 	 * distributor for the recorded buffer and also as an interrupt
14390da2b28SAriff Abdullah 	 * threshold progress indicator.
14490da2b28SAriff Abdullah 	 */
14590da2b28SAriff Abdullah 	b = c->bufsoft;
14690da2b28SAriff Abdullah 	b->rp = 0;
14790da2b28SAriff Abdullah 	b->rl = 0;
14890da2b28SAriff Abdullah 	cnt = sndbuf_getsize(b);
14990da2b28SAriff Abdullah 	maxfeed = SND_FXROUND(SND_FXDIV_MAX, sndbuf_getalign(b));
15090da2b28SAriff Abdullah 
15190da2b28SAriff Abdullah 	do {
15290da2b28SAriff Abdullah 		cnt = FEEDER_FEED(c->feeder->source, c, b->tmpbuf,
15390da2b28SAriff Abdullah 		    min(cnt, maxfeed), c->bufhard);
15490da2b28SAriff Abdullah 		if (cnt != 0) {
15590da2b28SAriff Abdullah 			sndbuf_acquire(b, b->tmpbuf, cnt);
15690da2b28SAriff Abdullah 			cnt = sndbuf_getfree(b);
15790da2b28SAriff Abdullah 		}
15890da2b28SAriff Abdullah 	} while (cnt != 0);
15990da2b28SAriff Abdullah 
16090da2b28SAriff Abdullah 	/* Not enough data */
16190da2b28SAriff Abdullah 	if (b->rl < sndbuf_getalign(b)) {
16290da2b28SAriff Abdullah 		b->rl = 0;
16390da2b28SAriff Abdullah 		return (0);
16490da2b28SAriff Abdullah 	}
16590da2b28SAriff Abdullah 
16690da2b28SAriff Abdullah 	/*
16790da2b28SAriff Abdullah 	 * Keep track of ready and moving pointer since we will use
16890da2b28SAriff Abdullah 	 * bufsoft over and over again, pretending nothing has happened.
16990da2b28SAriff Abdullah 	 */
17090da2b28SAriff Abdullah 	rdy = b->rl;
17190da2b28SAriff Abdullah 
17290da2b28SAriff Abdullah 	CHN_FOREACH(ch, c, children.busy) {
17390da2b28SAriff Abdullah 		CHN_LOCK(ch);
17490da2b28SAriff Abdullah 		if (CHN_STOPPED(ch) || (ch->flags & CHN_F_DIRTY)) {
17590da2b28SAriff Abdullah 			CHN_UNLOCK(ch);
17690da2b28SAriff Abdullah 			continue;
17790da2b28SAriff Abdullah 		}
17890da2b28SAriff Abdullah #ifdef SND_DEBUG
17990da2b28SAriff Abdullah 		if ((c->flags & CHN_F_DIRTY) && VCHAN_SYNC_REQUIRED(ch)) {
18090da2b28SAriff Abdullah 			if (vchan_sync(ch) != 0) {
18190da2b28SAriff Abdullah 				CHN_UNLOCK(ch);
18290da2b28SAriff Abdullah 				continue;
18390da2b28SAriff Abdullah 			}
18490da2b28SAriff Abdullah 		}
18590da2b28SAriff Abdullah #endif
18690da2b28SAriff Abdullah 		bs = ch->bufsoft;
18790da2b28SAriff Abdullah 		if (ch->flags & CHN_F_MMAP)
18890da2b28SAriff Abdullah 			sndbuf_dispose(bs, NULL, sndbuf_getready(bs));
18990da2b28SAriff Abdullah 		cnt = sndbuf_getfree(bs);
19090da2b28SAriff Abdullah 		if (cnt < sndbuf_getalign(bs)) {
19190da2b28SAriff Abdullah 			CHN_UNLOCK(ch);
19290da2b28SAriff Abdullah 			continue;
19390da2b28SAriff Abdullah 		}
19490da2b28SAriff Abdullah 		maxfeed = SND_FXROUND(SND_FXDIV_MAX, sndbuf_getalign(bs));
19590da2b28SAriff Abdullah 		do {
19690da2b28SAriff Abdullah 			cnt = FEEDER_FEED(ch->feeder, ch, bs->tmpbuf,
19790da2b28SAriff Abdullah 			    min(cnt, maxfeed), b);
19890da2b28SAriff Abdullah 			if (cnt != 0) {
19990da2b28SAriff Abdullah 				sndbuf_acquire(bs, bs->tmpbuf, cnt);
20090da2b28SAriff Abdullah 				cnt = sndbuf_getfree(bs);
20190da2b28SAriff Abdullah 			}
20290da2b28SAriff Abdullah 		} while (cnt != 0);
20390da2b28SAriff Abdullah 		/*
20490da2b28SAriff Abdullah 		 * Not entirely flushed out...
20590da2b28SAriff Abdullah 		 */
20690da2b28SAriff Abdullah 		if (b->rl != 0)
20790da2b28SAriff Abdullah 			ch->xruns++;
20890da2b28SAriff Abdullah 		CHN_UNLOCK(ch);
20990da2b28SAriff Abdullah 		/*
21090da2b28SAriff Abdullah 		 * Rewind buffer position for next virtual channel.
21190da2b28SAriff Abdullah 		 */
21290da2b28SAriff Abdullah 		b->rp = 0;
21390da2b28SAriff Abdullah 		b->rl = rdy;
21490da2b28SAriff Abdullah 	}
21590da2b28SAriff Abdullah 
21690da2b28SAriff Abdullah 	/*
21790da2b28SAriff Abdullah 	 * Set ready pointer to indicate that our children are ready
21890da2b28SAriff Abdullah 	 * to be woken up, also as an interrupt threshold progress
21990da2b28SAriff Abdullah 	 * indicator.
22090da2b28SAriff Abdullah 	 */
22190da2b28SAriff Abdullah 	b->rl = 1;
22290da2b28SAriff Abdullah 
22390da2b28SAriff Abdullah 	c->flags &= ~CHN_F_DIRTY;
22490da2b28SAriff Abdullah 
22590da2b28SAriff Abdullah 	/*
22690da2b28SAriff Abdullah 	 * Return 0 to bail out early from sndbuf_feed() loop.
22790da2b28SAriff Abdullah 	 * No need to increase feedcount counter since part of this
22890da2b28SAriff Abdullah 	 * feeder chains already include feed_root().
22990da2b28SAriff Abdullah 	 */
23090da2b28SAriff Abdullah 	return (0);
23190da2b28SAriff Abdullah }
23290da2b28SAriff Abdullah 
23390da2b28SAriff Abdullah static int
feed_mixer_feed(struct pcm_feeder * f,struct pcm_channel * c,uint8_t * b,uint32_t count,void * source)23490da2b28SAriff Abdullah feed_mixer_feed(struct pcm_feeder *f, struct pcm_channel *c, uint8_t *b,
23590da2b28SAriff Abdullah     uint32_t count, void *source)
23690da2b28SAriff Abdullah {
23790da2b28SAriff Abdullah 	struct feed_mixer_info *info;
23890da2b28SAriff Abdullah 	struct snd_dbuf *src = source;
23990da2b28SAriff Abdullah 	struct pcm_channel *ch;
24090da2b28SAriff Abdullah 	uint32_t cnt, mcnt, rcnt, sz;
24190da2b28SAriff Abdullah 	int passthrough;
24290da2b28SAriff Abdullah 	uint8_t *tmp;
24390da2b28SAriff Abdullah 
24490da2b28SAriff Abdullah 	if (c->direction == PCMDIR_REC)
24590da2b28SAriff Abdullah 		return (feed_mixer_rec(c));
24690da2b28SAriff Abdullah 
24790da2b28SAriff Abdullah 	sz = sndbuf_getsize(src);
24890da2b28SAriff Abdullah 	if (sz < count)
24990da2b28SAriff Abdullah 		count = sz;
25090da2b28SAriff Abdullah 
2514021fa32SChristos Margiolis 	info = f->data;
2524021fa32SChristos Margiolis 	sz = info->bps * info->channels;
25390da2b28SAriff Abdullah 	count = SND_FXROUND(count, sz);
25490da2b28SAriff Abdullah 	if (count < sz)
25590da2b28SAriff Abdullah 		return (0);
25690da2b28SAriff Abdullah 
25790da2b28SAriff Abdullah 	/*
25890da2b28SAriff Abdullah 	 * We are going to use our source as a temporary buffer since it's
25990da2b28SAriff Abdullah 	 * got no other purpose.  We obtain our data by traversing the channel
26090da2b28SAriff Abdullah 	 * list of children and calling mixer function to mix count bytes from
26190da2b28SAriff Abdullah 	 * each into our destination buffer, b.
26290da2b28SAriff Abdullah 	 */
26390da2b28SAriff Abdullah 	tmp = sndbuf_getbuf(src);
26490da2b28SAriff Abdullah 	rcnt = 0;
26590da2b28SAriff Abdullah 	mcnt = 0;
26690da2b28SAriff Abdullah 	passthrough = 0;	/* 'passthrough' / 'exclusive' marker */
26790da2b28SAriff Abdullah 
26890da2b28SAriff Abdullah 	CHN_FOREACH(ch, c, children.busy) {
26990da2b28SAriff Abdullah 		CHN_LOCK(ch);
27090da2b28SAriff Abdullah 		if (CHN_STOPPED(ch) || (ch->flags & CHN_F_DIRTY)) {
27190da2b28SAriff Abdullah 			CHN_UNLOCK(ch);
27290da2b28SAriff Abdullah 			continue;
27390da2b28SAriff Abdullah 		}
27490da2b28SAriff Abdullah #ifdef SND_DEBUG
27590da2b28SAriff Abdullah 		if ((c->flags & CHN_F_DIRTY) && VCHAN_SYNC_REQUIRED(ch)) {
27690da2b28SAriff Abdullah 			if (vchan_sync(ch) != 0) {
27790da2b28SAriff Abdullah 				CHN_UNLOCK(ch);
27890da2b28SAriff Abdullah 				continue;
27990da2b28SAriff Abdullah 			}
28090da2b28SAriff Abdullah 		}
28190da2b28SAriff Abdullah #endif
28290da2b28SAriff Abdullah 		if ((ch->flags & CHN_F_MMAP) && !(ch->flags & CHN_F_CLOSING))
28390da2b28SAriff Abdullah 			sndbuf_acquire(ch->bufsoft, NULL,
28490da2b28SAriff Abdullah 			    sndbuf_getfree(ch->bufsoft));
2854021fa32SChristos Margiolis 		if (c->flags & CHN_F_PASSTHROUGH) {
28690da2b28SAriff Abdullah 			/*
28790da2b28SAriff Abdullah 			 * Passthrough. Dump the first digital/passthrough
28890da2b28SAriff Abdullah 			 * channel into destination buffer, and the rest into
28990da2b28SAriff Abdullah 			 * nothingness (mute effect).
29090da2b28SAriff Abdullah 			 */
29190da2b28SAriff Abdullah 			if (passthrough == 0 &&
29290da2b28SAriff Abdullah 			    (ch->format & AFMT_PASSTHROUGH)) {
29390da2b28SAriff Abdullah 				rcnt = SND_FXROUND(FEEDER_FEED(ch->feeder, ch,
29490da2b28SAriff Abdullah 				    b, count, ch->bufsoft), sz);
29590da2b28SAriff Abdullah 				passthrough = 1;
29690da2b28SAriff Abdullah 			} else
29790da2b28SAriff Abdullah 				FEEDER_FEED(ch->feeder, ch, tmp, count,
29890da2b28SAriff Abdullah 				    ch->bufsoft);
29990da2b28SAriff Abdullah 		} else if (c->flags & CHN_F_EXCLUSIVE) {
30090da2b28SAriff Abdullah 			/*
30190da2b28SAriff Abdullah 			 * Exclusive. Dump the first 'exclusive' channel into
30290da2b28SAriff Abdullah 			 * destination buffer, and the rest into nothingness
30390da2b28SAriff Abdullah 			 * (mute effect).
30490da2b28SAriff Abdullah 			 */
30590da2b28SAriff Abdullah 			if (passthrough == 0 && (ch->flags & CHN_F_EXCLUSIVE)) {
30690da2b28SAriff Abdullah 				rcnt = SND_FXROUND(FEEDER_FEED(ch->feeder, ch,
30790da2b28SAriff Abdullah 				    b, count, ch->bufsoft), sz);
30890da2b28SAriff Abdullah 				passthrough = 1;
30990da2b28SAriff Abdullah 			} else
31090da2b28SAriff Abdullah 				FEEDER_FEED(ch->feeder, ch, tmp, count,
31190da2b28SAriff Abdullah 				    ch->bufsoft);
31290da2b28SAriff Abdullah 		} else {
31390da2b28SAriff Abdullah 			if (rcnt == 0) {
31490da2b28SAriff Abdullah 				rcnt = SND_FXROUND(FEEDER_FEED(ch->feeder, ch,
31590da2b28SAriff Abdullah 				    b, count, ch->bufsoft), sz);
31690da2b28SAriff Abdullah 				mcnt = count - rcnt;
31790da2b28SAriff Abdullah 			} else {
31890da2b28SAriff Abdullah 				cnt = SND_FXROUND(FEEDER_FEED(ch->feeder, ch,
31990da2b28SAriff Abdullah 				    tmp, count, ch->bufsoft), sz);
32090da2b28SAriff Abdullah 				if (cnt != 0) {
32190da2b28SAriff Abdullah 					if (mcnt != 0) {
32290da2b28SAriff Abdullah 						memset(b + rcnt,
32390da2b28SAriff Abdullah 						    sndbuf_zerodata(
32490da2b28SAriff Abdullah 						    f->desc->out), mcnt);
32590da2b28SAriff Abdullah 						mcnt = 0;
32690da2b28SAriff Abdullah 					}
3274021fa32SChristos Margiolis 					switch (info->format) {
3284021fa32SChristos Margiolis 					case AFMT_S16_NE:
3294021fa32SChristos Margiolis 						feed_mixer_apply(tmp, b, cnt,
3304021fa32SChristos Margiolis 						    AFMT_S16_NE);
3314021fa32SChristos Margiolis 						break;
3324021fa32SChristos Margiolis 					case AFMT_S24_NE:
3334021fa32SChristos Margiolis 						feed_mixer_apply(tmp, b, cnt,
3344021fa32SChristos Margiolis 						    AFMT_S24_NE);
3354021fa32SChristos Margiolis 						break;
3364021fa32SChristos Margiolis 					case AFMT_S32_NE:
3374021fa32SChristos Margiolis 						feed_mixer_apply(tmp, b, cnt,
3384021fa32SChristos Margiolis 						    AFMT_S32_NE);
3394021fa32SChristos Margiolis 						break;
340*b6420b5eSChristos Margiolis 					default:
3414021fa32SChristos Margiolis 						feed_mixer_apply(tmp, b, cnt,
3424021fa32SChristos Margiolis 						    info->format);
343*b6420b5eSChristos Margiolis 						break;
344*b6420b5eSChristos Margiolis 					}
34590da2b28SAriff Abdullah 					if (cnt > rcnt)
34690da2b28SAriff Abdullah 						rcnt = cnt;
34790da2b28SAriff Abdullah 				}
34890da2b28SAriff Abdullah 			}
34990da2b28SAriff Abdullah 		}
35090da2b28SAriff Abdullah 		CHN_UNLOCK(ch);
35190da2b28SAriff Abdullah 	}
35290da2b28SAriff Abdullah 
35390da2b28SAriff Abdullah 	if (++c->feedcount == 0)
35490da2b28SAriff Abdullah 		c->feedcount = 2;
35590da2b28SAriff Abdullah 
35690da2b28SAriff Abdullah 	c->flags &= ~CHN_F_DIRTY;
35790da2b28SAriff Abdullah 
35890da2b28SAriff Abdullah 	return (rcnt);
35990da2b28SAriff Abdullah }
36090da2b28SAriff Abdullah 
36190da2b28SAriff Abdullah static struct pcm_feederdesc feeder_mixer_desc[] = {
36290da2b28SAriff Abdullah 	{ FEEDER_MIXER, 0, 0, 0, 0 },
36390da2b28SAriff Abdullah 	{ 0, 0, 0, 0, 0 }
36490da2b28SAriff Abdullah };
36590da2b28SAriff Abdullah 
36690da2b28SAriff Abdullah static kobj_method_t feeder_mixer_methods[] = {
36790da2b28SAriff Abdullah 	KOBJMETHOD(feeder_init,		feed_mixer_init),
3684021fa32SChristos Margiolis 	KOBJMETHOD(feeder_free,		feed_mixer_free),
36990da2b28SAriff Abdullah 	KOBJMETHOD(feeder_set,		feed_mixer_set),
37090da2b28SAriff Abdullah 	KOBJMETHOD(feeder_feed,		feed_mixer_feed),
37190da2b28SAriff Abdullah 	KOBJMETHOD_END
37290da2b28SAriff Abdullah };
37390da2b28SAriff Abdullah 
37490da2b28SAriff Abdullah FEEDER_DECLARE(feeder_mixer, NULL);
375