vfs: check userland buffers before reading them.
[haiku.git] / src / add-ons / kernel / drivers / audio / echo / generic / CChannelMask.h
blob1aa9f78234998329d43a1fcccffdc74004cf34f1
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.
17 //---------------------------------------------------------------------------
19 // ----------------------------------------------------------------------------
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
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.
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.
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
40 // ****************************************************************************
42 // Prevent problems with multiple includes
43 #ifndef _CHMASKOBJECT_
44 #define _CHMASKOBJECT_
47 // Defines
49 typedef unsigned long CH_MASK;
51 #define CH_MASK_BITS (sizeof( CH_MASK ) * 8)
52 // Max bits per mask entry
54 #define ECHO_INVALID_CHANNEL ((WORD)(-1))
55 // Marks unused channel #
57 typedef unsigned long CH_MASK_DSP;
58 #define CH_MASK_DSP_BITS (sizeof( CH_MASK_DSP ) * 8)
59 // Max bits per mask entry
61 /****************************************************************************
63 CChannelMask
65 ****************************************************************************/
67 class CChannelMask
69 protected:
71 #ifdef ECHO_OS9
72 friend class CInOutChannelMask;
73 #endif
75 CH_MASK m_Mask; // One bit per output or input channel
77 public:
79 CChannelMask();
80 ~CChannelMask() {}
82 CH_MASK GetMask()
84 return m_Mask;
87 // Returns TRUE if no bits set
88 BOOL IsEmpty();
90 // Set the wPipeIndex bit in the mask
91 void SetIndexInMask( WORD wPipeIndex );
93 // Clear the wPipeIndex bit in the mask
94 void ClearIndexInMask( WORD wPipeIndex );
96 // Return the next bit set starting with wStartPipeIndex as an index.
97 // If nothing set, returns ECHO_INVALID_CHANNEL.
98 // Use this interface for enumerating thru a channel mask.
99 WORD GetIndexFromMask( WORD wStartPipeIndex );
101 // Test driver channel index in mask.
102 // Return TRUE if set
103 BOOL TestIndexInMask( WORD wPipeIndex );
105 // Clear all bits in the mask
106 void Clear();
108 // Clear bits in this mask that are in SrcMask
109 void ClearMask( CChannelMask SrcMask );
111 // Return TRUE if any bits in source mask are set in this mask
112 BOOL Test( CChannelMask * pSrcMask );
115 // Return TRUE if the Test Mask contains all of the channels
116 // enabled in this instance.
117 // Use to be sure all channels in this instance exist in
118 // another instance.
120 BOOL IsSubsetOf( CChannelMask& TstMask );
123 // Return TRUE if the Test Mask contains at least one of the channels
124 // enabled in this instance.
125 // Use to find out if any channels in this instance exist in
126 // another instance.
128 BOOL IsIntersectionOf( CChannelMask& TstMask );
131 // Overload new & delete so memory for this object is allocated
132 // from non-paged memory.
134 PVOID operator new( size_t Size );
135 VOID operator delete( PVOID pVoid );
138 // Macintosh compiler likes "class" after friend, PC doesn't care
140 friend class CChMaskDsp;
142 // Return TRUE if source mask equals this mask
143 friend BOOLEAN operator == ( CONST CChannelMask &LVal,
144 CONST CChannelMask &RVal );
146 // Copy mask bits in source to this mask
147 CChannelMask& operator = (CONST CChannelMask & RVal);
149 // Add mask bits in source to this mask
150 VOID operator += (CONST CChannelMask & RVal);
152 // Subtract mask bits in source to this mask
153 VOID operator -= (CONST CChannelMask & RVal);
155 // AND mask bits in source to this mask
156 VOID operator &= (CONST CChannelMask & RVal);
158 // OR mask bits in source to this mask
159 VOID operator |= (CONST CChannelMask & RVal);
161 protected :
164 // Store an output bit mask and an input bitmask.
165 // We assume here that the # of outputs fits in one mask reg
167 void SetMask( CH_MASK OutMask, CH_MASK InMask, int nOutputs );
168 void SetOutMask( CH_MASK OutMask, int nOutputs );
169 void SetInMask( CH_MASK InMask, int nOutputs );
172 // Retrieve an output bit mask and an input bitmask.
173 // We assume here that the # of outputs fits in one mask reg
175 void GetMask( CH_MASK & OutMask, CH_MASK & InMask, int nOutputs );
176 CH_MASK GetOutMask( int nOutputs );
177 CH_MASK GetInMask( int nOutputs );
179 }; // class CChannelMask
181 typedef CChannelMask * PCChannelMask;
184 /****************************************************************************
186 CChMaskDsp
188 ****************************************************************************/
190 class CChMaskDsp
192 public:
193 CH_MASK_DSP m_Mask; // One bit per output or input channel
194 // 32 bits total
195 CChMaskDsp();
196 ~CChMaskDsp() {}
198 // Returns TRUE if no bits set
199 BOOL IsEmpty();
201 // Set the wPipeIndex bit in the mask
202 void SetIndexInMask( WORD wPipeIndex );
204 // Clear the wPipeIndex bit in the mask
205 void ClearIndexInMask( WORD wPipeIndex );
207 // Test pipe index in mask.
208 // Return TRUE if set
209 BOOL TestIndexInMask( WORD wPipeIndex );
211 // Clear all bits in the mask
212 void Clear();
215 // Overload new & delete so memory for this object is allocated
216 // from non-paged memory.
218 PVOID operator new( size_t Size );
219 VOID operator delete( PVOID pVoid );
222 // Macintosh compiler likes "class" after friend, PC doesn't care
224 friend class CChannelMask;
226 // Copy mask bits in source to this mask
227 CChMaskDsp& operator = (CONST CChannelMask & RVal);
229 protected :
231 }; // class CChMaskDsp
233 typedef CChMaskDsp * PCChMaskDsp;
235 #endif // _CHMASKOBJECT_
237 // CChannelMask.h