xref: /haiku/src/add-ons/kernel/drivers/audio/echo/generic/CIndigoIO.cpp (revision 93a78ecaa45114d68952d08c4778f073515102f2)
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 // 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 "CIndigoIO.h"
32 #include "CIndigoDJ.h"
33 
34 #define INDIGO_IO_OUTPUT_LATENCY_SINGLE_SPEED	44
35 #define INDIGO_IO_OUTPUT_LATENCY_DOUBLE_SPEED	37
36 #define INDIGO_IO_INPUT_LATENCY_SINGLE_SPEED		44
37 #define INDIGO_IO_INPUT_LATENCY_DOUBLE_SPEED		41
38 
39 
40 /****************************************************************************
41 
42 	Construction and destruction
43 
44  ****************************************************************************/
45 
46 //===========================================================================
47 //
48 // Overload new & delete so memory for this object is allocated
49 //	from non-paged memory.
50 //
51 //===========================================================================
52 
53 PVOID CIndigoIO::operator new( size_t Size )
54 {
55 	PVOID 		pMemory;
56 	ECHOSTATUS 	Status;
57 
58 	Status = OsAllocateNonPaged(Size,&pMemory);
59 
60 	if ( (ECHOSTATUS_OK != Status) || (NULL == pMemory ))
61 	{
62 		ECHO_DEBUGPRINTF(("CIndigoIO::operator new - memory allocation failed\n"));
63 
64 		pMemory = NULL;
65 	}
66 	else
67 	{
68 		memset( pMemory, 0, Size );
69 	}
70 
71 	return pMemory;
72 
73 }	// PVOID CIndigoIO::operator new( size_t Size )
74 
75 
76 VOID  CIndigoIO::operator delete( PVOID pVoid )
77 {
78 	if ( ECHOSTATUS_OK != OsFreeNonPaged( pVoid ) )
79 	{
80 		ECHO_DEBUGPRINTF(("CIndigoIO::operator delete memory free failed\n"));
81 	}
82 }	// VOID CIndigoIO::operator delete( PVOID pVoid )
83 
84 
85 
86 //===========================================================================
87 //
88 // Constructor and destructor
89 //
90 //===========================================================================
91 
92 CIndigoIO::CIndigoIO( PCOsSupport pOsSupport )
93 	  : CEchoGalsVmixer( pOsSupport )
94 {
95 	ECHO_DEBUGPRINTF( ( "CIndigoIO::CIndigoIO() is born!\n" ) );
96 }
97 
98 CIndigoIO::~CIndigoIO()
99 {
100 	ECHO_DEBUGPRINTF( ( "CIndigoIO::~CIndigoIO() 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 
118 ECHOSTATUS CIndigoIO::InitHw()
119 {
120 	ECHOSTATUS	Status;
121 
122 	//
123 	// Call the base method
124 	//
125 	if ( ECHOSTATUS_OK != ( Status = CEchoGals::InitHw() ) )
126 		return Status;
127 
128 	//
129 	// Create the DSP comm object
130 	//
131 	ECHO_ASSERT(NULL == m_pDspCommObject );
132 	m_pDspCommObject = new CIndigoIODspCommObject( (PDWORD) m_pvSharedMemory,
133 															 m_pOsSupport );
134  	if (NULL == m_pDspCommObject)
135 	{
136 		ECHO_DEBUGPRINTF(("CIndigoIO::InitHw - could not create DSP comm object\n"));
137 		return ECHOSTATUS_NO_MEM;
138 	}
139 
140 	//
141 	// Load the DSP
142 	//
143 	GetDspCommObject()->LoadFirmware();
144 	if ( GetDspCommObject()->IsBoardBad() )
145 		return ECHOSTATUS_DSP_DEAD;
146 
147 	//
148 	// Do flags
149 	//
150 	m_wFlags &= ~ECHOGALS_FLAG_BADBOARD;
151 	m_wFlags |= ECHOGALS_ROFLAG_SUPER_INTERLEAVE_OK;
152 
153 	//
154 	//	Must call this here after DSP is init to
155 	//	init gains and mutes
156 	//
157 	Status = InitLineLevels();
158 	if ( ECHOSTATUS_OK != Status )
159 		return Status;
160 
161 	//
162 	//	Get default sample rate from DSP
163 	//
164 	m_dwSampleRate = GetDspCommObject()->GetSampleRate();
165 
166 	ECHO_DEBUGPRINTF( ( "CIndigoIO::InitHw() complete\n" ) );
167 	return Status;
168 
169 }	// ECHOSTATUS CIndigoIO::InitHw()
170 
171 
172 
173 
174 /****************************************************************************
175 
176 	Informational methods
177 
178  ****************************************************************************/
179 
180 //===========================================================================
181 //
182 // Override GetCapabilities to enumerate unique capabilties for this card
183 //
184 //===========================================================================
185 
186 ECHOSTATUS CIndigoIO::GetCapabilities
187 (
188 	PECHOGALS_CAPS	pCapabilities
189 )
190 {
191 	ECHOSTATUS Status;
192 
193 	Status = GetBaseCapabilities(pCapabilities);
194 	if ( ECHOSTATUS_OK != Status )
195 		return Status;
196 
197 	pCapabilities->dwOutClockTypes = 0;
198 
199 	return Status;
200 
201 }	// ECHOSTATUS CIndigoIO::GetCapabilities
202 
203 
204 //===========================================================================
205 //
206 // QueryAudioSampleRate is used to find out if this card can handle a
207 // given sample rate.
208 //
209 //===========================================================================
210 
211 ECHOSTATUS CIndigoIO::QueryAudioSampleRate
212 (
213 	DWORD		dwSampleRate
214 )
215 {
216 	if ( dwSampleRate != 32000 &&
217 		  dwSampleRate != 44100 &&
218 		  dwSampleRate != 48000 &&
219 		  dwSampleRate != 64000 &&
220 		  dwSampleRate != 88200 &&
221 		  dwSampleRate != 96000
222 		)
223 	{
224 		ECHO_DEBUGPRINTF(
225 			("CIndigoIO::QueryAudioSampleRate() - rate %ld invalid\n",dwSampleRate) );
226 		return ECHOSTATUS_BAD_FORMAT;
227 	}
228 
229 	ECHO_DEBUGPRINTF( ( "CIndigoIO::QueryAudioSampleRate()\n" ) );
230 	return ECHOSTATUS_OK;
231 
232 }	// ECHOSTATUS CIndigoIO::QueryAudioSampleRate
233 
234 
235 void CIndigoIO::QuerySampleRateRange(DWORD &dwMinRate,DWORD &dwMaxRate)
236 {
237 	dwMinRate = 32000;
238 	dwMaxRate = 96000;
239 }
240 
241 
242 //===========================================================================
243 //
244 // GetAudioLatency - returns the latency for a single pipe
245 //
246 //===========================================================================
247 
248 void CIndigoIO::GetAudioLatency(ECHO_AUDIO_LATENCY *pLatency)
249 {
250 	DWORD dwLatency;
251 	DWORD dwSampleRate;
252 
253 	//
254 	// The latency depends on the current sample rate
255 	//
256 	dwSampleRate = GetDspCommObject()->GetSampleRate();
257 	if (FALSE == pLatency->wIsInput)
258 	{
259 		if (dwSampleRate < 50000)
260 			dwLatency = INDIGO_IO_OUTPUT_LATENCY_SINGLE_SPEED;
261 		else
262 			dwLatency = INDIGO_IO_OUTPUT_LATENCY_DOUBLE_SPEED;
263 	}
264 	else
265 	{
266 		if (dwSampleRate < 50000)
267 			dwLatency = INDIGO_IO_INPUT_LATENCY_SINGLE_SPEED;
268 		else
269 			dwLatency = INDIGO_IO_INPUT_LATENCY_DOUBLE_SPEED;
270 	}
271 
272 	pLatency->dwLatency = dwLatency;
273 
274 }	// GetAudioLatency
275 
276 // *** CIndigoIO.cpp ***
277