BPicture: Fix archive constructor.
[haiku.git] / src / add-ons / kernel / drivers / audio / echo / generic / CGMLDspCommObject.cpp
blob16e68e8d3b3e00cb3975eec689df980868439423
1 // ****************************************************************************
2 //
3 // CGMLDspCommObject.cpp
4 //
5 // Implementation file for GML cards (Gina24, Mona, and Layla24).
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 "CGMLDspCommObject.h"
33 //===========================================================================
35 // Set the S/PDIF output format
36 //
37 //===========================================================================
39 void CGMLDspCommObject::SetProfessionalSpdif
41 BOOL bNewStatus
44 DWORD dwControlReg;
46 dwControlReg = GetControlRegister();
49 // Clear the current S/PDIF flags
51 dwControlReg &= GML_SPDIF_FORMAT_CLEAR_MASK;
54 // Set the new S/PDIF flags depending on the mode
55 //
56 dwControlReg |= GML_SPDIF_TWO_CHANNEL |
57 GML_SPDIF_24_BIT |
58 GML_SPDIF_COPY_PERMIT;
59 if ( bNewStatus )
62 // Professional mode
64 dwControlReg |= GML_SPDIF_PRO_MODE;
66 switch ( GetSampleRate() )
68 case 32000 :
69 dwControlReg |= GML_SPDIF_SAMPLE_RATE0 |
70 GML_SPDIF_SAMPLE_RATE1;
71 break;
73 case 44100 :
74 dwControlReg |= GML_SPDIF_SAMPLE_RATE0;
75 break;
77 case 48000 :
78 dwControlReg |= GML_SPDIF_SAMPLE_RATE1;
79 break;
82 else
85 // Consumer mode
87 switch ( GetSampleRate() )
89 case 32000 :
90 dwControlReg |= GML_SPDIF_SAMPLE_RATE0 |
91 GML_SPDIF_SAMPLE_RATE1;
92 break;
94 case 48000 :
95 dwControlReg |= GML_SPDIF_SAMPLE_RATE1;
96 break;
101 // Handle the non-audio bit
103 if (m_bNonAudio)
104 dwControlReg |= GML_SPDIF_NOT_AUDIO;
107 // Write the control reg
109 WriteControlReg( dwControlReg );
111 m_bProfessionalSpdif = bNewStatus;
113 ECHO_DEBUGPRINTF( ("CGMLDspCommObject::SetProfessionalSpdif to %s\n",
114 ( bNewStatus ) ? "Professional" : "Consumer") );
116 } // void CGMLDspCommObject::SetProfessionalSpdif( ... )
121 //===========================================================================
123 // SetSpdifOutNonAudio
125 // Set the state of the non-audio status bit in the S/PDIF out status bits
127 //===========================================================================
129 void CGMLDspCommObject::SetSpdifOutNonAudio(BOOL bNonAudio)
131 DWORD dwControlReg;
133 dwControlReg = GetControlRegister();
134 if (bNonAudio)
136 dwControlReg |= GML_SPDIF_NOT_AUDIO;
138 else
140 dwControlReg &= ~GML_SPDIF_NOT_AUDIO;
143 m_bNonAudio = bNonAudio;
145 WriteControlReg( dwControlReg );
150 //===========================================================================
152 // WriteControlReg
154 // Most configuration of Gina24, Layla24, or Mona is
155 // accomplished by writing the control register. WriteControlReg
156 // sends the new control register value to the DSP.
158 //===========================================================================
160 ECHOSTATUS CGMLDspCommObject::WriteControlReg
162 DWORD dwControlReg,
163 BOOL fForceWrite
166 ECHO_DEBUGPRINTF(("CGMLDspCommObject::WriteControlReg 0x%lx\n",dwControlReg));
168 if ( !m_bASICLoaded )
170 ECHO_DEBUGPRINTF(("CGMLDspCommObject::WriteControlReg - ASIC not loaded\n"));
171 return( ECHOSTATUS_ASIC_NOT_LOADED );
175 if ( !WaitForHandshake() )
177 ECHO_DEBUGPRINTF(("CGMLDspCommObject::WriteControlReg - no handshake\n"));
178 return ECHOSTATUS_DSP_DEAD;
181 #ifdef DIGITAL_INPUT_AUTO_MUTE_SUPPORT
183 // Handle the digital input auto-mute
185 if (TRUE == m_fDigitalInAutoMute)
186 dwControlReg |= GML_DIGITAL_IN_AUTO_MUTE;
187 else
188 dwControlReg &= ~GML_DIGITAL_IN_AUTO_MUTE;
189 #endif
192 // Write the control register
194 if (fForceWrite || (dwControlReg != GetControlRegister()) )
196 SetControlRegister( dwControlReg );
198 ECHO_DEBUGPRINTF( ("CGMLDspCommObject::WriteControlReg: Setting 0x%lx\n",
199 dwControlReg) );
201 ClearHandshake();
202 return SendVector( DSP_VC_WRITE_CONTROL_REG );
204 else
206 ECHO_DEBUGPRINTF( ("CGMLDspCommObject::WriteControlReg: control reg is already 0x%lx\n",
207 dwControlReg) );
210 return ECHOSTATUS_OK;
212 } // ECHOSTATUS CGMLDspCommObject::WriteControlReg( DWORD dwControlReg )
214 //===========================================================================
216 // SetDigitalMode
218 //===========================================================================
220 ECHOSTATUS CGMLDspCommObject::SetDigitalMode
222 BYTE byNewMode
225 WORD wInvalidClock;
228 // See if the current input clock doesn't match the new digital mode
230 switch (byNewMode)
232 case DIGITAL_MODE_SPDIF_RCA :
233 case DIGITAL_MODE_SPDIF_OPTICAL :
234 wInvalidClock = ECHO_CLOCK_ADAT;
235 break;
237 case DIGITAL_MODE_ADAT :
238 wInvalidClock = ECHO_CLOCK_SPDIF;
239 break;
241 default :
242 wInvalidClock = 0xffff;
243 break;
246 if (wInvalidClock == GetInputClock())
248 SetInputClock( ECHO_CLOCK_INTERNAL );
249 SetSampleRate( 48000 );
253 // Clear the current digital mode
255 DWORD dwControlReg;
257 dwControlReg = GetControlRegister();
258 dwControlReg &= GML_DIGITAL_MODE_CLEAR_MASK;
261 // Tweak the control reg
263 switch ( byNewMode )
265 case DIGITAL_MODE_SPDIF_RCA :
266 break;
268 case DIGITAL_MODE_SPDIF_OPTICAL :
269 dwControlReg |= GML_SPDIF_OPTICAL_MODE;
270 break;
272 case DIGITAL_MODE_ADAT :
273 dwControlReg |= GML_ADAT_MODE;
274 dwControlReg &= ~GML_DOUBLE_SPEED_MODE;
275 break;
277 default :
278 return ECHOSTATUS_DIGITAL_MODE_NOT_SUPPORTED;
282 // Write the control reg
284 WriteControlReg( dwControlReg );
286 m_byDigitalMode = byNewMode;
288 ECHO_DEBUGPRINTF( ("CGMLDspCommObject::SetDigitalMode to %ld\n",
289 (DWORD) m_byDigitalMode) );
291 return ECHOSTATUS_OK;
293 } // ECHOSTATUS CGMLDspCommObject::SetDigitalMode
296 // **** CGMLDspCommObject.cpp ****