xref: /haiku/src/add-ons/kernel/drivers/audio/echo/generic/CChannelMask.h (revision 51978af14a173e7fae0563b562be5603bc652aeb)
1 // ****************************************************************************
2 //
3 //		CChannelMask.h
4 //
5 //		Include file for interfacing with the CChannelMask and CChMaskDsp
6 //		classes.
7 //		Set editor tabs to 3 for your viewing pleasure.
8 //
9 // 	CChannelMask is a handy way to specify a group of pipes simultaneously.
10 //		It should really be called "CPipeMask", but the class name predates
11 //		the term "pipe".
12 //
13 //		CChMaskDsp is used in the comm page to specify a group of channels
14 //		at once; these are read by the DSP and must therefore be kept
15 //		in little-endian format.
16 //
17 //---------------------------------------------------------------------------
18 //
19 //		Copyright Echo Digital Audio Corporation (c) 1998 - 2002
20 //		All rights reserved
21 //		www.echoaudio.com
22 //
23 //		Permission is hereby granted, free of charge, to any person obtaining a
24 //		copy of this software and associated documentation files (the
25 //		"Software"), to deal with the Software without restriction, including
26 //		without limitation the rights to use, copy, modify, merge, publish,
27 //		distribute, sublicense, and/or sell copies of the Software, and to
28 //		permit persons to whom the Software is furnished to do so, subject to
29 //		the following conditions:
30 //
31 //		- Redistributions of source code must retain the above copyright
32 //		notice, this list of conditions and the following disclaimers.
33 //
34 //		- Redistributions in binary form must reproduce the above copyright
35 //		notice, this list of conditions and the following disclaimers in the
36 //		documentation and/or other materials provided with the distribution.
37 //
38 //		- Neither the name of Echo Digital Audio, nor the names of its
39 //		contributors may be used to endorse or promote products derived from
40 //		this Software without specific prior written permission.
41 //
42 //		THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
43 //		EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
44 //		MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
45 //		IN NO EVENT SHALL THE CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR
46 //		ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
47 //		TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
48 //		SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE SOFTWARE.
49 //
50 // ****************************************************************************
51 
52 //	Prevent problems with multiple includes
53 #ifndef _CHMASKOBJECT_
54 #define _CHMASKOBJECT_
55 
56 //
57 //	Defines
58 //
59 typedef unsigned long	CH_MASK;
60 
61 #define	CH_MASK_SZ		(2)				// Max channel mask array size
62 #define	CH_MASK_BITS	(sizeof( CH_MASK ) * 8)
63 													// Max bits per mask entry
64 
65 #define	ECHO_INVALID_CHANNEL	((WORD)(-1))
66 													// Marks unused channel #
67 
68 typedef unsigned short		CH_MASK_DSP;
69 #define	CH_MASK_DSP_BITS	(sizeof( CH_MASK_DSP ) * 8)
70 													// Max bits per mask entry
71 
72 /****************************************************************************
73 
74 	CChannelMask
75 
76  ****************************************************************************/
77 
78 class CChannelMask
79 {
80 protected:
81 
82 #ifdef ECHO_OS9
83 	friend class CInOutChannelMask;
84 #endif
85 
86 	CH_MASK	m_MaskRegs[ CH_MASK_SZ ];	// One bit per output or input channel
87 
88 public:
89 
90 	CChannelMask();
91 	~CChannelMask() {}
92 
93 	// Returns TRUE if no bits set
94 	BOOL IsEmpty();
95 
96 	// Set the wPipeIndex bit in the mask
97 	void SetIndexInMask( WORD wPipeIndex );
98 
99 	// Clear the wPipeIndex bit in the mask
100 	void ClearIndexInMask( WORD wPipeIndex );
101 
102 	// Return the next bit set starting with wStartPipeIndex as an index.
103 	//	If nothing set, returns ECHO_INVALID_CHANNEL.
104 	//	Use this interface for enumerating thru a channel mask.
105 	WORD GetIndexFromMask( WORD wStartPipeIndex );
106 
107 	// Test driver channel index in mask.
108 	//	Return TRUE if set
109 	BOOL TestIndexInMask( WORD wPipeIndex );
110 
111 	// Clear all bits in the mask
112 	void Clear();
113 
114 	// Clear bits in this mask that are in SrcMask
115 	void ClearMask( CChannelMask SrcMask );
116 
117 	//	Return TRUE if any bits in source mask are set in this mask
118 	BOOL Test( CChannelMask * pSrcMask );
119 
120 	//
121 	//	Return TRUE if the Test Mask contains all of the channels
122 	//	enabled in this instance.
123 	//	Use to be sure all channels in this instance exist in
124 	//	another instance.
125 	//
126 	BOOL IsSubsetOf( CChannelMask& TstMask );
127 
128 	//
129 	//	Return TRUE if the Test Mask contains at least one of the channels
130 	//	enabled in this instance.
131 	//	Use to find out if any channels in this instance exist in
132 	//	another instance.
133 	//
134 	BOOL IsIntersectionOf( CChannelMask& TstMask );
135 
136 	//
137 	//	Overload new & delete so memory for this object is allocated
138 	//	from non-paged memory.
139 	//
140 	PVOID operator new( size_t Size );
141 	VOID  operator delete( PVOID pVoid );
142 
143 	//
144 	//	Macintosh compiler likes "class" after friend, PC doesn't care
145 	//
146 	friend class CChMaskDsp;
147 
148 	inline CH_MASK operator []  ( int iNdx )
149 		{ return SWAP( m_MaskRegs[ iNdx ] ); }
150 
151 	//	Return TRUE if source mask equals this mask
152 	friend BOOLEAN operator == ( CONST CChannelMask &LVal,
153 										  CONST CChannelMask &RVal );
154 
155 	// Copy mask bits in source to this mask
156 	CChannelMask& operator = (CONST CChannelMask & RVal);
157 
158 	// Copy mask bits in source to this mask
159 	CChannelMask& operator = (CONST CChMaskDsp & RVal);
160 
161 	// Add mask bits in source to this mask
162 	VOID operator += (CONST CChannelMask & RVal);
163 
164 	// Subtract mask bits in source to this mask
165 	VOID operator -= (CONST CChannelMask & RVal);
166 
167 	// AND mask bits in source to this mask
168 	VOID operator &= (CONST CChannelMask & RVal);
169 
170 	// OR mask bits in source to this mask
171 	VOID operator |= (CONST CChannelMask & RVal);
172 
173 protected :
174 
175 	//
176 	//	Store an output bit mask and an input bitmask.
177 	//	We assume here that the # of outputs fits in one mask reg
178 	//
179 	void SetMask( CH_MASK OutMask, CH_MASK InMask, int nOutputs );
180 	void SetOutMask( CH_MASK OutMask, int nOutputs );
181 	void SetInMask( CH_MASK InMask, int nOutputs );
182 
183 	//
184 	//	Retrieve an output bit mask and an input bitmask.
185 	//	We assume here that the # of outputs fits in one mask reg
186 	//
187 	void GetMask( CH_MASK & OutMask, CH_MASK & InMask, int nOutputs );
188 	CH_MASK GetOutMask( int nOutputs );
189 	CH_MASK GetInMask( int nOutputs );
190 
191 };	// class CChannelMask
192 
193 typedef	CChannelMask *		PCChannelMask;
194 
195 
196 /****************************************************************************
197 
198 	CChMaskDsp
199 
200  ****************************************************************************/
201 
202 class CChMaskDsp
203 {
204 protected:
205 
206 	CH_MASK_DSP	m_MaskRegs[ CH_MASK_SZ ];	// One bit per output or input channel
207 
208 public:
209 
210 	CChMaskDsp();
211 	~CChMaskDsp() {}
212 
213 	// Returns TRUE if no bits set
214 	BOOL IsEmpty();
215 
216 	// Set the wPipeIndex bit in the mask
217 	void SetIndexInMask( WORD wPipeIndex );
218 
219 	// Clear the wPipeIndex bit in the mask
220 	void ClearIndexInMask( WORD wPipeIndex );
221 
222 	// Test pipe index in mask.
223 	//	Return TRUE if set
224 	BOOL TestIndexInMask( WORD wPipeIndex );
225 
226 	// Clear all bits in the mask
227 	void Clear();
228 
229 	//
230 	//	Overload new & delete so memory for this object is allocated
231 	//	from non-paged memory.
232 	//
233 	PVOID operator new( size_t Size );
234 	VOID  operator delete( PVOID pVoid );
235 
236 	//
237 	//	Macintosh compiler likes "class" after friend, PC doesn't care
238 	//
239 	friend class CChannelMask;
240 
241 	inline CH_MASK_DSP operator []  ( int iNdx )
242 		{ return SWAP( m_MaskRegs[ iNdx ] ); }
243 
244 	// Copy mask bits in source to this mask
245 	CChMaskDsp& operator = (CONST CChannelMask & RVal);
246 
247 	// Add mask bits in source to this mask
248 	VOID operator += (CONST CChannelMask & RVal);
249 
250 	// Subtract mask bits in source to this mask
251 	VOID operator -= (CONST CChannelMask & RVal);
252 
253 protected :
254 
255 };	// class CChMaskDsp
256 
257 typedef	CChMaskDsp *		PCChMaskDsp;
258 
259 #endif // _CHMASKOBJECT_
260 
261 //	CChannelMask.h
262