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 // ----------------------------------------------------------------------------
11 //
12 // This file is part of Echo Digital Audio's generic driver library.
13 // Copyright Echo Digital Audio Corporation (c) 1998 - 2005
14 // All rights reserved
15 // www.echoaudio.com
16 //
17 // This library is free software; you can redistribute it and/or
18 // modify it under the terms of the GNU Lesser General Public
19 // License as published by the Free Software Foundation; either
20 // version 2.1 of the License, or (at your option) any later version.
21 //
22 // This library is distributed in the hope that it will be useful,
23 // but WITHOUT ANY WARRANTY; without even the implied warranty of
24 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
25 // Lesser General Public License for more details.
26 //
27 // You should have received a copy of the GNU Lesser General Public
28 // License along with this library; if not, write to the Free Software
29 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30 //
31 // ****************************************************************************
32
33 #include "CDarla.h"
34
35 #define DARLA20_ANALOG_OUTPUT_LATENCY 137
36 #define DARLA20_ANALOG_INPUT_LATENCY 240
37
38
39 /****************************************************************************
40
41 Construction and destruction
42
43 ****************************************************************************/
44
45 //===========================================================================
46 //
47 // Overload new & delete so memory for this object is allocated
48 // from non-paged memory.
49 //
50 //===========================================================================
51
operator new(size_t Size)52 PVOID CDarla::operator new( size_t Size )
53 {
54 PVOID pMemory;
55 ECHOSTATUS Status;
56
57 Status = OsAllocateNonPaged(Size,&pMemory);
58
59 if ( (ECHOSTATUS_OK != Status) || (NULL == pMemory ))
60 {
61 ECHO_DEBUGPRINTF(("CDarla::operator new - memory allocation failed\n"));
62
63 pMemory = NULL;
64 }
65 else
66 {
67 memset( pMemory, 0, Size );
68 }
69
70 return pMemory;
71
72 } // PVOID CDarla::operator new( size_t Size )
73
74
operator delete(PVOID pVoid)75 VOID CDarla::operator delete( PVOID pVoid )
76 {
77 if ( ECHOSTATUS_OK != OsFreeNonPaged( pVoid ) )
78 {
79 ECHO_DEBUGPRINTF(("CDarla::operator delete memory free failed\n"));
80 }
81 } // VOID CDarla::operator delete( PVOID pVoid )
82
83
84 //===========================================================================
85 //
86 // Constructor and destructor
87 //
88 //===========================================================================
89
CDarla(PCOsSupport pOsSupport)90 CDarla::CDarla( PCOsSupport pOsSupport )
91 : CEchoGals( pOsSupport )
92 {
93 ECHO_DEBUGPRINTF( ( "CDarla::CDarla() is born!\n" ) );
94
95 m_wAnalogOutputLatency = DARLA20_ANALOG_OUTPUT_LATENCY;
96 m_wAnalogInputLatency = DARLA20_ANALOG_INPUT_LATENCY;
97 }
98
~CDarla()99 CDarla::~CDarla()
100 {
101 ECHO_DEBUGPRINTF( ( "CDarla::~CDarla() 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
InitHw()119 ECHOSTATUS CDarla::InitHw()
120 {
121 ECHOSTATUS Status;
122
123 //
124 // Call the base InitHw method
125 //
126 if ( ECHOSTATUS_OK != ( Status = CEchoGals::InitHw() ) )
127 return Status;
128
129 //
130 // Create the DSP comm object
131 //
132 ECHO_ASSERT(NULL == m_pDspCommObject );
133 m_pDspCommObject = new CDarlaDspCommObject( (PDWORD) m_pvSharedMemory,
134 m_pOsSupport );
135 if (NULL == m_pDspCommObject)
136 {
137 ECHO_DEBUGPRINTF(("CDarla::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 // Clear the "bad board" flag
150 //
151 m_wFlags &= ~ECHOGALS_FLAG_BADBOARD;
152
153 //
154 // Must call this here *after* DSP is init
155 //
156 Status = InitLineLevels();
157
158 //
159 // Get default sample rate from DSP
160 //
161 m_dwSampleRate = GetDspCommObject()->GetSampleRate();
162
163 ECHO_DEBUGPRINTF( ( "CDarla::InitHw()\n" ) );
164
165 return Status;
166
167 } // ECHOSTATUS CDarla::InitHw()
168
169
170
171
172 /****************************************************************************
173
174 Informational methods
175
176 ****************************************************************************/
177
178 //===========================================================================
179 //
180 // QueryAudioSampleRate is used to find out if this card can handle a
181 // given sample rate.
182 //
183 //===========================================================================
184
QueryAudioSampleRate(DWORD dwSampleRate)185 ECHOSTATUS CDarla::QueryAudioSampleRate
186 (
187 DWORD dwSampleRate
188 )
189 {
190 if ( dwSampleRate != 44100 &&
191 dwSampleRate != 48000 )
192 {
193 ECHO_DEBUGPRINTF(
194 ("CDarla::QueryAudioSampleRate() - rate %ld invalid\n",
195 dwSampleRate));
196 return ECHOSTATUS_BAD_FORMAT;
197 }
198
199 ECHO_DEBUGPRINTF( ( "CDarla::QueryAudioSampleRate()\n" ) );
200 return ECHOSTATUS_OK;
201
202 } // ECHOSTATUS CDarla::QueryAudioSampleRate
203
204
QuerySampleRateRange(DWORD & dwMinRate,DWORD & dwMaxRate)205 void CDarla::QuerySampleRateRange(DWORD &dwMinRate,DWORD &dwMaxRate)
206 {
207 dwMinRate = 44100;
208 dwMaxRate = 48000;
209 }
210
211
212
213 // *** CDarla.cpp ***
214