Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

180 lines
4.7 KiB

  1. /*==========================================================================
  2. *
  3. * Copyright (C) 1995-1999 Microsoft Corporation. All Rights Reserved.
  4. *
  5. * File: misc.cpp
  6. * Content: Misc Support Routines
  7. * History:
  8. *
  9. * Date By Reason
  10. * ==== == ======
  11. * 10/15/99 rodtoll created it
  12. *
  13. ***************************************************************************/
  14. #include "dxvhelppch.h"
  15. #undef DPF_SUBCOMP
  16. #define DPF_SUBCOMP DN_SUBCOMP_VOICE
  17. // MicrophoneGetVolume
  18. //
  19. // This function retrieves the current volume of the microphone
  20. // recording line.
  21. //
  22. // Parameters:
  23. // UINT waveInDevice -
  24. // This specifies the device for which we wish to get
  25. // the microphone recording volume. This is the
  26. // waveIN device ID for the desired device.
  27. //
  28. // BYTE &volume -
  29. // [output] The current volume of the microphone recording
  30. // line for the specified device. (DSound Range)
  31. //
  32. // BOOL -
  33. // true on success, false on failure
  34. //
  35. #undef DPF_MODNAME
  36. #define DPF_MODNAME "MicrophoneGetVolume"
  37. BOOL MicrophoneGetVolume( UINT waveInDevice, LONG &volume ) {
  38. MMRESULT result;
  39. // Open the mixer device
  40. HMIXER hmx = NULL;
  41. LPMIXERCONTROLDETAILS_UNSIGNED pUnsigned = NULL;
  42. LPMIXERCONTROL pmxctrl = NULL;
  43. bool foundMicrophone = false;
  44. DWORD i;
  45. if( mixerOpen(&hmx, waveInDevice, 0, 0, MIXER_OBJECTF_WAVEIN) != MMSYSERR_NOERROR )
  46. return FALSE;
  47. // Get the line info for the wave in destination line
  48. MIXERLINE mxl;
  49. mxl.cbStruct = sizeof(mxl);
  50. mxl.dwComponentType = MIXERLINE_COMPONENTTYPE_DST_WAVEIN;
  51. mixerGetLineInfo((HMIXEROBJ)hmx, &mxl, MIXER_GETLINEINFOF_COMPONENTTYPE);
  52. // Now find the microphone source line connected to this wave in
  53. // destination
  54. DWORD cConnections = mxl.cConnections;
  55. for(i=0; i<cConnections; i++)
  56. {
  57. mxl.dwSource = i;
  58. mixerGetLineInfo((HMIXEROBJ)hmx, &mxl, MIXER_GETLINEINFOF_SOURCE);
  59. if (MIXERLINE_COMPONENTTYPE_SRC_MICROPHONE == mxl.dwComponentType)
  60. {
  61. foundMicrophone = true;
  62. break;
  63. }
  64. }
  65. if( !foundMicrophone )
  66. {
  67. for(i=0; i<cConnections; i++)
  68. {
  69. mxl.dwSource = i;
  70. if( mixerGetLineInfo((HMIXEROBJ)hmx, &mxl, MIXER_GETLINEINFOF_SOURCE) != MMSYSERR_NOERROR )
  71. {
  72. return false;
  73. }
  74. if (MIXERLINE_COMPONENTTYPE_SRC_LINE == mxl.dwComponentType)
  75. {
  76. foundMicrophone = true;
  77. break;
  78. }
  79. }
  80. if( !foundMicrophone )
  81. {
  82. for(i=0; i<cConnections; i++)
  83. {
  84. mxl.dwSource = i;
  85. if( mixerGetLineInfo((HMIXEROBJ)hmx, &mxl, MIXER_GETLINEINFOF_SOURCE) != MMSYSERR_NOERROR )
  86. {
  87. return false;
  88. }
  89. if (MIXERLINE_COMPONENTTYPE_SRC_AUXILIARY == mxl.dwComponentType)
  90. {
  91. foundMicrophone = true;
  92. break;
  93. }
  94. }
  95. }
  96. }
  97. if( !foundMicrophone )
  98. {
  99. DPFX(DPFPREP, DVF_INFOLEVEL, "ERROR: Unable to find microphone source" );
  100. return FALSE;
  101. }
  102. // Find a volume control, if any, of the microphone line
  103. pmxctrl = new MIXERCONTROL;
  104. if( pmxctrl == NULL )
  105. {
  106. DPFX(DPFPREP, DVF_ERRORLEVEL, "Unable to alloc mixercontrol" );
  107. return FALSE;
  108. }
  109. MIXERLINECONTROLS mxlctrl = {
  110. sizeof(mxlctrl), mxl.dwLineID, MIXERCONTROL_CONTROLTYPE_VOLUME,
  111. 1, sizeof(MIXERCONTROL), pmxctrl
  112. };
  113. if( (result = mixerGetLineControls((HMIXEROBJ) hmx, &mxlctrl, MIXER_GETLINECONTROLSF_ONEBYTYPE)) == MMSYSERR_NOERROR )
  114. {
  115. // Found!
  116. DWORD cChannels = mxl.cChannels;
  117. if (MIXERCONTROL_CONTROLF_UNIFORM & pmxctrl->fdwControl)
  118. cChannels = 1;
  119. pUnsigned = new MIXERCONTROLDETAILS_UNSIGNED[cChannels];
  120. if( pUnsigned == NULL )
  121. {
  122. DPFX(DPFPREP, DVF_ERRORLEVEL, "Unable to alloc unsigneds" );
  123. delete pmxctrl;
  124. return FALSE;
  125. }
  126. MIXERCONTROLDETAILS mxcd = {
  127. sizeof(mxcd), pmxctrl->dwControlID,
  128. cChannels, (HWND)0, sizeof(MIXERCONTROLDETAILS_UNSIGNED),
  129. (LPVOID) pUnsigned
  130. };
  131. if( mixerGetControlDetails((HMIXEROBJ)hmx, &mxcd, MIXER_GETCONTROLDETAILSF_VALUE) != MMSYSERR_NOERROR )
  132. return false;
  133. volume = ((pUnsigned[0].dwValue) * (DSBVOLUME_MAX-DSBVOLUME_MIN)) / 0xFFFF;
  134. volume += DSBVOLUME_MIN;
  135. if( mixerSetControlDetails((HMIXEROBJ)hmx, &mxcd, MIXER_SETCONTROLDETAILSF_VALUE) != MMSYSERR_NOERROR )
  136. return FALSE;
  137. if( mixerClose(hmx) != MMSYSERR_NOERROR )
  138. return FALSE;
  139. delete pmxctrl;
  140. delete [] pUnsigned;
  141. return TRUE;
  142. }
  143. else
  144. {
  145. return FALSE;
  146. }
  147. }