BPicture: Fix archive constructor.
[haiku.git] / src / add-ons / kernel / drivers / audio / echo / generic / CLineLevel.cpp
blob396f579bc63bd65b4e7808f6fe0ef9e2a204ee4b
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.
12 // ----------------------------------------------------------------------------
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
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.
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.
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
33 // ****************************************************************************
35 #include "CEchoGals.h"
38 /****************************************************************************
40 CLineLevel - Construction and destruction
42 ****************************************************************************/
44 //===========================================================================
46 // Constructor
48 //===========================================================================
50 CLineLevel::CLineLevel()
53 Init( 0, NULL, NULL );
55 } // CLineLevel::CLineLevel()
58 //===========================================================================
60 // Destructor
62 //===========================================================================
64 CLineLevel::~CLineLevel()
66 } // CLineLevel::~CLineLevel()
69 //===========================================================================
71 // Initialization
73 //===========================================================================
75 void CLineLevel::Init
77 WORD wChannelIndex, // Which channel we represent
78 CEchoGals * pEchoGals, // For setting line levels
79 INT32 iGain // Initial gain setting
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
88 } // void CLineLevel::Init
91 /****************************************************************************
93 CLineLevel - Set and get stuff
95 ****************************************************************************/
97 //===========================================================================
99 // Set the mute
101 //===========================================================================
103 ECHOSTATUS CLineLevel::SetMute( BOOL fMute )
105 m_fMuted = fMute;
106 return SetGain(ECHOGAIN_UPDATE);
111 /****************************************************************************
113 CBusInLineLevel - Construction and destruction
115 ****************************************************************************/
117 //===========================================================================
119 // Construction/destruction
121 //===========================================================================
123 CBusInLineLevel::CBusInLineLevel()
125 } // CBusInLineLevel::CBusInLineLevel()
128 CBusInLineLevel::~CBusInLineLevel()
130 } // COutLineLevel::~COutLineLevel()
134 /****************************************************************************
136 CBusInLineLevel - Get and set stuff
138 ****************************************************************************/
141 //===========================================================================
143 // Set the mute
145 //===========================================================================
147 ECHOSTATUS CBusInLineLevel::SetMute( BOOL fMute )
149 if (fMute != m_fMuted)
151 m_pEchoGals->MixerControlChanged(ECHO_BUS_IN,
152 MXN_MUTE,
153 m_wChannelIndex);
155 return CLineLevel::SetMute(fMute);
159 //===========================================================================
161 // Set the gain
163 //===========================================================================
165 ECHOSTATUS CBusInLineLevel::SetGain
167 INT32 iGain,
168 BOOL fImmediate
171 ECHOSTATUS Status;
173 if ( NULL == m_pEchoGals ||
174 NULL == m_pEchoGals->GetDspCommObject() ||
175 m_pEchoGals->GetDspCommObject()->IsBoardBad() )
176 return ECHOSTATUS_DSP_DEAD;
179 // If the magic ECHOGAIN_UPDATE value was passed in,
180 // use the stored gain. Otherwise, clamp the gain.
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;
190 // Generate a control notify if necessary
192 if ( m_iGain != iGain )
194 m_iGain = iGain;
195 m_pEchoGals->MixerControlChanged(ECHO_BUS_IN,
196 MXN_LEVEL,
197 m_wChannelIndex);
201 // Mute?
203 if (m_fMuted)
205 iGain = ECHOGAIN_MININP;
209 // Tell the DSP what to do
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
218 return Status;
220 } // ECHOSTATUS CBusInLineLevel::SetGain
224 /****************************************************************************
226 CBusOutLineLevel - Construction and destruction
228 ****************************************************************************/
230 //===========================================================================
232 // Construction/destruction
234 //===========================================================================
237 // Construction/destruction
239 CBusOutLineLevel::CBusOutLineLevel()
241 } // CBusOutLineLevel::CBusOutLineLevel()
244 CBusOutLineLevel::~CBusOutLineLevel()
246 } // CBusOutLineLevel::~CBusOutLineLevel()
251 /****************************************************************************
253 CBusOutLineLevel - Get and set stuff
255 ****************************************************************************/
258 //===========================================================================
260 // Set the mute
262 //===========================================================================
264 ECHOSTATUS CBusOutLineLevel::SetMute( BOOL fMute )
266 if (fMute != m_fMuted)
268 m_pEchoGals->MixerControlChanged(ECHO_BUS_OUT,
269 MXN_MUTE,
270 m_wChannelIndex);
272 return CLineLevel::SetMute(fMute);
276 //===========================================================================
278 // Set the gain
280 //===========================================================================
282 ECHOSTATUS CBusOutLineLevel::SetGain
284 INT32 iGain,
285 BOOL fImmediate
288 ECHOSTATUS Status = ECHOSTATUS_OK;
290 if ( NULL == m_pEchoGals ||
291 NULL == m_pEchoGals->GetDspCommObject() ||
292 m_pEchoGals->GetDspCommObject()->IsBoardBad() )
293 return ECHOSTATUS_DSP_DEAD;
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
300 // Otherwise, clamp the gain setting
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;
310 // Mark this control as changed
312 if ( m_iGain != iGain )
314 m_iGain = iGain;
316 if ( ECHOSTATUS_OK == Status )
317 Status = m_pEchoGals->MixerControlChanged(ECHO_BUS_OUT,
318 MXN_LEVEL,
319 m_wChannelIndex);
323 // Set the gain to mute if this bus is muted
325 INT32 iGainTemp = iGain;
326 if ( m_fMuted )
327 iGainTemp = ECHOGAIN_MUTED;
330 // Tell all the monitors for this output bus to
331 // update their gains
333 m_pEchoGals->AdjustMonitorsForBusOut(m_wChannelIndex);
336 // Tell all the output pipes for this output bus
337 // to update their gains
339 m_pEchoGals->AdjustPipesOutForBusOut(m_wChannelIndex,iGainTemp);
341 return Status;
343 } // ECHOSTATUS CBusOutLineLevel::SetGain
346 // **** CLineLevel.cpp ****