xref: /haiku/src/add-ons/kernel/drivers/audio/echo/generic/CDarla.cpp (revision f2ced752a08ff5d2618826bcd3ae3976c9f3e92e)
1 // ****************************************************************************
2 //
3 //		CDarla.cpp
4 //
5 //		Implementation file for the CDarla driver class; this supports 20 bit
6 //		Darla, not Darla24.
7 //
8 //		Set editor tabs to 3 for your viewing pleasure.
9 //
10 //		Copyright Echo Digital Audio Corporation (c) 1998 - 2002
11 //		All rights reserved
12 //		www.echoaudio.com
13 //
14 //		Permission is hereby granted, free of charge, to any person obtaining a
15 //		copy of this software and associated documentation files (the
16 //		"Software"), to deal with the Software without restriction, including
17 //		without limitation the rights to use, copy, modify, merge, publish,
18 //		distribute, sublicense, and/or sell copies of the Software, and to
19 //		permit persons to whom the Software is furnished to do so, subject to
20 //		the following conditions:
21 //
22 //		- Redistributions of source code must retain the above copyright
23 //		notice, this list of conditions and the following disclaimers.
24 //
25 //		- Redistributions in binary form must reproduce the above copyright
26 //		notice, this list of conditions and the following disclaimers in the
27 //		documentation and/or other materials provided with the distribution.
28 //
29 //		- Neither the name of Echo Digital Audio, nor the names of its
30 //		contributors may be used to endorse or promote products derived from
31 //		this Software without specific prior written permission.
32 //
33 //		THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
34 //		EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
35 //		MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
36 //		IN NO EVENT SHALL THE CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR
37 //		ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
38 //		TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
39 //		SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE SOFTWARE.
40 //
41 // ****************************************************************************
42 
43 #include "CDarla.h"
44 
45 
46 /****************************************************************************
47 
48 	Construction and destruction
49 
50  ****************************************************************************/
51 
52 //===========================================================================
53 //
54 // Overload new & delete so memory for this object is allocated
55 //	from non-paged memory.
56 //
57 //===========================================================================
58 
59 PVOID CDarla::operator new( size_t Size )
60 {
61 	PVOID 		pMemory;
62 	ECHOSTATUS 	Status;
63 
64 	Status = OsAllocateNonPaged(Size,&pMemory);
65 
66 	if ( (ECHOSTATUS_OK != Status) || (NULL == pMemory ))
67 	{
68 		ECHO_DEBUGPRINTF(("CDarla::operator new - memory allocation failed\n"));
69 
70 		pMemory = NULL;
71 	}
72 	else
73 	{
74 		memset( pMemory, 0, Size );
75 	}
76 
77 	return pMemory;
78 
79 }	// PVOID CDarla::operator new( size_t Size )
80 
81 
82 VOID  CDarla::operator delete( PVOID pVoid )
83 {
84 	if ( ECHOSTATUS_OK != OsFreeNonPaged( pVoid ) )
85 	{
86 		ECHO_DEBUGPRINTF(("CDarla::operator delete memory free failed\n"));
87 	}
88 }	// VOID  CDarla::operator delete( PVOID pVoid )
89 
90 
91 //===========================================================================
92 //
93 // Constructor and destructor
94 //
95 //===========================================================================
96 
97 CDarla::CDarla( PCOsSupport pOsSupport )
98 		: CEchoGals( pOsSupport )
99 {
100 	ECHO_DEBUGPRINTF( ( "CDarla::CDarla() is born!\n" ) );
101 }
102 
103 CDarla::~CDarla()
104 {
105 	ECHO_DEBUGPRINTF( ( "CDarla::~CDarla() is toast!\n" ) );
106 }
107 
108 
109 
110 
111 /****************************************************************************
112 
113 	Setup and hardware initialization
114 
115  ****************************************************************************/
116 
117 //===========================================================================
118 //
119 // Every card has an InitHw method
120 //
121 //===========================================================================
122 
123 ECHOSTATUS CDarla::InitHw()
124 {
125 	ECHOSTATUS	Status;
126 
127 	//
128 	// Call the base InitHw method
129 	//
130 	if ( ECHOSTATUS_OK != ( Status = CEchoGals::InitHw() ) )
131 		return Status;
132 
133 	//
134 	// Create the DSP comm object
135 	//
136 	ASSERT( NULL == m_pDspCommObject );
137 	m_pDspCommObject = new CDarlaDspCommObject( (PDWORD) m_pvSharedMemory,
138 																m_pOsSupport );
139 	if (NULL == m_pDspCommObject)
140 	{
141 		ECHO_DEBUGPRINTF(("CDarla::InitHw - could not create DSP comm object\n"));
142 		return ECHOSTATUS_NO_MEM;
143 	}
144 
145 	//
146 	// Load the DSP
147 	//
148 	GetDspCommObject()->LoadFirmware();
149 	if ( GetDspCommObject()->IsBoardBad() )
150 		return ECHOSTATUS_DSP_DEAD;
151 
152 	//
153 	// Clear the "bad board" flag
154 	//
155 	m_wFlags &= ~ECHOGALS_FLAG_BADBOARD;
156 
157 	//
158 	//	Must call this here *after* DSP is init
159 	//
160 	Status = InitLineLevels();
161 
162 	//
163 	//	Get default sample rate from DSP
164 	//
165 	m_dwSampleRate = GetDspCommObject()->GetSampleRate();
166 
167 	ECHO_DEBUGPRINTF( ( "CDarla::InitHw()\n" ) );
168 
169 	return Status;
170 
171 }	// ECHOSTATUS CDarla::InitHw()
172 
173 
174 
175 
176 /****************************************************************************
177 
178 	Informational methods
179 
180  ****************************************************************************/
181 
182 //===========================================================================
183 //
184 // QueryAudioSampleRate is used to find out if this card can handle a
185 // given sample rate.
186 //
187 //===========================================================================
188 
189 ECHOSTATUS CDarla::QueryAudioSampleRate
190 (
191 	DWORD		dwSampleRate
192 )
193 {
194 	if ( dwSampleRate != 44100 &&
195 		  dwSampleRate != 48000 )
196 	{
197 		ECHO_DEBUGPRINTF(
198 			("CDarla::QueryAudioSampleRate() Sample rate must be"
199 			 " 44,100 Hz or 48,000 Hz\n") );
200 		return ECHOSTATUS_BAD_FORMAT;
201 	}
202 
203 	ECHO_DEBUGPRINTF( ( "CDarla::QueryAudioSampleRate()\n" ) );
204 	return ECHOSTATUS_OK;
205 
206 }	// ECHOSTATUS CDarla::QueryAudioSampleRate
207 
208 
209 // *** CDarla.cpp ***
210