xref: /haiku/src/add-ons/kernel/drivers/audio/echo/generic/CChannelMask.h (revision 24159a0c7d6d6dcba9f2a0c1a7c08d2c8167f21b)
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 // ----------------------------------------------------------------------------
20 //
21 // This file is part of Echo Digital Audio's generic driver library.
22 // Copyright Echo Digital Audio Corporation (c) 1998 - 2005
23 // All rights reserved
24 // www.echoaudio.com
25 //
26 // This library is free software; you can redistribute it and/or
27 // modify it under the terms of the GNU Lesser General Public
28 // License as published by the Free Software Foundation; either
29 // version 2.1 of the License, or (at your option) any later version.
30 //
31 // This library is distributed in the hope that it will be useful,
32 // but WITHOUT ANY WARRANTY; without even the implied warranty of
33 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
34 // Lesser General Public License for more details.
35 //
36 // You should have received a copy of the GNU Lesser General Public
37 // License along with this library; if not, write to the Free Software
38 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
39 //
40 // ****************************************************************************
41 
42 //	Prevent problems with multiple includes
43 #ifndef _CHMASKOBJECT_
44 #define _CHMASKOBJECT_
45 
46 //
47 //	Defines
48 //
49 typedef unsigned long	CH_MASK;
50 
51 #define	CH_MASK_BITS	(sizeof( CH_MASK ) * 8)
52 													// Max bits per mask entry
53 
54 #define	ECHO_INVALID_CHANNEL	((WORD)(-1))
55 													// Marks unused channel #
56 
57 typedef unsigned short		CH_MASK_DSP;
58 #define	CH_MASK_DSP_BITS	(sizeof( CH_MASK_DSP ) * 8)
59 													// Max bits per mask entry
60 
61 /****************************************************************************
62 
63 	CChannelMask
64 
65  ****************************************************************************/
66 
67 class CChannelMask
68 {
69 protected:
70 
71 #ifdef ECHO_OS9
72 	friend class CInOutChannelMask;
73 #endif
74 
75 	CH_MASK	m_Mask;						// One bit per output or input channel
76 
77 public:
78 
79 	CChannelMask();
80 	~CChannelMask() {}
81 
82 	// Returns TRUE if no bits set
83 	BOOL IsEmpty();
84 
85 	// Set the wPipeIndex bit in the mask
86 	void SetIndexInMask( WORD wPipeIndex );
87 
88 	// Clear the wPipeIndex bit in the mask
89 	void ClearIndexInMask( WORD wPipeIndex );
90 
91 	// Return the next bit set starting with wStartPipeIndex as an index.
92 	//	If nothing set, returns ECHO_INVALID_CHANNEL.
93 	//	Use this interface for enumerating thru a channel mask.
94 	WORD GetIndexFromMask( WORD wStartPipeIndex );
95 
96 	// Test driver channel index in mask.
97 	//	Return TRUE if set
98 	BOOL TestIndexInMask( WORD wPipeIndex );
99 
100 	// Clear all bits in the mask
101 	void Clear();
102 
103 	// Clear bits in this mask that are in SrcMask
104 	void ClearMask( CChannelMask SrcMask );
105 
106 	//	Return TRUE if any bits in source mask are set in this mask
107 	BOOL Test( CChannelMask * pSrcMask );
108 
109 	//
110 	//	Return TRUE if the Test Mask contains all of the channels
111 	//	enabled in this instance.
112 	//	Use to be sure all channels in this instance exist in
113 	//	another instance.
114 	//
115 	BOOL IsSubsetOf( CChannelMask& TstMask );
116 
117 	//
118 	//	Return TRUE if the Test Mask contains at least one of the channels
119 	//	enabled in this instance.
120 	//	Use to find out if any channels in this instance exist in
121 	//	another instance.
122 	//
123 	BOOL IsIntersectionOf( CChannelMask& TstMask );
124 
125 	//
126 	//	Overload new & delete so memory for this object is allocated
127 	//	from non-paged memory.
128 	//
129 	PVOID operator new( size_t Size );
130 	VOID  operator delete( PVOID pVoid );
131 
132 	//
133 	//	Macintosh compiler likes "class" after friend, PC doesn't care
134 	//
135 	friend class CChMaskDsp;
136 
137 	//	Return TRUE if source mask equals this mask
138 	friend BOOLEAN operator == ( CONST CChannelMask &LVal,
139 										  CONST CChannelMask &RVal );
140 
141 	// Copy mask bits in source to this mask
142 	CChannelMask& operator = (CONST CChannelMask & RVal);
143 
144 	// Add mask bits in source to this mask
145 	VOID operator += (CONST CChannelMask & RVal);
146 
147 	// Subtract mask bits in source to this mask
148 	VOID operator -= (CONST CChannelMask & RVal);
149 
150 	// AND mask bits in source to this mask
151 	VOID operator &= (CONST CChannelMask & RVal);
152 
153 	// OR mask bits in source to this mask
154 	VOID operator |= (CONST CChannelMask & RVal);
155 
156 protected :
157 
158 	//
159 	//	Store an output bit mask and an input bitmask.
160 	//	We assume here that the # of outputs fits in one mask reg
161 	//
162 	void SetMask( CH_MASK OutMask, CH_MASK InMask, int nOutputs );
163 	void SetOutMask( CH_MASK OutMask, int nOutputs );
164 	void SetInMask( CH_MASK InMask, int nOutputs );
165 
166 	//
167 	//	Retrieve an output bit mask and an input bitmask.
168 	//	We assume here that the # of outputs fits in one mask reg
169 	//
170 	void GetMask( CH_MASK & OutMask, CH_MASK & InMask, int nOutputs );
171 	CH_MASK GetOutMask( int nOutputs );
172 	CH_MASK GetInMask( int nOutputs );
173 
174 };	// class CChannelMask
175 
176 typedef	CChannelMask *		PCChannelMask;
177 
178 
179 /****************************************************************************
180 
181 	CChMaskDsp
182 
183  ****************************************************************************/
184 
185 class CChMaskDsp
186 {
187 protected:
188 
189 	enum
190 	{
191 		CH_MASK_SZ = 4 / sizeof(CH_MASK_DSP)
192 	};
193 
194 	CH_MASK_DSP	m_MaskRegs[ CH_MASK_SZ  ];	// One bit per output or input channel
195 														// 32 bits total
196 
197 public:
198 
199 	CChMaskDsp();
200 	~CChMaskDsp() {}
201 
202 	// Returns TRUE if no bits set
203 	BOOL IsEmpty();
204 
205 	// Set the wPipeIndex bit in the mask
206 	void SetIndexInMask( WORD wPipeIndex );
207 
208 	// Clear the wPipeIndex bit in the mask
209 	void ClearIndexInMask( WORD wPipeIndex );
210 
211 	// Test pipe index in mask.
212 	//	Return TRUE if set
213 	BOOL TestIndexInMask( WORD wPipeIndex );
214 
215 	// Clear all bits in the mask
216 	void Clear();
217 
218 	//
219 	//	Overload new & delete so memory for this object is allocated
220 	//	from non-paged memory.
221 	//
222 	PVOID operator new( size_t Size );
223 	VOID  operator delete( PVOID pVoid );
224 
225 	//
226 	//	Macintosh compiler likes "class" after friend, PC doesn't care
227 	//
228 	friend class CChannelMask;
229 
230 	inline CH_MASK_DSP operator []  ( int iNdx )
231 		{ return SWAP( m_MaskRegs[ iNdx ] ); }
232 
233 	// Copy mask bits in source to this mask
234 	CChMaskDsp& operator = (CONST CChannelMask & RVal);
235 
236 	// Add mask bits in source to this mask
237 	VOID operator += (CONST CChannelMask & RVal);
238 
239 	// Subtract mask bits in source to this mask
240 	VOID operator -= (CONST CChannelMask & RVal);
241 
242 protected :
243 
244 };	// class CChMaskDsp
245 
246 typedef	CChMaskDsp *		PCChMaskDsp;
247 
248 #endif // _CHMASKOBJECT_
249 
250 //	CChannelMask.h
251