BPicture: Fix archive constructor.
[haiku.git] / src / add-ons / kernel / drivers / audio / echo / generic / CDspCommObjectVmixer.cpp
blobb12c5095e781fd74ea4a821c49ccf9f228476f01
1 // ****************************************************************************
2 //
3 // CDspCommObjectVmixer.cpp
4 //
5 // Implementation file for DSP interface class with vmixer support.
6 //
7 // ----------------------------------------------------------------------------
8 //
9 // This file is part of Echo Digital Audio's generic driver library.
10 // Copyright Echo Digital Audio Corporation (c) 1998 - 2005
11 // All rights reserved
12 // www.echoaudio.com
14 // This library is free software; you can redistribute it and/or
15 // modify it under the terms of the GNU Lesser General Public
16 // License as published by the Free Software Foundation; either
17 // version 2.1 of the License, or (at your option) any later version.
19 // This library is distributed in the hope that it will be useful,
20 // but WITHOUT ANY WARRANTY; without even the implied warranty of
21 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 // Lesser General Public License for more details.
24 // You should have received a copy of the GNU Lesser General Public
25 // License along with this library; if not, write to the Free Software
26 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 // ****************************************************************************
30 #include "CEchoGals.h"
31 #include "CDspCommObjectVmixer.h"
34 /****************************************************************************
36 Construction and destruction
38 ****************************************************************************/
40 //===========================================================================
42 // Constructor
44 //===========================================================================
46 CDspCommObjectVmixer::CDspCommObjectVmixer
48 PDWORD pdwRegBase, // Virtual ptr to DSP registers
49 PCOsSupport pOsSupport
50 ) : CDspCommObject( pdwRegBase, pOsSupport )
52 } // CDspCommObjectVmixer::CDspCommObjectVmixer( DWORD dwPhysRegBase )
55 //===========================================================================
57 // Destructor
59 //===========================================================================
61 CDspCommObjectVmixer::~CDspCommObjectVmixer()
63 } // CDspCommObjectVmixer::~CDspCommObjectVmixer()
68 /****************************************************************************
70 Hardware setup and config
72 ****************************************************************************/
74 //===========================================================================
76 // GetAudioMeters
77 //
78 // Meters are written to the comm page by the DSP as follows:
80 // Output busses
81 // Input busses
82 // Output pipes (vmixer cards only)
84 //===========================================================================
86 ECHOSTATUS CDspCommObjectVmixer::GetAudioMeters
88 PECHOGALS_METERS pMeters
91 WORD i;
93 pMeters->iNumPipesIn = 0;
96 // Output
97 //
98 DWORD dwCh = 0;
100 pMeters->iNumBussesOut = (INT32) m_wNumBussesOut;
101 for (i = 0; i < m_wNumBussesOut; i++)
103 pMeters->iBusOutVU[i] =
104 DSP_TO_GENERIC( ((INT32) (char) m_pDspCommPage->VUMeter[ dwCh ]) );
106 pMeters->iBusOutPeak[i] =
107 DSP_TO_GENERIC( ((INT32) (char) m_pDspCommPage->PeakMeter[ dwCh ]) );
109 dwCh++;
112 pMeters->iNumBussesIn = (INT32) m_wNumBussesIn;
113 for (i = 0; i < m_wNumPipesIn; i++)
115 pMeters->iBusInVU[i] =
116 DSP_TO_GENERIC( ((INT32) (char) m_pDspCommPage->VUMeter[ dwCh ]) );
117 pMeters->iBusInPeak[i] =
118 DSP_TO_GENERIC( ((INT32) (char) m_pDspCommPage->PeakMeter[ dwCh ]) );
120 dwCh++;
123 pMeters->iNumPipesOut = (INT32) m_wNumPipesOut;
124 for (i = 0; i < m_wNumPipesOut; i++)
126 pMeters->iPipeOutVU[i] =
127 DSP_TO_GENERIC( ((INT32) (char) m_pDspCommPage->VUMeter[ dwCh ]) );
128 pMeters->iPipeOutPeak[i] =
129 DSP_TO_GENERIC( ((INT32) (char) m_pDspCommPage->PeakMeter[ dwCh ]) );
131 dwCh++;
134 return ECHOSTATUS_OK;
136 } // GetAudioMeters
139 //===========================================================================
141 // GetPipeOutGain and SetPipeOutGain
143 // This doesn't set the line out volume; instead, it sets the
144 // vmixer volume.
146 //===========================================================================
148 ECHOSTATUS CDspCommObjectVmixer::SetPipeOutGain
150 WORD wPipeOut,
151 WORD wBusOut,
152 INT32 iGain,
153 BOOL fImmediate
156 if (wPipeOut >= m_wNumPipesOut)
158 ECHO_DEBUGPRINTF( ("CDspCommObjectVmixer::SetPipeOutGain: Invalid out pipe "
159 "%d\n",
160 wPipeOut) );
162 return ECHOSTATUS_INVALID_CHANNEL;
165 iGain = GENERIC_TO_DSP(iGain);
167 if ( wBusOut < m_wNumBussesOut )
169 if ( !WaitForHandshake() )
170 return ECHOSTATUS_DSP_DEAD;
172 DWORD dwIndex = wBusOut * m_wNumPipesOut + wPipeOut;
173 m_pDspCommPage->byVmixerLevel[ dwIndex ] = (BYTE) iGain;
176 ECHO_DEBUGPRINTF( ("CDspCommObjectVmixer::SetPipeOutGain: Out pipe %d, "
177 "out bus %d = 0x%lx\n",
178 wPipeOut,
179 wBusOut,
180 iGain) );
183 if (fImmediate)
185 return UpdateVmixerLevel();
188 return ECHOSTATUS_OK;
191 ECHO_DEBUGPRINTF( ("CDspCommObjectVmixer::SetPipeOutGain: Invalid out bus "
192 "%d\n",
193 wBusOut) );
195 return ECHOSTATUS_INVALID_CHANNEL;
197 } // SetPipeOutGain
200 ECHOSTATUS CDspCommObjectVmixer::GetPipeOutGain
202 WORD wPipeOut,
203 WORD wBusOut,
204 INT32 &iGain
207 if (wPipeOut >= m_wNumPipesOut)
209 ECHO_DEBUGPRINTF( ("CDspCommObjectVmixer::GetPipeOutGain: Invalid out pipe "
210 "%d\n",
211 wPipeOut) );
213 return ECHOSTATUS_INVALID_CHANNEL;
216 if (wBusOut < m_wNumBussesOut)
218 iGain = m_pDspCommPage->byVmixerLevel[ wBusOut * m_wNumPipesOut + wPipeOut ];
219 iGain = DSP_TO_GENERIC(iGain);
220 return ECHOSTATUS_OK;
223 ECHO_DEBUGPRINTF( ("CDspCommObjectVmixer::GetPipeOutGain: Invalid out bus "
224 "%d\n",
225 wBusOut) );
227 return ECHOSTATUS_INVALID_CHANNEL;
229 } // GetPipeOutGain
231 //===========================================================================
233 // SetBusOutGain
235 //===========================================================================
237 ECHOSTATUS CDspCommObjectVmixer::SetBusOutGain(WORD wBusOut,INT32 iGain)
239 if ( wBusOut < m_wNumBussesOut )
241 if ( !WaitForHandshake() )
242 return ECHOSTATUS_DSP_DEAD;
244 iGain = GENERIC_TO_DSP(iGain);
245 m_pDspCommPage->OutLineLevel[ wBusOut ] = (BYTE) iGain;
247 ECHO_DEBUGPRINTF( ("CDspCommObjectVmixer::SetBusOutGain: Out bus %d "
248 "= %lu\n",
249 wBusOut,
250 iGain) );
252 return UpdateAudioOutLineLevel();
256 ECHO_DEBUGPRINTF( ("CDspCommObjectVmixer::SetBusOutGain: Invalid out bus "
257 "%d\n",
258 wBusOut) );
260 return ECHOSTATUS_INVALID_CHANNEL;
264 //===========================================================================
266 // Tell the DSP to read and update vmixer levels
267 // from the comm page.
269 //===========================================================================
271 ECHOSTATUS CDspCommObjectVmixer::UpdateVmixerLevel()
273 //ECHO_DEBUGPRINTF( ( "CDspCommObjectVmixer::UpdateVmixerLevel:\n" ) );
275 ClearHandshake();
276 return( SendVector( DSP_VC_SET_VMIXER_GAIN ) );
280 // **** CDspCommObjectVmixer.cpp ****