Debian Codegraph @

3rdparty/iaxclient/lib/portmixer/px_win_wmme/px_win_wmme.c

raw symbols SCIP
1 /*
2 * PortMixer
3 * Windows WMME Implementation
4 *
5 * Copyright (c) 2002
6 *
7 * Written by Dominic Mazzoni and Augustus Saunders
8 *
9 * PortMixer is intended to work side-by-side with PortAudio,
10 * the Portable Real-Time Audio Library by Ross Bencina and
11 * Phil Burk.
12 *
13 * Permission is hereby granted, free of charge, to any person obtaining
14 * a copy of this software and associated documentation files
15 * (the "Software"), to deal in the Software without restriction,
16 * including without limitation the rights to use, copy, modify, merge,
17 * publish, distribute, sublicense, and/or sell copies of the Software,
18 * and to permit persons to whom the Software is furnished to do so,
19 * subject to the following conditions:
20 *
21 * The above copyright notice and this permission notice shall be
22 * included in all copies or substantial portions of the Software.
23 *
24 * Any person wishing to distribute modifications to the Software is
25 * requested to send the modifications to the original developer so that
26 * they can be incorporated into the canonical version.
27 *
28 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
29 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
30 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
31 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
32 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
33 * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
34 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35 *
36 */
37
38 #if defined(WIN32) || defined(_WIN32_WCE)
39 #include <stdlib.h>
40 #define strcasecmp _stricmp
41 #define strncasecmp _strnicmp
42 #else
43 #include <strings.h>
44 #endif
45
46 #include <windows.h>
47
48 #include "portaudio.h"
49 #include "portmixer.h"
50
51 #include "pa_cpuload.h"
52 #include "pa_process.h"
53 #include "pa_stream.h"
54
55 typedef struct
56 {
57 HANDLE bufferEvent;
58 void *waveHandles;
59 unsigned int deviceCount;
60 /* unsigned int channelCount; */
61 WAVEHDR **waveHeaders; /* waveHeaders[device][buffer] */
62 unsigned int bufferCount;
63 unsigned int currentBufferIndex;
64 unsigned int framesPerBuffer;
65 unsigned int framesUsedInCurrentBuffer;
66 }PaWinMmeSingleDirectionHandlesAndBuffers;
67
68 /* PaWinMmeStream - a stream data structure specifically for this implementation */
69 /* note that struct PaWinMmeStream is typedeffed to PaWinMmeStream above. */
70 struct PaWinMmeStream
71 {
72 PaUtilStreamRepresentation streamRepresentation;
73 PaUtilCpuLoadMeasurer cpuLoadMeasurer;
74 PaUtilBufferProcessor bufferProcessor;
75
76 int primeStreamUsingCallback;
77
78 PaWinMmeSingleDirectionHandlesAndBuffers input;
79 PaWinMmeSingleDirectionHandlesAndBuffers output;
80
81 /* Processing thread management -------------- */
82 HANDLE abortEvent;
83 HANDLE processingThread;
84 DWORD processingThreadId;
85
86 char throttleProcessingThreadOnOverload; /* 0 -> don't throtte, non-0 -> throttle */
87 int processingThreadPriority;
88 int highThreadPriority;
89 int throttledThreadPriority;
90 unsigned long throttledSleepMsecs;
91
92 int isStopped;
93 volatile int isActive;
94 volatile int stopProcessing; /* stop thread once existing buffers have been returned */
95 volatile int abortProcessing; /* stop thread immediately */
96
97 DWORD allBuffersDurationMs; /* used to calculate timeouts */
98 };
99
100 typedef struct PxSrcInfo
101 {
102 char name[256];
103 DWORD lineID;
104 DWORD controlID;
105 } PxSrcInfo;
106
107 typedef struct PxInfo
108 {
109 HMIXEROBJ hInputMixer;
110 HMIXEROBJ hOutputMixer;
111 int numInputs;
112 PxSrcInfo src[32];
113 DWORD muxID;
114 DWORD speakerID;
115 DWORD waveID;
116 } PxInfo;
117
118 int Px_GetNumMixers( void *pa_stream )
119 {
120 return 1;
121 }
122
123 const char *Px_GetMixerName( void *pa_stream, int index )
124 {
125 return "Mixer";
126 }
127
128 PxMixer *Px_OpenMixer( void *pa_stream, int index )
129 {
130 struct PaWinMmeStream *past;
131 HWAVEIN hWaveIn;
132 HWAVEOUT hWaveOut;
133 PxInfo *mixer;
134 MMRESULT result;
135
136 if (!pa_stream)
137 return NULL;
138
139 mixer = (PxInfo *)malloc(sizeof(PxInfo));
140 if (mixer == NULL)
141 return NULL;
142
143 mixer->hInputMixer = NULL;
144 mixer->hOutputMixer = NULL;
145
146 past = (struct PaWinMmeStream *) pa_stream;
147
148 hWaveIn = 0;
149 if (past->input.waveHandles) {
150 hWaveIn = ((HWAVEIN *)past->input.waveHandles)[0];
151 }
152
153 hWaveOut = 0;
154 if (past->output.waveHandles) {
155 hWaveOut = ((HWAVEOUT *)past->output.waveHandles)[0];
156 }
157
158 if (hWaveIn) {
159 result = mixerOpen((HMIXER *)&mixer->hInputMixer, (UINT)hWaveIn, 0, 0, MIXER_OBJECTF_HWAVEIN);
160 if (result != MMSYSERR_NOERROR) {
161 free(mixer);
162 return NULL;
163 }
164 }
165
166 if (hWaveOut) {
167 result = mixerOpen((HMIXER *)&mixer->hOutputMixer, (UINT)hWaveOut, 0, 0, MIXER_OBJECTF_HWAVEOUT);
168 if (result != MMSYSERR_NOERROR) {
169 free(mixer);
170 return NULL;
171 }
172 }
173
174 mixer->numInputs = 0;
175 mixer->muxID = -1;
176
177 if (mixer->hInputMixer)
178 {
179 MIXERLINE line;
180 line.cbStruct = sizeof(MIXERLINE);
181 line.dwComponentType = MIXERLINE_COMPONENTTYPE_DST_WAVEIN;
182
183 result = mixerGetLineInfo(mixer->hInputMixer,
184 &line,
185 MIXER_GETLINEINFOF_COMPONENTTYPE);
186 if (result == MMSYSERR_NOERROR)
187 {
188 /* if the WaveInDestination has an InputSelectorControl (Mux or Mixer)
189 * get the names and IDs of all of the input sources
190 * make sure the name of the MicrophoneSource (if there is one)
191 * is "microphone" since pa_start() checks for it
192 */
193
194 MIXERLINECONTROLS controls;
195 MIXERCONTROL control;
196
197 controls.cbStruct = sizeof(MIXERLINECONTROLS);
198 controls.cbmxctrl = sizeof(MIXERCONTROL);
199 controls.pamxctrl = &control;
200
201 control.cbStruct = sizeof(MIXERCONTROL);
202
203 controls.dwLineID = line.dwLineID;
204 controls.dwControlType = MIXERCONTROL_CONTROLTYPE_MUX;
205 result = mixerGetLineControls(mixer->hInputMixer,
206 &controls,
207 MIXER_GETLINECONTROLSF_ONEBYTYPE);
208
209 if (result != MMSYSERR_NOERROR)
210 {
211 controls.dwControlType = MIXERCONTROL_CONTROLTYPE_MIXER;
212 result = mixerGetLineControls(mixer->hInputMixer,
213 &controls,
214 MIXER_GETLINECONTROLSF_ONEBYTYPE);
215 }
216
217 if (result == MMSYSERR_NOERROR)
218 {
219 int j;
220 int exactMic = -1;
221 int startMic = -1;
222 int firstMic = -1;
223 MIXERCONTROLDETAILS details;
224 MIXERCONTROLDETAILS_LISTTEXT mixList[32];
225
226 mixer->numInputs = control.cMultipleItems;
227 mixer->muxID = control.dwControlID;
228
229 details.cbStruct = sizeof(MIXERCONTROLDETAILS);
230 details.dwControlID = mixer->muxID;
231 details.cChannels = 1;
232 details.cbDetails = sizeof(MIXERCONTROLDETAILS_LISTTEXT);
233 details.paDetails = (LPMIXERCONTROLDETAILS_LISTTEXT)&mixList[0];
234 details.cMultipleItems = mixer->numInputs;
235
236 controls.dwControlType = MIXERCONTROL_CONTROLTYPE_VOLUME;
237 result = mixerGetControlDetails(mixer->hInputMixer,
238 (LPMIXERCONTROLDETAILS)&details,
239 MIXER_GETCONTROLDETAILSF_LISTTEXT);
240
241 if (result != MMSYSERR_NOERROR)
242 mixer->numInputs = 0;
243
244 for (j=0; j < mixer->numInputs; j++)
245 {
246 mixer->src[j].lineID = mixList[j].dwParam1;
247
248 controls.dwLineID = mixer->src[j].lineID;
249 result = mixerGetLineControls(mixer->hInputMixer,
250 &controls,
251 MIXER_GETLINECONTROLSF_ONEBYTYPE);
252 if (result == MMSYSERR_NOERROR)
253 {
254 /* mark as volume control */
255 mixer->src[j].controlID = control.dwControlID;
256 }
257 else
258 {
259 /* mark as NOT volume control */
260 mixer->src[j].controlID = 0;
261 }
262
263 line.dwLineID = mixer->src[j].lineID;
264
265 result = mixerGetLineInfo(mixer->hInputMixer, &line, MIXER_GETLINEINFOF_LINEID);
266 if (result == MMSYSERR_NOERROR &&
267 line.dwComponentType == MIXERLINE_COMPONENTTYPE_SRC_MICROPHONE)
268 {
269 if (exactMic == -1)
270 {
271 if (strcasecmp(mixList[j].szName, "microphone") == 0)
272 {
273 exactMic = j;
274 }
275 else if (startMic == -1)
276 {
277 if (strncasecmp(mixList[j].szName, "microphone",
278 strlen("microphone")) == 0)
279 {
280 startMic = j;
281 }
282 else if (firstMic == -1)
283 {
284 firstMic = j;
285 }
286 }
287 }
288 }
289 strcpy(mixer->src[j].name, mixList[j].szName);
290 }
291
292 if (exactMic == -1)
293 {
294 if (startMic != -1)
295 {
296 strcpy(mixer->src[startMic].name, "microphone");
297 }
298 else if (firstMic != -1)
299 {
300 strcpy(mixer->src[firstMic].name, "microphone");
301 }
302 }
303 }
304 else
305 {
306 /* if the WaveInDestination does not have an InputSelector
307 * see if the WaveInDestination SourceLine has a VolumeControl
308 */
309 controls.dwControlType = MIXERCONTROL_CONTROLTYPE_VOLUME;
310 result = mixerGetLineControls(mixer->hInputMixer,
311 &controls,
312 MIXER_GETLINECONTROLSF_ONEBYTYPE);
313 if (result == MMSYSERR_NOERROR)
314 {
315 mixer->src[0].lineID = line.dwLineID;
316 strcpy(mixer->src[0].name, line.szName);
317 mixer->src[0].controlID = control.dwControlID;
318 mixer->numInputs = 1;
319 }
320 else
321 {
322 line.dwSource = 0;
323 result = mixerGetLineInfo(mixer->hInputMixer,
324 &line,
325 MIXER_GETLINEINFOF_SOURCE);
326 if (result == MMSYSERR_NOERROR)
327 {
328 mixer->src[0].lineID = line.dwLineID;
329 strcpy(mixer->src[0].name, line.szName);
330
331 controls.dwLineID = line.dwLineID;
332 result = mixerGetLineControls(mixer->hInputMixer,
333 &controls,
334 MIXER_GETLINECONTROLSF_ONEBYTYPE);
335
336 if (result == MMSYSERR_NOERROR)
337 {
338 mixer->src[0].controlID = control.dwControlID;
339 }
340 else
341 {
342 mixer->src[0].controlID = 0;
343 }
344
345 mixer->numInputs = 1;
346 }
347 }
348 }
349 }
350 }
351
352 // mixer->speakerID = MIXERLINE_COMPONENTTYPE_DST_SPEAKERS/VolumeControl
353 // mixer->speakerID = MIXERLINE_COMPONENTTYPE_DST_HEADPHONES/VolumeControl
354 // mixer->speakerID = MIXERLINE_COMPONENTTYPE_DST_UNDEFINED/VolumeControl
355
356 mixer->speakerID = -1;
357 mixer->waveID = -1;
358
359 if (mixer->hOutputMixer) {
360
361 const DWORD componentTypes [] =
362 {
363 MIXERLINE_COMPONENTTYPE_DST_SPEAKERS,
364 MIXERLINE_COMPONENTTYPE_DST_HEADPHONES,
365 MIXERLINE_COMPONENTTYPE_DST_UNDEFINED,
366 };
367 const size_t componentTypeLen = sizeof(componentTypes) / sizeof(DWORD);
368 DWORD j;
369
370 MIXERLINE line;
371 line.cbStruct = sizeof(MIXERLINE);
372
373 for (j = 0; j < componentTypeLen; j++)
374 {
375 line.dwComponentType = componentTypes[j];
376 result = mixerGetLineInfo(mixer->hOutputMixer,
377 &line,
378 MIXER_GETLINEINFOF_COMPONENTTYPE);
379
380 if (result == MMSYSERR_NOERROR)
381 break;
382 }
383
384 if (result == MMSYSERR_NOERROR)
385 {
386 MIXERLINECONTROLS controls;
387 MIXERCONTROL control;
388
389 controls.cbStruct = sizeof(MIXERLINECONTROLS);
390 controls.dwLineID = line.dwLineID;
391 controls.dwControlType = MIXERCONTROL_CONTROLTYPE_VOLUME;
392 controls.cbmxctrl = sizeof(MIXERCONTROL);
393 controls.pamxctrl = &control;
394
395 control.cbStruct = sizeof(MIXERCONTROL);
396
397 result = mixerGetLineControls(mixer->hOutputMixer,
398 &controls,
399 MIXER_GETLINECONTROLSF_ONEBYTYPE);
400
401 if (result == MMSYSERR_NOERROR)
402 mixer->speakerID = control.dwControlID;
403
404 // mixer->waveID = MIXERLINE_COMPONENTTYPE_SRC_WAVEOUT/VolumeControl
405
406 const DWORD numSources = line.cConnections;
407
408 for (j = 0; j < numSources; j++)
409 {
410 line.dwSource = j;
411 result = mixerGetLineInfo(mixer->hOutputMixer,
412 &line,
413 MIXER_GETLINEINFOF_SOURCE);
414 if (result == MMSYSERR_NOERROR &&
415 line.dwComponentType == MIXERLINE_COMPONENTTYPE_SRC_WAVEOUT)
416 {
417 controls.dwLineID = line.dwLineID;
418 result = mixerGetLineControls(mixer->hOutputMixer,
419 &controls,
420 MIXER_GETLINECONTROLSF_ONEBYTYPE);
421 if (result == MMSYSERR_NOERROR)
422 {
423 mixer->waveID = control.dwControlID;
424 break;
425 }
426 }
427 }
428 }
429 }
430
431 return (PxMixer *)mixer;
432 }
433
434 void VolumeFunction(HMIXEROBJ hMixer, DWORD controlID, PxVolume *volume)
435 {
436 MIXERCONTROLDETAILS details;
437 MMRESULT result;
438 MIXERCONTROLDETAILS_UNSIGNED value;
439
440 memset(&value, 0, sizeof(MIXERCONTROLDETAILS_UNSIGNED));
441
442 details.cbStruct = sizeof(MIXERCONTROLDETAILS);
443 details.dwControlID = controlID;
444 details.cChannels = 1; /* all channels */
445 details.cMultipleItems = 0;
446 details.cbDetails = sizeof(MIXERCONTROLDETAILS_UNSIGNED);
447 details.paDetails = &value;
448
449 result = mixerGetControlDetails(hMixer, &details,
450 MIXER_GETCONTROLDETAILSF_VALUE);
451
452 if (*volume < 0.0) {
453 *volume = (PxVolume)(value.dwValue / 65535.0);
454 }
455 else {
456 if (result != MMSYSERR_NOERROR)
457 return;
458 value.dwValue = (unsigned short)(*volume * 65535.0);
459 mixerSetControlDetails(hMixer, &details,
460 MIXER_GETCONTROLDETAILSF_VALUE);
461 }
462 }
463
464 /*
465 Px_CloseMixer() closes a mixer opened using Px_OpenMixer and frees any
466 memory associated with it.
467 */
468
469 void Px_CloseMixer(PxMixer *mixer)
470 {
471 PxInfo *info = (PxInfo *)mixer;
472
473 if (info->hInputMixer)
474 mixerClose((HMIXER)info->hInputMixer);
475 if (info->hOutputMixer)
476 mixerClose((HMIXER)info->hOutputMixer);
477 free( mixer );
478 }
479
480 /*
481 Master (output) volume
482 */
483
484 PxVolume Px_GetMasterVolume( PxMixer *mixer )
485 {
486 PxInfo *info = (PxInfo *)mixer;
487 PxVolume vol;
488
489 vol = -1.0;
490 VolumeFunction(info->hOutputMixer, info->speakerID, &vol);
491 return vol;
492 }
493
494 void Px_SetMasterVolume( PxMixer *mixer, PxVolume volume )
495 {
496 PxInfo *info = (PxInfo *)mixer;
497
498 VolumeFunction(info->hOutputMixer, info->speakerID, &volume);
499 }
500
501 /*
502 PCM output volume
503 */
504
505 int Px_SupportsPCMOutputVolume( PxMixer* mixer )
506 {
507 PxInfo* info = ( PxInfo* )( mixer ) ;
508 return ( info->waveID == -1 ) ? 0 : 1 ;
509 }
510
511 PxVolume Px_GetPCMOutputVolume( PxMixer *mixer )
512 {
513 PxInfo *info = (PxInfo *)mixer;
514 PxVolume vol;
515
516 vol = -1.0;
517 VolumeFunction(info->hOutputMixer, info->waveID, &vol);
518 return vol;
519 }
520
521 void Px_SetPCMOutputVolume( PxMixer *mixer, PxVolume volume )
522 {
523 PxInfo *info = (PxInfo *)mixer;
524
525 VolumeFunction(info->hOutputMixer, info->waveID, &volume);
526 }
527
528
529 /*
530 All output volumes
531 */
532
533 int Px_GetNumOutputVolumes( PxMixer *mixer )
534 {
535 PxInfo *info = (PxInfo *)mixer;
536
537 return 2;
538 }
539
540 const char *Px_GetOutputVolumeName( PxMixer *mixer, int i )
541 {
542 PxInfo *info = (PxInfo *)mixer;
543
544 if (i==1)
545 return "Wave Out";
546 else
547 return "Master Volume";
548 }
549
550 PxVolume Px_GetOutputVolume( PxMixer *mixer, int i )
551 {
552 PxInfo *info = (PxInfo *)mixer;
553
554 if (i==1)
555 return Px_GetPCMOutputVolume(mixer);
556 else
557 return Px_GetMasterVolume(mixer);
558 }
559
560 void Px_SetOutputVolume( PxMixer *mixer, int i, PxVolume volume )
561 {
562 PxInfo *info = (PxInfo *)mixer;
563
564 if (i==1)
565 Px_SetPCMOutputVolume(mixer, volume);
566 else
567 Px_SetMasterVolume(mixer, volume);
568 }
569
570 /*
571 Input sources
572 */
573
574 int Px_GetNumInputSources( PxMixer *mixer )
575 {
576 PxInfo *info = (PxInfo *)mixer;
577
578 return info->numInputs;
579 }
580
581 const char *Px_GetInputSourceName( PxMixer *mixer, int i)
582 {
583 PxInfo *info = (PxInfo *)mixer;
584
585 return info->src[i].name;
586 }
587
588 int Px_GetCurrentInputSource( PxMixer *mixer )
589 {
590 PxInfo *info = (PxInfo *)mixer;
591 MIXERCONTROLDETAILS details;
592 MIXERCONTROLDETAILS_BOOLEAN flags[32];
593 MMRESULT result;
594 int i;
595
596 details.cbStruct = sizeof(MIXERCONTROLDETAILS);
597 details.dwControlID = info->muxID;
598 details.cMultipleItems = info->numInputs;
599 details.cChannels = 1;
600 details.cbDetails = sizeof(MIXERCONTROLDETAILS_BOOLEAN);
601 details.paDetails = (LPMIXERCONTROLDETAILS_BOOLEAN)&flags[0];
602
603 result = mixerGetControlDetails(info->hInputMixer,
604 (LPMIXERCONTROLDETAILS)&details,
605 MIXER_GETCONTROLDETAILSF_VALUE);
606
607 if (result == MMSYSERR_NOERROR) {
608 for(i=0; i<info->numInputs; i++)
609 if (flags[i].fValue)
610 return i;
611 }
612
613 return 0;
614 }
615
616 void Px_SetCurrentInputSource( PxMixer *mixer, int i )
617 {
618 PxInfo *info = (PxInfo *)mixer;
619 MIXERCONTROLDETAILS details;
620 MIXERCONTROLDETAILS_BOOLEAN flags[32];
621 MMRESULT result;
622 int j;
623
624 details.cbStruct = sizeof(MIXERCONTROLDETAILS);
625 details.dwControlID = info->muxID;
626 details.cMultipleItems = info->numInputs;
627 details.cChannels = 1;
628 details.cbDetails = sizeof(MIXERCONTROLDETAILS_BOOLEAN);
629 details.paDetails = (LPMIXERCONTROLDETAILS_BOOLEAN)&flags[0];
630
631 for(j=0; j<info->numInputs; j++)
632 flags[j].fValue = (i == j);
633
634 result = mixerSetControlDetails(info->hInputMixer,
635 (LPMIXERCONTROLDETAILS)&details,
636 MIXER_SETCONTROLDETAILSF_VALUE);
637 }
638
639 /*
640 Input volume
641 */
642
643 PxVolume Px_GetInputVolume( PxMixer *mixer )
644 {
645 PxInfo *info = (PxInfo *)mixer;
646 PxVolume vol;
647 int src = Px_GetCurrentInputSource(mixer);
648
649 vol = -1.0;
650 VolumeFunction(info->hInputMixer, info->src[src].controlID, &vol);
651 return vol;
652 }
653
654 void Px_SetInputVolume( PxMixer *mixer, PxVolume volume )
655 {
656 PxInfo *info = (PxInfo *)mixer;
657 int src = Px_GetCurrentInputSource(mixer);
658
659 VolumeFunction(info->hInputMixer, info->src[src].controlID, &volume);
660 }
661
662 /*
663 Balance
664 */
665
666 int Px_SupportsOutputBalance( PxMixer *mixer )
667 {
668 return 0;
669 }
670
671 PxBalance Px_GetOutputBalance( PxMixer *mixer )
672 {
673 return 0.0;
674 }
675
676 void Px_SetOutputBalance( PxMixer *mixer, PxBalance balance )
677 {
678 }
679
680 /*
681 Playthrough
682 */
683
684 int Px_SupportsPlaythrough( PxMixer *mixer )
685 {
686 return 0;
687 }
688
689 PxVolume Px_GetPlaythrough( PxMixer *mixer )
690 {
691 return 0.0;
692 }
693
694 void Px_SetPlaythrough( PxMixer *mixer, PxVolume volume )
695 {
696 }
697
698 int Px_SetMicrophoneBoost( PxMixer* mixer, int enable )
699 {
700 MIXERLINE mixerLine ;
701 LPMIXERCONTROL mixerControl ;
702 MIXERLINECONTROLS mixerLineControls ;
703 MIXERCONTROLDETAILS mixerControlDetails ;
704 MIXERCONTROLDETAILS_BOOLEAN value ;
705 MMRESULT mmr = MMSYSERR_ERROR ;
706 DWORD boost_id = -1 ;
707 DWORD x ;
708
709 // cast void pointer
710 PxInfo* info = ( PxInfo* )( mixer ) ;
711
712 if ( info == NULL )
713 return MMSYSERR_ERROR ;
714
715 //
716 // get line info
717 //
718
719 mixerLine.cbStruct = sizeof( MIXERLINE ) ;
720 mixerLine.dwComponentType = MIXERLINE_COMPONENTTYPE_SRC_MICROPHONE ;
721
722 mmr = mixerGetLineInfo(
723 ( HMIXEROBJ )( info->hInputMixer ),
724 &mixerLine,
725 MIXER_GETLINEINFOF_COMPONENTTYPE
726 ) ;
727
728 if ( mmr != MMSYSERR_NOERROR )
729 return mmr ;
730
731 //
732 // get all controls
733 //
734
735 mixerControl = (MIXERCONTROL *)malloc( sizeof( MIXERCONTROL ) * mixerLine.cControls ) ;
736
737 mixerLineControls.cbStruct = sizeof( MIXERLINECONTROLS ) ;
738 mixerLineControls.dwLineID = mixerLine.dwLineID ;
739 mixerLineControls.cControls = mixerLine.cControls ;
740 mixerLineControls.cbmxctrl = sizeof( MIXERCONTROL ) ;
741 mixerLineControls.pamxctrl = ( LPMIXERCONTROL )( mixerControl ) ;
742
743 mmr = mixerGetLineControls(
744 ( HMIXEROBJ )( info->hInputMixer ),
745 &mixerLineControls,
746 MIXER_GETLINECONTROLSF_ALL
747 ) ;
748
749 if ( mmr != MMSYSERR_NOERROR )
750 {
751 free(mixerControl);
752
753 return mmr ;
754 }
755
756 //
757 // find boost control
758 //
759
760 for ( x = 0 ; x < mixerLineControls.cControls ; ++x )
761 {
762 // check control type
763 if ( mixerControl[x].dwControlType & MIXERCONTROL_CONTROLTYPE_BOOLEAN )
764 {
765 // normalize control name
766 char* name = _strupr( mixerControl[x].szName ) ;
767
768 // check for 'mic' and 'boost'
769 if (
770 ( strstr( name, "MIC" ) != NULL )
771 && ( strstr( name, "BOOST" ) != NULL )
772 )
773 {
774 boost_id = mixerControl[x].dwControlID ;
775 break ;
776 }
777 }
778 }
779
780 if ( boost_id == -1 )
781 {
782 free(mixerControl);
783
784 return MMSYSERR_ERROR ;
785 }
786
787 //
788 // get control details
789 //
790
791 mixerControlDetails.cbStruct = sizeof( MIXERCONTROLDETAILS ) ;
792 mixerControlDetails.dwControlID = boost_id ;
793 mixerControlDetails.cChannels = 1 ;
794 mixerControlDetails.cMultipleItems = 0 ;
795 mixerControlDetails.cbDetails = sizeof( MIXERCONTROLDETAILS_BOOLEAN ) ;
796 mixerControlDetails.paDetails = &value ;
797
798 mmr = mixerGetControlDetails(
799 ( HMIXEROBJ )( info->hInputMixer ),
800 &mixerControlDetails,
801 MIXER_GETCONTROLDETAILSF_VALUE
802 ) ;
803
804 if ( mmr != MMSYSERR_NOERROR )
805 {
806 free(mixerControl);
807
808 return mmr ;
809 }
810
811 //
812 // update value
813 //
814
815 value.fValue = ( enable == 0 ) ? 0L : 1L ;
816
817 //
818 // set control details
819 //
820
821 mmr = mixerSetControlDetails(
822 ( HMIXEROBJ )( info->hInputMixer ),
823 &mixerControlDetails,
824 MIXER_SETCONTROLDETAILSF_VALUE
825 ) ;
826
827 free(mixerControl);
828
829 if ( mmr != MMSYSERR_NOERROR )
830 return mmr ;
831
832 return mmr ;
833 }
834
835 int Px_GetMicrophoneBoost( PxMixer* mixer )
836 {
837 MIXERLINE mixerLine ;
838 LPMIXERCONTROL mixerControl ;
839 MIXERLINECONTROLS mixerLineControls ;
840 MIXERCONTROLDETAILS mixerControlDetails ;
841 MIXERCONTROLDETAILS_BOOLEAN value ;
842 MMRESULT mmr = MMSYSERR_ERROR ;
843 DWORD boost_id = -1 ;
844 DWORD x ;
845
846 // cast void pointer
847 PxInfo* info = ( PxInfo* )( mixer ) ;
848
849 if ( info == NULL )
850 return -1 ;
851
852 //
853 // get line info
854 //
855
856 mixerLine.cbStruct = sizeof( MIXERLINE ) ;
857 mixerLine.dwComponentType = MIXERLINE_COMPONENTTYPE_SRC_MICROPHONE ;
858
859 mmr = mixerGetLineInfo(
860 ( HMIXEROBJ )( info->hInputMixer ),
861 &mixerLine,
862 MIXER_GETLINEINFOF_COMPONENTTYPE
863 ) ;
864
865 if ( mmr != MMSYSERR_NOERROR )
866 return -1 ;
867
868 //
869 // get all controls
870 //
871
872 mixerControl = (MIXERCONTROL *)malloc( sizeof( MIXERCONTROL ) * mixerLine.cControls ) ;
873
874 mixerLineControls.cbStruct = sizeof( MIXERLINECONTROLS ) ;
875 mixerLineControls.dwLineID = mixerLine.dwLineID ;
876 mixerLineControls.cControls = mixerLine.cControls ;
877 mixerLineControls.cbmxctrl = sizeof( MIXERCONTROL ) ;
878 mixerLineControls.pamxctrl = ( LPMIXERCONTROL )( mixerControl ) ;
879
880 mmr = mixerGetLineControls(
881 ( HMIXEROBJ )( info->hInputMixer ),
882 &mixerLineControls,
883 MIXER_GETLINECONTROLSF_ALL
884 ) ;
885
886 if ( mmr != MMSYSERR_NOERROR )
887 {
888 free(mixerControl);
889
890 return -1 ;
891 }
892
893 //
894 // find boost control
895 //
896
897 for ( x = 0 ; x < mixerLineControls.cControls ; ++x )
898 {
899 // check control type
900 if ( mixerControl[x].dwControlType & MIXERCONTROL_CONTROLTYPE_BOOLEAN )
901 {
902 // normalize control name
903 char* name = _strupr( mixerControl[x].szName ) ;
904
905 // check for 'mic' and 'boost'
906 if (
907 ( strstr( name, "MIC" ) != NULL )
908 && ( strstr( name, "BOOST" ) != NULL )
909 )
910 {
911 boost_id = mixerControl[x].dwControlID ;
912 break ;
913 }
914 }
915 }
916
917 if ( boost_id == -1 )
918 {
919 free(mixerControl);
920
921 return -1 ;
922 }
923
924 //
925 // get control details
926 //
927
928 mixerControlDetails.cbStruct = sizeof( MIXERCONTROLDETAILS ) ;
929 mixerControlDetails.dwControlID = boost_id ;
930 mixerControlDetails.cChannels = 1 ;
931 mixerControlDetails.cMultipleItems = 0 ;
932 mixerControlDetails.cbDetails = sizeof( MIXERCONTROLDETAILS_BOOLEAN ) ;
933 mixerControlDetails.paDetails = &value ;
934
935 mmr = mixerGetControlDetails(
936 ( HMIXEROBJ )( info->hInputMixer ),
937 &mixerControlDetails,
938 MIXER_GETCONTROLDETAILSF_VALUE
939 ) ;
940
941 free(mixerControl);
942
943 if ( mmr != MMSYSERR_NOERROR )
944 return -1 ;
945
946 return ( int )( value.fValue ) ;
947 }
948
949 int Px_SetCurrentInputSourceByName( PxMixer* mixer, const char* name )
950 {
951 int x ;
952
953 // cast void pointer
954 PxInfo* info = ( PxInfo* )( mixer ) ;
955
956 // make sure we have a mixer
957 if ( info == NULL )
958 return MMSYSERR_ERROR ;
959
960 // make sure we have a search name
961 if ( name == NULL )
962 return MMSYSERR_ERROR ;
963
964 //
965 // set input source
966 //
967
968 for ( x = 0 ; x < info->numInputs ; ++x )
969 {
970 // compare passed name with control name
971 if ( strcasecmp( info->src[x].name, name ) == 0 )
972 {
973 // set input source
974 Px_SetCurrentInputSource( mixer, x ) ;
975
976 // make sure set'ing worked
977 if ( Px_GetCurrentInputSource( mixer ) == x )
978 return MMSYSERR_NOERROR ;
979 else
980 return MMSYSERR_ERROR ;
981 }
982 }
983
984 return MMSYSERR_ERROR ;
985 }
986