// This function is for muting volume of a specific line in
// volume control panel by using the line's component type
// as its parameter. It can mute Line In,Wave and Microphone
// with parameters MIXERLINE_COMPONENTTYPE_SRC_LINE,MIXERLINE
// _COMPONENTTYPE_SRC_WAVEOUT and MIXERLINE_COMPONENTTYPE_SRC
// _MICROPHONE accordingly.
// The parameter dwComponentTypeOfLine is component type of the
// line to mute.
// This function is only for line in,wave and microphone.
void MutePlayLineByComponentType(DWORD dwComponentTypeOfLine)
{
MMRESULT mmResult;
HMIXER hMixer;
MIXERCAPS mixercaps;
MIXERLINE mixerline;
memset(&mixerline,0,sizeof(MIXERLINE));
mixerline.cbStruct = sizeof(MIXERLINE);
MIXERLINECONTROLS mlc;
memset(&mlc,0,sizeof(MIXERLINECONTROLS));
mlc.cbStruct = sizeof(MIXERLINECONTROLS);
MIXERCONTROL mc;
memset(&mc,0,sizeof(MIXERCONTROL));
mc.cbStruct = sizeof(MIXERCONTROL);
DWORD dwStereoSelControlID;
DWORD dwTotalItems;
BOOL bFinished = FALSE;
UINT uNum = mixerGetNumDevs();
for ( int i = 0; i < uNum; i++ )
{
mmResult = mixerOpen(&hMixer,i,0,0,MIXER_OBJECTF_MIXER);
mmResult = mixerGetDevCaps(i,&mixercaps,sizeof(MIXERCAPS));
for ( int j = 0; j < mixercaps.cDestinations; j++ )
{
mixerline.dwDestination = j;
mmResult = mixerGetLineInfo((HMIXEROBJ)hMixer,&mixerline,MIXER_GETLINEINFOF_DESTINATION);
if ( mixerline.dwComponentType == MIXERLINE_COMPONENTTYPE_DST_SPEAKERS )
{
DWORD dwConnections = mixerline.cConnections;
for ( int count = 0; count < dwConnections; count++ )
{
mixerline.dwSource = count;
mmResult = mixerGetLineInfo((HMIXEROBJ)hMixer,&mixerline,MIXER_OBJECTF_HMIXER | MIXER_GETLINEINFOF_SOURCE);
if ( mixerline.dwComponentType == dwComponentTypeOfLine )
{
mlc.cControls = 1;
mlc.cbmxctrl = sizeof(MIXERCONTROL);
mlc.pamxctrl = &mc;
mlc.dwLineID = mixerline.dwLineID;
mlc.dwControlType = MIXERCONTROL_CONTROLTYPE_MUTE;
mmResult = mixerGetLineControls((HMIXEROBJ)hMixer,&mlc,MIXER_OBJECTF_HMIXER | MIXER_GETLINECONTROLSF_ONEBYTYPE);
MIXERCONTROLDETAILS_BOOLEAN* pControlDetail_BOOL = (MIXERCONTROLDETAILS_BOOLEAN*)malloc(/*dwChannel**/sizeof(MIXERCONTROLDETAILS_BOOLEAN));
if ( !pControlDetail_BOOL )
return;
pControlDetail_BOOL->fValue = TRUE;
MIXERCONTROLDETAILS mixercontroldetails;
memset(&mixercontroldetails,0,sizeof(MIXERCONTROLDETAILS));
mixercontroldetails.cbStruct = sizeof(MIXERCONTROLDETAILS);
mixercontroldetails.cbDetails = sizeof(MIXERCONTROLDETAILS_BOOLEAN);
mixercontroldetails.cChannels = 1;
mixercontroldetails.cMultipleItems = 0;
mixercontroldetails.paDetails = &pControlDetail_BOOL;
mixercontroldetails.dwControlID = mc.dwControlID;
mmResult = mixerSetControlDetails((HMIXEROBJ)hMixer,&mixercontroldetails,MIXER_SETCONTROLDETAILSF_VALUE | MIXER_OBJECTF_HMIXER);
free(pControlDetail_BOOL);
bFinished = TRUE;
break;
}
}
break;
}
}
mixerClose(hMixer);
if ( bFinished )
break;
}
}
// This function is for setting volume of a specific line in
// volume control panel by using the line's component type as
// its parameter. It can set volume of Line In,Wave and Microphone
// with parameters MIXERLINE_COMPONENTTYPE_SRC_LINE,MIXERLINE
// _COMPONENTTYPE_SRC_WAVEOUT and MIXERLINE_COMPONENTTYPE_SRC
// _MICROPHONE accordingly.
// The parameter dwComponentTypeOfLine is component type of the
// line whose volume is to be set and the parameter lVolumeValue
// is the new volume to set.
// This function is only for line in,wave and microphone too.
// The parameter lVolumeValue has a range from 0 to 65535.
void SetPlayLineVolume(DWORD dwComponentTypeOfLine,long lVolumeValue)
{
MMRESULT mmResult;
HMIXER hMixer;
MIXERCAPS mixercaps;
MIXERLINE mixerline;
memset(&mixerline,0,sizeof(MIXERLINE));
mixerline.cbStruct = sizeof(MIXERLINE);
MIXERLINECONTROLS mlc;
memset(&mlc,0,sizeof(MIXERLINECONTROLS));
mlc.cbStruct = sizeof(MIXERLINECONTROLS);
MIXERCONTROL mc;
memset(&mc,0,sizeof(MIXERCONTROL));
mc.cbStruct = sizeof(MIXERCONTROL);
DWORD dwStereoSelControlID;
DWORD dwTotalItems;
BOOL bFinished = FALSE;
UINT uNum = mixerGetNumDevs();
for ( int i = 0; i < uNum; i++ )
{
mmResult = mixerOpen(&hMixer,i,0,0,MIXER_OBJECTF_MIXER);
mmResult = mixerGetDevCaps(i,&mixercaps,sizeof(MIXERCAPS));
for ( int j = 0; j < mixercaps.cDestinations; j++ )
{
mixerline.dwDestination = j;
mmResult = mixerGetLineInfo((HMIXEROBJ)hMixer,&mixerline,MIXER_GETLINEINFOF_DESTINATION);
if ( mixerline.dwComponentType == MIXERLINE_COMPONENTTYPE_DST_SPEAKERS )
{
DWORD dwConnections = mixerline.cConnections;
for ( int count = 0; count < dwConnections; count++ )
{
mixerline.dwSource = count;
mmResult = mixerGetLineInfo((HMIXEROBJ)hMixer,&mixerline,MIXER_OBJECTF_HMIXER | MIXER_GETLINEINFOF_SOURCE);
if ( mixerline.dwComponentType == dwComponentTypeOfLine )
{
DWORD dwChannel = mixerline.cChannels;
mlc.cControls = 1;
mlc.cbmxctrl = sizeof(MIXERCONTROL);
mlc.pamxctrl = &mc;
mlc.dwLineID = mixerline.dwLineID;
mlc.dwControlType = MIXERCONTROL_CONTROLTYPE_VOLUME;
mmResult = mixerGetLineControls((HMIXEROBJ)hMixer,&mlc,MIXER_OBJECTF_HMIXER | MIXER_GETLINECONTROLSF_ONEBYTYPE);
MIXERCONTROLDETAILS_BOOLEAN* pControlDetail_BOOL = (MIXERCONTROLDETAILS_BOOLEAN*)malloc(dwChannel*sizeof(MIXERCONTROLDETAILS_BOOLEAN));
if ( !pControlDetail_BOOL )
return;
for ( int i = 0; i < dwChannel; i++ )
{
pControlDetail_BOOL[i].fValue = lVolumeValue;
}
MIXERCONTROLDETAILS mixercontroldetails;
memset(&mixercontroldetails,0,sizeof(MIXERCONTROLDETAILS));
mixercontroldetails.cbStruct = sizeof(MIXERCONTROLDETAILS);
mixercontroldetails.cbDetails = sizeof(MIXERCONTROLDETAILS_BOOLEAN);
mixercontroldetails.cChannels = 1;
mixercontroldetails.cMultipleItems = 0;
mixercontroldetails.paDetails = &pControlDetail_BOOL[0];
mixercontroldetails.dwControlID = mc.dwControlID;
mmResult = mixerSetControlDetails((HMIXEROBJ)hMixer,&mixercontroldetails,MIXER_SETCONTROLDETAILSF_VALUE | MIXER_OBJECTF_HMIXER);
free(pControlDetail_BOOL);
bFinished = TRUE;
break;
}
}
break;
}
}
mixerClose(hMixer);
if ( bFinished )
break;
}
}
// This function is for selecting a specific line for recording in
// recording control panel and setting its volume by using the line's
// component type as its parameter. It can be used for Line In and
// Microphone with parameters MIXERLINE_COMPONENTTYPE_SRC_LINE and
// MIXERLINE_COMPONENTTYPE_SRC_MICROPHONE accordingly.
// The parameter dwComponentTypeOfLine is component type of the
// line and the parameter lVolumeValue is the new volume to set.
// This function is only for line in and microphone.
// The parameter lVolumeValue has a range from 0 to 65535.
void SelRecordLineAndSetVolume(DWORD dwComponentTypeOfLine,long lVolumeValue)
{
MMRESULT mmResult;
HMIXER hMixer;
MIXERCAPS mixercaps;
MIXERLINE mixerline;
memset(&mixerline,0,sizeof(MIXERLINE));
mixerline.cbStruct = sizeof(MIXERLINE);
MIXERLINECONTROLS mlc;
memset(&mlc,0,sizeof(MIXERLINECONTROLS));
mlc.cbStruct = sizeof(MIXERLINECONTROLS);
MIXERCONTROL mc;
memset(&mc,0,sizeof(MIXERCONTROL));
mc.cbStruct = sizeof(MIXERCONTROL);
DWORD dwStereoSelControlID;
DWORD dwTotalItems;
BOOL bFinished = FALSE;
UINT uNum = mixerGetNumDevs();
for ( int i = 0; i < uNum; i++ )
{
mmResult = mixerOpen(&hMixer,i,0,0,MIXER_OBJECTF_MIXER);
mmResult = mixerGetDevCaps(i,&mixercaps,sizeof(MIXERCAPS));
for ( int j = 0; j < mixercaps.cDestinations; j++ )
{
mixerline.dwDestination = j;
mmResult = mixerGetLineInfo((HMIXEROBJ)hMixer,&mixerline,MIXER_GETLINEINFOF_DESTINATION);
if ( mixerline.dwComponentType == MIXERLINE_COMPONENTTYPE_DST_WAVEIN && mixerline.dwLineID == 4294901761 )
{
mlc.cControls = 1;
mlc.cbmxctrl = sizeof(MIXERCONTROL);
mlc.pamxctrl = &mc;
mlc.dwLineID = mixerline.dwLineID;
mlc.dwControlType = MIXERCONTROL_CONTROLTYPE_MUX;
mmResult = mixerGetLineControls((HMIXEROBJ)hMixer,&mlc,MIXER_OBJECTF_HMIXER | MIXER_GETLINECONTROLSF_ONEBYTYPE);
dwStereoSelControlID = mc.dwControlID;
dwTotalItems = mc.cMultipleItems;
MIXERLINE line;
memset(&line,0,sizeof(MIXERLINE));
line.cbStruct = sizeof(MIXERLINE);
line.dwDestination = j;
MIXERCONTROLDETAILS_BOOLEAN *pmxcdMute = (MIXERCONTROLDETAILS_BOOLEAN*)malloc(sizeof(MIXERCONTROLDETAILS_BOOLEAN)*dwTotalItems);
for ( int i = 0; i < dwTotalItems; i++ )
{
line.dwSource = i;
mmResult = mixerGetLineInfo((HMIXEROBJ)hMixer,&line,MIXER_GETLINEINFOF_SOURCE);
if ( line.dwComponentType == dwComponentTypeOfLine ) // && line.dwLineID == 65537 )
{
int nIndex = dwTotalItems-1-i;
for ( int k = 0; k < dwTotalItems; k++ )
{
pmxcdMute[k].fValue = FALSE;
}
pmxcdMute[nIndex].fValue = TRUE;
}
}
MIXERCONTROLDETAILS mixercontroldetails;
memset(&mixercontroldetails,0,sizeof(MIXERCONTROLDETAILS));
mixercontroldetails.cbStruct = sizeof(MIXERCONTROLDETAILS);
mixercontroldetails.cbDetails = sizeof(MIXERCONTROLDETAILS_BOOLEAN);
mixercontroldetails.cChannels = 1;
mixercontroldetails.paDetails = pmxcdMute;
mixercontroldetails.dwControlID = dwStereoSelControlID;
mixercontroldetails.cMultipleItems = dwTotalItems;
mmResult = mixerSetControlDetails((HMIXEROBJ)hMixer,&mixercontroldetails,MIXER_SETCONTROLDETAILSF_VALUE | MIXER_OBJECTF_HMIXER);
free(pmxcdMute);
DWORD dwConnections = mixerline.cConnections;
for ( int count = 0; count < dwConnections; count++ )
{
mixerline.dwSource = count;
mmResult = mixerGetLineInfo((HMIXEROBJ)hMixer,&mixerline,MIXER_OBJECTF_HMIXER | MIXER_GETLINEINFOF_SOURCE);
if ( mixerline.dwComponentType == dwComponentTypeOfLine ) // && mixerline.dwLineID == 65537 )
{
DWORD dwChannel = mixerline.cChannels;
mlc.cControls = 1;
mlc.cbmxctrl = sizeof(MIXERCONTROL);
mlc.pamxctrl = &mc;
mlc.dwLineID = mixerline.dwLineID;
mlc.dwControlType = MIXERCONTROL_CONTROLTYPE_VOLUME;
mmResult = mixerGetLineControls((HMIXEROBJ)hMixer,&mlc,MIXER_OBJECTF_HMIXER | MIXER_GETLINECONTROLSF_ONEBYTYPE);
MIXERCONTROLDETAILS_BOOLEAN* pControlDetail_BOOL = (MIXERCONTROLDETAILS_BOOLEAN*)malloc(dwChannel*sizeof(MIXERCONTROLDETAILS_BOOLEAN));
if ( !pControlDetail_BOOL )
return;
for ( int i = 0; i < dwChannel; i++ )
{
pControlDetail_BOOL[i].fValue = lVolumeValue;
}
MIXERCONTROLDETAILS mixercontroldetails;
memset(&mixercontroldetails,0,sizeof(MIXERCONTROLDETAILS));
mixercontroldetails.cbStruct = sizeof(MIXERCONTROLDETAILS);
mixercontroldetails.cbDetails = sizeof(MIXERCONTROLDETAILS_BOOLEAN);
mixercontroldetails.cChannels = 1;
mixercontroldetails.cMultipleItems = 0;
mixercontroldetails.paDetails = &pControlDetail_BOOL[0];
mixercontroldetails.dwControlID = mc.dwControlID;
mmResult = mixerSetControlDetails((HMIXEROBJ)hMixer,&mixercontroldetails,MIXER_SETCONTROLDETAILSF_VALUE | MIXER_OBJECTF_HMIXER);
free(pControlDetail_BOOL);
bFinished = TRUE;
break;
}
}
break;
}
}
mixerClose(hMixer);
if ( bFinished )
break;
}
}