xref: /haiku/src/add-ons/kernel/drivers/audio/echo/generic/CDspCommObjectVmixer.cpp (revision 68ea01249e1e2088933cb12f9c28d4e5c5d1c9ef)
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
13 //
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.
18 //
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.
23 //
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
27 //
28 // ****************************************************************************
29 
30 #include "CEchoGals.h"
31 #include "CDspCommObjectVmixer.h"
32 
33 
34 /****************************************************************************
35 
36 	Construction and destruction
37 
38  ****************************************************************************/
39 
40 //===========================================================================
41 //
42 // Constructor
43 //
44 //===========================================================================
45 
46 CDspCommObjectVmixer::CDspCommObjectVmixer
47 (
48 	PDWORD		pdwRegBase,				// Virtual ptr to DSP registers
49 	PCOsSupport	pOsSupport
50 ) : CDspCommObject( pdwRegBase, pOsSupport )
51 {
52 }	// CDspCommObjectVmixer::CDspCommObjectVmixer( DWORD dwPhysRegBase )
53 
54 
55 //===========================================================================
56 //
57 // Destructor
58 //
59 //===========================================================================
60 
61 CDspCommObjectVmixer::~CDspCommObjectVmixer()
62 {
63 }	// CDspCommObjectVmixer::~CDspCommObjectVmixer()
64 
65 
66 
67 
68 /****************************************************************************
69 
70 	Hardware setup and config
71 
72  ****************************************************************************/
73 
74 //===========================================================================
75 //
76 // GetAudioMeters
77 //
78 // Meters are written to the comm page by the DSP as follows:
79 //
80 // Output busses
81 // Input busses
82 // Output pipes (vmixer cards only)
83 //
84 //===========================================================================
85 
86 ECHOSTATUS CDspCommObjectVmixer::GetAudioMeters
87 (
88 	PECHOGALS_METERS	pMeters
89 )
90 {
91 	WORD i;
92 
93 	pMeters->iNumPipesIn = 0;
94 
95 	//
96 	//	Output
97 	//
98 	DWORD dwCh = 0;
99 
100 	pMeters->iNumBussesOut = (INT32) m_wNumBussesOut;
101 	for (i = 0; i < m_wNumBussesOut; i++)
102 	{
103 		pMeters->iBusOutVU[i] =
104 			DSP_TO_GENERIC( ((INT32) (char) m_pDspCommPage->VUMeter[ dwCh ]) );
105 
106 		pMeters->iBusOutPeak[i] =
107 			DSP_TO_GENERIC( ((INT32) (char) m_pDspCommPage->PeakMeter[ dwCh ]) );
108 
109 		dwCh++;
110 	}
111 
112 	pMeters->iNumBussesIn = (INT32) m_wNumBussesIn;
113 	for (i = 0; i < m_wNumPipesIn; i++)
114 	{
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 ]) );
119 
120 		dwCh++;
121 	}
122 
123 	pMeters->iNumPipesOut = (INT32) m_wNumPipesOut;
124 	for (i = 0; i < m_wNumPipesOut; i++)
125 	{
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 ]) );
130 
131 		dwCh++;
132 	}
133 
134 	return ECHOSTATUS_OK;
135 
136 } // GetAudioMeters
137 
138 
139 //===========================================================================
140 //
141 // GetPipeOutGain and SetPipeOutGain
142 //
143 // This doesn't set the line out volume; instead, it sets the
144 // vmixer volume.
145 //
146 //===========================================================================
147 
148 ECHOSTATUS CDspCommObjectVmixer::SetPipeOutGain
149 (
150 	WORD wPipeOut,
151 	WORD wBusOut,
152 	INT32 iGain,
153 	BOOL fImmediate
154 )
155 {
156 	if (wPipeOut >= m_wNumPipesOut)
157 	{
158 		ECHO_DEBUGPRINTF( ("CDspCommObjectVmixer::SetPipeOutGain: Invalid out pipe "
159 								 "%d\n",
160 								 wPipeOut) );
161 
162 		return ECHOSTATUS_INVALID_CHANNEL;
163 	}
164 
165 	iGain = GENERIC_TO_DSP(iGain);
166 
167 	if ( wBusOut < m_wNumBussesOut )
168 	{
169 		if ( !WaitForHandshake() )
170 			return ECHOSTATUS_DSP_DEAD;
171 
172 		DWORD dwIndex = wBusOut * m_wNumPipesOut + wPipeOut;
173 		m_pDspCommPage->byVmixerLevel[ dwIndex ] = (BYTE) iGain;
174 
175 /*
176 		ECHO_DEBUGPRINTF( ("CDspCommObjectVmixer::SetPipeOutGain: Out pipe %d, "
177 								 "out bus %d = 0x%lx\n",
178 								 wPipeOut,
179 								 wBusOut,
180 								 iGain) );
181 */
182 
183 		if (fImmediate)
184 		{
185 			return UpdateVmixerLevel();
186 		}
187 
188 		return ECHOSTATUS_OK;
189 	}
190 
191 	ECHO_DEBUGPRINTF( ("CDspCommObjectVmixer::SetPipeOutGain: Invalid out bus "
192 							 "%d\n",
193 							 wBusOut) );
194 
195 	return ECHOSTATUS_INVALID_CHANNEL;
196 
197 }	// SetPipeOutGain
198 
199 
200 ECHOSTATUS CDspCommObjectVmixer::GetPipeOutGain
201 (
202 	WORD wPipeOut,
203 	WORD wBusOut,
204 	INT32 &iGain
205 )
206 {
207 	if (wPipeOut >= m_wNumPipesOut)
208 	{
209 		ECHO_DEBUGPRINTF( ("CDspCommObjectVmixer::GetPipeOutGain: Invalid out pipe "
210 								 "%d\n",
211 								 wPipeOut) );
212 
213 		return ECHOSTATUS_INVALID_CHANNEL;
214 	}
215 
216 	if (wBusOut < m_wNumBussesOut)
217 	{
218 		iGain = m_pDspCommPage->byVmixerLevel[ wBusOut * m_wNumPipesOut + wPipeOut ];
219 		iGain = DSP_TO_GENERIC(iGain);
220 		return ECHOSTATUS_OK;
221 	}
222 
223 	ECHO_DEBUGPRINTF( ("CDspCommObjectVmixer::GetPipeOutGain: Invalid out bus "
224 							 "%d\n",
225 							 wBusOut) );
226 
227 	return ECHOSTATUS_INVALID_CHANNEL;
228 
229 }	// GetPipeOutGain
230 
231 //===========================================================================
232 //
233 // SetBusOutGain
234 //
235 //===========================================================================
236 
237 ECHOSTATUS CDspCommObjectVmixer::SetBusOutGain(WORD wBusOut,INT32 iGain)
238 {
239 	if ( wBusOut < m_wNumBussesOut )
240 	{
241 		if ( !WaitForHandshake() )
242 			return ECHOSTATUS_DSP_DEAD;
243 
244 		iGain = GENERIC_TO_DSP(iGain);
245 		m_pDspCommPage->OutLineLevel[ wBusOut ] = (BYTE) iGain;
246 
247 		ECHO_DEBUGPRINTF( ("CDspCommObjectVmixer::SetBusOutGain: Out bus %d "
248 								 "= %lu\n",
249 								 wBusOut,
250 								 iGain) );
251 
252 		return UpdateAudioOutLineLevel();
253 
254 	}
255 
256 	ECHO_DEBUGPRINTF( ("CDspCommObjectVmixer::SetBusOutGain: Invalid out bus "
257 							 "%d\n",
258 							 wBusOut) );
259 
260 	return ECHOSTATUS_INVALID_CHANNEL;
261 }
262 
263 
264 //===========================================================================
265 //
266 // Tell the DSP to read and update vmixer levels
267 //	from the comm page.
268 //
269 //===========================================================================
270 
271 ECHOSTATUS CDspCommObjectVmixer::UpdateVmixerLevel()
272 {
273 	//ECHO_DEBUGPRINTF( ( "CDspCommObjectVmixer::UpdateVmixerLevel:\n" ) );
274 
275 	ClearHandshake();
276 	return( SendVector( DSP_VC_SET_VMIXER_GAIN ) );
277 }
278 
279 
280 // **** CDspCommObjectVmixer.cpp ****
281