2 * Copyright (c) 2008-2009 Ariff Abdullah <ariff@FreeBSD.org>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 #ifdef HAVE_KERNEL_OPTION_HEADERS
31 #include <dev/sound/pcm/sound.h>
33 #include "feeder_if.h"
35 SND_DECLARE_FILE("$FreeBSD$");
38 struct feeder_chain_state {
39 uint32_t afmt; /* audio format */
40 uint32_t rate; /* sampling rate */
41 struct pcmchan_matrix *matrix; /* matrix map */
45 * chain descriptor that will be passed around from the beginning until the
46 * end of chain process.
48 struct feeder_chain_desc {
49 struct feeder_chain_state origin; /* original state */
50 struct feeder_chain_state current; /* current state */
51 struct feeder_chain_state target; /* target state */
52 struct pcm_feederdesc desc; /* feeder descriptor */
53 uint32_t afmt_ne; /* prefered native endian */
54 int mode; /* chain mode */
55 int use_eq; /* need EQ? */
56 int use_matrix; /* need channel matrixing? */
57 int use_volume; /* need softpcmvol? */
58 int dummy; /* dummy passthrough */
59 int expensive; /* possibly expensive */
62 #define FEEDER_CHAIN_LEAN 0
63 #define FEEDER_CHAIN_16 1
64 #define FEEDER_CHAIN_32 2
65 #define FEEDER_CHAIN_MULTI 3
66 #define FEEDER_CHAIN_FULLMULTI 4
67 #define FEEDER_CHAIN_LAST 5
69 #if defined(SND_FEEDER_FULL_MULTIFORMAT)
70 #define FEEDER_CHAIN_DEFAULT FEEDER_CHAIN_FULLMULTI
71 #elif defined(SND_FEEDER_MULTIFORMAT)
72 #define FEEDER_CHAIN_DEFAULT FEEDER_CHAIN_MULTI
74 #define FEEDER_CHAIN_DEFAULT FEEDER_CHAIN_LEAN
78 * List of prefered formats that might be required during
79 * processing. It will be decided through snd_fmtbest().
82 /* 'Lean' mode, signed 16 or 32 bit native endian. */
83 static uint32_t feeder_chain_formats_lean[] = {
84 AFMT_S16_NE, AFMT_S32_NE,
88 /* Force everything to signed 16 bit native endian. */
89 static uint32_t feeder_chain_formats_16[] = {
94 /* Force everything to signed 32 bit native endian. */
95 static uint32_t feeder_chain_formats_32[] = {
100 /* Multiple choices, all except 8 bit. */
101 static uint32_t feeder_chain_formats_multi[] = {
102 AFMT_S16_LE, AFMT_S16_BE, AFMT_U16_LE, AFMT_U16_BE,
103 AFMT_S24_LE, AFMT_S24_BE, AFMT_U24_LE, AFMT_U24_BE,
104 AFMT_S32_LE, AFMT_S32_BE, AFMT_U32_LE, AFMT_U32_BE,
108 /* Everything that is convertible. */
109 static uint32_t feeder_chain_formats_fullmulti[] = {
111 AFMT_S16_LE, AFMT_S16_BE, AFMT_U16_LE, AFMT_U16_BE,
112 AFMT_S24_LE, AFMT_S24_BE, AFMT_U24_LE, AFMT_U24_BE,
113 AFMT_S32_LE, AFMT_S32_BE, AFMT_U32_LE, AFMT_U32_BE,
117 static uint32_t *feeder_chain_formats[FEEDER_CHAIN_LAST] = {
118 [FEEDER_CHAIN_LEAN] = feeder_chain_formats_lean,
119 [FEEDER_CHAIN_16] = feeder_chain_formats_16,
120 [FEEDER_CHAIN_32] = feeder_chain_formats_32,
121 [FEEDER_CHAIN_MULTI] = feeder_chain_formats_multi,
122 [FEEDER_CHAIN_FULLMULTI] = feeder_chain_formats_fullmulti
125 static int feeder_chain_mode = FEEDER_CHAIN_DEFAULT;
127 #if defined(_KERNEL) && defined(SND_DEBUG) && defined(SND_FEEDER_FULL_MULTIFORMAT)
128 SYSCTL_INT(_hw_snd, OID_AUTO, feeder_chain_mode, CTLFLAG_RWTUN,
129 &feeder_chain_mode, 0,
131 "(0=lean, 1=16bit, 2=32bit, 3=multiformat, 4=fullmultiformat)");
135 * feeder_build_format(): Chain any format converter.
138 feeder_build_format(struct pcm_channel *c, struct feeder_chain_desc *cdesc)
140 struct feeder_class *fc;
141 struct pcm_feederdesc *desc;
144 desc = &(cdesc->desc);
145 desc->type = FEEDER_FORMAT;
150 fc = feeder_getclass(desc);
152 device_printf(c->dev,
153 "%s(): can't find feeder_format\n", __func__);
157 desc->in = cdesc->current.afmt;
158 desc->out = cdesc->target.afmt;
160 ret = chn_addfeeder(c, fc, desc);
162 device_printf(c->dev,
163 "%s(): can't add feeder_format\n", __func__);
167 c->feederflags |= 1 << FEEDER_FORMAT;
169 cdesc->current.afmt = cdesc->target.afmt;
175 * feeder_build_formatne(): Chain format converter that suite best for native
179 feeder_build_formatne(struct pcm_channel *c, struct feeder_chain_desc *cdesc)
181 struct feeder_chain_state otarget;
184 if (cdesc->afmt_ne == 0 ||
185 AFMT_ENCODING(cdesc->current.afmt) == cdesc->afmt_ne)
188 otarget = cdesc->target;
189 cdesc->target = cdesc->current;
190 cdesc->target.afmt = SND_FORMAT(cdesc->afmt_ne,
191 cdesc->current.matrix->channels, cdesc->current.matrix->ext);
193 ret = feeder_build_format(c, cdesc);
197 cdesc->target = otarget;
203 * feeder_build_rate(): Chain sample rate converter.
206 feeder_build_rate(struct pcm_channel *c, struct feeder_chain_desc *cdesc)
208 struct feeder_class *fc;
209 struct pcm_feeder *f;
210 struct pcm_feederdesc *desc;
213 ret = feeder_build_formatne(c, cdesc);
217 desc = &(cdesc->desc);
218 desc->type = FEEDER_RATE;
223 fc = feeder_getclass(desc);
225 device_printf(c->dev,
226 "%s(): can't find feeder_rate\n", __func__);
230 desc->in = cdesc->current.afmt;
231 desc->out = desc->in;
233 ret = chn_addfeeder(c, fc, desc);
235 device_printf(c->dev,
236 "%s(): can't add feeder_rate\n", __func__);
243 * If in 'dummy' mode (possibly due to passthrough mode), set the
244 * conversion quality to the lowest possible (should be fastest) since
245 * listener won't be hearing anything. Theoretically we can just
246 * disable it, but that will cause weird runtime behaviour:
247 * application appear to play something that is either too fast or too
250 if (cdesc->dummy != 0) {
251 ret = FEEDER_SET(f, FEEDRATE_QUALITY, 0);
253 device_printf(c->dev,
254 "%s(): can't set resampling quality\n", __func__);
259 ret = FEEDER_SET(f, FEEDRATE_SRC, cdesc->current.rate);
261 device_printf(c->dev,
262 "%s(): can't set source rate\n", __func__);
266 ret = FEEDER_SET(f, FEEDRATE_DST, cdesc->target.rate);
268 device_printf(c->dev,
269 "%s(): can't set destination rate\n", __func__);
273 c->feederflags |= 1 << FEEDER_RATE;
275 cdesc->current.rate = cdesc->target.rate;
281 * feeder_build_matrix(): Chain channel matrixing converter.
284 feeder_build_matrix(struct pcm_channel *c, struct feeder_chain_desc *cdesc)
286 struct feeder_class *fc;
287 struct pcm_feeder *f;
288 struct pcm_feederdesc *desc;
291 ret = feeder_build_formatne(c, cdesc);
295 desc = &(cdesc->desc);
296 desc->type = FEEDER_MATRIX;
301 fc = feeder_getclass(desc);
303 device_printf(c->dev,
304 "%s(): can't find feeder_matrix\n", __func__);
308 desc->in = cdesc->current.afmt;
309 desc->out = SND_FORMAT(cdesc->current.afmt,
310 cdesc->target.matrix->channels, cdesc->target.matrix->ext);
312 ret = chn_addfeeder(c, fc, desc);
314 device_printf(c->dev,
315 "%s(): can't add feeder_matrix\n", __func__);
320 ret = feeder_matrix_setup(f, cdesc->current.matrix,
321 cdesc->target.matrix);
323 device_printf(c->dev,
324 "%s(): feeder_matrix_setup() failed\n", __func__);
328 c->feederflags |= 1 << FEEDER_MATRIX;
330 cdesc->current.afmt = desc->out;
331 cdesc->current.matrix = cdesc->target.matrix;
332 cdesc->use_matrix = 0;
338 * feeder_build_volume(): Chain soft volume.
341 feeder_build_volume(struct pcm_channel *c, struct feeder_chain_desc *cdesc)
343 struct feeder_class *fc;
344 struct pcm_feeder *f;
345 struct pcm_feederdesc *desc;
348 ret = feeder_build_formatne(c, cdesc);
352 desc = &(cdesc->desc);
353 desc->type = FEEDER_VOLUME;
358 fc = feeder_getclass(desc);
360 device_printf(c->dev,
361 "%s(): can't find feeder_volume\n", __func__);
365 desc->in = cdesc->current.afmt;
366 desc->out = desc->in;
368 ret = chn_addfeeder(c, fc, desc);
370 device_printf(c->dev,
371 "%s(): can't add feeder_volume\n", __func__);
378 * If in 'dummy' mode (possibly due to passthrough mode), set BYPASS
379 * mode since listener won't be hearing anything. Theoretically we can
380 * just disable it, but that will confuse volume per channel mixer.
382 if (cdesc->dummy != 0) {
383 ret = FEEDER_SET(f, FEEDVOLUME_STATE, FEEDVOLUME_BYPASS);
385 device_printf(c->dev,
386 "%s(): can't set volume bypass\n", __func__);
391 ret = feeder_volume_apply_matrix(f, cdesc->current.matrix);
393 device_printf(c->dev,
394 "%s(): feeder_volume_apply_matrix() failed\n", __func__);
398 c->feederflags |= 1 << FEEDER_VOLUME;
400 cdesc->use_volume = 0;
406 * feeder_build_eq(): Chain parametric software equalizer.
409 feeder_build_eq(struct pcm_channel *c, struct feeder_chain_desc *cdesc)
411 struct feeder_class *fc;
412 struct pcm_feeder *f;
413 struct pcm_feederdesc *desc;
416 ret = feeder_build_formatne(c, cdesc);
420 desc = &(cdesc->desc);
421 desc->type = FEEDER_EQ;
426 fc = feeder_getclass(desc);
428 device_printf(c->dev,
429 "%s(): can't find feeder_eq\n", __func__);
433 desc->in = cdesc->current.afmt;
434 desc->out = desc->in;
436 ret = chn_addfeeder(c, fc, desc);
438 device_printf(c->dev,
439 "%s(): can't add feeder_eq\n", __func__);
445 ret = FEEDER_SET(f, FEEDEQ_RATE, cdesc->current.rate);
447 device_printf(c->dev,
448 "%s(): can't set rate on feeder_eq\n", __func__);
452 c->feederflags |= 1 << FEEDER_EQ;
460 * feeder_build_root(): Chain root feeder, the top, father of all.
463 feeder_build_root(struct pcm_channel *c, struct feeder_chain_desc *cdesc)
465 struct feeder_class *fc;
468 fc = feeder_getclass(NULL);
470 device_printf(c->dev,
471 "%s(): can't find feeder_root\n", __func__);
475 ret = chn_addfeeder(c, fc, NULL);
477 device_printf(c->dev,
478 "%s(): can't add feeder_root\n", __func__);
482 c->feederflags |= 1 << FEEDER_ROOT;
484 c->feeder->desc->in = cdesc->current.afmt;
485 c->feeder->desc->out = cdesc->current.afmt;
491 * feeder_build_mixer(): Chain software mixer for virtual channels.
494 feeder_build_mixer(struct pcm_channel *c, struct feeder_chain_desc *cdesc)
496 struct feeder_class *fc;
497 struct pcm_feederdesc *desc;
500 desc = &(cdesc->desc);
501 desc->type = FEEDER_MIXER;
506 fc = feeder_getclass(desc);
508 device_printf(c->dev,
509 "%s(): can't find feeder_mixer\n", __func__);
513 desc->in = cdesc->current.afmt;
514 desc->out = desc->in;
516 ret = chn_addfeeder(c, fc, desc);
518 device_printf(c->dev,
519 "%s(): can't add feeder_mixer\n", __func__);
523 c->feederflags |= 1 << FEEDER_MIXER;
528 /* Macrosses to ease our job doing stuffs later. */
529 #define FEEDER_BW(c, t) ((c)->t.matrix->channels * (c)->t.rate)
531 #define FEEDRATE_UP(c) ((c)->target.rate > (c)->current.rate)
532 #define FEEDRATE_DOWN(c) ((c)->target.rate < (c)->current.rate)
533 #define FEEDRATE_REQUIRED(c) (FEEDRATE_UP(c) || FEEDRATE_DOWN(c))
535 #define FEEDMATRIX_UP(c) ((c)->target.matrix->channels > \
536 (c)->current.matrix->channels)
537 #define FEEDMATRIX_DOWN(c) ((c)->target.matrix->channels < \
538 (c)->current.matrix->channels)
539 #define FEEDMATRIX_REQUIRED(c) (FEEDMATRIX_UP(c) || \
540 FEEDMATRIX_DOWN(c) || (c)->use_matrix != 0)
542 #define FEEDFORMAT_REQUIRED(c) (AFMT_ENCODING((c)->current.afmt) != \
543 AFMT_ENCODING((c)->target.afmt))
545 #define FEEDVOLUME_REQUIRED(c) ((c)->use_volume != 0)
547 #define FEEDEQ_VALIDRATE(c, t) (feeder_eq_validrate((c)->t.rate) != 0)
548 #define FEEDEQ_ECONOMY(c) (FEEDER_BW(c, current) < FEEDER_BW(c, target))
549 #define FEEDEQ_REQUIRED(c) ((c)->use_eq != 0 && \
550 FEEDEQ_VALIDRATE(c, current))
552 #define FEEDFORMAT_NE_REQUIRED(c) \
553 ((c)->afmt_ne != AFMT_S32_NE && \
554 (((c)->mode == FEEDER_CHAIN_16 && \
555 AFMT_ENCODING((c)->current.afmt) != AFMT_S16_NE) || \
556 ((c)->mode == FEEDER_CHAIN_32 && \
557 AFMT_ENCODING((c)->current.afmt) != AFMT_S32_NE) || \
558 (c)->mode == FEEDER_CHAIN_FULLMULTI || \
559 ((c)->mode == FEEDER_CHAIN_MULTI && \
560 ((c)->current.afmt & AFMT_8BIT)) || \
561 ((c)->mode == FEEDER_CHAIN_LEAN && \
562 !((c)->current.afmt & (AFMT_S16_NE | AFMT_S32_NE)))))
565 feeder_default_matrix(struct pcmchan_matrix *m, uint32_t fmt, int id)
569 memset(m, 0, sizeof(*m));
572 m->channels = AFMT_CHANNEL(fmt);
573 m->ext = AFMT_EXTCHANNEL(fmt);
574 for (x = 0; x != SND_CHN_T_MAX; x++)
579 feeder_chain(struct pcm_channel *c)
581 struct snddev_info *d;
582 struct pcmchan_caps *caps;
583 struct feeder_chain_desc cdesc;
584 struct pcmchan_matrix *hwmatrix, *softmatrix;
585 uint32_t hwfmt, softfmt;
590 /* Remove everything first. */
591 while (chn_removefeeder(c) == 0)
594 KASSERT(c->feeder == NULL, ("feeder chain not empty"));
596 /* clear and populate chain descriptor. */
597 bzero(&cdesc, sizeof(cdesc));
599 switch (feeder_chain_mode) {
600 case FEEDER_CHAIN_LEAN:
601 case FEEDER_CHAIN_16:
602 case FEEDER_CHAIN_32:
603 #if defined(SND_FEEDER_MULTIFORMAT) || defined(SND_FEEDER_FULL_MULTIFORMAT)
604 case FEEDER_CHAIN_MULTI:
606 #if defined(SND_FEEDER_FULL_MULTIFORMAT)
607 case FEEDER_CHAIN_FULLMULTI:
611 feeder_chain_mode = FEEDER_CHAIN_DEFAULT;
615 cdesc.mode = feeder_chain_mode;
616 cdesc.expensive = 1; /* XXX faster.. */
618 #define VCHAN_PASSTHROUGH(c) (((c)->flags & (CHN_F_VIRTUAL | \
619 CHN_F_PASSTHROUGH)) == \
620 (CHN_F_VIRTUAL | CHN_F_PASSTHROUGH))
622 /* Get the best possible hardware format. */
623 if (VCHAN_PASSTHROUGH(c))
624 hwfmt = c->parentchannel->format;
626 caps = chn_getcaps(c);
627 if (caps == NULL || caps->fmtlist == NULL) {
628 device_printf(c->dev,
629 "%s(): failed to get channel caps\n", __func__);
633 if ((c->format & AFMT_PASSTHROUGH) &&
634 !snd_fmtvalid(c->format, caps->fmtlist))
637 hwfmt = snd_fmtbest(c->format, caps->fmtlist);
638 if (hwfmt == 0 || !snd_fmtvalid(hwfmt, caps->fmtlist)) {
639 device_printf(c->dev,
640 "%s(): invalid hardware format 0x%08x\n",
644 for (i = 0; caps->fmtlist[i] != 0; i++)
645 printf("0x%08x\n", caps->fmtlist[i]);
646 printf("Req: 0x%08x\n", c->format);
653 * The 'hardware' possibly have different intepretation of channel
654 * matrixing, so get it first .....
656 hwmatrix = CHANNEL_GETMATRIX(c->methods, c->devinfo, hwfmt);
657 if (hwmatrix == NULL) {
658 /* setup a default matrix */
659 hwmatrix = &c->matrix_scratch;
660 feeder_default_matrix(hwmatrix, hwfmt,
661 SND_CHN_MATRIX_UNKNOWN);
663 /* ..... and rebuild hwfmt. */
664 hwfmt = SND_FORMAT(hwfmt, hwmatrix->channels, hwmatrix->ext);
666 /* Reset and rebuild default channel format/matrix map. */
668 softmatrix = &c->matrix;
669 if (softmatrix->channels != AFMT_CHANNEL(softfmt) ||
670 softmatrix->ext != AFMT_EXTCHANNEL(softfmt)) {
671 softmatrix = feeder_matrix_format_map(softfmt);
672 if (softmatrix == NULL) {
673 /* setup a default matrix */
674 softmatrix = &c->matrix;
675 feeder_default_matrix(softmatrix, softfmt,
676 SND_CHN_MATRIX_PCMCHANNEL);
678 c->matrix = *softmatrix;
679 c->matrix.id = SND_CHN_MATRIX_PCMCHANNEL;
682 softfmt = SND_FORMAT(softfmt, softmatrix->channels, softmatrix->ext);
683 if (softfmt != c->format)
684 device_printf(c->dev,
685 "%s(): WARNING: %s Soft format 0x%08x -> 0x%08x\n",
686 __func__, CHN_DIRSTR(c), c->format, softfmt);
689 * PLAY and REC are opposite.
691 if (c->direction == PCMDIR_PLAY) {
692 cdesc.origin.afmt = softfmt;
693 cdesc.origin.matrix = softmatrix;
694 cdesc.origin.rate = c->speed;
695 cdesc.target.afmt = hwfmt;
696 cdesc.target.matrix = hwmatrix;
697 cdesc.target.rate = sndbuf_getspd(c->bufhard);
699 cdesc.origin.afmt = hwfmt;
700 cdesc.origin.matrix = hwmatrix;
701 cdesc.origin.rate = sndbuf_getspd(c->bufhard);
702 cdesc.target.afmt = softfmt;
703 cdesc.target.matrix = softmatrix;
704 cdesc.target.rate = c->speed;
710 * If channel is in bitperfect or passthrough mode, make it appear
711 * that 'origin' and 'target' identical, skipping mostly chain
714 if (CHN_BITPERFECT(c) || (c->format & AFMT_PASSTHROUGH)) {
715 if (c->direction == PCMDIR_PLAY)
716 cdesc.origin = cdesc.target;
718 cdesc.target = cdesc.origin;
719 c->format = cdesc.target.afmt;
720 c->speed = cdesc.target.rate;
722 /* hwfmt is not convertible, so 'dummy' it. */
723 if (hwfmt & AFMT_PASSTHROUGH)
726 if ((softfmt & AFMT_CONVERTIBLE) &&
727 (((d->flags & SD_F_VPC) && !(c->flags & CHN_F_HAS_VCHAN)) ||
728 (!(d->flags & SD_F_VPC) && (d->flags & SD_F_SOFTPCMVOL) &&
729 !(c->flags & CHN_F_VIRTUAL))))
730 cdesc.use_volume = 1;
732 if (feeder_matrix_compare(cdesc.origin.matrix,
733 cdesc.target.matrix) != 0)
734 cdesc.use_matrix = 1;
736 /* Soft EQ only applicable for PLAY. */
737 if (cdesc.dummy == 0 &&
738 c->direction == PCMDIR_PLAY && (d->flags & SD_F_EQ) &&
739 (((d->flags & SD_F_EQ_PC) &&
740 !(c->flags & CHN_F_HAS_VCHAN)) ||
741 (!(d->flags & SD_F_EQ_PC) && !(c->flags & CHN_F_VIRTUAL))))
744 if (FEEDFORMAT_NE_REQUIRED(&cdesc)) {
747 snd_fmtbest(AFMT_ENCODING(softfmt),
748 feeder_chain_formats[cdesc.mode]) :
749 snd_fmtbest(AFMT_ENCODING(cdesc.target.afmt),
750 feeder_chain_formats[cdesc.mode]);
751 if (cdesc.afmt_ne == 0) {
752 device_printf(c->dev,
753 "%s(): snd_fmtbest failed!\n", __func__);
755 (((cdesc.dummy != 0) ? softfmt :
757 (AFMT_24BIT | AFMT_32BIT)) ?
758 AFMT_S32_NE : AFMT_S16_NE;
763 cdesc.current = cdesc.origin;
765 /* Build everything. */
769 #define FEEDER_BUILD(t) do { \
770 ret = feeder_build_##t(c, &cdesc); \
775 if (!(c->flags & CHN_F_HAS_VCHAN) || c->direction == PCMDIR_REC)
777 else if (c->direction == PCMDIR_PLAY && (c->flags & CHN_F_HAS_VCHAN))
783 * The basic idea is: The smaller the bandwidth, the cheaper the
784 * conversion process, with following constraints:-
786 * 1) Almost all feeders work best in 16/32 native endian.
787 * 2) Try to avoid 8bit feeders due to poor dynamic range.
788 * 3) Avoid volume, format, matrix and rate in BITPERFECT or
790 * 4) Try putting volume before EQ or rate. Should help to
791 * avoid/reduce possible clipping.
792 * 5) EQ require specific, valid rate, unless it allow sloppy
795 if (FEEDMATRIX_UP(&cdesc)) {
796 if (FEEDEQ_REQUIRED(&cdesc) &&
797 (!FEEDEQ_VALIDRATE(&cdesc, target) ||
798 (cdesc.expensive == 0 && FEEDEQ_ECONOMY(&cdesc))))
800 if (FEEDRATE_REQUIRED(&cdesc))
802 FEEDER_BUILD(matrix);
803 if (FEEDVOLUME_REQUIRED(&cdesc))
804 FEEDER_BUILD(volume);
805 if (FEEDEQ_REQUIRED(&cdesc))
807 } else if (FEEDMATRIX_DOWN(&cdesc)) {
808 FEEDER_BUILD(matrix);
809 if (FEEDVOLUME_REQUIRED(&cdesc))
810 FEEDER_BUILD(volume);
811 if (FEEDEQ_REQUIRED(&cdesc) &&
812 (!FEEDEQ_VALIDRATE(&cdesc, target) ||
813 FEEDEQ_ECONOMY(&cdesc)))
815 if (FEEDRATE_REQUIRED(&cdesc))
817 if (FEEDEQ_REQUIRED(&cdesc))
820 if (FEEDRATE_DOWN(&cdesc)) {
821 if (FEEDEQ_REQUIRED(&cdesc) &&
822 !FEEDEQ_VALIDRATE(&cdesc, target)) {
823 if (FEEDVOLUME_REQUIRED(&cdesc))
824 FEEDER_BUILD(volume);
829 if (FEEDMATRIX_REQUIRED(&cdesc))
830 FEEDER_BUILD(matrix);
831 if (FEEDVOLUME_REQUIRED(&cdesc))
832 FEEDER_BUILD(volume);
833 if (FEEDRATE_UP(&cdesc)) {
834 if (FEEDEQ_REQUIRED(&cdesc) &&
835 !FEEDEQ_VALIDRATE(&cdesc, target))
839 if (FEEDEQ_REQUIRED(&cdesc))
843 if (FEEDFORMAT_REQUIRED(&cdesc))
844 FEEDER_BUILD(format);
846 if (c->direction == PCMDIR_REC && (c->flags & CHN_F_HAS_VCHAN))
849 sndbuf_setfmt(c->bufsoft, c->format);
850 sndbuf_setspd(c->bufsoft, c->speed);
852 sndbuf_setfmt(c->bufhard, hwfmt);