1// ****************************************************************************
2//
3//  	CMiaDspCommObject.cpp
4//
5//		Implementation file for EchoGals generic driver Mia DSP
6//		interface class.
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 "CEchoGals.h"
32#include "CMiaDspCommObject.h"
33
34#include "MiaDSP.c"
35
36
37/****************************************************************************
38
39	Construction and destruction
40
41 ****************************************************************************/
42
43//===========================================================================
44//
45// Constructor
46//
47//===========================================================================
48
49CMiaDspCommObject::CMiaDspCommObject
50(
51	PDWORD		pdwRegBase,				// Virtual ptr to DSP registers
52	PCOsSupport	pOsSupport
53) : CDspCommObjectVmixer( pdwRegBase, pOsSupport )
54{
55	strcpy( m_szCardName, "Mia" );
56	m_pdwDspRegBase = pdwRegBase;		// Virtual addr DSP's register base
57
58	m_wNumPipesOut = 8;
59	m_wNumPipesIn = 4;
60	m_wNumBussesOut = 4;
61	m_wNumBussesIn = 4;
62	m_wFirstDigitalBusOut = 2;
63	m_wFirstDigitalBusIn = 2;
64
65	m_fHasVmixer = TRUE;
66
67	if (MIA_MIDI_REV == pOsSupport->GetCardRev())
68	{
69		m_wNumMidiOut = 1;					// # MIDI out channels
70		m_wNumMidiIn = 1;						// # MIDI in  channels
71	}
72
73	m_pDspCommPage->dwSampleRate = SWAP( (DWORD) 44100 );
74
75	m_bHasASIC = FALSE;
76
77	m_pwDspCodeToLoad = pwMiaDSP;
78
79	m_byDigitalMode = DIGITAL_MODE_NONE;
80
81	//
82	// Since this card has no ASIC, mark it as loaded so everything works OK
83	//
84	m_bASICLoaded = TRUE;
85
86}	// CMiaDspCommObject::CMiaDspCommObject( DWORD dwPhysRegBase )
87
88
89//===========================================================================
90//
91// Destructor
92//
93//===========================================================================
94
95CMiaDspCommObject::~CMiaDspCommObject()
96{
97}	// CMiaDspCommObject::~CMiaDspCommObject()
98
99
100
101
102/****************************************************************************
103
104	Hardware setup and config
105
106 ****************************************************************************/
107
108//===========================================================================
109//
110//	Set the input clock
111//
112//===========================================================================
113
114ECHOSTATUS CMiaDspCommObject::SetInputClock(WORD wClock)
115{
116	DWORD	dwSampleRate = GetSampleRate();
117
118	ECHO_DEBUGPRINTF( ("CMiaDspCommObject::SetInputClock:\n") );
119
120	switch ( wClock )
121	{
122		case ECHO_CLOCK_INTERNAL :
123		{
124			ECHO_DEBUGPRINTF( ( "\tSet Mia clock to INTERNAL\n" ) );
125
126			// If the sample rate is out of range for some reason, set it
127			// to a reasonable value.  mattg
128			if ( ( dwSampleRate < 32000  ) ||
129			     ( dwSampleRate > 96000 ) )
130			{
131				dwSampleRate = 48000;
132			}
133
134			break;
135		} // CLK_CLOCKININTERNAL
136
137		case ECHO_CLOCK_SPDIF :
138		{
139			ECHO_DEBUGPRINTF( ( "\tSet Mia clock to SPDIF\n" ) );
140			break;
141		} // CLK_CLOCKINSPDIF
142
143		default :
144			ECHO_DEBUGPRINTF(("Input clock 0x%x not supported for Mia\n",wClock));
145			ECHO_DEBUGBREAK();
146				return ECHOSTATUS_CLOCK_NOT_SUPPORTED;
147	}	// switch (wInputClock)
148
149	m_wInputClock = wClock;
150
151	SetSampleRate( dwSampleRate );
152
153	return ECHOSTATUS_OK;
154}	// ECHOSTATUS CMiaDspCommObject::SetInputClock
155
156
157//===========================================================================
158//
159// SetSampleRate
160//
161// Set the audio sample rate for Mia
162//
163//===========================================================================
164
165DWORD CMiaDspCommObject::SetSampleRate( DWORD dwNewSampleRate )
166{
167	//
168	// Set the sample rate
169	//
170	DWORD dwControlReg = MIA_48000;
171
172	switch ( dwNewSampleRate )
173	{
174		case 96000 :
175			dwControlReg = MIA_96000;
176			break;
177
178		case 88200 :
179			dwControlReg = MIA_88200;
180			break;
181
182		case 44100 :
183			dwControlReg = MIA_44100;
184			break;
185
186		case 32000 :
187			dwControlReg = MIA_32000;
188			break;
189	}
190
191	//
192	// Override the clock setting if this Mia is set to S/PDIF clock
193	//
194	if ( ECHO_CLOCK_SPDIF == GetInputClock() )
195		dwControlReg |= MIA_SPDIF;
196
197	//
198	//	Set the control register if it has changed
199	//
200	if (dwControlReg != GetControlRegister())
201	{
202		if ( !WaitForHandshake() )
203			return 0xffffffff;
204
205		//
206		// Set the values in the comm page; the dwSampleRate
207		// field isn't used by the DSP, but is read by the call
208		// to GetSampleRate below
209		//
210		m_pDspCommPage->dwSampleRate = SWAP( dwNewSampleRate );
211		SetControlRegister( dwControlReg );
212
213		//
214		//	Poke the DSP
215		//
216		ClearHandshake();
217		SendVector( DSP_VC_UPDATE_CLOCKS );
218	}
219
220	return GetSampleRate();
221
222} // DWORD CMiaDspCommObject::SetSampleRate( DWORD dwNewSampleRate )
223
224// **** CMiaDspCommObject.cpp ****
225