xref: /haiku/src/add-ons/kernel/drivers/audio/echo/generic/CLineLevel.cpp (revision 7120e97489acbf17d86d3f33e3b2e68974fd4b23)
1 // ****************************************************************************
2 //
3 //		CLineLevel.cpp
4 //
5 //		Source file for EchoGals generic driver line level control class.
6 //
7 // 	Controls line levels for input and output busses.
8 //
9 //		Implemented as a base class with 2 derived classes, one for
10 //		each type of bus.
11 //
12 //		Copyright Echo Digital Audio Corporation (c) 1998 - 2002
13 //		All rights reserved
14 //		www.echoaudio.com
15 //
16 //		Permission is hereby granted, free of charge, to any person obtaining a
17 //		copy of this software and associated documentation files (the
18 //		"Software"), to deal with the Software without restriction, including
19 //		without limitation the rights to use, copy, modify, merge, publish,
20 //		distribute, sublicense, and/or sell copies of the Software, and to
21 //		permit persons to whom the Software is furnished to do so, subject to
22 //		the following conditions:
23 //
24 //		- Redistributions of source code must retain the above copyright
25 //		notice, this list of conditions and the following disclaimers.
26 //
27 //		- Redistributions in binary form must reproduce the above copyright
28 //		notice, this list of conditions and the following disclaimers in the
29 //		documentation and/or other materials provided with the distribution.
30 //
31 //		- Neither the name of Echo Digital Audio, nor the names of its
32 //		contributors may be used to endorse or promote products derived from
33 //		this Software without specific prior written permission.
34 //
35 //		THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
36 //		EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
37 //		MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
38 //		IN NO EVENT SHALL THE CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR
39 //		ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
40 //		TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
41 //		SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE SOFTWARE.
42 //
43 // ****************************************************************************
44 
45 #include "CEchoGals.h"
46 
47 
48 /****************************************************************************
49 
50 	CLineLevel - Construction and destruction
51 
52  ****************************************************************************/
53 
54 //===========================================================================
55 //
56 // Constructor
57 //
58 //===========================================================================
59 
60 CLineLevel::CLineLevel()
61 {
62 
63 	Init( 0, NULL, NULL );
64 
65 }	// CLineLevel::CLineLevel()
66 
67 
68 //===========================================================================
69 //
70 // Destructor
71 //
72 //===========================================================================
73 
74 CLineLevel::~CLineLevel()
75 {
76 }	// CLineLevel::~CLineLevel()
77 
78 
79 //===========================================================================
80 //
81 // Initialization
82 //
83 //===========================================================================
84 
85 void CLineLevel::Init
86 (
87 	WORD				wChannelIndex,	// Which channel we represent
88 	CEchoGals *		pEchoGals,		// For setting line levels
89 	INT32				iGain				// Initial gain setting
90 )
91 {
92 	m_iGain = 0;						// Current gain in dB X 256
93 	m_fMuted = FALSE;
94 	m_pEchoGals = pEchoGals;		// Ptr to our creator object
95 	m_wChannelIndex = wChannelIndex;
96 											// pipe index for this line
97 
98 	if ( NULL != m_pEchoGals &&
99 		  NULL != m_pEchoGals->GetDspCommObject() &&
100 		  !m_pEchoGals->GetDspCommObject()->IsBoardBad() )
101 	{
102 		SetGain( iGain );				// If DSP is up, then set gain to caller's
103 											//	initial value
104 	}
105 }	// void CLineLevel::Init
106 
107 
108 /****************************************************************************
109 
110 	CLineLevel - Set and get stuff
111 
112  ****************************************************************************/
113 
114 //===========================================================================
115 //
116 // Set the mute
117 //
118 //===========================================================================
119 
120 ECHOSTATUS CLineLevel::SetMute( BOOL fMute )
121 {
122 	m_fMuted = fMute;
123 	return SetGain(ECHOGAIN_UPDATE);
124 }
125 
126 
127 
128 /****************************************************************************
129 
130 	CBusInLineLevel - Construction and destruction
131 
132  ****************************************************************************/
133 
134 //===========================================================================
135 //
136 //	Construction/destruction
137 //
138 //===========================================================================
139 
140 CBusInLineLevel::CBusInLineLevel()
141 {
142 }	// CBusInLineLevel::CBusInLineLevel()
143 
144 
145 CBusInLineLevel::~CBusInLineLevel()
146 {
147 }	// COutLineLevel::~COutLineLevel()
148 
149 
150 
151 /****************************************************************************
152 
153 	CBusInLineLevel - Get and set stuff
154 
155  ****************************************************************************/
156 
157 
158 //===========================================================================
159 //
160 // Set the mute
161 //
162 //===========================================================================
163 
164 ECHOSTATUS CBusInLineLevel::SetMute( BOOL fMute )
165 {
166 	if (fMute != m_fMuted)
167 	{
168 		m_pEchoGals->MixerControlChanged(ECHO_BUS_IN,
169 													MXN_MUTE,
170 													m_wChannelIndex);
171 	}
172 	return CLineLevel::SetMute(fMute);
173 }
174 
175 
176 //===========================================================================
177 //
178 // Set the gain
179 //
180 //===========================================================================
181 
182 ECHOSTATUS CBusInLineLevel::SetGain
183 (
184 	INT32 	iGain,
185 	BOOL 	fImmediate
186 )
187 {
188 	ECHOSTATUS	Status;
189 
190 	if ( NULL == m_pEchoGals ||
191 		  NULL == m_pEchoGals->GetDspCommObject() ||
192 		  m_pEchoGals->GetDspCommObject()->IsBoardBad() )
193 		return ECHOSTATUS_DSP_DEAD;
194 
195 	//
196 	// If the magic ECHOGAIN_UPDATE value was passed in,
197 	// use the stored gain.  Otherwise, clamp the gain.
198 	//
199 	if ( ECHOGAIN_UPDATE == iGain )
200 		iGain = m_iGain;
201 	else if ( iGain < ECHOGAIN_MININP )
202 		iGain = ECHOGAIN_MININP;
203 	else if ( iGain > ECHOGAIN_MAXINP )
204 		iGain = ECHOGAIN_MAXINP;
205 
206 	//
207 	// Generate a control notify if necessary
208 	//
209 	if ( m_iGain != iGain )
210 	{
211 		m_iGain = iGain;
212 		m_pEchoGals->MixerControlChanged(ECHO_BUS_IN,
213 													MXN_LEVEL,
214 													m_wChannelIndex);
215 	}
216 
217 	//
218 	// Mute?
219 	//
220 	if (m_fMuted)
221 	{
222 		iGain = ECHOGAIN_MININP;
223 	}
224 
225 	//
226 	// Tell the DSP what to do
227 	//
228 	iGain <<= 1; 	// Preserver half-dB steps in input gain
229 	Status =
230 		m_pEchoGals->GetDspCommObject()->SetBusInGain
231 						( m_wChannelIndex,
232 						  (BYTE) ( GENERIC_TO_DSP( iGain ) ) );
233 								  // Shift iGain up by 1 to preserve half-dB steps
234 
235 	return Status;
236 
237 }	// ECHOSTATUS CBusInLineLevel::SetGain
238 
239 
240 
241 /****************************************************************************
242 
243 	CBusOutLineLevel - Construction and destruction
244 
245  ****************************************************************************/
246 
247 //===========================================================================
248 //
249 //	Construction/destruction
250 //
251 //===========================================================================
252 
253 //
254 //	Construction/destruction
255 //
256 CBusOutLineLevel::CBusOutLineLevel()
257 {
258 }	// CBusOutLineLevel::CBusOutLineLevel()
259 
260 
261 CBusOutLineLevel::~CBusOutLineLevel()
262 {
263 }	// CBusOutLineLevel::~CBusOutLineLevel()
264 
265 
266 
267 
268 /****************************************************************************
269 
270 	CBusOutLineLevel - Get and set stuff
271 
272  ****************************************************************************/
273 
274 
275 //===========================================================================
276 //
277 // Set the mute
278 //
279 //===========================================================================
280 
281 ECHOSTATUS CBusOutLineLevel::SetMute( BOOL fMute )
282 {
283 	if (fMute != m_fMuted)
284 	{
285 		m_pEchoGals->MixerControlChanged(ECHO_BUS_OUT,
286 													MXN_MUTE,
287 													m_wChannelIndex);
288 	}
289 	return CLineLevel::SetMute(fMute);
290 }
291 
292 
293 //===========================================================================
294 //
295 // Set the gain
296 //
297 //===========================================================================
298 
299 ECHOSTATUS CBusOutLineLevel::SetGain
300 (
301 	INT32 	iGain,
302 	BOOL 	fImmediate
303 )
304 {
305 	ECHOSTATUS	Status = ECHOSTATUS_OK;
306 
307 	if ( NULL == m_pEchoGals ||
308 		  NULL == m_pEchoGals->GetDspCommObject() ||
309 		  m_pEchoGals->GetDspCommObject()->IsBoardBad() )
310 		return ECHOSTATUS_DSP_DEAD;
311 
312 	//
313 	// If iGain is ECHOGAIN_UPDATE, then the caller
314 	// wants this function to re-do the gain setting
315 	// with the currently stored value
316 	//
317 	// Otherwise, clamp the gain setting
318 	//
319 	if ( ECHOGAIN_UPDATE == iGain )
320 		iGain = m_iGain;
321 	else if ( iGain < ECHOGAIN_MUTED )
322 		iGain = ECHOGAIN_MUTED;
323 	else if ( iGain > ECHOGAIN_MAXOUT )
324 		iGain = ECHOGAIN_MAXOUT;
325 
326 	//
327 	// Mark this control as changed
328 	//
329 	if ( m_iGain != iGain )
330 	{
331 		m_iGain = iGain;
332 
333 		if ( ECHOSTATUS_OK == Status )
334 			Status = m_pEchoGals->MixerControlChanged(ECHO_BUS_OUT,
335 																	MXN_LEVEL,
336 																	m_wChannelIndex);
337 	}
338 
339 	//
340 	// Set the gain to mute if this bus is muted
341 	//
342 	int iGainTemp = iGain;
343 	if ( m_fMuted )
344 		iGainTemp = ECHOGAIN_MUTED;
345 
346 	//
347 	// Tell all the monitors for this output bus to
348 	// update their gains
349 	//
350 	m_pEchoGals->AdjustMonitorsForBusOut(m_wChannelIndex);
351 
352 	//
353 	// Tell all the output pipes for this output bus
354 	// to update their gains
355 	//
356 	m_pEchoGals->AdjustPipesOutForBusOut(m_wChannelIndex,iGainTemp);
357 
358 	return Status;
359 
360 }	// ECHOSTATUS CBusOutLineLevel::SetGain
361 
362 
363 // **** CLineLevel.cpp ****
364