xref: /freebsd/sys/dev/sound/pcm/matrix.h (revision fed1ca4b719c56c930f2259d80663cd34be812bb)
1 /*-
2  * Copyright (c) 2007-2009 Ariff Abdullah <ariff@FreeBSD.org>
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
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.
13  *
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
24  * SUCH DAMAGE.
25  *
26  * $FreeBSD$
27  */
28 
29 #ifndef _SND_MATRIX_H_
30 #define _SND_MATRIX_H_
31 
32 #undef SND_MULTICHANNEL
33 #ifndef SND_OLDSTEREO
34 #define SND_MULTICHANNEL	1
35 #endif
36 
37 /*
38  * XXX = unused, but part of the definition (will be used someday, maybe).
39  */
40 #define SND_CHN_T_FL		0	/* Front Left         */
41 #define SND_CHN_T_FR		1	/* Front Right        */
42 #define SND_CHN_T_FC		2	/* Front Center       */
43 #define SND_CHN_T_LF		3	/* Low Frequency      */
44 #define SND_CHN_T_BL		4	/* Back Left          */
45 #define SND_CHN_T_BR		5	/* Back Right         */
46 #define SND_CHN_T_FLC		6	/* Front Left Center  XXX */
47 #define SND_CHN_T_FRC		7	/* Front Right Center XXX */
48 #define SND_CHN_T_BC		8	/* Back Center        */
49 #define SND_CHN_T_SL		9	/* Side Left          */
50 #define SND_CHN_T_SR		10	/* Side Right         */
51 #define SND_CHN_T_TC		11	/* Top Center         XXX */
52 #define SND_CHN_T_TFL		12	/* Top Front Left     XXX */
53 #define SND_CHN_T_TFC		13	/* Top Front Center   XXX */
54 #define SND_CHN_T_TFR		14	/* Top Front Right    XXX */
55 #define SND_CHN_T_TBL		15	/* Top Back Left      XXX */
56 #define SND_CHN_T_TBC		16	/* Top Back Center    XXX */
57 #define SND_CHN_T_TBR		17	/* Top Back Right     XXX */
58 #define SND_CHN_T_MAX		18	/* Maximum channels   */
59 
60 #define SND_CHN_T_ZERO		(SND_CHN_T_MAX + 1)	/* Zero samples */
61 
62 #define SND_CHN_T_LABELS	{					\
63 	 "fl",  "fr",  "fc",  "lf",  "bl",  "br",			\
64 	"flc", "frc",  "bc",  "sl",  "sr",  "tc",			\
65 	"tfl", "tfc", "tfr", "tbl", "tbc", "tbr"			\
66 }
67 
68 #define SND_CHN_T_NAMES	{						\
69 	"Front Left", "Front Right", "Front Center",			\
70 	"Low Frequency Effects",					\
71 	"Back Left", "Back Right",					\
72 	"Front Left Center", "Front Right Center",			\
73 	"Back Center",							\
74 	"Side Left", "Side Right",					\
75 	"Top Center",							\
76 	"Top Front Left", "Top Front Center", "Top Front Right",	\
77 	"Top Back Left", "Top Back Center", "Top Back Right"		\
78 }
79 
80 #define SND_CHN_T_MASK_FL	(1 << SND_CHN_T_FL)
81 #define SND_CHN_T_MASK_FR	(1 << SND_CHN_T_FR)
82 #define SND_CHN_T_MASK_FC	(1 << SND_CHN_T_FC)
83 #define SND_CHN_T_MASK_LF	(1 << SND_CHN_T_LF)
84 #define SND_CHN_T_MASK_BL	(1 << SND_CHN_T_BL)
85 #define SND_CHN_T_MASK_BR	(1 << SND_CHN_T_BR)
86 #define SND_CHN_T_MASK_FLC	(1 << SND_CHN_T_FLC)
87 #define SND_CHN_T_MASK_FRC	(1 << SND_CHN_T_FRC)
88 #define SND_CHN_T_MASK_BC	(1 << SND_CHN_T_BC)
89 #define SND_CHN_T_MASK_SL	(1 << SND_CHN_T_SL)
90 #define SND_CHN_T_MASK_SR	(1 << SND_CHN_T_SR)
91 #define SND_CHN_T_MASK_TC	(1 << SND_CHN_T_TC)
92 #define SND_CHN_T_MASK_TFL	(1 << SND_CHN_T_TFL)
93 #define SND_CHN_T_MASK_TFC	(1 << SND_CHN_T_TFC)
94 #define SND_CHN_T_MASK_TFR	(1 << SND_CHN_T_TFR)
95 #define SND_CHN_T_MASK_TBL	(1 << SND_CHN_T_TBL)
96 #define SND_CHN_T_MASK_TBC	(1 << SND_CHN_T_TBC)
97 #define SND_CHN_T_MASK_TBR	(1 << SND_CHN_T_TBR)
98 
99 #define SND_CHN_LEFT_MASK	(SND_CHN_T_MASK_FL  |			\
100 				 SND_CHN_T_MASK_BL  |			\
101 				 SND_CHN_T_MASK_FLC |			\
102 				 SND_CHN_T_MASK_SL  |			\
103 				 SND_CHN_T_MASK_TFL |			\
104 				 SND_CHN_T_MASK_TBL)
105 
106 #define SND_CHN_RIGHT_MASK	(SND_CHN_T_MASK_FR  |			\
107 				 SND_CHN_T_MASK_BR  |			\
108 				 SND_CHN_T_MASK_FRC |			\
109 				 SND_CHN_T_MASK_SR  |			\
110 				 SND_CHN_T_MASK_TFR |			\
111 				 SND_CHN_T_MASK_TBR)
112 
113 #define SND_CHN_CENTER_MASK	(SND_CHN_T_MASK_FC  |			\
114 				 SND_CHN_T_MASK_BC  |			\
115 				 SND_CHN_T_MASK_TC  |			\
116 				 SND_CHN_T_MASK_TFC |			\
117 				 SND_CHN_T_MASK_TBC |			\
118 				 SND_CHN_T_MASK_LF)	/* XXX what?!? */
119 
120 /*
121  * Matrix identity.
122  */
123 
124 /* 1 @ Mono 1.0 */
125 #define SND_CHN_MATRIX_1_0	0
126 #define SND_CHN_MATRIX_1	SND_CHN_MATRIX_1_0
127 
128 /* 2 @ Stereo 2.0 */
129 #define SND_CHN_MATRIX_2_0	1
130 #define SND_CHN_MATRIX_2	SND_CHN_MATRIX_2_0
131 
132 /* 3 @ 2.1 (lfe), 3.0 (rear center, DEFAULT) */
133 #define SND_CHN_MATRIX_2_1	2
134 #define SND_CHN_MATRIX_3_0	3
135 #define SND_CHN_MATRIX_3	SND_CHN_MATRIX_3_0
136 
137 /* 4 @ 3.1 (lfe), 4.0 (Quadraphonic, DEFAULT) */
138 #define SND_CHN_MATRIX_3_1	4
139 #define SND_CHN_MATRIX_4_0	5
140 #define SND_CHN_MATRIX_4	SND_CHN_MATRIX_4_0
141 
142 /* 5 @ 4.1 (lfe), 5.0 (center, DEFAULT) */
143 #define SND_CHN_MATRIX_4_1	6
144 #define SND_CHN_MATRIX_5_0	7
145 #define SND_CHN_MATRIX_5	SND_CHN_MATRIX_5_0
146 
147 /* 6 @ 5.1 (lfe, DEFAULT), 6.0 (rear center) */
148 #define SND_CHN_MATRIX_5_1	8
149 #define SND_CHN_MATRIX_6_0	9
150 #define SND_CHN_MATRIX_6	SND_CHN_MATRIX_5_1
151 
152 /* 7 @ 6.1 (lfe, DEFAULT), 7.0 */
153 #define SND_CHN_MATRIX_6_1	10
154 #define SND_CHN_MATRIX_7_0	11
155 #define SND_CHN_MATRIX_7	SND_CHN_MATRIX_6_1
156 
157 /* 8 @ 7.1 (lfe) */
158 #define SND_CHN_MATRIX_7_1	12
159 #define SND_CHN_MATRIX_8	SND_CHN_MATRIX_7_1
160 
161 #define SND_CHN_MATRIX_MAX	13
162 
163 #define SND_CHN_MATRIX_BEGIN	SND_CHN_MATRIX_1_0
164 #define SND_CHN_MATRIX_END	SND_CHN_MATRIX_7_1
165 
166 /* Custom matrix identity */
167 #define SND_CHN_MATRIX_DRV		-4	/* driver own identity   */
168 #define SND_CHN_MATRIX_PCMCHANNEL	-3	/* PCM channel identity  */
169 #define SND_CHN_MATRIX_MISC		-2	/* misc, custom defined  */
170 #define SND_CHN_MATRIX_UNKNOWN		-1	/* unknown               */
171 
172 #define SND_CHN_T_VOL_0DB	SND_CHN_T_MAX
173 #define SND_CHN_T_VOL_MAX	(SND_CHN_T_VOL_0DB + 1)
174 
175 #define SND_CHN_T_BEGIN		SND_CHN_T_FL
176 #define SND_CHN_T_END		SND_CHN_T_TBR
177 #define SND_CHN_T_STEP		1
178 #define SND_CHN_MIN		1
179 
180 #ifdef SND_MULTICHANNEL
181 #define SND_CHN_MAX		8
182 #else
183 #define SND_CHN_MAX		2
184 #endif
185 
186 /*
187  * Multichannel interleaved volume matrix. Each calculated value relative
188  * to master and 0db will be stored in each CLASS + 1 as long as
189  * chn_setvolume_matrix() or the equivalent CHN_SETVOLUME() macros is
190  * used (see channel.c).
191  */
192 #define SND_VOL_C_MASTER	0
193 #define SND_VOL_C_PCM		1
194 #define SND_VOL_C_PCM_VAL	2
195 #define SND_VOL_C_MAX		3
196 
197 #define SND_VOL_C_BEGIN		SND_VOL_C_PCM
198 #define SND_VOL_C_END		SND_VOL_C_PCM
199 #define SND_VOL_C_STEP		2
200 
201 #define SND_VOL_C_VAL(x)	((x) + 1)
202 
203 #define SND_VOL_0DB_MIN		1
204 #define SND_VOL_0DB_MAX		100
205 
206 #define SND_VOL_0DB_MASTER	100
207 #define SND_VOL_0DB_PCM		45
208 
209 #define SND_VOL_RESOLUTION	8
210 #define SND_VOL_FLAT		(1 << SND_VOL_RESOLUTION)
211 
212 #define SND_VOL_CALC_SAMPLE(x, y)	(((x) * (y)) >> SND_VOL_RESOLUTION)
213 
214 #define SND_VOL_CALC_VAL(x, y, z)					\
215 			(((((x)[y][z] << SND_VOL_RESOLUTION) /		\
216 			 (x)[y][SND_CHN_T_VOL_0DB]) *			\
217 			 (x)[SND_VOL_C_MASTER][z]) /			\
218 			 (x)[SND_VOL_C_MASTER][SND_CHN_T_VOL_0DB])	\
219 
220 #endif	/* !_SND_MATRIX_H_ */
221