混音器DEMO
#include "stdafx.h"
void SetAudio()
{
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 == MIXERLINE_COMPONENTTYPE_SRC_ANALOG && 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 == MIXERLINE_COMPONENTTYPE_SRC_ANALOG && 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 = 65535;
}
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;
}
}
int _tmain(int argc, _TCHAR* argv[])
{
SetAudio();
return 0;
}