FreeBSD kernel sound device code
feeder_eq.c
Go to the documentation of this file.
1/*-
2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3 *
4 * Copyright (c) 2008-2009 Ariff Abdullah <ariff@FreeBSD.org>
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
27 */
28
29/*
30 * feeder_eq: Parametric (compile time) Software Equalizer. Though accidental,
31 * it proves good enough for educational and general consumption.
32 *
33 * "Cookbook formulae for audio EQ biquad filter coefficients"
34 * by Robert Bristow-Johnson <rbj@audioimagination.com>
35 * - http://www.musicdsp.org/files/Audio-EQ-Cookbook.txt
36 */
37
38#ifdef _KERNEL
39#ifdef HAVE_KERNEL_OPTION_HEADERS
40#include "opt_snd.h"
41#endif
42#include <dev/sound/pcm/sound.h>
43#include <dev/sound/pcm/pcm.h>
44#include "feeder_if.h"
45
46#define SND_USE_FXDIV
47#include "snd_fxdiv_gen.h"
48
49SND_DECLARE_FILE("$FreeBSD$");
50#endif
51
52#include "feeder_eq_gen.h"
53
54#define FEEDEQ_LEVELS \
55 (((FEEDEQ_GAIN_MAX - FEEDEQ_GAIN_MIN) * \
56 (FEEDEQ_GAIN_DIV / FEEDEQ_GAIN_STEP)) + 1)
57
58#define FEEDEQ_L2GAIN(v) \
59 ((int)min(((v) * FEEDEQ_LEVELS) / 100, FEEDEQ_LEVELS - 1))
60
61#define FEEDEQ_PREAMP_IPART(x) (abs(x) >> FEEDEQ_GAIN_SHIFT)
62#define FEEDEQ_PREAMP_FPART(x) (abs(x) & FEEDEQ_GAIN_FMASK)
63#define FEEDEQ_PREAMP_SIGNVAL(x) ((x) < 0 ? -1 : 1)
64#define FEEDEQ_PREAMP_SIGNMARK(x) (((x) < 0) ? '-' : '+')
65
66#define FEEDEQ_PREAMP_IMIN -192
67#define FEEDEQ_PREAMP_IMAX 192
68#define FEEDEQ_PREAMP_FMIN 0
69#define FEEDEQ_PREAMP_FMAX 9
70
71#define FEEDEQ_PREAMP_INVALID INT_MAX
72
73#define FEEDEQ_IF2PREAMP(i, f) \
74 ((abs(i) << FEEDEQ_GAIN_SHIFT) | \
75 (((abs(f) / FEEDEQ_GAIN_STEP) * FEEDEQ_GAIN_STEP) & \
76 FEEDEQ_GAIN_FMASK))
77
78#define FEEDEQ_PREAMP_MIN \
79 (FEEDEQ_PREAMP_SIGNVAL(FEEDEQ_GAIN_MIN) * \
80 FEEDEQ_IF2PREAMP(FEEDEQ_GAIN_MIN, 0))
81
82#define FEEDEQ_PREAMP_MAX \
83 (FEEDEQ_PREAMP_SIGNVAL(FEEDEQ_GAIN_MAX) * \
84 FEEDEQ_IF2PREAMP(FEEDEQ_GAIN_MAX, 0))
85
86#define FEEDEQ_PREAMP_DEFAULT FEEDEQ_IF2PREAMP(0, 0)
87
88#define FEEDEQ_PREAMP2IDX(v) \
89 ((int32_t)((FEEDEQ_GAIN_MAX * (FEEDEQ_GAIN_DIV / \
90 FEEDEQ_GAIN_STEP)) + (FEEDEQ_PREAMP_SIGNVAL(v) * \
91 FEEDEQ_PREAMP_IPART(v) * (FEEDEQ_GAIN_DIV / \
92 FEEDEQ_GAIN_STEP)) + (FEEDEQ_PREAMP_SIGNVAL(v) * \
93 (FEEDEQ_PREAMP_FPART(v) / FEEDEQ_GAIN_STEP))))
94
95static int feeder_eq_exact_rate = 0;
96
97#ifdef _KERNEL
98static char feeder_eq_presets[] = FEEDER_EQ_PRESETS;
99SYSCTL_STRING(_hw_snd, OID_AUTO, feeder_eq_presets, CTLFLAG_RD,
100 &feeder_eq_presets, 0, "compile-time eq presets");
101
102SYSCTL_INT(_hw_snd, OID_AUTO, feeder_eq_exact_rate, CTLFLAG_RWTUN,
103 &feeder_eq_exact_rate, 0, "force exact rate validation");
104#endif
105
106struct feed_eq_info;
107
108typedef void (*feed_eq_t)(struct feed_eq_info *, uint8_t *, uint32_t);
109
115 int gain;
116};
117
121 struct feed_eq_coeff *coeff;
123 uint32_t channels;
124 uint32_t rate;
125 uint32_t align;
126 int32_t preamp;
127 int state;
128};
129
130#if !defined(_KERNEL) && defined(FEEDEQ_ERR_CLIP)
131#define FEEDEQ_ERR_CLIP_CHECK(t, v) do { \
132 if ((v) < PCM_S32_MIN || (v) > PCM_S32_MAX) \
133 errx(1, "\n\n%s(): ["#t"] Sample clipping: %jd\n", \
134 __func__, (intmax_t)(v)); \
135} while (0)
136#else
137#define FEEDEQ_ERR_CLIP_CHECK(...)
138#endif
139
140#define FEEDEQ_CLAMP(v) (((v) > PCM_S32_MAX) ? PCM_S32_MAX : \
141 (((v) < PCM_S32_MIN) ? PCM_S32_MIN : \
142 (v)))
143
144#define FEEDEQ_DECLARE(SIGN, BIT, ENDIAN) \
145static void \
146feed_eq_biquad_##SIGN##BIT##ENDIAN(struct feed_eq_info *info, \
147 uint8_t *dst, uint32_t count) \
148{ \
149 struct feed_eq_coeff_tone *treble, *bass; \
150 intpcm64_t w; \
151 intpcm_t v; \
152 uint32_t i, j; \
153 int32_t pmul, pshift; \
154 \
155 pmul = feed_eq_preamp[info->preamp].mul; \
156 pshift = feed_eq_preamp[info->preamp].shift; \
157 \
158 if (info->state == FEEDEQ_DISABLE) { \
159 j = count * info->channels; \
160 dst += j * PCM_##BIT##_BPS; \
161 do { \
162 dst -= PCM_##BIT##_BPS; \
163 v = _PCM_READ_##SIGN##BIT##_##ENDIAN(dst); \
164 v = ((intpcm64_t)pmul * v) >> pshift; \
165 _PCM_WRITE_##SIGN##BIT##_##ENDIAN(dst, v); \
166 } while (--j != 0); \
167 \
168 return; \
169 } \
170 \
171 treble = &(info->coeff[info->treble.gain].treble); \
172 bass = &(info->coeff[info->bass.gain].bass); \
173 \
174 do { \
175 i = 0; \
176 j = info->channels; \
177 do { \
178 v = _PCM_READ_##SIGN##BIT##_##ENDIAN(dst); \
179 v <<= 32 - BIT; \
180 v = ((intpcm64_t)pmul * v) >> pshift; \
181 \
182 w = (intpcm64_t)v * treble->b0; \
183 w += (intpcm64_t)info->treble.i1[i] * treble->b1; \
184 w += (intpcm64_t)info->treble.i2[i] * treble->b2; \
185 w -= (intpcm64_t)info->treble.o1[i] * treble->a1; \
186 w -= (intpcm64_t)info->treble.o2[i] * treble->a2; \
187 info->treble.i2[i] = info->treble.i1[i]; \
188 info->treble.i1[i] = v; \
189 info->treble.o2[i] = info->treble.o1[i]; \
190 w >>= FEEDEQ_COEFF_SHIFT; \
191 FEEDEQ_ERR_CLIP_CHECK(treble, w); \
192 v = FEEDEQ_CLAMP(w); \
193 info->treble.o1[i] = v; \
194 \
195 w = (intpcm64_t)v * bass->b0; \
196 w += (intpcm64_t)info->bass.i1[i] * bass->b1; \
197 w += (intpcm64_t)info->bass.i2[i] * bass->b2; \
198 w -= (intpcm64_t)info->bass.o1[i] * bass->a1; \
199 w -= (intpcm64_t)info->bass.o2[i] * bass->a2; \
200 info->bass.i2[i] = info->bass.i1[i]; \
201 info->bass.i1[i] = v; \
202 info->bass.o2[i] = info->bass.o1[i]; \
203 w >>= FEEDEQ_COEFF_SHIFT; \
204 FEEDEQ_ERR_CLIP_CHECK(bass, w); \
205 v = FEEDEQ_CLAMP(w); \
206 info->bass.o1[i] = v; \
207 \
208 v >>= 32 - BIT; \
209 _PCM_WRITE_##SIGN##BIT##_##ENDIAN(dst, v); \
210 dst += PCM_##BIT##_BPS; \
211 i++; \
212 } while (--j != 0); \
213 } while (--count != 0); \
214}
215
216#if BYTE_ORDER == LITTLE_ENDIAN || defined(SND_FEEDER_MULTIFORMAT)
217FEEDEQ_DECLARE(S, 16, LE)
218FEEDEQ_DECLARE(S, 32, LE)
219#endif
220#if BYTE_ORDER == BIG_ENDIAN || defined(SND_FEEDER_MULTIFORMAT)
221FEEDEQ_DECLARE(S, 16, BE)
222FEEDEQ_DECLARE(S, 32, BE)
223#endif
224#ifdef SND_FEEDER_MULTIFORMAT
225FEEDEQ_DECLARE(S, 8, NE)
226FEEDEQ_DECLARE(S, 24, LE)
227FEEDEQ_DECLARE(S, 24, BE)
228FEEDEQ_DECLARE(U, 8, NE)
229FEEDEQ_DECLARE(U, 16, LE)
230FEEDEQ_DECLARE(U, 24, LE)
231FEEDEQ_DECLARE(U, 32, LE)
232FEEDEQ_DECLARE(U, 16, BE)
233FEEDEQ_DECLARE(U, 24, BE)
234FEEDEQ_DECLARE(U, 32, BE)
235#endif
236
237#define FEEDEQ_ENTRY(SIGN, BIT, ENDIAN) \
238 { \
239 AFMT_##SIGN##BIT##_##ENDIAN, \
240 feed_eq_biquad_##SIGN##BIT##ENDIAN \
241 }
242
243static const struct {
244 uint32_t format;
246} feed_eq_biquad_tab[] = {
247#if BYTE_ORDER == LITTLE_ENDIAN || defined(SND_FEEDER_MULTIFORMAT)
248 FEEDEQ_ENTRY(S, 16, LE),
249 FEEDEQ_ENTRY(S, 32, LE),
250#endif
251#if BYTE_ORDER == BIG_ENDIAN || defined(SND_FEEDER_MULTIFORMAT)
252 FEEDEQ_ENTRY(S, 16, BE),
253 FEEDEQ_ENTRY(S, 32, BE),
254#endif
255#ifdef SND_FEEDER_MULTIFORMAT
256 FEEDEQ_ENTRY(S, 8, NE),
257 FEEDEQ_ENTRY(S, 24, LE),
258 FEEDEQ_ENTRY(S, 24, BE),
259 FEEDEQ_ENTRY(U, 8, NE),
260 FEEDEQ_ENTRY(U, 16, LE),
261 FEEDEQ_ENTRY(U, 24, LE),
262 FEEDEQ_ENTRY(U, 32, LE),
263 FEEDEQ_ENTRY(U, 16, BE),
264 FEEDEQ_ENTRY(U, 24, BE),
265 FEEDEQ_ENTRY(U, 32, BE)
266#endif
268
269#define FEEDEQ_BIQUAD_TAB_SIZE \
270 ((int32_t)(sizeof(feed_eq_biquad_tab) / sizeof(feed_eq_biquad_tab[0])))
271
272static struct feed_eq_coeff *
274{
275 uint32_t spd, threshold;
276 int i;
277
278 if (rate < FEEDEQ_RATE_MIN || rate > FEEDEQ_RATE_MAX)
279 return (NULL);
280
281 /*
282 * Not all rates are supported. Choose the best rate that we can to
283 * allow 'sloppy' conversion. Good enough for naive listeners.
284 */
285 for (i = 0; i < FEEDEQ_TAB_SIZE; i++) {
286 spd = feed_eq_tab[i].rate;
287 threshold = spd + ((i < (FEEDEQ_TAB_SIZE - 1) &&
288 feed_eq_tab[i + 1].rate > spd) ?
289 ((feed_eq_tab[i + 1].rate - spd) >> 1) : 0);
290 if (rate == spd ||
291 (feeder_eq_exact_rate == 0 && rate <= threshold))
292 return (feed_eq_tab[i].coeff);
293 }
294
295 return (NULL);
296}
297
298int
300{
301
302 if (feed_eq_coeff_rate(rate) != NULL)
303 return (1);
304
305 return (0);
306}
307
308static void
310{
311 uint32_t i;
312
313 for (i = 0; i < info->channels; i++) {
314 info->treble.i1[i] = 0;
315 info->treble.i2[i] = 0;
316 info->treble.o1[i] = 0;
317 info->treble.o2[i] = 0;
318 info->bass.i1[i] = 0;
319 info->bass.i2[i] = 0;
320 info->bass.o1[i] = 0;
321 info->bass.o2[i] = 0;
322 }
323}
324
325static int
327{
328
329 info->coeff = feed_eq_coeff_rate(info->rate);
330 if (info->coeff == NULL)
331 return (EINVAL);
332
333 feed_eq_reset(info);
334
335 return (0);
336}
337
338static int
340{
341 struct feed_eq_info *info;
342 feed_eq_t biquad_op;
343 int i;
344
345 if (f->desc->in != f->desc->out)
346 return (EINVAL);
347
348 biquad_op = NULL;
349
350 for (i = 0; i < FEEDEQ_BIQUAD_TAB_SIZE && biquad_op == NULL; i++) {
351 if (AFMT_ENCODING(f->desc->in) == feed_eq_biquad_tab[i].format)
352 biquad_op = feed_eq_biquad_tab[i].biquad;
353 }
354
355 if (biquad_op == NULL)
356 return (EINVAL);
357
358 info = malloc(sizeof(*info), M_DEVBUF, M_NOWAIT | M_ZERO);
359 if (info == NULL)
360 return (ENOMEM);
361
362 info->channels = AFMT_CHANNEL(f->desc->in);
363 info->align = info->channels * AFMT_BPS(f->desc->in);
364
365 info->rate = FEEDEQ_RATE_MIN;
366 info->treble.gain = FEEDEQ_L2GAIN(50);
367 info->bass.gain = FEEDEQ_L2GAIN(50);
369 info->state = FEEDEQ_UNKNOWN;
370
371 info->biquad = biquad_op;
372
373 f->data = info;
374
375 return (feed_eq_setup(info));
376}
377
378static int
379feed_eq_set(struct pcm_feeder *f, int what, int value)
380{
381 struct feed_eq_info *info;
382
383 info = f->data;
384
385 switch (what) {
386 case FEEDEQ_CHANNELS:
387 if (value < SND_CHN_MIN || value > SND_CHN_MAX)
388 return (EINVAL);
389 info->channels = (uint32_t)value;
390 info->align = info->channels * AFMT_BPS(f->desc->in);
391 feed_eq_reset(info);
392 break;
393 case FEEDEQ_RATE:
394 if (feeder_eq_validrate(value) == 0)
395 return (EINVAL);
396 info->rate = (uint32_t)value;
397 if (info->state == FEEDEQ_UNKNOWN)
398 info->state = FEEDEQ_ENABLE;
399 return (feed_eq_setup(info));
400 break;
401 case FEEDEQ_TREBLE:
402 case FEEDEQ_BASS:
403 if (value < 0 || value > 100)
404 return (EINVAL);
405 if (what == FEEDEQ_TREBLE)
407 else
408 info->bass.gain = FEEDEQ_L2GAIN(value);
409 break;
410 case FEEDEQ_PREAMP:
411 if (value < FEEDEQ_PREAMP_MIN || value > FEEDEQ_PREAMP_MAX)
412 return (EINVAL);
414 break;
415 case FEEDEQ_STATE:
416 if (!(value == FEEDEQ_BYPASS || value == FEEDEQ_ENABLE ||
418 return (EINVAL);
419 info->state = value;
420 feed_eq_reset(info);
421 break;
422 default:
423 return (EINVAL);
424 break;
425 }
426
427 return (0);
428}
429
430static int
432{
433 struct feed_eq_info *info;
434
435 info = f->data;
436 if (info != NULL)
437 free(info, M_DEVBUF);
438
439 f->data = NULL;
440
441 return (0);
442}
443
444static int
445feed_eq_feed(struct pcm_feeder *f, struct pcm_channel *c, uint8_t *b,
446 uint32_t count, void *source)
447{
448 struct feed_eq_info *info;
449 uint32_t j;
450 uint8_t *dst;
451
452 info = f->data;
453
454 /*
455 * 3 major states:
456 * FEEDEQ_BYPASS - Bypass entirely, nothing happened.
457 * FEEDEQ_ENABLE - Preamp+biquad filtering.
458 * FEEDEQ_DISABLE - Preamp only.
459 */
460 if (info->state == FEEDEQ_BYPASS)
461 return (FEEDER_FEED(f->source, c, b, count, source));
462
463 dst = b;
464 count = SND_FXROUND(count, info->align);
465
466 do {
467 if (count < info->align)
468 break;
469
470 j = SND_FXDIV(FEEDER_FEED(f->source, c, dst, count, source),
471 info->align);
472 if (j == 0)
473 break;
474
475 info->biquad(info, dst, j);
476
477 j *= info->align;
478 dst += j;
479 count -= j;
480
481 } while (count != 0);
482
483 return (dst - b);
484}
485
487 { FEEDER_EQ, 0, 0, 0, 0 },
488 { 0, 0, 0, 0, 0 }
489};
490
491static kobj_method_t feeder_eq_methods[] = {
492 KOBJMETHOD(feeder_init, feed_eq_init),
493 KOBJMETHOD(feeder_free, feed_eq_free),
494 KOBJMETHOD(feeder_set, feed_eq_set),
495 KOBJMETHOD(feeder_feed, feed_eq_feed),
497};
498
499FEEDER_DECLARE(feeder_eq, NULL);
500
501static int32_t
503{
504 int r, i, f;
505 size_t len;
506 char buf[32];
507
508 bzero(buf, sizeof(buf));
509
510 /* XXX kind of ugly, but works for now.. */
511
512 r = sscanf(s, "%d.%d", &i, &f);
513
514 if (r == 1 && !(i < FEEDEQ_PREAMP_IMIN || i > FEEDEQ_PREAMP_IMAX)) {
515 snprintf(buf, sizeof(buf), "%c%d",
516 FEEDEQ_PREAMP_SIGNMARK(i), abs(i));
517 f = 0;
518 } else if (r == 2 &&
519 !(i < FEEDEQ_PREAMP_IMIN || i > FEEDEQ_PREAMP_IMAX ||
520 f < FEEDEQ_PREAMP_FMIN || f > FEEDEQ_PREAMP_FMAX))
521 snprintf(buf, sizeof(buf), "%c%d.%d",
522 FEEDEQ_PREAMP_SIGNMARK(i), abs(i), f);
523 else
524 return (FEEDEQ_PREAMP_INVALID);
525
526 len = strlen(s);
527 if (len > 2 && strcasecmp(s + len - 2, "dB") == 0)
528 strlcat(buf, "dB", sizeof(buf));
529
530 if (i == 0 && *s == '-')
531 *buf = '-';
532
533 if (strcasecmp(buf + ((*s >= '0' && *s <= '9') ? 1 : 0), s) != 0)
534 return (FEEDEQ_PREAMP_INVALID);
535
536 while ((f / FEEDEQ_GAIN_DIV) > 0)
537 f /= FEEDEQ_GAIN_DIV;
538
539 return (((i < 0 || *buf == '-') ? -1 : 1) * FEEDEQ_IF2PREAMP(i, f));
540}
541
542#ifdef _KERNEL
543static int
544sysctl_dev_pcm_eq(SYSCTL_HANDLER_ARGS)
545{
546 struct snddev_info *d;
547 struct pcm_channel *c;
548 struct pcm_feeder *f;
549 int err, val, oval;
550
551 d = oidp->oid_arg1;
552 if (!PCM_REGISTERED(d))
553 return (ENODEV);
554
555 PCM_LOCK(d);
556 PCM_WAIT(d);
557 if (d->flags & SD_F_EQ_BYPASSED)
558 val = 2;
559 else if (d->flags & SD_F_EQ_ENABLED)
560 val = 1;
561 else
562 val = 0;
563 PCM_ACQUIRE(d);
564 PCM_UNLOCK(d);
565
566 oval = val;
567 err = sysctl_handle_int(oidp, &val, 0, req);
568
569 if (err == 0 && req->newptr != NULL && val != oval) {
570 if (!(val == 0 || val == 1 || val == 2)) {
572 return (EINVAL);
573 }
574
575 PCM_LOCK(d);
576
578 if (val == 2) {
581 } else if (val == 1) {
584 } else
586
587 CHN_FOREACH(c, d, channels.pcm.busy) {
588 CHN_LOCK(c);
590 if (f != NULL)
591 (void)FEEDER_SET(f, FEEDEQ_STATE, val);
592 CHN_UNLOCK(c);
593 }
594
595 PCM_RELEASE(d);
596 PCM_UNLOCK(d);
597 } else
599
600 return (err);
601}
602
603static int
604sysctl_dev_pcm_eq_preamp(SYSCTL_HANDLER_ARGS)
605{
606 struct snddev_info *d;
607 struct pcm_channel *c;
608 struct pcm_feeder *f;
609 int err, val, oval;
610 char buf[32];
611
612 d = oidp->oid_arg1;
613 if (!PCM_REGISTERED(d))
614 return (ENODEV);
615
616 PCM_LOCK(d);
617 PCM_WAIT(d);
618 val = d->eqpreamp;
619 bzero(buf, sizeof(buf));
620 (void)snprintf(buf, sizeof(buf), "%c%d.%ddB",
623 PCM_ACQUIRE(d);
624 PCM_UNLOCK(d);
625
626 oval = val;
627 err = sysctl_handle_string(oidp, buf, sizeof(buf), req);
628
629 if (err == 0 && req->newptr != NULL) {
631 if (val == FEEDEQ_PREAMP_INVALID) {
633 return (EINVAL);
634 }
635
636 PCM_LOCK(d);
637
638 if (val != oval) {
641 else if (val > FEEDEQ_PREAMP_MAX)
643
644 d->eqpreamp = val;
645
646 CHN_FOREACH(c, d, channels.pcm.busy) {
647 CHN_LOCK(c);
649 if (f != NULL)
650 (void)FEEDER_SET(f, FEEDEQ_PREAMP, val);
651 CHN_UNLOCK(c);
652 }
653 }
654
655 PCM_RELEASE(d);
656 PCM_UNLOCK(d);
657 } else
659
660 return (err);
661}
662
663void
665{
666 struct snddev_info *d;
667 const char *preamp;
668 char buf[64];
669
670 d = device_get_softc(dev);
671
672 if (!(resource_string_value(device_get_name(dev), device_get_unit(dev),
673 "eq_preamp", &preamp) == 0 &&
674 (d->eqpreamp = feed_eq_scan_preamp_arg(preamp)) !=
677
680 else if (d->eqpreamp > FEEDEQ_PREAMP_MAX)
682
683 SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev),
684 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), OID_AUTO,
685 "eq", CTLTYPE_INT | CTLFLAG_RWTUN | CTLFLAG_MPSAFE, d,
686 sizeof(d), sysctl_dev_pcm_eq, "I",
687 "Bass/Treble Equalizer (0=disable, 1=enable, 2=bypass)");
688
689 (void)snprintf(buf, sizeof(buf), "Bass/Treble Equalizer Preamp "
690 "(-/+ %d.0dB , %d.%ddB step)",
691 FEEDEQ_GAIN_MAX, FEEDEQ_GAIN_STEP / FEEDEQ_GAIN_DIV,
692 FEEDEQ_GAIN_STEP - ((FEEDEQ_GAIN_STEP / FEEDEQ_GAIN_DIV) *
693 FEEDEQ_GAIN_DIV));
694
695 SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev),
696 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), OID_AUTO,
697 "eq_preamp", CTLTYPE_STRING | CTLFLAG_RWTUN | CTLFLAG_MPSAFE,
698 d, sizeof(d), sysctl_dev_pcm_eq_preamp, "A", buf);
699}
700#endif
uint32_t rate
Definition: audio_dai_if.m:58
#define CHN_UNLOCK(c)
Definition: channel.h:322
#define CHN_LOCK(c)
Definition: channel.h:321
#define CHN_FOREACH(x, y, z)
Definition: channel.h:181
struct pcm_channel * c
Definition: channel_if.m:106
METHOD int free
Definition: channel_if.m:110
struct snd_dbuf * b
Definition: channel_if.m:105
uint32_t spd
Definition: dsp.c:394
uint16_t len
struct pcm_feeder * chn_findfeeder(struct pcm_channel *c, u_int32_t type)
Definition: feeder.c:270
@ FEEDEQ_RATE
Definition: feeder.h:126
@ FEEDEQ_BYPASS
Definition: feeder.h:133
@ FEEDEQ_BASS
Definition: feeder.h:128
@ FEEDEQ_CHANNELS
Definition: feeder.h:125
@ FEEDEQ_DISABLE
Definition: feeder.h:131
@ FEEDEQ_UNKNOWN
Definition: feeder.h:134
@ 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_EQ
Definition: feeder.h:86
#define FEEDEQ_PREAMP_IMAX
Definition: feeder_eq.c:67
#define FEEDEQ_ENTRY(SIGN, BIT, ENDIAN)
Definition: feeder_eq.c:237
static int sysctl_dev_pcm_eq_preamp(SYSCTL_HANDLER_ARGS)
Definition: feeder_eq.c:604
static struct feed_eq_coeff * feed_eq_coeff_rate(uint32_t rate)
Definition: feeder_eq.c:273
FEEDER_DECLARE(feeder_eq, NULL)
#define FEEDEQ_IF2PREAMP(i, f)
Definition: feeder_eq.c:73
static int feeder_eq_exact_rate
Definition: feeder_eq.c:95
static struct pcm_feederdesc feeder_eq_desc[]
Definition: feeder_eq.c:486
static char feeder_eq_presets[]
Definition: feeder_eq.c:98
void feeder_eq_initsys(device_t dev)
Definition: feeder_eq.c:664
#define FEEDEQ_PREAMP_INVALID
Definition: feeder_eq.c:71
#define FEEDEQ_PREAMP_FPART(x)
Definition: feeder_eq.c:62
int feeder_eq_validrate(uint32_t rate)
Definition: feeder_eq.c:299
static int32_t feed_eq_scan_preamp_arg(const char *s)
Definition: feeder_eq.c:502
uint32_t format
Definition: feeder_eq.c:244
static const struct @42 feed_eq_biquad_tab[]
static int feed_eq_set(struct pcm_feeder *f, int what, int value)
Definition: feeder_eq.c:379
#define FEEDEQ_PREAMP_FMAX
Definition: feeder_eq.c:69
SND_DECLARE_FILE("$FreeBSD$")
#define FEEDEQ_PREAMP2IDX(v)
Definition: feeder_eq.c:88
#define FEEDEQ_PREAMP_MIN
Definition: feeder_eq.c:78
static int feed_eq_init(struct pcm_feeder *f)
Definition: feeder_eq.c:339
static int feed_eq_setup(struct feed_eq_info *info)
Definition: feeder_eq.c:326
SYSCTL_STRING(_hw_snd, OID_AUTO, feeder_eq_presets, CTLFLAG_RD, &feeder_eq_presets, 0, "compile-time eq presets")
void(* feed_eq_t)(struct feed_eq_info *, uint8_t *, uint32_t)
Definition: feeder_eq.c:108
SYSCTL_INT(_hw_snd, OID_AUTO, feeder_eq_exact_rate, CTLFLAG_RWTUN, &feeder_eq_exact_rate, 0, "force exact rate validation")
static int feed_eq_feed(struct pcm_feeder *f, struct pcm_channel *c, uint8_t *b, uint32_t count, void *source)
Definition: feeder_eq.c:445
static void feed_eq_reset(struct feed_eq_info *info)
Definition: feeder_eq.c:309
#define FEEDEQ_BIQUAD_TAB_SIZE
Definition: feeder_eq.c:269
static kobj_method_t feeder_eq_methods[]
Definition: feeder_eq.c:491
#define FEEDEQ_L2GAIN(v)
Definition: feeder_eq.c:58
feed_eq_t biquad
Definition: feeder_eq.c:245
#define FEEDEQ_PREAMP_DEFAULT
Definition: feeder_eq.c:86
#define FEEDEQ_PREAMP_MAX
Definition: feeder_eq.c:82
static int feed_eq_free(struct pcm_feeder *f)
Definition: feeder_eq.c:431
#define FEEDEQ_DECLARE(SIGN, BIT, ENDIAN)
Definition: feeder_eq.c:144
#define FEEDEQ_PREAMP_IPART(x)
Definition: feeder_eq.c:61
static int sysctl_dev_pcm_eq(SYSCTL_HANDLER_ARGS)
Definition: feeder_eq.c:544
#define FEEDEQ_PREAMP_SIGNMARK(x)
Definition: feeder_eq.c:64
u_int32_t count
Definition: feeder_if.m:86
void * source
Definition: feeder_if.m:87
int what
Definition: feeder_if.m:73
uint32_t value
Definition: hdaa.c:58
bus_addr_t buf
Definition: hdac_if.m:63
uint8_t r
#define SND_CHN_MAX
Definition: matrix.h:183
#define KOBJMETHOD_END
Definition: midi.c:76
unsigned dev
Definition: mixer_if.m:59
u_int32_t val
int32_t intpcm_t
Definition: pcm.h:54
#define AFMT_ENCODING(v)
Definition: sound.h:222
#define SD_F_EQ_ENABLED
Definition: sound.h:143
#define PCM_RELEASE_QUICK(x)
Definition: sound.h:573
#define PCM_RELEASE(x)
Definition: sound.h:554
#define AFMT_BPS(v)
Definition: sound.h:235
#define PCM_ACQUIRE(x)
Definition: sound.h:546
#define PCM_WAIT(x)
Definition: sound.h:540
#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 PCM_REGISTERED(x)
Definition: sound.h:178
struct feed_eq_tone treble
Definition: feeder_eq.c:119
uint32_t align
Definition: feeder_eq.c:125
struct feed_eq_tone bass
Definition: feeder_eq.c:120
uint32_t channels
Definition: feeder_eq.c:123
feed_eq_t biquad
Definition: feeder_eq.c:122
uint32_t rate
Definition: feeder_eq.c:124
struct feed_eq_coeff * coeff
Definition: feeder_eq.c:121
int32_t preamp
Definition: feeder_eq.c:126
intpcm_t i2[SND_CHN_MAX]
Definition: feeder_eq.c:114
intpcm_t o1[SND_CHN_MAX]
Definition: feeder_eq.c:111
intpcm_t i1[SND_CHN_MAX]
Definition: feeder_eq.c:113
intpcm_t o2[SND_CHN_MAX]
Definition: feeder_eq.c:112
struct pcm_feeder * source
Definition: feeder.h:51
void * data
Definition: feeder.h:49
struct pcm_feederdesc * desc
Definition: feeder.h:48
u_int32_t out
Definition: feeder.h:34
u_int32_t in
Definition: feeder.h:34
struct snddev_info::@49::@50::@51 busy
unsigned flags
Definition: sound.h:396
struct snddev_info::@49::@50 pcm
int32_t eqpreamp
Definition: sound.h:406
const void * req