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// ----------------------------------------------------------------------------
9//
10// This file is part of Echo Digital Audio's generic driver library.
11// Copyright Echo Digital Audio Corporation (c) 1998 - 2005
12// All rights reserved
13// www.echoaudio.com
14//
15// This library is free software; you can redistribute it and/or
16// modify it under the terms of the GNU Lesser General Public
17// License as published by the Free Software Foundation; either
18// version 2.1 of the License, or (at your option) any later version.
19//
20// This library is distributed in the hope that it will be useful,
21// but WITHOUT ANY WARRANTY; without even the implied warranty of
22// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
23// Lesser General Public License for more details.
24//
25// You should have received a copy of the GNU Lesser General Public
26// License along with this library; if not, write to the Free Software
27// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
28//
29// ****************************************************************************
30
31#include "CDarla24.h"
32
33#define DARLA24_ANALOG_OUTPUT_LATENCY	59
34#define DARLA24_ANALOG_INPUT_LATENCY	71
35
36
37/****************************************************************************
38
39	Construction and destruction
40
41 ****************************************************************************/
42
43//===========================================================================
44//
45// Overload new & delete so memory for this object is allocated
46//	from non-paged memory.
47//
48//===========================================================================
49
50PVOID CDarla24::operator new( size_t Size )
51{
52	PVOID 		pMemory;
53	ECHOSTATUS 	Status;
54
55	Status = OsAllocateNonPaged(Size,&pMemory);
56
57	if ( (ECHOSTATUS_OK != Status) || (NULL == pMemory ))
58	{
59		ECHO_DEBUGPRINTF(("CDarla24::operator new - memory allocation failed\n"));
60
61		pMemory = NULL;
62	}
63	else
64	{
65		memset( pMemory, 0, Size );
66	}
67
68	return pMemory;
69
70}	// PVOID CDarla24::operator new( size_t Size )
71
72
73VOID  CDarla24::operator delete( PVOID pVoid )
74{
75	if ( ECHOSTATUS_OK != OsFreeNonPaged( pVoid ) )
76	{
77		ECHO_DEBUGPRINTF(("CDarla24::operator delete memory free failed\n"));
78	}
79}	// VOID CDarla24::operator delete( PVOID pVoid )
80
81
82//===========================================================================
83//
84// Constructor and destructor
85//
86//===========================================================================
87
88CDarla24::CDarla24( PCOsSupport pOsSupport )
89			: CEchoGals( pOsSupport )
90{
91	ECHO_DEBUGPRINTF( ( "CDarla24::CDarla24() is born!\n" ) );
92
93	m_wAnalogOutputLatency = DARLA24_ANALOG_OUTPUT_LATENCY;
94	m_wAnalogInputLatency = DARLA24_ANALOG_INPUT_LATENCY;
95
96}
97
98CDarla24::~CDarla24()
99{
100	ECHO_DEBUGPRINTF( ( "CDarla24::~CDarla24() is toast!\n" ) );
101}
102
103
104
105
106/****************************************************************************
107
108	Setup and hardware initialization
109
110 ****************************************************************************/
111
112//===========================================================================
113//
114// Every card has an InitHw method
115//
116//===========================================================================
117
118ECHOSTATUS CDarla24::InitHw()
119{
120	ECHOSTATUS	Status;
121	WORD			i;
122
123	//
124	// Call the base method
125	//
126	if ( ECHOSTATUS_OK != ( Status = CEchoGals::InitHw() ) )
127		return Status;
128
129	//
130	// Create the DSP comm object
131	//
132	ECHO_ASSERT(NULL == m_pDspCommObject );
133	m_pDspCommObject = new CDarla24DspCommObject( (PDWORD) m_pvSharedMemory,
134																 m_pOsSupport );
135	if (NULL == m_pDspCommObject)
136	{
137		ECHO_DEBUGPRINTF(("CDarla24::InitHw - could not create DSP comm object\n"));
138		return ECHOSTATUS_NO_MEM;
139	}
140
141	//
142	//	Load the DSP
143	//
144	GetDspCommObject()->LoadFirmware();
145	if ( GetDspCommObject()->IsBoardBad() )
146		return ECHOSTATUS_DSP_DEAD;
147
148	//
149	// Clear the "bad board" flag; set the flag to indicate that
150	// Darla24 can handle super-interleave.
151	//
152	m_wFlags &= ~ECHOGALS_FLAG_BADBOARD;
153	m_wFlags |= ECHOGALS_ROFLAG_SUPER_INTERLEAVE_OK;
154
155	//
156	//	Must call this here after DSP is init to
157	//	init gains
158	//
159	Status = InitLineLevels();
160	if ( ECHOSTATUS_OK != Status )
161		return Status;
162
163	//
164	// Set defaults for +4/-10
165	//
166	for (i = 0; i < GetNumBusses(); i++ )
167	{
168		GetDspCommObject()->SetNominalLevel( i, FALSE );	// FALSE is +4 here
169	}
170
171	//
172	//	Get default sample rate from DSP
173	//
174	m_dwSampleRate = GetDspCommObject()->GetSampleRate();
175	ECHO_DEBUGPRINTF( ( "CDarla24::InitHw()\n" ) );
176
177	return Status;
178
179}	// ECHOSTATUS CDarla24::InitHw()
180
181
182
183
184/****************************************************************************
185
186	Informational methods
187
188 ****************************************************************************/
189
190//===========================================================================
191//
192// Override GetCapabilities to enumerate unique capabilties for this card
193//
194//===========================================================================
195
196ECHOSTATUS CDarla24::GetCapabilities
197(
198	PECHOGALS_CAPS	pCapabilities
199)
200{
201	ECHOSTATUS	Status;
202	WORD			i;
203
204	Status = GetBaseCapabilities(pCapabilities);
205
206	//
207	// Add nominal level control to in & out busses
208	//
209	for (i = 0 ; i < GetNumBussesOut(); i++)
210	{
211		pCapabilities->dwBusOutCaps[i] |= ECHOCAPS_NOMINAL_LEVEL;
212	}
213
214	for (i = 0 ; i < GetNumBussesIn(); i++)
215	{
216		pCapabilities->dwBusInCaps[i] |= ECHOCAPS_NOMINAL_LEVEL;
217	}
218
219	if ( ECHOSTATUS_OK != Status )
220		return Status;
221
222	pCapabilities->dwInClockTypes |= ECHO_CLOCK_BIT_ESYNC;
223
224	return Status;
225
226}	// ECHOSTATUS CDarla24::GetCapabilities
227
228
229//===========================================================================
230//
231// GetInputClockDetect returns a bitmask consisting of all the input
232// clocks currently connected to the hardware; this changes as the user
233// connects and disconnects clock inputs.
234//
235// You should use this information to determine which clocks the user is
236// allowed to select.
237//
238// Darla24 only supports Esync input clock.
239//
240//===========================================================================
241
242ECHOSTATUS CDarla24::GetInputClockDetect(DWORD &dwClockDetectBits)
243{
244	if ( NULL == GetDspCommObject() || GetDspCommObject()->IsBoardBad() )
245	{
246		ECHO_DEBUGPRINTF( ("CDarla24::GetInputClockDetect: DSP Dead!\n") );
247		return ECHOSTATUS_DSP_DEAD;
248	}
249
250	DWORD dwClocksFromDsp = GetDspCommObject()->GetInputClockDetect();
251
252	dwClockDetectBits = ECHO_CLOCK_BIT_INTERNAL;
253
254	if (0 != (dwClocksFromDsp & GLDM_CLOCK_DETECT_BIT_ESYNC))
255		dwClockDetectBits |= ECHO_CLOCK_BIT_ESYNC;
256
257	return ECHOSTATUS_OK;
258
259}	// GetInputClockDetect
260
261
262//===========================================================================
263//
264// QueryAudioSampleRate is used to find out if this card can handle a
265// given sample rate.
266//
267//===========================================================================
268
269ECHOSTATUS CDarla24::QueryAudioSampleRate
270(
271	DWORD		dwSampleRate
272)
273{
274	if ( dwSampleRate != 8000 &&
275		  dwSampleRate != 11025 &&
276		  dwSampleRate != 16000 &&
277		  dwSampleRate != 22050 &&
278		  dwSampleRate != 32000 &&
279		  dwSampleRate != 44100 &&
280		  dwSampleRate != 48000 &&
281		  dwSampleRate != 88200 &&
282		  dwSampleRate != 96000 )
283	{
284		ECHO_DEBUGPRINTF(
285			("CDarla24::QueryAudioSampleRate() - rate %ld invalid\n",
286			dwSampleRate) );
287		return ECHOSTATUS_BAD_FORMAT;
288	}
289
290	ECHO_DEBUGPRINTF( ( "CDarla24::QueryAudioSampleRate()\n" ) );
291	return ECHOSTATUS_OK;
292
293}	// ECHOSTATUS CDarla24::QueryAudioSampleRate
294
295void CDarla24::QuerySampleRateRange(DWORD &dwMinRate,DWORD &dwMaxRate)
296{
297	dwMinRate = 8000;
298	dwMaxRate = 96000;
299}
300
301
302
303// *** CDarla24.cpp ***
304