source: cmedia/trunk/Vsd/AudioIF/vsdopen.c@ 354

Last change on this file since 354 was 354, checked in by stevenhl, 17 years ago

Import untested baseline cmedia sources, work products and binaries
Binaries and work products should be deleted from repository.
once new builds are verified to work.

File size: 11.1 KB
Line 
1/************************* START OF SPECIinCATIONS ***
2*
3* SOURCE FILE NAME: VSDOPEN.C
4*
5* DESCRIPTIVE NAME: Open routines for the VSD.
6*
7* COPYRIGHT: IBM Confidential
8* Copyright (c) IBM Corporation 1991,1993
9* All Rights Reserved
10*
11*
12* FUNCTION: This source module will open the vsd (and associated audio
13* device driver). This VSD utilizes the AUDIODD interface and an
14* associated resource file to work around limitations in the AUDIODD
15* interface (which has been corrected with the capability IOCTL).
16*
17*
18* The following concepts are illustrated:
19* 1. How to share the same instance with another DLL (MCI Amp-mixer).
20* 2. Call to open the connected AUDIODD driver.
21* 3. Bring in the VSD resource file (and why it is necessary) or
22* utilize new device capability IOCTL.
23* 4. Setup for resource allocation.
24*
25* NOTES:
26*
27* Change History:
28* DATE DEVELOPER CHANGE DESCRIPTION
29* 07/22/93 Linden deCarmo File created
30* 05/24/94 Linden deCarmo Moved DosOpen to vsdioctl
31* 05/24/94 Linden deCarmo Eliminated mixOpen
32* 06/03/94 Linden deCarmo Added vsdOpen variable and fill in
33* 06/11/94 Linden deCarmo datasubtype field MUST be filled in
34* 06/14/94 Linden deCarmo Removed calls to setup io ports
35* 06/14/94 Linden deCarmo Updated initial comments for .c file
36* 06/19/94 Linden deCarmo Improved initial comments.
37* 07/22/94 Mike Koval WPOS Changes for WorkPlace OS
38* 10/11/94 Linden deCarmo Move DosClose to vsdioctl (os-specific).
39* 06/29/95 Linden deCarmo Cleanup Hardware mixer support (15552).
40*
41************************** END OF SPECIFICATIONS **************************/
42
43//#define INCL_NOPMAPI
44#define INCL_DOS
45#define INCL_ERRORS
46//#define INCL_WINSHELLDATA
47//#define INCL_WINWINDOWMGR
48//#define INCL_WINATOM
49//#define INCL_WIN
50#define INCL_AUDIO_VSD
51
52
53#include <os2.h>
54#include <os2me.h>
55#include <mcd.h>
56#include <audio.h>
57#include <stdio.h>
58#include <string.h>
59#include <hhpheap.h>
60
61
62#include <vsdcmds.h>
63#include <vsdaud.h>
64#include <os2mixer.h>
65#include <vsdmix.h>
66
67
68
69/************************ START OF SPECIFICATIONS **************************
70*
71* SUBROUTINE NAME: Open_Driver()
72*
73* FUNCTION: Verifies that the Audio DD has been loaded. Note, the open
74* should not consume any resources.
75*
76* INPUT: pInstance - pointer to VSD instance structure
77*
78* OUTPUT:
79*
80* SUCESS : VSDERR_SUCCESS
81*
82* FAILURE: VSDERR_NO_DEVICE_DRIVER
83*
84* OS/2 CALLS: DosOpen(), DosClose(),
85*
86* C CALLS: None
87*
88* INTERNAL CALLS:
89* *
90*************************** END OF SPECIFICATIONS *************************/
91
92LONG VSDOpen( PVSD_OPEN_PARMS pVSDOpenParms )
93
94{
95
96 LONG rc;
97// LONG lError = VSDERR_SUCCESS;
98
99 PVSD_INSTANCE pInstance;
100
101// ULONG ulAction;
102// ULONG ulOffset;
103// ULONG ulIniSize;
104
105// extern HHUGEHEAP hhpHeap;
106
107// HAB hab;
108// HINI hini;
109// BOOL fFoundMix;
110
111 PVSD_AUDIOOPEN_PARMS pvsddata;
112
113// CHAR szIniFile[261];
114// CHAR *pIniName;
115#ifdef PERFORMANCE_TRACE
116 ULONG ulTime = 0;
117 CHAR LoadError[100];
118 CHAR DebugBuf[256];
119 PerfStartTime();
120#endif
121
122 /* If the caller passed in a primer, prime the instance with it */
123
124 pvsddata = ( PVSD_AUDIOOPEN_PARMS ) pVSDOpenParms->pDevInfo;
125
126 /*-------------------------------------------
127 * Retrieve IBM instance from vsdData parms
128 * note: other VSD writers should NOT use
129 * this instance--rather allocate their
130 * own instance--since it is liable to
131 * change.
132 *------------------------------------------*/
133
134 pInstance = ( PVSD_INSTANCE )pvsddata->pDevInfo ;
135 pInstance->lSRate = pvsddata->ulSamplingRate;
136 pInstance->lBitsPerSRate = pvsddata->ulBitsPerSample;
137 pInstance->sChannels = pvsddata->ulChannels;
138 pInstance->sMode = pvsddata->ulDataType;
139 pInstance->usDeviceID = (USHORT) pvsddata->ulDeviceID;
140 pInstance->ulOperation = pvsddata->ulOperation;
141
142
143 pVSDOpenParms->hvsd = ( HVSD ) pInstance;
144
145
146 /* Store the name of the DD for future DosOpens */
147
148 memmove( pInstance->szDeviceName,
149 pVSDOpenParms->szPDDName,
150 strlen( pVSDOpenParms->szPDDName ) );
151
152// PERFORMANCE enhancements--hhp sets memory to 0
153// pInstance->ulActive = FALSE;
154// pInstance->fMute = FALSE;
155// pInstance->ulNumInputs = 0;
156// pInstance->ulNumOutputs = 0;
157// pInstance->ulGainLevel = 70;
158
159 /*-----------------------------------------------------
160 * Some devices (w/o mixer support) can create some
161 * horrible feedback effects. So allow the manufacturer
162 * to determine whether monitoring should be enabled.
163 *-----------------------------------------------------*/
164// PERFORMANCE enhancements--hhp sets memory to 0
165// pInstance->lMonitor = MCI_FALSE;
166
167
168 /*-----------------------*
169 * Open the audio device
170 *-----------------------*/
171
172 rc = OpenDevice ( pInstance );
173 if ( rc )
174 {
175 return ( rc );
176 }
177
178
179 /*-----------------------------------------------------------------*
180 * New device drivers will support the AUDIO_CAPABILITIES IOCTL. This
181 * IOCTL lets the mixer determine what sampling rate/bit per sample
182 * channels etc. the device supports. If the driver doesn't support
183 * the IOCTL, then we must load the information from a resource file.
184 *-----------------------------------------------------------------*/
185 rc = CapIOCTL( pInstance );
186 if ( rc )
187 {
188 /*-----------------------------------------------------------------*
189 * Each manufacturer is responsible for creating a resource file with
190 * all the device specific information we require. Retreive this
191 * resource table.
192 *-----------------------------------------------------------------*/
193//-----------------------------------------------------------------------------
194#ifdef INCL_MM_OS2
195 rc = SetupResourceTable( pInstance );
196
197 if ( rc )
198 {
199 CloseDevice( pInstance );
200 return ( rc );
201 }
202#endif
203//-----------------------------------------------------------------------------
204
205//-----------------------------------------------------------------------------
206#ifdef INCL_MM_WPOS
207 CloseDevice( pInstance );
208 return ( rc );
209#endif
210//-----------------------------------------------------------------------------
211
212 }
213// 15552
214 else
215 {
216 // setup instance to indicate mode device should go into.
217 // normally done with GetClassInformation if resource
218 // DLL is to be loaded.
219
220 pInstance->ulHardwareMode = pInstance->ulDataType;
221 }
222// 15552
223// LAD--check ulState variable--can
224 if ( pInstance->fDriverCaps & SUPPORT_MIX )
225 {
226// rc = mixOpen( ( PHMIXER ) &pInstance->hMix, 0 );
227 pInstance->hMix = pInstance->hFile;
228
229
230 // 10253--this means that we will have to close/reopen the VSD if data-types
231 // change.
232
233 switch ( pInstance->sMode )
234 {
235 case DATATYPE_MIDI :
236 pInstance->ulLine = SOURCE_SYNTHESIZER;
237
238 break;
239 default :
240 pInstance->ulLine = SOURCE_WAVE;
241 break;
242 }
243
244// PERFORMANCE enhancements--hhp sets memory to 0
245// pInstance->lOutput = FALSE; // Indicate that wave connector must be enabled.
246
247 /*-----------------------------------------
248 * This flag will indicate whether or not
249 * we will use the AUDIODD interface or
250 * use the new mixer IOCTL's.
251 *----------------------------------------*/
252
253// if ( pInstance->fDriverCaps & SUPPORT_MIX )
254// {
255 pInstance->fHardwareMix = TRUE;
256// }
257
258 // lad--capability addition
259 /*---------------------------------------------------------
260 * Figure out the capabilities of each input/output line.
261 *--------------------------------------------------------*/
262 DetermineLineCaps(pInstance );
263
264 // lad--capability addition
265
266 } /* If we are to open a real mixer */
267
268 /*---------------------------------------------------------
269 * We will ignore errors right now, since all DD's may not
270 * support the mixer functions.
271 *--------------------------------------------------------*/
272
273 /*-----------------------------------------------------------------*
274 * Return the resource class and number of resource units for the
275 * mode that the caller has specified.
276 *-----------------------------------------------------------------*/
277 // 15552--not necessary if one has caps already
278
279#ifndef INCL_MM_WPOS
280 // 15552
281 if ( !( pInstance->fDriverCaps & SUPPORT_CAP) )
282 {
283 rc = GetClassInformation( pInstance );
284
285 /*-------------------------------------------------
286 * Work around ACPA problems. Since we cannot ask
287 * the device driver if it can best fit until after
288 * the MCIDRV_RESTORE, perform the best fit on
289 * the open.
290 *-------------------------------------------------*/
291
292 if ( pInstance->ulDeviceID == MACPA &&
293 rc == VSDERR_UNSUPP_SAMPLESPERSEC )
294 {
295 ACPABestFit( pInstance );
296 rc = VSDERR_SUCCESS;
297 }
298 else if ( rc )
299 {
300 /*-------------------------------------------------
301 * If an error occurs because the VSD can't support the
302 * requested mode (i.e. some type of ADPCM the VSD doesn't
303 * support, then it should update the following fields
304 * in the vsddata parms to the NEAREST mode that is
305 * supported.
306 *-------------------------------------------------*/
307
308 pvsddata->ulSamplingRate = pInstance->ulBestFitRate;
309 pvsddata->ulBitsPerSample = pInstance->ulBestFitBPS ;
310 pvsddata->ulChannels = pInstance->ulBestFitChan;
311 pvsddata->ulDataType = pInstance->sBestFitMode ;
312
313 CloseDevice( pInstance);
314 }
315 }
316#endif
317 // 15552--not necessary if one has caps already
318
319 pvsddata->ulDataSubType = pInstance->ulSubType;
320
321 /*-------------------------------------------------
322 * The information is only utilized by the IBM VSD.
323 * Other VSDs do not have fill in this field.
324 *-------------------------------------------------*/
325
326 pvsddata->ulReserved1 = pInstance->ulGlobalFile;
327
328 return(rc);
329
330} /* Open Driver */
331
Note: See TracBrowser for help on using the repository browser.