CIndigoIO.cpp revision c2ddc71c
1// ****************************************************************************
2//
3//		CIndigoIO.cpp
4//
5//		Implementation file for the CIndigoIO driver class.
6//		Set editor tabs to 3 for your viewing pleasure.
7//
8// ----------------------------------------------------------------------------
9//
10//   Copyright Echo Digital Audio Corporation (c) 1998 - 2004
11//   All rights reserved
12//   www.echoaudio.com
13//
14//   This file is part of Echo Digital Audio's generic driver library.
15//
16//   Echo Digital Audio's generic driver library is free software;
17//   you can redistribute it and/or modify it under the terms of
18//   the GNU General Public License as published by the Free Software Foundation.
19//
20//   This program 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
23//   GNU General Public License for more details.
24//
25//   You should have received a copy of the GNU General Public License
26//   along with this program; if not, write to the Free Software
27//   Foundation, Inc., 59 Temple Place - Suite 330, Boston,
28//   MA  02111-1307, USA.
29//
30// ****************************************************************************
31
32#include "CIndigoIO.h"
33#include "CIndigoDJ.h"
34
35#define INDIGO_IO_OUTPUT_LATENCY_SINGLE_SPEED	44
36#define INDIGO_IO_OUTPUT_LATENCY_DOUBLE_SPEED	37
37#define INDIGO_IO_INPUT_LATENCY_SINGLE_SPEED		44
38#define INDIGO_IO_INPUT_LATENCY_DOUBLE_SPEED		41
39
40
41/****************************************************************************
42
43	Construction and destruction
44
45 ****************************************************************************/
46
47//===========================================================================
48//
49// Overload new & delete so memory for this object is allocated
50//	from non-paged memory.
51//
52//===========================================================================
53
54PVOID CIndigoIO::operator new( size_t Size )
55{
56	PVOID 		pMemory;
57	ECHOSTATUS 	Status;
58
59	Status = OsAllocateNonPaged(Size,&pMemory);
60
61	if ( (ECHOSTATUS_OK != Status) || (NULL == pMemory ))
62	{
63		ECHO_DEBUGPRINTF(("CIndigoIO::operator new - memory allocation failed\n"));
64
65		pMemory = NULL;
66	}
67	else
68	{
69		memset( pMemory, 0, Size );
70	}
71
72	return pMemory;
73
74}	// PVOID CIndigoIO::operator new( size_t Size )
75
76
77VOID  CIndigoIO::operator delete( PVOID pVoid )
78{
79	if ( ECHOSTATUS_OK != OsFreeNonPaged( pVoid ) )
80	{
81		ECHO_DEBUGPRINTF(("CIndigoIO::operator delete memory free failed\n"));
82	}
83}	// VOID CIndigoIO::operator delete( PVOID pVoid )
84
85
86
87//===========================================================================
88//
89// Constructor and destructor
90//
91//===========================================================================
92
93CIndigoIO::CIndigoIO( PCOsSupport pOsSupport )
94	  : CEchoGalsVmixer( pOsSupport )
95{
96	ECHO_DEBUGPRINTF( ( "CIndigoIO::CIndigoIO() is born!\n" ) );
97}
98
99CIndigoIO::~CIndigoIO()
100{
101	ECHO_DEBUGPRINTF( ( "CIndigoIO::~CIndigoIO() is toast!\n" ) );
102}
103
104
105
106
107/****************************************************************************
108
109	Setup and hardware initialization
110
111 ****************************************************************************/
112
113//===========================================================================
114//
115// Every card has an InitHw method
116//
117//===========================================================================
118
119ECHOSTATUS CIndigoIO::InitHw()
120{
121	ECHOSTATUS	Status;
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	ASSERT( NULL == m_pDspCommObject );
133	m_pDspCommObject = new CIndigoIODspCommObject( (PDWORD) m_pvSharedMemory,
134															 m_pOsSupport );
135 	if (NULL == m_pDspCommObject)
136	{
137		ECHO_DEBUGPRINTF(("CIndigoIO::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	// Do flags
150	//
151	m_wFlags &= ~ECHOGALS_FLAG_BADBOARD;
152	m_wFlags |= ECHOGALS_ROFLAG_SUPER_INTERLEAVE_OK;
153
154	//
155	//	Must call this here after DSP is init to
156	//	init gains and mutes
157	//
158	Status = InitLineLevels();
159	if ( ECHOSTATUS_OK != Status )
160		return Status;
161
162	//
163	// Set the digital mode to S/PDIF RCA
164	//
165	SetDigitalMode( DIGITAL_MODE_SPDIF_RCA );
166
167	//
168	//	Get default sample rate from DSP
169	//
170	m_dwSampleRate = GetDspCommObject()->GetSampleRate();
171
172	ECHO_DEBUGPRINTF( ( "CIndigoIO::InitHw() complete\n" ) );
173	return Status;
174
175}	// ECHOSTATUS CIndigoIO::InitHw()
176
177
178
179
180/****************************************************************************
181
182	Informational methods
183
184 ****************************************************************************/
185
186//===========================================================================
187//
188// Override GetCapabilities to enumerate unique capabilties for this card
189//
190//===========================================================================
191
192ECHOSTATUS CIndigoIO::GetCapabilities
193(
194	PECHOGALS_CAPS	pCapabilities
195)
196{
197	ECHOSTATUS Status;
198
199	Status = GetBaseCapabilities(pCapabilities);
200	if ( ECHOSTATUS_OK != Status )
201		return Status;
202
203	pCapabilities->dwOutClockTypes = 0;
204
205	return Status;
206
207}	// ECHOSTATUS CIndigoIO::GetCapabilities
208
209
210//===========================================================================
211//
212// QueryAudioSampleRate is used to find out if this card can handle a
213// given sample rate.
214//
215//===========================================================================
216
217ECHOSTATUS CIndigoIO::QueryAudioSampleRate
218(
219	DWORD		dwSampleRate
220)
221{
222	if ( dwSampleRate != 32000 &&
223		  dwSampleRate != 44100 &&
224		  dwSampleRate != 48000 &&
225		  dwSampleRate != 64000 &&
226		  dwSampleRate != 88200 &&
227		  dwSampleRate != 96000
228		)
229	{
230		ECHO_DEBUGPRINTF(
231			("CIndigoIO::QueryAudioSampleRate() - rate %ld invalid\n",dwSampleRate) );
232		return ECHOSTATUS_BAD_FORMAT;
233	}
234
235	ECHO_DEBUGPRINTF( ( "CIndigoIO::QueryAudioSampleRate()\n" ) );
236	return ECHOSTATUS_OK;
237
238}	// ECHOSTATUS CIndigoIO::QueryAudioSampleRate
239
240
241//===========================================================================
242//
243// GetAudioLatency - returns the latency for a single pipe
244//
245//===========================================================================
246
247void CIndigoIO::GetAudioLatency(ECHO_AUDIO_LATENCY *pLatency)
248{
249	DWORD dwLatency;
250	DWORD dwSampleRate;
251
252	//
253	// The latency depends on the current sample rate
254	//
255	dwSampleRate = GetDspCommObject()->GetSampleRate();
256	if (FALSE == pLatency->wIsInput)
257	{
258		if (dwSampleRate < 50000)
259			dwLatency = INDIGO_IO_OUTPUT_LATENCY_SINGLE_SPEED;
260		else
261			dwLatency = INDIGO_IO_OUTPUT_LATENCY_DOUBLE_SPEED;
262	}
263	else
264	{
265		if (dwSampleRate < 50000)
266			dwLatency = INDIGO_IO_INPUT_LATENCY_SINGLE_SPEED;
267		else
268			dwLatency = INDIGO_IO_INPUT_LATENCY_DOUBLE_SPEED;
269	}
270
271	pLatency->dwLatency = dwLatency;
272
273}	// GetAudioLatency
274
275// *** CIndigoIO.cpp ***
276