BPicture: Fix archive constructor.
[haiku.git] / src / add-ons / kernel / drivers / audio / echo / generic / CDarla.cpp
blob536bf625d942f5db73756345b3a745639247e541
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 // ----------------------------------------------------------------------------
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
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.
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.
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
31 // ****************************************************************************
33 #include "CDarla.h"
35 #define DARLA20_ANALOG_OUTPUT_LATENCY 137
36 #define DARLA20_ANALOG_INPUT_LATENCY 240
39 /****************************************************************************
41 Construction and destruction
43 ****************************************************************************/
45 //===========================================================================
47 // Overload new & delete so memory for this object is allocated
48 // from non-paged memory.
50 //===========================================================================
52 PVOID CDarla::operator new( size_t Size )
54 PVOID pMemory;
55 ECHOSTATUS Status;
57 Status = OsAllocateNonPaged(Size,&pMemory);
59 if ( (ECHOSTATUS_OK != Status) || (NULL == pMemory ))
61 ECHO_DEBUGPRINTF(("CDarla::operator new - memory allocation failed\n"));
63 pMemory = NULL;
65 else
67 memset( pMemory, 0, Size );
70 return pMemory;
72 } // PVOID CDarla::operator new( size_t Size )
75 VOID CDarla::operator delete( PVOID pVoid )
77 if ( ECHOSTATUS_OK != OsFreeNonPaged( pVoid ) )
79 ECHO_DEBUGPRINTF(("CDarla::operator delete memory free failed\n"));
81 } // VOID CDarla::operator delete( PVOID pVoid )
84 //===========================================================================
86 // Constructor and destructor
88 //===========================================================================
90 CDarla::CDarla( PCOsSupport pOsSupport )
91 : CEchoGals( pOsSupport )
93 ECHO_DEBUGPRINTF( ( "CDarla::CDarla() is born!\n" ) );
95 m_wAnalogOutputLatency = DARLA20_ANALOG_OUTPUT_LATENCY;
96 m_wAnalogInputLatency = DARLA20_ANALOG_INPUT_LATENCY;
99 CDarla::~CDarla()
101 ECHO_DEBUGPRINTF( ( "CDarla::~CDarla() is toast!\n" ) );
107 /****************************************************************************
109 Setup and hardware initialization
111 ****************************************************************************/
113 //===========================================================================
115 // Every card has an InitHw method
117 //===========================================================================
119 ECHOSTATUS CDarla::InitHw()
121 ECHOSTATUS Status;
124 // Call the base InitHw method
126 if ( ECHOSTATUS_OK != ( Status = CEchoGals::InitHw() ) )
127 return Status;
130 // Create the DSP comm object
132 ECHO_ASSERT(NULL == m_pDspCommObject );
133 m_pDspCommObject = new CDarlaDspCommObject( (PDWORD) m_pvSharedMemory,
134 m_pOsSupport );
135 if (NULL == m_pDspCommObject)
137 ECHO_DEBUGPRINTF(("CDarla::InitHw - could not create DSP comm object\n"));
138 return ECHOSTATUS_NO_MEM;
142 // Load the DSP
144 GetDspCommObject()->LoadFirmware();
145 if ( GetDspCommObject()->IsBoardBad() )
146 return ECHOSTATUS_DSP_DEAD;
149 // Clear the "bad board" flag
151 m_wFlags &= ~ECHOGALS_FLAG_BADBOARD;
154 // Must call this here *after* DSP is init
156 Status = InitLineLevels();
159 // Get default sample rate from DSP
161 m_dwSampleRate = GetDspCommObject()->GetSampleRate();
163 ECHO_DEBUGPRINTF( ( "CDarla::InitHw()\n" ) );
165 return Status;
167 } // ECHOSTATUS CDarla::InitHw()
172 /****************************************************************************
174 Informational methods
176 ****************************************************************************/
178 //===========================================================================
180 // QueryAudioSampleRate is used to find out if this card can handle a
181 // given sample rate.
183 //===========================================================================
185 ECHOSTATUS CDarla::QueryAudioSampleRate
187 DWORD dwSampleRate
190 if ( dwSampleRate != 44100 &&
191 dwSampleRate != 48000 )
193 ECHO_DEBUGPRINTF(
194 ("CDarla::QueryAudioSampleRate() - rate %ld invalid\n",
195 dwSampleRate));
196 return ECHOSTATUS_BAD_FORMAT;
199 ECHO_DEBUGPRINTF( ( "CDarla::QueryAudioSampleRate()\n" ) );
200 return ECHOSTATUS_OK;
202 } // ECHOSTATUS CDarla::QueryAudioSampleRate
205 void CDarla::QuerySampleRateRange(DWORD &dwMinRate,DWORD &dwMaxRate)
207 dwMinRate = 44100;
208 dwMaxRate = 48000;
213 // *** CDarla.cpp ***