xref: /haiku/src/add-ons/kernel/drivers/audio/echo/generic/CDarla24.cpp (revision d5cd5d63ff0ad395989db6cf4841a64d5b545d1d)
1 // ****************************************************************************
2 //
3 //		CDarla24.cpp
4 //
5 //		Implementation file for the CDarla24 driver class.
6 //		Set editor tabs to 3 for your viewing pleasure.
7 //
8 //		Copyright Echo Digital Audio Corporation (c) 1998 - 2002
9 //		All rights reserved
10 //		www.echoaudio.com
11 //
12 //		Permission is hereby granted, free of charge, to any person obtaining a
13 //		copy of this software and associated documentation files (the
14 //		"Software"), to deal with the Software without restriction, including
15 //		without limitation the rights to use, copy, modify, merge, publish,
16 //		distribute, sublicense, and/or sell copies of the Software, and to
17 //		permit persons to whom the Software is furnished to do so, subject to
18 //		the following conditions:
19 //
20 //		- Redistributions of source code must retain the above copyright
21 //		notice, this list of conditions and the following disclaimers.
22 //
23 //		- Redistributions in binary form must reproduce the above copyright
24 //		notice, this list of conditions and the following disclaimers in the
25 //		documentation and/or other materials provided with the distribution.
26 //
27 //		- Neither the name of Echo Digital Audio, nor the names of its
28 //		contributors may be used to endorse or promote products derived from
29 //		this Software without specific prior written permission.
30 //
31 //		THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
32 //		EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
33 //		MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
34 //		IN NO EVENT SHALL THE CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR
35 //		ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
36 //		TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
37 //		SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE SOFTWARE.
38 //
39 // ****************************************************************************
40 
41 #include "CDarla24.h"
42 
43 
44 /****************************************************************************
45 
46 	Construction and destruction
47 
48  ****************************************************************************/
49 
50 //===========================================================================
51 //
52 // Overload new & delete so memory for this object is allocated
53 //	from non-paged memory.
54 //
55 //===========================================================================
56 
57 PVOID CDarla24::operator new( size_t Size )
58 {
59 	PVOID 		pMemory;
60 	ECHOSTATUS 	Status;
61 
62 	Status = OsAllocateNonPaged(Size,&pMemory);
63 
64 	if ( (ECHOSTATUS_OK != Status) || (NULL == pMemory ))
65 	{
66 		ECHO_DEBUGPRINTF(("CDarla24::operator new - memory allocation failed\n"));
67 
68 		pMemory = NULL;
69 	}
70 	else
71 	{
72 		memset( pMemory, 0, Size );
73 	}
74 
75 	return pMemory;
76 
77 }	// PVOID CDarla24::operator new( size_t Size )
78 
79 
80 VOID  CDarla24::operator delete( PVOID pVoid )
81 {
82 	if ( ECHOSTATUS_OK != OsFreeNonPaged( pVoid ) )
83 	{
84 		ECHO_DEBUGPRINTF(("CDarla24::operator delete memory free failed\n"));
85 	}
86 }	// VOID CDarla24::operator delete( PVOID pVoid )
87 
88 
89 //===========================================================================
90 //
91 // Constructor and destructor
92 //
93 //===========================================================================
94 
95 CDarla24::CDarla24( PCOsSupport pOsSupport )
96 			: CEchoGals( pOsSupport )
97 {
98 	ECHO_DEBUGPRINTF( ( "CDarla24::CDarla24() is born!\n" ) );
99 }
100 
101 CDarla24::~CDarla24()
102 {
103 	ECHO_DEBUGPRINTF( ( "CDarla24::~CDarla24() is toast!\n" ) );
104 }
105 
106 
107 
108 
109 /****************************************************************************
110 
111 	Setup and hardware initialization
112 
113  ****************************************************************************/
114 
115 //===========================================================================
116 //
117 // Every card has an InitHw method
118 //
119 //===========================================================================
120 
121 ECHOSTATUS CDarla24::InitHw()
122 {
123 	ECHOSTATUS	Status;
124 	WORD			i;
125 
126 	//
127 	// Call the base method
128 	//
129 	if ( ECHOSTATUS_OK != ( Status = CEchoGals::InitHw() ) )
130 		return Status;
131 
132 	//
133 	// Create the DSP comm object
134 	//
135 	ASSERT( NULL == m_pDspCommObject );
136 	m_pDspCommObject = new CDarla24DspCommObject( (PDWORD) m_pvSharedMemory,
137 																 m_pOsSupport );
138 	if (NULL == m_pDspCommObject)
139 	{
140 		ECHO_DEBUGPRINTF(("CDarla24::InitHw - could not create DSP comm object\n"));
141 		return ECHOSTATUS_NO_MEM;
142 	}
143 
144 	//
145 	//	Load the DSP
146 	//
147 	GetDspCommObject()->LoadFirmware();
148 	if ( GetDspCommObject()->IsBoardBad() )
149 		return ECHOSTATUS_DSP_DEAD;
150 
151 	//
152 	// Clear the "bad board" flag; set the flag to indicate that
153 	// Darla24 can handle super-interleave.
154 	//
155 	m_wFlags &= ~ECHOGALS_FLAG_BADBOARD;
156 	m_wFlags |= ECHOGALS_ROFLAG_SUPER_INTERLEAVE_OK;
157 
158 	//
159 	//	Must call this here after DSP is init to
160 	//	init gains
161 	//
162 	Status = InitLineLevels();
163 	if ( ECHOSTATUS_OK != Status )
164 		return Status;
165 
166 	//
167 	// Set defaults for +4/-10
168 	//
169 	for (i = 0; i < GetNumBusses(); i++ )
170 	{
171 		GetDspCommObject()->SetNominalLevel( i, FALSE );	// FALSE is +4 here
172 	}
173 
174 	//
175 	//	Get default sample rate from DSP
176 	//
177 	m_dwSampleRate = GetDspCommObject()->GetSampleRate();
178 	ECHO_DEBUGPRINTF( ( "CDarla24::InitHw()\n" ) );
179 
180 	return Status;
181 
182 }	// ECHOSTATUS CDarla24::InitHw()
183 
184 
185 
186 
187 /****************************************************************************
188 
189 	Informational methods
190 
191  ****************************************************************************/
192 
193 //===========================================================================
194 //
195 // QueryAudioSampleRate is used to find out if this card can handle a
196 // given sample rate.
197 //
198 //===========================================================================
199 
200 ECHOSTATUS CDarla24::GetCapabilities
201 (
202 	PECHOGALS_CAPS	pCapabilities
203 )
204 {
205 	ECHOSTATUS	Status;
206 	WORD			i;
207 
208 	Status = GetBaseCapabilities(pCapabilities);
209 
210 	//
211 	// Add nominal level control to in & out busses
212 	//
213 	for (i = 0 ; i < GetNumBussesOut(); i++)
214 	{
215 		pCapabilities->dwBusOutCaps[i] |= ECHOCAPS_NOMINAL_LEVEL;
216 	}
217 
218 	for (i = 0 ; i < GetNumBussesIn(); i++)
219 	{
220 		pCapabilities->dwBusInCaps[i] |= ECHOCAPS_NOMINAL_LEVEL;
221 	}
222 
223 	if ( ECHOSTATUS_OK != Status )
224 		return Status;
225 
226 	pCapabilities->dwInClockTypes |= ECHO_CLOCK_BIT_ESYNC;
227 
228 	return Status;
229 
230 }	// ECHOSTATUS CDarla24::GetCapabilities
231 
232 
233 //===========================================================================
234 //
235 // GetInputClockDetect returns a bitmask consisting of all the input
236 // clocks currently connected to the hardware; this changes as the user
237 // connects and disconnects clock inputs.
238 //
239 // You should use this information to determine which clocks the user is
240 // allowed to select.
241 //
242 // Darla24 only supports Esync input clock.
243 //
244 //===========================================================================
245 
246 ECHOSTATUS CDarla24::GetInputClockDetect(DWORD &dwClockDetectBits)
247 {
248 	if ( NULL == GetDspCommObject() || GetDspCommObject()->IsBoardBad() )
249 	{
250 		ECHO_DEBUGPRINTF( ("CDarla24::GetInputClockDetect: DSP Dead!\n") );
251 		return ECHOSTATUS_DSP_DEAD;
252 	}
253 
254 	DWORD dwClocksFromDsp = GetDspCommObject()->GetInputClockDetect();
255 
256 	dwClockDetectBits = ECHO_CLOCK_BIT_INTERNAL;
257 
258 	if (0 != (dwClocksFromDsp & GLDM_CLOCK_DETECT_BIT_ESYNC))
259 		dwClockDetectBits |= ECHO_CLOCK_BIT_ESYNC;
260 
261 	return ECHOSTATUS_OK;
262 
263 }	// GetInputClockDetect
264 
265 
266 //===========================================================================
267 //
268 // QueryAudioSampleRate is used to find out if this card can handle a
269 // given sample rate.
270 //
271 //===========================================================================
272 
273 ECHOSTATUS CDarla24::QueryAudioSampleRate
274 (
275 	DWORD		dwSampleRate
276 )
277 {
278 	if ( dwSampleRate != 8000 &&
279 		  dwSampleRate != 11025 &&
280 		  dwSampleRate != 16000 &&
281 		  dwSampleRate != 22050 &&
282 		  dwSampleRate != 32000 &&
283 		  dwSampleRate != 44100 &&
284 		  dwSampleRate != 48000 &&
285 		  dwSampleRate != 88200 &&
286 		  dwSampleRate != 96000 )
287 	{
288 		ECHO_DEBUGPRINTF(
289 			("CDarla24::QueryAudioSampleRate() Sample rate must be 8,000 Hz,"
290 			 " 11,025 Hz, 16,000 Hz, 22,050 Hz, 32,000 Hz, 44,100 Hz, "
291 			 "48,000 Hz, 88,200 Hz or 96,000 Hz\n") );
292 		return ECHOSTATUS_BAD_FORMAT;
293 	}
294 
295 	ECHO_DEBUGPRINTF( ( "CDarla24::QueryAudioSampleRate()\n" ) );
296 	return ECHOSTATUS_OK;
297 
298 }	// ECHOSTATUS CDarla24::QueryAudioSampleRate
299 
300 
301 // *** CDarla24.cpp ***
302