1626bc4beSJérôme Duval// ****************************************************************************
2626bc4beSJérôme Duval//
3626bc4beSJérôme Duval//		CDarla.cpp
4626bc4beSJérôme Duval//
5626bc4beSJérôme Duval//		Implementation file for the CDarla driver class; this supports 20 bit
6626bc4beSJérôme Duval//		Darla, not Darla24.
7626bc4beSJérôme Duval//
8626bc4beSJérôme Duval//		Set editor tabs to 3 for your viewing pleasure.
9626bc4beSJérôme Duval//
10626bc4beSJérôme Duval// ----------------------------------------------------------------------------
11626bc4beSJérôme Duval//
12626bc4beSJérôme Duval// This file is part of Echo Digital Audio's generic driver library.
13626bc4beSJérôme Duval// Copyright Echo Digital Audio Corporation (c) 1998 - 2005
14626bc4beSJérôme Duval// All rights reserved
15626bc4beSJérôme Duval// www.echoaudio.com
16626bc4beSJérôme Duval//
17626bc4beSJérôme Duval// This library is free software; you can redistribute it and/or
18626bc4beSJérôme Duval// modify it under the terms of the GNU Lesser General Public
19626bc4beSJérôme Duval// License as published by the Free Software Foundation; either
20626bc4beSJérôme Duval// version 2.1 of the License, or (at your option) any later version.
21626bc4beSJérôme Duval//
22626bc4beSJérôme Duval// This library is distributed in the hope that it will be useful,
23626bc4beSJérôme Duval// but WITHOUT ANY WARRANTY; without even the implied warranty of
24626bc4beSJérôme Duval// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
25626bc4beSJérôme Duval// Lesser General Public License for more details.
26626bc4beSJérôme Duval//
27626bc4beSJérôme Duval// You should have received a copy of the GNU Lesser General Public
28626bc4beSJérôme Duval// License along with this library; if not, write to the Free Software
29626bc4beSJérôme Duval// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
30626bc4beSJérôme Duval//
31626bc4beSJérôme Duval// ****************************************************************************
32626bc4beSJérôme Duval
33626bc4beSJérôme Duval#include "CDarla.h"
34626bc4beSJérôme Duval
35626bc4beSJérôme Duval#define DARLA20_ANALOG_OUTPUT_LATENCY	137
36626bc4beSJérôme Duval#define DARLA20_ANALOG_INPUT_LATENCY	240
37626bc4beSJérôme Duval
38626bc4beSJérôme Duval
39626bc4beSJérôme Duval/****************************************************************************
40626bc4beSJérôme Duval
41626bc4beSJérôme Duval	Construction and destruction
42626bc4beSJérôme Duval
43626bc4beSJérôme Duval ****************************************************************************/
44626bc4beSJérôme Duval
45626bc4beSJérôme Duval//===========================================================================
46626bc4beSJérôme Duval//
47626bc4beSJérôme Duval// Overload new & delete so memory for this object is allocated
48626bc4beSJérôme Duval//	from non-paged memory.
49626bc4beSJérôme Duval//
50626bc4beSJérôme Duval//===========================================================================
51626bc4beSJérôme Duval
52626bc4beSJérôme DuvalPVOID CDarla::operator new( size_t Size )
53626bc4beSJérôme Duval{
54626bc4beSJérôme Duval	PVOID 		pMemory;
55626bc4beSJérôme Duval	ECHOSTATUS 	Status;
56626bc4beSJérôme Duval
57626bc4beSJérôme Duval	Status = OsAllocateNonPaged(Size,&pMemory);
58626bc4beSJérôme Duval
59626bc4beSJérôme Duval	if ( (ECHOSTATUS_OK != Status) || (NULL == pMemory ))
60626bc4beSJérôme Duval	{
61626bc4beSJérôme Duval		ECHO_DEBUGPRINTF(("CDarla::operator new - memory allocation failed\n"));
62626bc4beSJérôme Duval
63626bc4beSJérôme Duval		pMemory = NULL;
64626bc4beSJérôme Duval	}
65626bc4beSJérôme Duval	else
66626bc4beSJérôme Duval	{
67626bc4beSJérôme Duval		memset( pMemory, 0, Size );
68626bc4beSJérôme Duval	}
69626bc4beSJérôme Duval
70626bc4beSJérôme Duval	return pMemory;
71626bc4beSJérôme Duval
72626bc4beSJérôme Duval}	// PVOID CDarla::operator new( size_t Size )
73626bc4beSJérôme Duval
74626bc4beSJérôme Duval
75626bc4beSJérôme DuvalVOID  CDarla::operator delete( PVOID pVoid )
76626bc4beSJérôme Duval{
77626bc4beSJérôme Duval	if ( ECHOSTATUS_OK != OsFreeNonPaged( pVoid ) )
78626bc4beSJérôme Duval	{
79626bc4beSJérôme Duval		ECHO_DEBUGPRINTF(("CDarla::operator delete memory free failed\n"));
80626bc4beSJérôme Duval	}
81626bc4beSJérôme Duval}	// VOID  CDarla::operator delete( PVOID pVoid )
82626bc4beSJérôme Duval
83626bc4beSJérôme Duval
84626bc4beSJérôme Duval//===========================================================================
85626bc4beSJérôme Duval//
86626bc4beSJérôme Duval// Constructor and destructor
87626bc4beSJérôme Duval//
88626bc4beSJérôme Duval//===========================================================================
89626bc4beSJérôme Duval
90626bc4beSJérôme DuvalCDarla::CDarla( PCOsSupport pOsSupport )
91626bc4beSJérôme Duval		: CEchoGals( pOsSupport )
92626bc4beSJérôme Duval{
93626bc4beSJérôme Duval	ECHO_DEBUGPRINTF( ( "CDarla::CDarla() is born!\n" ) );
94626bc4beSJérôme Duval
95626bc4beSJérôme Duval	m_wAnalogOutputLatency = DARLA20_ANALOG_OUTPUT_LATENCY;
96626bc4beSJérôme Duval	m_wAnalogInputLatency = DARLA20_ANALOG_INPUT_LATENCY;
97626bc4beSJérôme Duval}
98626bc4beSJérôme Duval
99626bc4beSJérôme DuvalCDarla::~CDarla()
100626bc4beSJérôme Duval{
101626bc4beSJérôme Duval	ECHO_DEBUGPRINTF( ( "CDarla::~CDarla() is toast!\n" ) );
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
109626bc4beSJérôme Duval	Setup and hardware initialization
110626bc4beSJérôme Duval
111626bc4beSJérôme Duval ****************************************************************************/
112626bc4beSJérôme Duval
113626bc4beSJérôme Duval//===========================================================================
114626bc4beSJérôme Duval//
115626bc4beSJérôme Duval// Every card has an InitHw method
116626bc4beSJérôme Duval//
117626bc4beSJérôme Duval//===========================================================================
118626bc4beSJérôme Duval
119626bc4beSJérôme DuvalECHOSTATUS CDarla::InitHw()
120626bc4beSJérôme Duval{
121626bc4beSJérôme Duval	ECHOSTATUS	Status;
122626bc4beSJérôme Duval
123626bc4beSJérôme Duval	//
124626bc4beSJérôme Duval	// Call the base InitHw 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 CDarlaDspCommObject( (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(("CDarla::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
150626bc4beSJérôme Duval	//
151626bc4beSJérôme Duval	m_wFlags &= ~ECHOGALS_FLAG_BADBOARD;
152626bc4beSJérôme Duval
153626bc4beSJérôme Duval	//
154626bc4beSJérôme Duval	//	Must call this here *after* DSP is init
155626bc4beSJérôme Duval	//
156626bc4beSJérôme Duval	Status = InitLineLevels();
157626bc4beSJérôme Duval
158626bc4beSJérôme Duval	//
159626bc4beSJérôme Duval	//	Get default sample rate from DSP
160626bc4beSJérôme Duval	//
161626bc4beSJérôme Duval	m_dwSampleRate = GetDspCommObject()->GetSampleRate();
162626bc4beSJérôme Duval
163626bc4beSJérôme Duval	ECHO_DEBUGPRINTF( ( "CDarla::InitHw()\n" ) );
164626bc4beSJérôme Duval
165626bc4beSJérôme Duval	return Status;
166626bc4beSJérôme Duval
167626bc4beSJérôme Duval}	// ECHOSTATUS CDarla::InitHw()
168626bc4beSJérôme Duval
169626bc4beSJérôme Duval
170626bc4beSJérôme Duval
171626bc4beSJérôme Duval
172626bc4beSJérôme Duval/****************************************************************************
173626bc4beSJérôme Duval
174626bc4beSJérôme Duval	Informational methods
175626bc4beSJérôme Duval
176626bc4beSJérôme Duval ****************************************************************************/
177626bc4beSJérôme Duval
178626bc4beSJérôme Duval//===========================================================================
179626bc4beSJérôme Duval//
180626bc4beSJérôme Duval// QueryAudioSampleRate is used to find out if this card can handle a
181626bc4beSJérôme Duval// given sample rate.
182626bc4beSJérôme Duval//
183626bc4beSJérôme Duval//===========================================================================
184626bc4beSJérôme Duval
185626bc4beSJérôme DuvalECHOSTATUS CDarla::QueryAudioSampleRate
186626bc4beSJérôme Duval(
187626bc4beSJérôme Duval	DWORD		dwSampleRate
188626bc4beSJérôme Duval)
189626bc4beSJérôme Duval{
190626bc4beSJérôme Duval	if ( dwSampleRate != 44100 &&
191626bc4beSJérôme Duval		  dwSampleRate != 48000 )
192626bc4beSJérôme Duval	{
193626bc4beSJérôme Duval		ECHO_DEBUGPRINTF(
194626bc4beSJérôme Duval			("CDarla::QueryAudioSampleRate() - rate %ld invalid\n",
195626bc4beSJérôme Duval				dwSampleRate));
196626bc4beSJérôme Duval		return ECHOSTATUS_BAD_FORMAT;
197626bc4beSJérôme Duval	}
198626bc4beSJérôme Duval
199626bc4beSJérôme Duval	ECHO_DEBUGPRINTF( ( "CDarla::QueryAudioSampleRate()\n" ) );
200626bc4beSJérôme Duval	return ECHOSTATUS_OK;
201626bc4beSJérôme Duval
202626bc4beSJérôme Duval}	// ECHOSTATUS CDarla::QueryAudioSampleRate
203626bc4beSJérôme Duval
204626bc4beSJérôme Duval
2054dd9e436SJérôme Duvalvoid CDarla::QuerySampleRateRange(DWORD &dwMinRate,DWORD &dwMaxRate)
2064dd9e436SJérôme Duval{
2074dd9e436SJérôme Duval	dwMinRate = 44100;
2084dd9e436SJérôme Duval	dwMaxRate = 48000;
2094dd9e436SJérôme Duval}
2104dd9e436SJérôme Duval
2114dd9e436SJérôme Duval
2124dd9e436SJérôme Duval
213626bc4beSJérôme Duval// *** CDarla.cpp ***
214