xref: /haiku/src/add-ons/kernel/drivers/audio/echo/generic/CIndigo.cpp (revision 4dd9e43637031d2c5a6755a0184040f0de8f2884)
1 // ****************************************************************************
2 //
3 //		CIndigo.cpp
4 //
5 //		Implementation file for the CIndigo 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 "CIndigo.h"
32 
33 #define INDIGO_ANALOG_OUTPUT_LATENCY	91
34 
35 
36 /****************************************************************************
37 
38 	Construction and destruction
39 
40  ****************************************************************************/
41 
42 //===========================================================================
43 //
44 // Overload new & delete so memory for this object is allocated
45 //	from non-paged memory.
46 //
47 //===========================================================================
48 
operator new(size_t Size)49 PVOID CIndigo::operator new( size_t Size )
50 {
51 	PVOID 		pMemory;
52 	ECHOSTATUS 	Status;
53 
54 	Status = OsAllocateNonPaged(Size,&pMemory);
55 
56 	if ( (ECHOSTATUS_OK != Status) || (NULL == pMemory ))
57 	{
58 		ECHO_DEBUGPRINTF(("CIndigo::operator new - memory allocation failed\n"));
59 
60 		pMemory = NULL;
61 	}
62 	else
63 	{
64 		memset( pMemory, 0, Size );
65 	}
66 
67 	return pMemory;
68 
69 }	// PVOID CIndigo::operator new( size_t Size )
70 
71 
operator delete(PVOID pVoid)72 VOID  CIndigo::operator delete( PVOID pVoid )
73 {
74 	if ( ECHOSTATUS_OK != OsFreeNonPaged( pVoid ) )
75 	{
76 		ECHO_DEBUGPRINTF(("CIndigo::operator delete memory free failed\n"));
77 	}
78 }	// VOID CIndigo::operator delete( PVOID pVoid )
79 
80 
81 
82 //===========================================================================
83 //
84 // Constructor and destructor
85 //
86 //===========================================================================
87 
CIndigo(PCOsSupport pOsSupport)88 CIndigo::CIndigo( PCOsSupport pOsSupport )
89 	  : CEchoGalsVmixer( pOsSupport )
90 {
91 	ECHO_DEBUGPRINTF( ( "CIndigo::CIndigo() is born!\n" ) );
92 
93 	m_wAnalogOutputLatency = INDIGO_ANALOG_OUTPUT_LATENCY;
94 }
95 
~CIndigo()96 CIndigo::~CIndigo()
97 {
98 	ECHO_DEBUGPRINTF( ( "CIndigo::~CIndigo() is toast!\n" ) );
99 }
100 
101 
102 
103 
104 /****************************************************************************
105 
106 	Setup and hardware initialization
107 
108  ****************************************************************************/
109 
110 //===========================================================================
111 //
112 // Every card has an InitHw method
113 //
114 //===========================================================================
115 
InitHw()116 ECHOSTATUS CIndigo::InitHw()
117 {
118 	ECHOSTATUS	Status;
119 
120 	//
121 	// Call the base method
122 	//
123 	if ( ECHOSTATUS_OK != ( Status = CEchoGals::InitHw() ) )
124 		return Status;
125 
126 	//
127 	// Create the DSP comm object
128 	//
129 	m_pDspCommObject = new CIndigoDspCommObject( (PDWORD) m_pvSharedMemory,
130 															 m_pOsSupport );
131  	if (NULL == m_pDspCommObject)
132 	{
133 		ECHO_DEBUGPRINTF(("CIndigo::InitHw - could not create DSP comm object\n"));
134 		return ECHOSTATUS_NO_MEM;
135 	}
136 
137 	//
138 	// Load the DSP
139 	//
140 	GetDspCommObject()->LoadFirmware();
141 	if ( GetDspCommObject()->IsBoardBad() )
142 		return ECHOSTATUS_DSP_DEAD;
143 
144 	//
145 	// Do flags
146 	//
147 	m_wFlags &= ~ECHOGALS_FLAG_BADBOARD;
148 	m_wFlags |= ECHOGALS_ROFLAG_SUPER_INTERLEAVE_OK;
149 
150 	//
151 	//	Must call this here after DSP is init to
152 	//	init gains and mutes
153 	//
154 	Status = InitLineLevels();
155 	if ( ECHOSTATUS_OK != Status )
156 		return Status;
157 
158 	//
159 	//	Get default sample rate from DSP
160 	//
161 	m_dwSampleRate = GetDspCommObject()->GetSampleRate();
162 
163 	ECHO_DEBUGPRINTF( ( "CIndigo::InitHw()\n" ) );
164 	return Status;
165 
166 }	// ECHOSTATUS CIndigo::InitHw()
167 
168 
169 
170 
171 /****************************************************************************
172 
173 	Informational methods
174 
175  ****************************************************************************/
176 
177 //===========================================================================
178 //
179 // Override GetCapabilities to enumerate unique capabilties for this card
180 //
181 //===========================================================================
182 
GetCapabilities(PECHOGALS_CAPS pCapabilities)183 ECHOSTATUS CIndigo::GetCapabilities
184 (
185 	PECHOGALS_CAPS	pCapabilities
186 )
187 {
188 	ECHOSTATUS Status;
189 
190 	Status = GetBaseCapabilities(pCapabilities);
191 	if ( ECHOSTATUS_OK != Status )
192 		return Status;
193 
194 	pCapabilities->dwOutClockTypes = 0;
195 
196 	pCapabilities->dwPipeInCaps[0] = ECHOCAPS_DUMMY;
197 	pCapabilities->dwPipeInCaps[1] = ECHOCAPS_DUMMY;
198 	pCapabilities->dwBusInCaps[0] = ECHOCAPS_DUMMY;
199 	pCapabilities->dwBusInCaps[1] = ECHOCAPS_DUMMY;
200 
201 	return Status;
202 
203 }	// ECHOSTATUS CIndigo::GetCapabilities
204 
205 
206 //===========================================================================
207 //
208 // QueryAudioSampleRate is used to find out if this card can handle a
209 // given sample rate.
210 //
211 //===========================================================================
212 
QueryAudioSampleRate(DWORD dwSampleRate)213 ECHOSTATUS CIndigo::QueryAudioSampleRate
214 (
215 	DWORD		dwSampleRate
216 )
217 {
218 	if ( dwSampleRate != 32000 &&
219 		  dwSampleRate != 44100 &&
220 		  dwSampleRate != 48000 &&
221 		  dwSampleRate != 88200 &&
222 		  dwSampleRate != 96000 )
223 	{
224 		ECHO_DEBUGPRINTF(
225 			("CIndigo::QueryAudioSampleRate() - rate %ld invalid\n",dwSampleRate) );
226 		return ECHOSTATUS_BAD_FORMAT;
227 	}
228 
229 	ECHO_DEBUGPRINTF( ( "CIndigo::QueryAudioSampleRate()\n" ) );
230 	return ECHOSTATUS_OK;
231 
232 }	// ECHOSTATUS CIndigo::QueryAudioSampleRate
233 
234 
QuerySampleRateRange(DWORD & dwMinRate,DWORD & dwMaxRate)235 void CIndigo::QuerySampleRateRange(DWORD &dwMinRate,DWORD &dwMaxRate)
236 {
237 	dwMinRate = 32000;
238 	dwMaxRate = 96000;
239 }
240 
241 
242 //===========================================================================
243 //
244 // Indigo & Indigo DJ don't have monitor mixers, so this works differently
245 // from other vmixer cards.
246 //
247 //===========================================================================
248 
AdjustMonitorsForBusOut(WORD wBusOut)249 ECHOSTATUS CIndigo::AdjustMonitorsForBusOut(WORD wBusOut)
250 {
251 	return ECHOSTATUS_OK;
252 }
253 
254 // *** CIndigo.cpp ***
255