xref: /haiku/src/add-ons/kernel/drivers/audio/echo/generic/CDarla24DspCommObject.cpp (revision 68ea01249e1e2088933cb12f9c28d4e5c5d1c9ef)
1 // ****************************************************************************
2 //
3 //  	CDarla24DspCommObject.cpp
4 //
5 //		Implementation file for Darla24 DSP interface class.
6 //
7 // ----------------------------------------------------------------------------
8 //
9 // This file is part of Echo Digital Audio's generic driver library.
10 // Copyright Echo Digital Audio Corporation (c) 1998 - 2005
11 // All rights reserved
12 // www.echoaudio.com
13 //
14 // This library is free software; you can redistribute it and/or
15 // modify it under the terms of the GNU Lesser General Public
16 // License as published by the Free Software Foundation; either
17 // version 2.1 of the License, or (at your option) any later version.
18 //
19 // This library is distributed in the hope that it will be useful,
20 // but WITHOUT ANY WARRANTY; without even the implied warranty of
21 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
22 // Lesser General Public License for more details.
23 //
24 // You should have received a copy of the GNU Lesser General Public
25 // License along with this library; if not, write to the Free Software
26 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
27 //
28 // ****************************************************************************
29 
30 #include "CEchoGals.h"
31 #include "CDarla24DspCommObject.h"
32 
33 #include "Darla24DSP.c"
34 
35 
36 /****************************************************************************
37 
38 	Magic constants for the Darla24 hardware
39 
40  ****************************************************************************/
41 
42 #define GD24_96000		0x0
43 #define GD24_48000		0x1
44 #define GD24_44100		0x2
45 #define GD24_32000		0x3
46 #define GD24_22050		0x4
47 #define GD24_16000		0x5
48 #define GD24_11025		0x6
49 #define GD24_8000			0x7
50 #define GD24_88200		0x8
51 #define GD24_EXT_SYNC	0x9
52 
53 
54 
55 
56 /****************************************************************************
57 
58 	Construction and destruction
59 
60  ****************************************************************************/
61 
62 //===========================================================================
63 //
64 // Constructor
65 //
66 //===========================================================================
67 
68 CDarla24DspCommObject::CDarla24DspCommObject
69 (
70 	PDWORD		pdwRegBase,				// Virtual ptr to DSP registers
71 	PCOsSupport	pOsSupport
72 ) : CGdDspCommObject( pdwRegBase, pOsSupport )
73 {
74 	strcpy( m_szCardName, "Darla24" );
75 	m_pdwDspRegBase = pdwRegBase;		// Virtual addr DSP's register base
76 
77 	m_wNumPipesOut = 8;
78 	m_wNumPipesIn = 2;
79 	m_wNumBussesOut = 8;
80 	m_wNumBussesIn = 2;
81 	m_wFirstDigitalBusOut = 8;
82 	m_wFirstDigitalBusIn = 2;
83 
84 	m_fHasVmixer = FALSE;
85 
86 	m_wNumMidiOut = 0;					// # MIDI out channels
87 	m_wNumMidiIn = 0;						// # MIDI in  channels
88 	m_pDspCommPage->dwSampleRate = SWAP( (DWORD) 44100 );
89 												// Need this in case we start with ESYNC
90 
91 	m_pwDspCodeToLoad = pwDarla24DSP;
92 
93 	//
94 	// Since this card has no ASIC, mark it as loaded so everything works OK
95 	//
96 	m_bASICLoaded = TRUE;
97 
98 }	// CDarla24DspCommObject::CDarla24DspCommObject( DWORD dwPhysRegBase )
99 
100 
101 //===========================================================================
102 //
103 // Destructor
104 //
105 //===========================================================================
106 
107 CDarla24DspCommObject::~CDarla24DspCommObject()
108 {
109 }	// CDarla24DspCommObject::~CDarla24DspCommObject()
110 
111 
112 
113 
114 /****************************************************************************
115 
116 	Hardware config
117 
118  ****************************************************************************/
119 
120 //===========================================================================
121 //
122 // SetSampleRate
123 //
124 // Set the audio sample rate for Darla24; this is fairly simple.  You
125 // just pick the right magic number.
126 //
127 //===========================================================================
128 
129 DWORD CDarla24DspCommObject::SetSampleRate( DWORD dwNewSampleRate )
130 {
131 	BYTE	bClock;
132 
133 	//
134 	// Pick the magic number
135 	//
136 	switch ( dwNewSampleRate )
137 	{
138 		case 96000 :
139 			bClock = GD24_96000;
140 			break;
141 		case 88200 :
142 			bClock = GD24_88200;
143 			break;
144 		case 48000 :
145 			bClock = GD24_48000;
146 			break;
147 		case 44100 :
148 			bClock = GD24_44100;
149 			break;
150 		case 32000 :
151 			bClock = GD24_32000;
152 			break;
153 		case 22050 :
154 			bClock = GD24_22050;
155 			break;
156 		case 16000 :
157 			bClock = GD24_16000;
158 			break;
159 		case 11025 :
160 			bClock = GD24_11025;
161 			break;
162 		case 8000 :
163 		 	bClock = GD24_8000;
164 			break;
165 		default :
166 			ECHO_DEBUGPRINTF( ("CDarla24DspCommObject::SetSampleRate: Error, "
167 									 "invalid sample rate 0x%lx\n", dwNewSampleRate) );
168 			return 0xffffffff;
169 	}
170 
171 	if ( !WaitForHandshake() )
172 		return 0xffffffff;
173 
174 	//
175 	// Override the sample rate if this card is set to Echo sync.
176 	// m_pDspCommPage->wInputClock is just being used as a parameter here;
177 	// the DSP ignores it.
178 	//
179 	if ( ECHO_CLOCK_ESYNC == GetInputClock() )
180 		bClock = GD24_EXT_SYNC;
181 
182 	m_pDspCommPage->dwSampleRate = SWAP( dwNewSampleRate );
183 
184 	//
185 	// Write the audio state to the comm page
186 	//
187 	m_pDspCommPage->byGDClockState = bClock;
188 
189 	// Send command to DSP
190 	ClearHandshake();
191 	SendVector( DSP_VC_SET_GD_AUDIO_STATE );
192 
193 	ECHO_DEBUGPRINTF( ("CDarla24DspCommObject::SetSampleRate: 0x%lx "
194 							 "clock %d\n", dwNewSampleRate, bClock) );
195 
196 	return GetSampleRate();
197 
198 } // DWORD CDarla24DspCommObject::SetSampleRate( DWORD dwNewSampleRate )
199 
200 
201 //===========================================================================
202 //
203 // Set input clock
204 //
205 // Darla24 supports internal and Esync clock.
206 //
207 //===========================================================================
208 
209 ECHOSTATUS CDarla24DspCommObject::SetInputClock(WORD wClock)
210 {
211 	if ( 	(ECHO_CLOCK_INTERNAL != wClock) &&
212 			(ECHO_CLOCK_ESYNC != wClock))
213 		return ECHOSTATUS_CLOCK_NOT_SUPPORTED;
214 
215 	m_wInputClock = wClock;
216 
217 	return SetSampleRate( GetSampleRate() );
218 
219 }	// SetInputClock
220 
221 
222 // **** Darla24DspCommObject.cpp ****
223