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// ----------------------------------------------------------------------------
13//
14// This file is part of Echo Digital Audio's generic driver library.
15// Copyright Echo Digital Audio Corporation (c) 1998 - 2005
16// All rights reserved
17// www.echoaudio.com
18//
19// This library is free software; you can redistribute it and/or
20// modify it under the terms of the GNU Lesser General Public
21// License as published by the Free Software Foundation; either
22// version 2.1 of the License, or (at your option) any later version.
23//
24// This library is distributed in the hope that it will be useful,
25// but WITHOUT ANY WARRANTY; without even the implied warranty of
26// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
27// Lesser General Public License for more details.
28//
29// You should have received a copy of the GNU Lesser General Public
30// License along with this library; if not, write to the Free Software
31// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
32//
33// ****************************************************************************
34
35#include "CEchoGals.h"
36
37
38/****************************************************************************
39
40	CLineLevel - Construction and destruction
41
42 ****************************************************************************/
43
44//===========================================================================
45//
46// Constructor
47//
48//===========================================================================
49
50CLineLevel::CLineLevel()
51{
52
53	Init( 0, NULL, NULL );
54
55}	// CLineLevel::CLineLevel()
56
57
58//===========================================================================
59//
60// Destructor
61//
62//===========================================================================
63
64CLineLevel::~CLineLevel()
65{
66}	// CLineLevel::~CLineLevel()
67
68
69//===========================================================================
70//
71// Initialization
72//
73//===========================================================================
74
75void CLineLevel::Init
76(
77	WORD				wChannelIndex,	// Which channel we represent
78	CEchoGals *		pEchoGals,		// For setting line levels
79	INT32				iGain				// Initial gain setting
80)
81{
82	m_iGain = 0;						// Current gain in dB X 256
83	m_fMuted = FALSE;
84	m_pEchoGals = pEchoGals;		// Ptr to our creator object
85	m_wChannelIndex = wChannelIndex;
86											// pipe index for this line
87
88}	// void CLineLevel::Init
89
90
91/****************************************************************************
92
93	CLineLevel - Set and get stuff
94
95 ****************************************************************************/
96
97//===========================================================================
98//
99// Set the mute
100//
101//===========================================================================
102
103ECHOSTATUS CLineLevel::SetMute( BOOL fMute )
104{
105	m_fMuted = fMute;
106	return SetGain(ECHOGAIN_UPDATE);
107}
108
109
110
111/****************************************************************************
112
113	CBusInLineLevel - Construction and destruction
114
115 ****************************************************************************/
116
117//===========================================================================
118//
119//	Construction/destruction
120//
121//===========================================================================
122
123CBusInLineLevel::CBusInLineLevel()
124{
125}	// CBusInLineLevel::CBusInLineLevel()
126
127
128CBusInLineLevel::~CBusInLineLevel()
129{
130}	// COutLineLevel::~COutLineLevel()
131
132
133
134/****************************************************************************
135
136	CBusInLineLevel - Get and set stuff
137
138 ****************************************************************************/
139
140
141//===========================================================================
142//
143// Set the mute
144//
145//===========================================================================
146
147ECHOSTATUS CBusInLineLevel::SetMute( BOOL fMute )
148{
149	if (fMute != m_fMuted)
150	{
151		m_pEchoGals->MixerControlChanged(ECHO_BUS_IN,
152													MXN_MUTE,
153													m_wChannelIndex);
154	}
155	return CLineLevel::SetMute(fMute);
156}
157
158
159//===========================================================================
160//
161// Set the gain
162//
163//===========================================================================
164
165ECHOSTATUS CBusInLineLevel::SetGain
166(
167	INT32 	iGain,
168	BOOL 	fImmediate
169)
170{
171	ECHOSTATUS	Status;
172
173	if ( NULL == m_pEchoGals ||
174		  NULL == m_pEchoGals->GetDspCommObject() ||
175		  m_pEchoGals->GetDspCommObject()->IsBoardBad() )
176		return ECHOSTATUS_DSP_DEAD;
177
178	//
179	// If the magic ECHOGAIN_UPDATE value was passed in,
180	// use the stored gain.  Otherwise, clamp the gain.
181	//
182	if ( ECHOGAIN_UPDATE == iGain )
183		iGain = m_iGain;
184	else if ( iGain < ECHOGAIN_MININP )
185		iGain = ECHOGAIN_MININP;
186	else if ( iGain > ECHOGAIN_MAXINP )
187		iGain = ECHOGAIN_MAXINP;
188
189	//
190	// Generate a control notify if necessary
191	//
192	if ( m_iGain != iGain )
193	{
194		m_iGain = iGain;
195		m_pEchoGals->MixerControlChanged(ECHO_BUS_IN,
196													MXN_LEVEL,
197													m_wChannelIndex);
198	}
199
200	//
201	// Mute?
202	//
203	if (m_fMuted)
204	{
205		iGain = ECHOGAIN_MININP;
206	}
207
208	//
209	// Tell the DSP what to do
210	//
211	iGain <<= 1; 	// Preserver half-dB steps in input gain
212	Status =
213		m_pEchoGals->GetDspCommObject()->SetBusInGain
214						( m_wChannelIndex,
215						  (BYTE) ( GENERIC_TO_DSP( iGain ) ) );
216								  // Shift iGain up by 1 to preserve half-dB steps
217
218	return Status;
219
220}	// ECHOSTATUS CBusInLineLevel::SetGain
221
222
223
224/****************************************************************************
225
226	CBusOutLineLevel - Construction and destruction
227
228 ****************************************************************************/
229
230//===========================================================================
231//
232//	Construction/destruction
233//
234//===========================================================================
235
236//
237//	Construction/destruction
238//
239CBusOutLineLevel::CBusOutLineLevel()
240{
241}	// CBusOutLineLevel::CBusOutLineLevel()
242
243
244CBusOutLineLevel::~CBusOutLineLevel()
245{
246}	// CBusOutLineLevel::~CBusOutLineLevel()
247
248
249
250
251/****************************************************************************
252
253	CBusOutLineLevel - Get and set stuff
254
255 ****************************************************************************/
256
257
258//===========================================================================
259//
260// Set the mute
261//
262//===========================================================================
263
264ECHOSTATUS CBusOutLineLevel::SetMute( BOOL fMute )
265{
266	if (fMute != m_fMuted)
267	{
268		m_pEchoGals->MixerControlChanged(ECHO_BUS_OUT,
269													MXN_MUTE,
270													m_wChannelIndex);
271	}
272	return CLineLevel::SetMute(fMute);
273}
274
275
276//===========================================================================
277//
278// Set the gain
279//
280//===========================================================================
281
282ECHOSTATUS CBusOutLineLevel::SetGain
283(
284	INT32 	iGain,
285	BOOL 		fImmediate
286)
287{
288	ECHOSTATUS	Status = ECHOSTATUS_OK;
289
290	if ( NULL == m_pEchoGals ||
291		  NULL == m_pEchoGals->GetDspCommObject() ||
292		  m_pEchoGals->GetDspCommObject()->IsBoardBad() )
293		return ECHOSTATUS_DSP_DEAD;
294
295	//
296	// If iGain is ECHOGAIN_UPDATE, then the caller
297	// wants this function to re-do the gain setting
298	// with the currently stored value
299	//
300	// Otherwise, clamp the gain setting
301	//
302	if ( ECHOGAIN_UPDATE == iGain )
303		iGain = m_iGain;
304	else if ( iGain < ECHOGAIN_MUTED )
305		iGain = ECHOGAIN_MUTED;
306	else if ( iGain > ECHOGAIN_MAXOUT )
307		iGain = ECHOGAIN_MAXOUT;
308
309	//
310	// Mark this control as changed
311	//
312	if ( m_iGain != iGain )
313	{
314		m_iGain = iGain;
315
316		if ( ECHOSTATUS_OK == Status )
317			Status = m_pEchoGals->MixerControlChanged(ECHO_BUS_OUT,
318																	MXN_LEVEL,
319																	m_wChannelIndex);
320	}
321
322	//
323	// Set the gain to mute if this bus is muted
324	//
325	INT32 iGainTemp = iGain;
326	if ( m_fMuted )
327		iGainTemp = ECHOGAIN_MUTED;
328
329	//
330	// Tell all the monitors for this output bus to
331	// update their gains
332	//
333	m_pEchoGals->AdjustMonitorsForBusOut(m_wChannelIndex);
334
335	//
336	// Tell all the output pipes for this output bus
337	// to update their gains
338	//
339	m_pEchoGals->AdjustPipesOutForBusOut(m_wChannelIndex,iGainTemp);
340
341	return Status;
342
343}	// ECHOSTATUS CBusOutLineLevel::SetGain
344
345
346// **** CLineLevel.cpp ****
347