source: cmedia/trunk/Vsd/AudioIF/os2mixer.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: 25.3 KB
Line 
1/********************* START OF SPECIFICATIONS *****************************
2* *
3* SOURCE FILE NAME: OS2MIXER.C *
4* *
5* DESCRIPTIVE NAME: Multi-Media Mixer Library *
6* *
7* COPYRIGHT: *
8* Copyright (c) Media Vision 1991,1992, 1993 *
9* All Rights Reserved *
10* Copyright (c) IBM Corp. 1993, 1994 *
11* *
12* 05/24/94 Linden deCarmo Eliminated mixOpen *
13* 06/08/94 Linden deCarmo Update structs per FRB *
14* 06/11/94 Linden deCarmo VSD documentation improvements *
15* 06/11/94 Linden deCarmo Removed unused mixer functions *
16* 06/15/94 Linden deCarmo Updated error mapping. *
17* 06/16/94 Linden deCarmo Created consistend comments. *
18* 07/22/94 Mike Koval WPOS Changes for WorkPlace OS *
19* 08/25/95 Linden deCarmo Update call to DD_MixerSetControl 16917*
20* *
21*********************** END OF SPECIFICATIONS ******************************/
22
23#define INCL_NOPMAPI // no PM include files required
24#define INCL_DOSFILEMGR // need for Dos File I/O API's
25#define INCL_DOSDEVICES // Device values
26#define INCL_DOS
27#define INCL_ERRORS
28
29#define INCL_AUDIO_VSD
30
31//-----------------------------------------------------------------------------
32#ifdef INCL_MM_WPOS
33//#include <mach.h>
34#include <mk.h>
35//#include <pns\dd_debug.h>
36//#include <pns\dd_audio.h>
37#include <dd_audio.h>
38#include <pns\dd_error.h>
39#endif
40//-----------------------------------------------------------------------------
41
42#include <os2.h>
43#include <os2def.h>
44
45#include <os2me.h>
46#include <mcd.h>
47
48#include <audio.h>
49
50#include <stdio.h>
51#include <string.h>
52#include <stdlib.h>
53
54#include <os2mixer.h> // header defs for this I/O proc
55#include <vsdcmds.h>
56#include <vsdaud.h>
57
58void MapMixErrors (PULONG pulError );
59ULONG MixMessage( HMIXER hMix, ULONG msg, PVOID pData, ULONG ulDataSize );
60
61//-----------------------------------------------------------------------------
62#ifdef INCL_MM_WPOS
63
64ULONG MMtoDDMap (ULONG);
65ULONG DDtoMMMap (ULONG);
66ULONG MixMMtoDDMap (ULONG);
67ULONG MixDDtoMMMap (ULONG);
68
69#define NUMSOURCEENTRY 8
70#define NUMSINKENTRY 7
71#define NUMMIXENTRY 19
72
73typedef struct
74 {
75 ULONG ulMMSource;
76 ULONG ulDDSource;
77 } SOURCETABLE;
78
79typedef struct
80 {
81 ULONG ulMMSink;
82 ULONG ulDDSink;
83 } SINKTABLE;
84
85typedef struct
86 {
87 ULONG ulMMMix;
88 ULONG ulDDMix;
89 } MIXTABLE;
90
91SOURCETABLE SourceSinkTable[NUMSOURCEENTRY*2] =
92 {
93 {SOURCE_SYNTHESIZER, AUDIO_SOURCE_SYNTHESIZER },
94 {SOURCE_LINE, AUDIO_SOURCE_LINE_IN },
95 {0, AUDIO_SOURCE_MIXER },
96 {SOURCE_INTERNAL_AUDIO, AUDIO_SOURCE_INTERNAL_AUDIO },
97 {SOURCE_MICROPHONE, AUDIO_SOURCE_MICROPHONE },
98 {SOURCE_WAVE, AUDIO_SOURCE_WAVE },
99 {SOURCE_PC_SPEAKER, AUDIO_SOURCE_PC_SPEAKER },
100 {SOURCE_MIDI, AUDIO_SOURCE_MIDI },
101
102 {SINK_LINE_OUT, AUDIO_SINK_LINE_OUT },
103 {SINK_SPEAKER, AUDIO_SINK_SPEAKER },
104 {SINK_HEADPHONES, AUDIO_SINK_HEADPHONES },
105 {SINK_NULL, AUDIO_SINK_NULL },
106 {SINK_ALL, AUDIO_SINK_GENERIC },
107 {SINK_WAVE, AUDIO_SINK_WAVE },
108 {SINK_MIDI, 0 }
109 };
110
111MIXTABLE aMixTable[NUMMIXENTRY] =
112 {
113 {MIX_BALANCE, AUDIO_MIX_BALANCE },
114 {MIX_ALC, AUDIO_MIX_ALC },
115 {MIX_MONITOR, AUDIO_MIX_MONITOR },
116 {MIX_CROSSOVER, AUDIO_MIX_CROSSOVER },
117 {MIX_LOUDNESS, AUDIO_MIX_LOUDNESS },
118 {MIX_MUTE, AUDIO_MIX_MUTE },
119 {MIX_REVERB, AUDIO_MIX_REVERB },
120 {MIX_STEREOENHANCE, AUDIO_MIX_STEREO_ENHANCE },
121 {MIX_CUSTOM1, AUDIO_MIX_CUSTOM1 },
122 {MIX_CUSTOM2, AUDIO_MIX_CUSTOM2 },
123 {MIX_CUSTOM3, AUDIO_MIX_CUSTOM3 },
124 {MIX_LRVOLUME, 0 },
125 {MIX_BASS, AUDIO_MIX_BASS },
126 {MIX_MID, 0 },
127 {MIX_TREBLE, AUDIO_MIX_TREBLE },
128 {MIX_PITCH, AUDIO_MIX_PITCH },
129 {MIX_GAIN, 0 },
130 {MIX_CHORUS, 0 },
131 {MIX_VOLUME, AUDIO_MIX_VOLUME }
132 };
133
134#endif
135//-----------------------------------------------------------------------------
136
137
138#ifdef MMDEBUG
139#include <stdio.h>
140#endif
141
142
143/************************** START OF SPECIFICATIONS ************************
144* *
145* SUBROUTINE NAME: mixGetConnections *
146* *
147* DESCRIPTIVE NAME: Determine if a mixer line is enabled. *
148* *
149* FUNCTION: Call audio device driver to determine if source (in ulLine) *
150* is connected to anything. Valid sinks are returned in *
151* ulConnection. *
152* *
153* OUTPUT: VSDERR_SUCESS if there was a match *
154* An MCI error otherwise *
155* *
156* SIDE EFFECTS: *
157* *
158*************************** END OF SPECIFICATIONS **************************/
159
160ULONG mixGetConnections ( HMIXER hMixer,
161 PLINECONNECTIONS pConnections)
162{
163 ULONG ulLastError;
164
165
166//-----------------------------------------------------------------------------
167#ifdef INCL_MM_OS2
168 ulLastError=MixMessage( hMixer,
169 MIX_GETCONNECTIONS,
170 (PVOID ) pConnections,
171 sizeof (LINECONNECTIONS ) );
172#endif
173//-----------------------------------------------------------------------------
174
175//-----------------------------------------------------------------------------
176#ifdef INCL_MM_WPOS
177 ULONG ulLine = MMtoDDMap( pConnections->ulLine );
178
179// ulLastError = DD_MixerGetConnections( (mach_port_t) hMixer,
180 ulLastError = DD_MixerGetConnections( (port_t) hMixer,
181 ulLine,
182 &pConnections->ulConnection);
183#ifdef MMHACK
184 ulLastError = 0;
185#endif
186
187 pConnections->ulConnection = DDtoMMMap( pConnections->ulConnection );
188#endif
189//-----------------------------------------------------------------------------
190
191#ifdef PERFORMANCE_TRACE
192 console_printf("mixGetConnections entry\n");
193#endif
194
195 return(ulLastError);
196
197} /* mixGetConnections */
198
199/************************** START OF SPECIFICATIONS ************************
200* *
201* SUBROUTINE NAME: mixSetConnections *
202* *
203* DESCRIPTIVE NAME: Connects a mixer source to a sink. *
204* *
205* FUNCTION: Call audio device driver to connect a source (in ulLine) *
206* to a sink (in ulConnection). *
207* *
208* OUTPUT: VSDERR_SUCESS if there was a match *
209* An MCI error otherwise *
210* *
211* SIDE EFFECTS: *
212* *
213*************************** END OF SPECIFICATIONS **************************/
214
215ULONG mixSetConnections ( HMIXER hMixer,
216 PLINECONNECTIONS pConnections)
217{
218 ULONG ulLastError = 0;
219#ifdef PERFORMANCE_TRACE
220 ULONG ulTime = 0;
221 CHAR LoadError[100];
222 CHAR DebugBuf[256];
223 console_printf("mixSetConnections entry\n");
224 PerfStartTime();
225#endif
226
227
228
229//-----------------------------------------------------------------------------
230#ifdef INCL_MM_OS2
231
232 ulLastError=MixMessage( hMixer,
233 MIX_SETCONNECTIONS,
234 (PVOID ) pConnections,
235 sizeof ( LINECONNECTIONS ) );
236#endif
237//-----------------------------------------------------------------------------
238
239//-----------------------------------------------------------------------------
240#ifdef INCL_MM_WPOS
241 ULONG ulLine = MMtoDDMap( pConnections->ulLine );
242 ULONG ulConnection = MMtoDDMap( pConnections->ulConnection );
243
244// ulLastError = DD_MixerSetConnections( (mach_port_t) hMixer,
245 ulLastError = DD_MixerSetConnections( (port_t) hMixer,
246 ulLine,
247 ulConnection);
248#ifndef MMHACK
249 // vivek's havk since this one stopped working
250 // after moving to the new build.
251 ulLastError = 0;
252#endif
253
254
255#ifdef PERFORMANCE_TRACE
256 ulTime += PerfGetTime();
257 strcpy(DebugBuf, "mixSetConnections exit: Time microseconds consumed ");
258 _ltoa((ULONG)ulTime, LoadError, 10);
259 strcat(DebugBuf, LoadError);
260
261 console_printf(DebugBuf );
262#endif
263
264
265#endif
266//-----------------------------------------------------------------------------
267
268
269
270 return(ulLastError);
271
272} /* mixSetConnections */
273
274
275
276/************************** START OF SPECIFICATIONS ************************
277* *
278* SUBROUTINE NAME: mixGetLineInfo *
279* *
280* DESCRIPTIVE NAME: Returns capabilities (i.e. volume etc.) for a given *
281* line. *
282* *
283* FUNCTION: Call audio device driver to determine the source's (in ulLine) *
284* capabilities (returned in ulSupport). *
285* *
286* OUTPUT: VSDERR_SUCESS if there was a match *
287* An MCI error otherwise *
288* *
289* SIDE EFFECTS: *
290* *
291*************************** END OF SPECIFICATIONS **************************/
292
293
294ULONG mixGetLineInfo( HMIXER hMixer,
295 PMIXERLINEINFO pInfo )
296{
297 ULONG ulLastError;
298//-----------------------------------------------------------------------------
299#ifdef INCL_MM_OS2
300 ulLastError=MixMessage( hMixer,
301 MIX_GETLINEINFO,
302 (PVOID) pInfo,
303 sizeof( MIXERLINEINFO ));
304#endif
305//-----------------------------------------------------------------------------
306
307//-----------------------------------------------------------------------------
308#ifdef INCL_MM_WPOS
309 audio_line_info_t AudioLineInfo;
310 ULONG ulLine = MMtoDDMap( pInfo->ulLine );
311#ifdef PERFORMANCE_TRACE
312 ULONG ulTime = 0;
313 CHAR LoadError[100];
314 CHAR DebugBuf[256];
315 console_printf("mixSetControl entry\n");
316 PerfStartTime();
317#endif
318
319// ulLastError = DD_MixerGetLineInfo( (mach_port_t) hMixer,
320 ulLastError = DD_MixerGetLineInfo( (port_t) hMixer,
321 ulLine,
322 &AudioLineInfo);
323#ifdef MMHACK
324 ulLastError = DD_SUCCESS;
325#endif
326 if (ulLastError == DD_SUCCESS) {
327 pInfo->ulNumChannels = AudioLineInfo.channel_count;
328 pInfo->ulSupport = MixDDtoMMMap( AudioLineInfo.supported_controls );
329 pInfo->ulConnectionsPossible = DDtoMMMap( AudioLineInfo.connections_possible );
330
331 //WPOS -- Is this not used???
332// pInfo->??? = AudioLineInfo.max_connections;
333 }
334
335#ifdef PERFORMANCE_TRACE
336 ulTime += PerfGetTime();
337 strcpy(DebugBuf, "mixGetLineInfo exit: Time microseconds consumed ");
338 _ltoa((ULONG)ulTime, LoadError, 10);
339 strcat(DebugBuf, LoadError);
340
341 console_printf(DebugBuf );
342#endif
343
344#endif
345//-----------------------------------------------------------------------------
346
347return(ulLastError);
348}
349
350/************************** START OF SPECIFICATIONS ************************
351* *
352* SUBROUTINE NAME: mixGetControl *
353* *
354* DESCRIPTIVE NAME: Determine the state of a line's controls. *
355* *
356* FUNCTION: Call audio device driver to determine the source's (in ulLine) *
357* control (in ulControl) setting (i.e. range 0-0xffff). *
358* *
359* OUTPUT: VSDERR_SUCESS if there was a match *
360* An MCI error otherwise *
361* *
362* SIDE EFFECTS: *
363* *
364*************************** END OF SPECIFICATIONS **************************/
365
366
367ULONG mixGetControl( HMIXER hMixer,
368
369 PMIXERCONTROL pMixControl )
370{
371 ULONG ulLastError;
372
373//-----------------------------------------------------------------------------
374#ifdef INCL_MM_OS2
375 ulLastError=MixMessage( hMixer,
376 MIX_GETCONTROL,
377 (PVOID) pMixControl,
378 sizeof( MIXERCONTROL) );
379#endif
380//-----------------------------------------------------------------------------
381
382//-----------------------------------------------------------------------------
383#ifdef INCL_MM_WPOS
384 ULONG ulLine = MMtoDDMap( pMixControl->ulLine );
385 ULONG ulControl = MixMMtoDDMap( pMixControl->ulControl );
386
387// ulLastError = DD_MixerGetControl( (mach_port_t) hMixer,
388 ulLastError = DD_MixerGetControl( (port_t) hMixer,
389 ulLine,
390 ulControl,
391 &pMixControl->ulSetting);
392#ifdef MMHACK
393 ulLastError = 0;
394#endif
395
396#endif
397//-----------------------------------------------------------------------------
398
399#ifdef PERFORMANCE_TRACE
400 console_printf("mixGetControl entry\n");
401#endif
402return(ulLastError);
403}
404/************************** START OF SPECIFICATIONS ************************
405* *
406* SUBROUTINE NAME: mixSetControl *
407* *
408* DESCRIPTIVE NAME: Set the state of a line's controls. *
409* *
410* FUNCTION: Call audio device driver to set the source's (in ulLine) *
411* control (in ulControl) setting (i.e. range 0-0xffff). *
412* *
413* OUTPUT: VSDERR_SUCESS if there was a match *
414* An MCI error otherwise *
415* *
416* SIDE EFFECTS: *
417* *
418*************************** END OF SPECIFICATIONS **************************/
419
420ULONG mixSetControl( HMIXER hMixer,
421 PMIXERCONTROL pMixControl )
422
423{
424 ULONG ulLastError;
425
426#ifdef PERFORMANCE_TRACE
427 ULONG ulTime = 0;
428 CHAR LoadError[100];
429 CHAR DebugBuf[256];
430#endif
431
432//-----------------------------------------------------------------------------
433#ifdef INCL_MM_OS2
434 ulLastError=MixMessage( hMixer,
435 MIX_SETCONTROL,
436 (PVOID) pMixControl,
437 sizeof( MIXERCONTROL) );
438#endif
439//-----------------------------------------------------------------------------
440
441//-----------------------------------------------------------------------------
442#ifdef INCL_MM_WPOS
443#ifdef PERFORMANCE_TRACE
444 console_printf("mixSetControl entry\n");
445 PerfStartTime();
446#endif
447 ULONG ulLine = MMtoDDMap( pMixControl->ulLine );
448 ULONG ulControl = MixMMtoDDMap( pMixControl->ulControl );
449
450// ulLastError = DD_MixerSetControl( (mach_port_t) hMixer,
451 ulLastError = DD_MixerSetControl( (port_t) hMixer,
452 ulLine,
453 ulControl,
454 pMixControl->ulSetting, //lad 16917
455 (LONG) pMixControl->ulFlags); //lad 16917
456#ifdef MMHACK
457 ulLastError = 0;
458#endif
459
460#endif
461//-----------------------------------------------------------------------------
462
463#ifdef PERFORMANCE_TRACE
464 ulTime += PerfGetTime();
465 strcpy(DebugBuf, "mixSetControl exit: Time microseconds consumed ");
466 _ltoa((ULONG)ulTime, LoadError, 10);
467 strcat(DebugBuf, LoadError);
468
469 console_printf(DebugBuf );
470#endif
471 return(ulLastError);
472
473} /* mixSetControl */
474
475
476
477/************************** START OF SPECIFICATIONS ************************
478* *
479* SUBROUTINE NAME: MixMessage *
480* *
481* DESCRIPTIVE NAME: Call Device driver with mixer message. *
482* *
483* FUNCTION: Send a mixer IOCTL to AUDIODD driver. *
484* *
485* OUTPUT: VSDERR_SUCESS if there was a match *
486* An MCI error otherwise *
487* *
488* SIDE EFFECTS: *
489* *
490*************************** END OF SPECIFICATIONS **************************/
491
492//-----------------------------------------------------------------------------
493#ifdef INCL_MM_OS2
494ULONG MixMessage( HMIXER hMix,
495 ULONG msg,
496 PVOID pData,
497 ULONG ulDataSize )
498{
499APIRET rc; /* Return code */
500
501ULONG ulParmOut;
502ULONG ulParmLengthInOut = 0L;
503
504
505 rc = DosDevIOCtl( hMix,
506 AUDIO_IOCTL_CAT,
507 msg,
508 NULL,
509 0,
510 &ulParmLengthInOut,
511 pData,
512 ulDataSize,
513 (PVOID) &ulParmOut);
514
515
516 MapMixErrors( &rc );
517 return ( rc );
518
519} /* mixmessage */
520#endif
521//-----------------------------------------------------------------------------
522
523
524/************************ START OF SPECIFICATIONS **************************
525*
526* SUBROUTINE NAME: MapMixErrrors
527*
528* FUNCTION: Converts mixer errors to MCI errors
529*
530* INPUT: PULONG -- error to map
531*
532* OUTPUT: void
533*
534* OS/2 CALLS:
535*
536* C CALLS: None.
537*
538*
539*************************** END OF SPECIFICATIONS *************************/
540
541//-----------------------------------------------------------------------------
542#ifdef INCL_MM_OS2
543void MapMixErrors (PULONG pulError )
544{
545 switch ( *pulError )
546 {
547 case MIXERR_INVALIDOUTPUT :
548 case MIXERR_INVALIDINPUT :
549 *pulError = VSDERR_INVALID_CONNECTOR_TYPE;
550 break;
551 default :
552 *pulError = VSDERR_SUCCESS;
553 }
554} // MapMixErrors
555#endif
556//-----------------------------------------------------------------------------
557
558/************************ START OF SPECIFICATIONS **************************
559*
560* SUBROUTINE NAME: MMtoDDMap
561*
562* FUNCTION: Map multimedia source defines to device driver source defines.
563*
564* INPUT: ULONG -- source to map
565*
566* OUTPUT: source mapped.
567*
568* OS/2 CALLS:
569*
570* C CALLS: None.
571*
572*
573*************************** END OF SPECIFICATIONS *************************/
574
575#ifdef INCL_MM_WPOS
576ULONG MMtoDDMap (ULONG ulSource)
577{
578 int i;
579 ULONG ulOutMap = 0;
580
581 for (i=0; i<NUMSOURCEENTRY*2; i++) {
582 if ( ulSource & SourceSinkTable[i].ulMMSource )
583 ulOutMap |= SourceSinkTable[i].ulDDSource;
584 }
585 return (ulOutMap);
586}
587#endif
588
589
590/************************ START OF SPECIFICATIONS **************************
591*
592* SUBROUTINE NAME: DDtoMMMap
593*
594* FUNCTION: Map device driver source defines to multimedia source defines.
595*
596* INPUT: ULONG -- source to map
597*
598* OUTPUT: source mapped.
599*
600* OS/2 CALLS:
601*
602* C CALLS: None.
603*
604*
605*************************** END OF SPECIFICATIONS *************************/
606
607//-----------------------------------------------------------------------------
608#ifdef INCL_MM_WPOS
609ULONG DDtoMMMap (ULONG ulSource)
610{
611 int i;
612 ULONG ulOutMap = 0;
613
614 for (i=0; i<NUMSOURCEENTRY*2; i++) {
615 if ( ulSource & SourceSinkTable[i].ulDDSource )
616 ulOutMap |= SourceSinkTable[i].ulMMSource;
617 }
618 return (ulOutMap);
619}
620#endif
621//-----------------------------------------------------------------------------
622
623/************************ START OF SPECIFICATIONS **************************
624*
625* SUBROUTINE NAME: MixMMtoDDMap
626*
627* FUNCTION: Map multimedia mix defines to device driver mix defines.
628*
629* INPUT: ULONG -- mix to map
630*
631* OUTPUT: mix mapped.
632*
633* OS/2 CALLS:
634*
635* C CALLS: None.
636*
637*
638*************************** END OF SPECIFICATIONS *************************/
639
640//-----------------------------------------------------------------------------
641#ifdef INCL_MM_WPOS
642ULONG MixMMtoDDMap (ULONG ulMix)
643{
644 int i;
645 ULONG ulOutMap = 0;
646 ULONG ulInMMMap;
647 ULONG ulInDDMap;
648
649 for (i=0; i<NUMMIXENTRY; i++)
650 {
651 ulInMMMap = aMixTable[i].ulMMMix;
652 ulInDDMap = aMixTable[i].ulDDMix;
653 if ( ulMix & ulInMMMap )
654 ulOutMap |= ulInDDMap;
655 }
656 return ulOutMap;
657}
658#endif
659//-----------------------------------------------------------------------------
660
661
662/************************ START OF SPECIFICATIONS **************************
663*
664* SUBROUTINE NAME: MixDDtoMMMap
665*
666* FUNCTION: Map device driver mix defines to multimedia mix defines.
667*
668* INPUT: ULONG -- mix to map
669* PULONG -- area to put mix map
670*
671* OUTPUT: mix mapped.
672*
673* OS/2 CALLS:
674*
675* C CALLS: None.
676*
677*
678*************************** END OF SPECIFICATIONS *************************/
679
680//-----------------------------------------------------------------------------
681#ifdef INCL_MM_WPOS
682ULONG MixDDtoMMMap (ULONG ulMix)
683{
684 int i;
685 ULONG ulOutMap = 0;
686 ULONG ulInMMMap;
687 ULONG ulInDDMap;
688
689 for (i=0; i<NUMMIXENTRY; i++)
690 {
691 ulInMMMap = aMixTable[i].ulMMMix;
692 ulInDDMap = aMixTable[i].ulDDMix;
693 if ( ulMix & ulInDDMap )
694 ulOutMap |= ulInMMMap;
695 }
696 return ulOutMap;
697}
698#endif
699//-----------------------------------------------------------------------------
Note: See TracBrowser for help on using the repository browser.