xref: /freebsd/sys/dev/sound/pcm/feeder.h (revision f4819a1b6c441f804d66d710678bf5558ee29eee)
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause
3  *
4  * Copyright (c) 2005-2009 Ariff Abdullah <ariff@FreeBSD.org>
5  * Copyright (c) 1999 Cameron Grant <cg@FreeBSD.org>
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  */
29 
30 enum feeder_type {
31 	FEEDER_ROOT,
32 	FEEDER_FORMAT,
33 	FEEDER_MIXER,
34 	FEEDER_RATE,
35 	FEEDER_EQ,
36 	FEEDER_VOLUME,
37 	FEEDER_MATRIX,
38 	FEEDER_LAST,
39 };
40 
41 struct pcm_feederdesc {
42 	u_int32_t in, out;
43 };
44 
45 struct feeder_class {
46 	KOBJ_CLASS_FIELDS;
47 	enum feeder_type type;
48 	SLIST_ENTRY(feeder_class) link;
49 };
50 
51 struct pcm_feeder {
52     	KOBJ_FIELDS;
53 	int align;
54 	struct pcm_feederdesc *desc, desc_static;
55 	void *data;
56 	struct feeder_class *class;
57 	struct pcm_feeder *source, *parent;
58 
59 };
60 
61 void feeder_register(void *p);
62 struct feeder_class *feeder_getclass(u_int32_t type);
63 
64 u_int32_t snd_fmtscore(u_int32_t fmt);
65 u_int32_t snd_fmtbestbit(u_int32_t fmt, u_int32_t *fmts);
66 u_int32_t snd_fmtbestchannel(u_int32_t fmt, u_int32_t *fmts);
67 u_int32_t snd_fmtbest(u_int32_t fmt, u_int32_t *fmts);
68 
69 int feeder_add(struct pcm_channel *c, struct feeder_class *fc,
70     struct pcm_feederdesc *desc);
71 void feeder_remove(struct pcm_channel *c);
72 struct pcm_feeder *feeder_find(struct pcm_channel *c, u_int32_t type);
73 int feeder_chain(struct pcm_channel *);
74 
75 #define FEEDER_DECLARE(feeder, ctype)					\
76 static struct feeder_class feeder ## _class = {				\
77 	.name =		#feeder,					\
78 	.methods =	feeder ## _methods,				\
79 	.size =		sizeof(struct pcm_feeder),			\
80 	.type =		ctype,						\
81 };									\
82 SYSINIT(feeder, SI_SUB_DRIVERS, SI_ORDER_ANY, feeder_register,		\
83     &feeder ## _class)
84 
85 /* feeder_format */
86 enum {
87 	FEEDFORMAT_CHANNELS
88 };
89 
90 /* feeder_mixer */
91 enum {
92 	FEEDMIXER_CHANNELS
93 };
94 
95 /* feeder_rate */
96 enum {
97 	FEEDRATE_SRC,
98 	FEEDRATE_DST,
99 	FEEDRATE_QUALITY,
100 	FEEDRATE_CHANNELS
101 };
102 
103 #define FEEDRATE_RATEMIN	1
104 #define FEEDRATE_RATEMAX	2016000		/* 48000 * 42 */
105 #define FEEDRATE_MIN		1
106 #define FEEDRATE_MAX		0x7fffff	/* sign 24bit ~ 8ghz ! */
107 #define FEEDRATE_ROUNDHZ	25
108 #define FEEDRATE_ROUNDHZ_MIN	0
109 #define FEEDRATE_ROUNDHZ_MAX	500
110 
111 extern int feeder_rate_min;
112 extern int feeder_rate_max;
113 extern int feeder_rate_round;
114 extern int feeder_rate_quality;
115 
116 /* feeder_eq */
117 enum {
118 	FEEDEQ_CHANNELS,
119 	FEEDEQ_RATE,
120 	FEEDEQ_TREBLE,
121 	FEEDEQ_BASS,
122 	FEEDEQ_PREAMP,
123 	FEEDEQ_STATE,
124 	FEEDEQ_DISABLE,
125 	FEEDEQ_ENABLE,
126 	FEEDEQ_BYPASS,
127 	FEEDEQ_UNKNOWN
128 };
129 
130 int feeder_eq_validrate(uint32_t);
131 void feeder_eq_initsys(device_t);
132 
133 /* feeder_volume */
134 enum {
135 	FEEDVOLUME_CLASS,
136 	FEEDVOLUME_CHANNELS,
137 	FEEDVOLUME_STATE,
138 	FEEDVOLUME_ENABLE,
139 	FEEDVOLUME_BYPASS
140 };
141 
142 int feeder_volume_apply_matrix(struct pcm_feeder *, struct pcmchan_matrix *);
143 
144 /* feeder_matrix */
145 int feeder_matrix_default_id(uint32_t);
146 struct pcmchan_matrix *feeder_matrix_default_channel_map(uint32_t);
147 
148 uint32_t feeder_matrix_default_format(uint32_t);
149 
150 int feeder_matrix_format_id(uint32_t);
151 struct pcmchan_matrix *feeder_matrix_format_map(uint32_t);
152 
153 struct pcmchan_matrix *feeder_matrix_id_map(int);
154 
155 int feeder_matrix_setup(struct pcm_feeder *, struct pcmchan_matrix *,
156     struct pcmchan_matrix *);
157 int feeder_matrix_compare(struct pcmchan_matrix *, struct pcmchan_matrix *);
158 
159 /* 4Front OSS stuffs */
160 int feeder_matrix_oss_get_channel_order(struct pcmchan_matrix *,
161     unsigned long long *);
162 int feeder_matrix_oss_set_channel_order(struct pcmchan_matrix *,
163     unsigned long long *);
164 
165 /*
166  * By default, various feeders only deal with sign 16/32 bit native-endian
167  * since it should provide the fastest processing path. Processing 8bit samples
168  * is too noisy due to limited dynamic range, while 24bit is quite slow due to
169  * unnatural per-byte read/write. However, for debugging purposes, ensuring
170  * implementation correctness and torture test, the following can be defined:
171  *
172  *      SND_FEEDER_MULTIFORMAT - Compile all type of converters, but force
173  *                               8bit samples to be converted to 16bit
174  *                               native-endian for better dynamic range.
175  *                               Process 24bit samples natively.
176  * SND_FEEDER_FULL_MULTIFORMAT - Ditto, but process 8bit samples natively.
177  */
178 #ifdef SND_FEEDER_FULL_MULTIFORMAT
179 #undef SND_FEEDER_MULTIFORMAT
180 #define SND_FEEDER_MULTIFORMAT	1
181 #endif
182