1626bc4beSJérôme Duval// ****************************************************************************
2626bc4beSJérôme Duval//
3626bc4beSJérôme Duval//		CDarla24.cpp
4626bc4beSJérôme Duval//
5626bc4beSJérôme Duval//		Implementation file for the CDarla24 driver class.
6626bc4beSJérôme Duval//		Set editor tabs to 3 for your viewing pleasure.
7626bc4beSJérôme Duval//
8626bc4beSJérôme Duval// ----------------------------------------------------------------------------
9626bc4beSJérôme Duval//
10626bc4beSJérôme Duval// This file is part of Echo Digital Audio's generic driver library.
11626bc4beSJérôme Duval// Copyright Echo Digital Audio Corporation (c) 1998 - 2005
12626bc4beSJérôme Duval// All rights reserved
13626bc4beSJérôme Duval// www.echoaudio.com
14626bc4beSJérôme Duval//
15626bc4beSJérôme Duval// This library is free software; you can redistribute it and/or
16626bc4beSJérôme Duval// modify it under the terms of the GNU Lesser General Public
17626bc4beSJérôme Duval// License as published by the Free Software Foundation; either
18626bc4beSJérôme Duval// version 2.1 of the License, or (at your option) any later version.
19626bc4beSJérôme Duval//
20626bc4beSJérôme Duval// This library is distributed in the hope that it will be useful,
21626bc4beSJérôme Duval// but WITHOUT ANY WARRANTY; without even the implied warranty of
22626bc4beSJérôme Duval// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
23626bc4beSJérôme Duval// Lesser General Public License for more details.
24626bc4beSJérôme Duval//
25626bc4beSJérôme Duval// You should have received a copy of the GNU Lesser General Public
26626bc4beSJérôme Duval// License along with this library; if not, write to the Free Software
27626bc4beSJérôme Duval// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
28626bc4beSJérôme Duval//
29626bc4beSJérôme Duval// ****************************************************************************
30626bc4beSJérôme Duval
31626bc4beSJérôme Duval#include "CDarla24.h"
32626bc4beSJérôme Duval
33626bc4beSJérôme Duval#define DARLA24_ANALOG_OUTPUT_LATENCY	59
34626bc4beSJérôme Duval#define DARLA24_ANALOG_INPUT_LATENCY	71
35626bc4beSJérôme Duval
36626bc4beSJérôme Duval
37626bc4beSJérôme Duval/****************************************************************************
38626bc4beSJérôme Duval
39626bc4beSJérôme Duval	Construction and destruction
40626bc4beSJérôme Duval
41626bc4beSJérôme Duval ****************************************************************************/
42626bc4beSJérôme Duval
43626bc4beSJérôme Duval//===========================================================================
44626bc4beSJérôme Duval//
45626bc4beSJérôme Duval// Overload new & delete so memory for this object is allocated
46626bc4beSJérôme Duval//	from non-paged memory.
47626bc4beSJérôme Duval//
48626bc4beSJérôme Duval//===========================================================================
49626bc4beSJérôme Duval
50626bc4beSJérôme DuvalPVOID CDarla24::operator new( size_t Size )
51626bc4beSJérôme Duval{
52626bc4beSJérôme Duval	PVOID 		pMemory;
53626bc4beSJérôme Duval	ECHOSTATUS 	Status;
54626bc4beSJérôme Duval
55626bc4beSJérôme Duval	Status = OsAllocateNonPaged(Size,&pMemory);
56626bc4beSJérôme Duval
57626bc4beSJérôme Duval	if ( (ECHOSTATUS_OK != Status) || (NULL == pMemory ))
58626bc4beSJérôme Duval	{
59626bc4beSJérôme Duval		ECHO_DEBUGPRINTF(("CDarla24::operator new - memory allocation failed\n"));
60626bc4beSJérôme Duval
61626bc4beSJérôme Duval		pMemory = NULL;
62626bc4beSJérôme Duval	}
63626bc4beSJérôme Duval	else
64626bc4beSJérôme Duval	{
65626bc4beSJérôme Duval		memset( pMemory, 0, Size );
66626bc4beSJérôme Duval	}
67626bc4beSJérôme Duval
68626bc4beSJérôme Duval	return pMemory;
69626bc4beSJérôme Duval
70626bc4beSJérôme Duval}	// PVOID CDarla24::operator new( size_t Size )
71626bc4beSJérôme Duval
72626bc4beSJérôme Duval
73626bc4beSJérôme DuvalVOID  CDarla24::operator delete( PVOID pVoid )
74626bc4beSJérôme Duval{
75626bc4beSJérôme Duval	if ( ECHOSTATUS_OK != OsFreeNonPaged( pVoid ) )
76626bc4beSJérôme Duval	{
77626bc4beSJérôme Duval		ECHO_DEBUGPRINTF(("CDarla24::operator delete memory free failed\n"));
78626bc4beSJérôme Duval	}
79626bc4beSJérôme Duval}	// VOID CDarla24::operator delete( PVOID pVoid )
80626bc4beSJérôme Duval
81626bc4beSJérôme Duval
82626bc4beSJérôme Duval//===========================================================================
83626bc4beSJérôme Duval//
84626bc4beSJérôme Duval// Constructor and destructor
85626bc4beSJérôme Duval//
86626bc4beSJérôme Duval//===========================================================================
87626bc4beSJérôme Duval
88626bc4beSJérôme DuvalCDarla24::CDarla24( PCOsSupport pOsSupport )
89626bc4beSJérôme Duval			: CEchoGals( pOsSupport )
90626bc4beSJérôme Duval{
91626bc4beSJérôme Duval	ECHO_DEBUGPRINTF( ( "CDarla24::CDarla24() is born!\n" ) );
92626bc4beSJérôme Duval
93626bc4beSJérôme Duval	m_wAnalogOutputLatency = DARLA24_ANALOG_OUTPUT_LATENCY;
94626bc4beSJérôme Duval	m_wAnalogInputLatency = DARLA24_ANALOG_INPUT_LATENCY;
95626bc4beSJérôme Duval
96626bc4beSJérôme Duval}
97626bc4beSJérôme Duval
98626bc4beSJérôme DuvalCDarla24::~CDarla24()
99626bc4beSJérôme Duval{
100626bc4beSJérôme Duval	ECHO_DEBUGPRINTF( ( "CDarla24::~CDarla24() is toast!\n" ) );
101626bc4beSJérôme Duval}
102626bc4beSJérôme Duval
103626bc4beSJérôme Duval
104626bc4beSJérôme Duval
105626bc4beSJérôme Duval
106626bc4beSJérôme Duval/****************************************************************************
107626bc4beSJérôme Duval
108626bc4beSJérôme Duval	Setup and hardware initialization
109626bc4beSJérôme Duval
110626bc4beSJérôme Duval ****************************************************************************/
111626bc4beSJérôme Duval
112626bc4beSJérôme Duval//===========================================================================
113626bc4beSJérôme Duval//
114626bc4beSJérôme Duval// Every card has an InitHw method
115626bc4beSJérôme Duval//
116626bc4beSJérôme Duval//===========================================================================
117626bc4beSJérôme Duval
118626bc4beSJérôme DuvalECHOSTATUS CDarla24::InitHw()
119626bc4beSJérôme Duval{
120626bc4beSJérôme Duval	ECHOSTATUS	Status;
121626bc4beSJérôme Duval	WORD			i;
122626bc4beSJérôme Duval
123626bc4beSJérôme Duval	//
124626bc4beSJérôme Duval	// Call the base method
125626bc4beSJérôme Duval	//
126626bc4beSJérôme Duval	if ( ECHOSTATUS_OK != ( Status = CEchoGals::InitHw() ) )
127626bc4beSJérôme Duval		return Status;
128626bc4beSJérôme Duval
129626bc4beSJérôme Duval	//
130626bc4beSJérôme Duval	// Create the DSP comm object
131626bc4beSJérôme Duval	//
1324dd9e436SJérôme Duval	ECHO_ASSERT(NULL == m_pDspCommObject );
133626bc4beSJérôme Duval	m_pDspCommObject = new CDarla24DspCommObject( (PDWORD) m_pvSharedMemory,
134626bc4beSJérôme Duval																 m_pOsSupport );
135626bc4beSJérôme Duval	if (NULL == m_pDspCommObject)
136626bc4beSJérôme Duval	{
137626bc4beSJérôme Duval		ECHO_DEBUGPRINTF(("CDarla24::InitHw - could not create DSP comm object\n"));
138626bc4beSJérôme Duval		return ECHOSTATUS_NO_MEM;
139626bc4beSJérôme Duval	}
140626bc4beSJérôme Duval
141626bc4beSJérôme Duval	//
142626bc4beSJérôme Duval	//	Load the DSP
143626bc4beSJérôme Duval	//
144626bc4beSJérôme Duval	GetDspCommObject()->LoadFirmware();
145626bc4beSJérôme Duval	if ( GetDspCommObject()->IsBoardBad() )
146626bc4beSJérôme Duval		return ECHOSTATUS_DSP_DEAD;
147626bc4beSJérôme Duval
148626bc4beSJérôme Duval	//
149626bc4beSJérôme Duval	// Clear the "bad board" flag; set the flag to indicate that
150626bc4beSJérôme Duval	// Darla24 can handle super-interleave.
151626bc4beSJérôme Duval	//
152626bc4beSJérôme Duval	m_wFlags &= ~ECHOGALS_FLAG_BADBOARD;
153626bc4beSJérôme Duval	m_wFlags |= ECHOGALS_ROFLAG_SUPER_INTERLEAVE_OK;
154626bc4beSJérôme Duval
155626bc4beSJérôme Duval	//
156626bc4beSJérôme Duval	//	Must call this here after DSP is init to
157626bc4beSJérôme Duval	//	init gains
158626bc4beSJérôme Duval	//
159626bc4beSJérôme Duval	Status = InitLineLevels();
160626bc4beSJérôme Duval	if ( ECHOSTATUS_OK != Status )
161626bc4beSJérôme Duval		return Status;
162626bc4beSJérôme Duval
163626bc4beSJérôme Duval	//
164626bc4beSJérôme Duval	// Set defaults for +4/-10
165626bc4beSJérôme Duval	//
166626bc4beSJérôme Duval	for (i = 0; i < GetNumBusses(); i++ )
167626bc4beSJérôme Duval	{
168626bc4beSJérôme Duval		GetDspCommObject()->SetNominalLevel( i, FALSE );	// FALSE is +4 here
169626bc4beSJérôme Duval	}
170626bc4beSJérôme Duval
171626bc4beSJérôme Duval	//
172626bc4beSJérôme Duval	//	Get default sample rate from DSP
173626bc4beSJérôme Duval	//
174626bc4beSJérôme Duval	m_dwSampleRate = GetDspCommObject()->GetSampleRate();
175626bc4beSJérôme Duval	ECHO_DEBUGPRINTF( ( "CDarla24::InitHw()\n" ) );
176626bc4beSJérôme Duval
177626bc4beSJérôme Duval	return Status;
178626bc4beSJérôme Duval
179626bc4beSJérôme Duval}	// ECHOSTATUS CDarla24::InitHw()
180626bc4beSJérôme Duval
181626bc4beSJérôme Duval
182626bc4beSJérôme Duval
183626bc4beSJérôme Duval
184626bc4beSJérôme Duval/****************************************************************************
185626bc4beSJérôme Duval
186626bc4beSJérôme Duval	Informational methods
187626bc4beSJérôme Duval
188626bc4beSJérôme Duval ****************************************************************************/
189626bc4beSJérôme Duval
190626bc4beSJérôme Duval//===========================================================================
191626bc4beSJérôme Duval//
192626bc4beSJérôme Duval// Override GetCapabilities to enumerate unique capabilties for this card
193626bc4beSJérôme Duval//
194626bc4beSJérôme Duval//===========================================================================
195626bc4beSJérôme Duval
196626bc4beSJérôme DuvalECHOSTATUS CDarla24::GetCapabilities
197626bc4beSJérôme Duval(
198626bc4beSJérôme Duval	PECHOGALS_CAPS	pCapabilities
199626bc4beSJérôme Duval)
200626bc4beSJérôme Duval{
201626bc4beSJérôme Duval	ECHOSTATUS	Status;
202626bc4beSJérôme Duval	WORD			i;
203626bc4beSJérôme Duval
204626bc4beSJérôme Duval	Status = GetBaseCapabilities(pCapabilities);
205626bc4beSJérôme Duval
206626bc4beSJérôme Duval	//
207626bc4beSJérôme Duval	// Add nominal level control to in & out busses
208626bc4beSJérôme Duval	//
209626bc4beSJérôme Duval	for (i = 0 ; i < GetNumBussesOut(); i++)
210626bc4beSJérôme Duval	{
211626bc4beSJérôme Duval		pCapabilities->dwBusOutCaps[i] |= ECHOCAPS_NOMINAL_LEVEL;
212626bc4beSJérôme Duval	}
213626bc4beSJérôme Duval
214626bc4beSJérôme Duval	for (i = 0 ; i < GetNumBussesIn(); i++)
215626bc4beSJérôme Duval	{
216626bc4beSJérôme Duval		pCapabilities->dwBusInCaps[i] |= ECHOCAPS_NOMINAL_LEVEL;
217626bc4beSJérôme Duval	}
218626bc4beSJérôme Duval
219626bc4beSJérôme Duval	if ( ECHOSTATUS_OK != Status )
220626bc4beSJérôme Duval		return Status;
221626bc4beSJérôme Duval
222626bc4beSJérôme Duval	pCapabilities->dwInClockTypes |= ECHO_CLOCK_BIT_ESYNC;
223626bc4beSJérôme Duval
224626bc4beSJérôme Duval	return Status;
225626bc4beSJérôme Duval
226626bc4beSJérôme Duval}	// ECHOSTATUS CDarla24::GetCapabilities
227626bc4beSJérôme Duval
228626bc4beSJérôme Duval
229626bc4beSJérôme Duval//===========================================================================
230626bc4beSJérôme Duval//
231626bc4beSJérôme Duval// GetInputClockDetect returns a bitmask consisting of all the input
232626bc4beSJérôme Duval// clocks currently connected to the hardware; this changes as the user
233626bc4beSJérôme Duval// connects and disconnects clock inputs.
234626bc4beSJérôme Duval//
235626bc4beSJérôme Duval// You should use this information to determine which clocks the user is
236626bc4beSJérôme Duval// allowed to select.
237626bc4beSJérôme Duval//
238626bc4beSJérôme Duval// Darla24 only supports Esync input clock.
239626bc4beSJérôme Duval//
240626bc4beSJérôme Duval//===========================================================================
241626bc4beSJérôme Duval
242626bc4beSJérôme DuvalECHOSTATUS CDarla24::GetInputClockDetect(DWORD &dwClockDetectBits)
243626bc4beSJérôme Duval{
244626bc4beSJérôme Duval	if ( NULL == GetDspCommObject() || GetDspCommObject()->IsBoardBad() )
245626bc4beSJérôme Duval	{
246626bc4beSJérôme Duval		ECHO_DEBUGPRINTF( ("CDarla24::GetInputClockDetect: DSP Dead!\n") );
247626bc4beSJérôme Duval		return ECHOSTATUS_DSP_DEAD;
248626bc4beSJérôme Duval	}
249626bc4beSJérôme Duval
250626bc4beSJérôme Duval	DWORD dwClocksFromDsp = GetDspCommObject()->GetInputClockDetect();
251626bc4beSJérôme Duval
252626bc4beSJérôme Duval	dwClockDetectBits = ECHO_CLOCK_BIT_INTERNAL;
253626bc4beSJérôme Duval
254626bc4beSJérôme Duval	if (0 != (dwClocksFromDsp & GLDM_CLOCK_DETECT_BIT_ESYNC))
255626bc4beSJérôme Duval		dwClockDetectBits |= ECHO_CLOCK_BIT_ESYNC;
256626bc4beSJérôme Duval
257626bc4beSJérôme Duval	return ECHOSTATUS_OK;
258626bc4beSJérôme Duval
259626bc4beSJérôme Duval}	// GetInputClockDetect
260626bc4beSJérôme Duval
261626bc4beSJérôme Duval
262626bc4beSJérôme Duval//===========================================================================
263626bc4beSJérôme Duval//
264626bc4beSJérôme Duval// QueryAudioSampleRate is used to find out if this card can handle a
265626bc4beSJérôme Duval// given sample rate.
266626bc4beSJérôme Duval//
267626bc4beSJérôme Duval//===========================================================================
268626bc4beSJérôme Duval
269626bc4beSJérôme DuvalECHOSTATUS CDarla24::QueryAudioSampleRate
270626bc4beSJérôme Duval(
271626bc4beSJérôme Duval	DWORD		dwSampleRate
272626bc4beSJérôme Duval)
273626bc4beSJérôme Duval{
274626bc4beSJérôme Duval	if ( dwSampleRate != 8000 &&
275626bc4beSJérôme Duval		  dwSampleRate != 11025 &&
276626bc4beSJérôme Duval		  dwSampleRate != 16000 &&
277626bc4beSJérôme Duval		  dwSampleRate != 22050 &&
278626bc4beSJérôme Duval		  dwSampleRate != 32000 &&
279626bc4beSJérôme Duval		  dwSampleRate != 44100 &&
280626bc4beSJérôme Duval		  dwSampleRate != 48000 &&
281626bc4beSJérôme Duval		  dwSampleRate != 88200 &&
282626bc4beSJérôme Duval		  dwSampleRate != 96000 )
283626bc4beSJérôme Duval	{
284626bc4beSJérôme Duval		ECHO_DEBUGPRINTF(
285626bc4beSJérôme Duval			("CDarla24::QueryAudioSampleRate() - rate %ld invalid\n",
286626bc4beSJérôme Duval			dwSampleRate) );
287626bc4beSJérôme Duval		return ECHOSTATUS_BAD_FORMAT;
288626bc4beSJérôme Duval	}
289626bc4beSJérôme Duval
290626bc4beSJérôme Duval	ECHO_DEBUGPRINTF( ( "CDarla24::QueryAudioSampleRate()\n" ) );
291626bc4beSJérôme Duval	return ECHOSTATUS_OK;
292626bc4beSJérôme Duval
293626bc4beSJérôme Duval}	// ECHOSTATUS CDarla24::QueryAudioSampleRate
294626bc4beSJérôme Duval
2954dd9e436SJérôme Duvalvoid CDarla24::QuerySampleRateRange(DWORD &dwMinRate,DWORD &dwMaxRate)
2964dd9e436SJérôme Duval{
2974dd9e436SJérôme Duval	dwMinRate = 8000;
2984dd9e436SJérôme Duval	dwMaxRate = 96000;
2994dd9e436SJérôme Duval}
3004dd9e436SJérôme Duval
3014dd9e436SJérôme Duval
302626bc4beSJérôme Duval
303626bc4beSJérôme Duval// *** CDarla24.cpp ***
304