BPicture: Fix archive constructor.
[haiku.git] / src / add-ons / kernel / drivers / audio / echo / generic / CMiaDspCommObject.cpp
blobf2f065119552ef3016e0dccdc40b6d921fe49731
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
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.
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.
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
29 // ****************************************************************************
31 #include "CEchoGals.h"
32 #include "CMiaDspCommObject.h"
34 #include "MiaDSP.c"
37 /****************************************************************************
39 Construction and destruction
41 ****************************************************************************/
43 //===========================================================================
45 // Constructor
47 //===========================================================================
49 CMiaDspCommObject::CMiaDspCommObject
51 PDWORD pdwRegBase, // Virtual ptr to DSP registers
52 PCOsSupport pOsSupport
53 ) : CDspCommObjectVmixer( pdwRegBase, pOsSupport )
55 strcpy( m_szCardName, "Mia" );
56 m_pdwDspRegBase = pdwRegBase; // Virtual addr DSP's register base
58 m_wNumPipesOut = 8;
59 m_wNumPipesIn = 4;
60 m_wNumBussesOut = 4;
61 m_wNumBussesIn = 4;
62 m_wFirstDigitalBusOut = 2;
63 m_wFirstDigitalBusIn = 2;
65 m_fHasVmixer = TRUE;
67 if (MIA_MIDI_REV == pOsSupport->GetCardRev())
69 m_wNumMidiOut = 1; // # MIDI out channels
70 m_wNumMidiIn = 1; // # MIDI in channels
73 m_pDspCommPage->dwSampleRate = SWAP( (DWORD) 44100 );
75 m_bHasASIC = FALSE;
77 m_pwDspCodeToLoad = pwMiaDSP;
79 m_byDigitalMode = DIGITAL_MODE_NONE;
82 // Since this card has no ASIC, mark it as loaded so everything works OK
84 m_bASICLoaded = TRUE;
86 } // CMiaDspCommObject::CMiaDspCommObject( DWORD dwPhysRegBase )
89 //===========================================================================
91 // Destructor
93 //===========================================================================
95 CMiaDspCommObject::~CMiaDspCommObject()
97 } // CMiaDspCommObject::~CMiaDspCommObject()
102 /****************************************************************************
104 Hardware setup and config
106 ****************************************************************************/
108 //===========================================================================
110 // Set the input clock
112 //===========================================================================
114 ECHOSTATUS CMiaDspCommObject::SetInputClock(WORD wClock)
116 DWORD dwSampleRate = GetSampleRate();
118 ECHO_DEBUGPRINTF( ("CMiaDspCommObject::SetInputClock:\n") );
120 switch ( wClock )
122 case ECHO_CLOCK_INTERNAL :
124 ECHO_DEBUGPRINTF( ( "\tSet Mia clock to INTERNAL\n" ) );
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 ) )
131 dwSampleRate = 48000;
134 break;
135 } // CLK_CLOCKININTERNAL
137 case ECHO_CLOCK_SPDIF :
139 ECHO_DEBUGPRINTF( ( "\tSet Mia clock to SPDIF\n" ) );
140 break;
141 } // CLK_CLOCKINSPDIF
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)
149 m_wInputClock = wClock;
151 SetSampleRate( dwSampleRate );
153 return ECHOSTATUS_OK;
154 } // ECHOSTATUS CMiaDspCommObject::SetInputClock
157 //===========================================================================
159 // SetSampleRate
161 // Set the audio sample rate for Mia
163 //===========================================================================
165 DWORD CMiaDspCommObject::SetSampleRate( DWORD dwNewSampleRate )
168 // Set the sample rate
170 DWORD dwControlReg = MIA_48000;
172 switch ( dwNewSampleRate )
174 case 96000 :
175 dwControlReg = MIA_96000;
176 break;
178 case 88200 :
179 dwControlReg = MIA_88200;
180 break;
182 case 44100 :
183 dwControlReg = MIA_44100;
184 break;
186 case 32000 :
187 dwControlReg = MIA_32000;
188 break;
192 // Override the clock setting if this Mia is set to S/PDIF clock
194 if ( ECHO_CLOCK_SPDIF == GetInputClock() )
195 dwControlReg |= MIA_SPDIF;
198 // Set the control register if it has changed
200 if (dwControlReg != GetControlRegister())
202 if ( !WaitForHandshake() )
203 return 0xffffffff;
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
210 m_pDspCommPage->dwSampleRate = SWAP( dwNewSampleRate );
211 SetControlRegister( dwControlReg );
214 // Poke the DSP
216 ClearHandshake();
217 SendVector( DSP_VC_UPDATE_CLOCKS );
220 return GetSampleRate();
222 } // DWORD CMiaDspCommObject::SetSampleRate( DWORD dwNewSampleRate )
224 // **** CMiaDspCommObject.cpp ****