Audio Device operation (mute, volume adjustment, microphone volume)
// Gtvolumemute. h: interface for the cgtvolumemute class.
//
//////////////////////////////////////// //////////////////////////////
# If! Defined (afx_gtvolumemute_h1_afd7d44e_54a3_48b6_a87e_7cfd0a17d1481_encoded _)
# Define afx_gtvolumemute_h1_afd7d44e_54a3_48b6_a87e_7cfd0a17d1481_encoded _
# If _ msc_ver> 1000
# Pragma once
# Endif // _ msc_ver> 1000
# Include <mmsystem. h>
# Include <mmreg. h>
Class cgtvolumemute
{
Public:
Cgtvolumemute ();
Virtual ~ Cgtvolumemute ();
Public:
Unsigned winapi getvolume (INT Dev );
Bool winapi setvolume (long Dev, long vol );
Bool winapi setmute (long Dev, bool vol );
Bool winapi getmute (long Dev );
PRIVATE:
Bool getvolumecontrol (hmixer, long componenttype, long ctrltype, mixercontrol * mxc );
Long getmutevalue (hmixer, mixercontrol * mxc );
Unsigned getvolumevalue (hmixer, mixercontrol * mxc );
Bool setmutevalue (hmixer, mixercontrol * mxc, bool mute );
Bool setvolumevalue (hmixer, mixercontrol * mxc, long volume );
};
# Endif //! Defined (afx_gtvolumemute_h1_afd7d44e_54a3_48b6_a87e_7cfd0a17d1481_encoded _)
//////////////////////////////////////// //////////////////////////////////////// //////////////////////////////////
// Gtvolumemute. cpp: Implementation of the cgtvolumemute class.
//
//////////////////////////////////////// //////////////////////////////
# Include "stdafx. H"
# Include "DLG. H"
# Include "gtvolumemute. H"
# Ifdef _ debug
# UNDEF this_file
Static char this_file [] =__ file __;
# Define new debug_new
# Endif
//////////////////////////////////////// //////////////////////////////
// Construction/destruction
//////////////////////////////////////// //////////////////////////////
Cgtvolumemute: cgtvolumemute ()
{
}
Cgtvolumemute ::~ Cgtvolumemute ()
{
}
Bool cgtvolumemute: getvolumecontrol (hmixer, long componenttype, long ctrltype, mixercontrol * mxc)
{
Mixerlinecontrols mxlc;
Mixerline mxl;
Mxl. cbstruct = sizeof (mxl );
Mxl. dwcomponenttype = componenttype;
If (! Mixergetlineinfo (hmixerobj) hmixer, & mxl, mixer_getlineinfof_componenttype ))
{
Mxlc. cbstruct = sizeof (mxlc );
Mxlc. dwlineid = mxl. dwlineid;
Mxlc. dwcontroltype = ctrltype;
Mxlc. ccontrols = 1;
Mxlc. cbmxctrl = sizeof (mixercontrol );
Mxlc. pamxctrl = mxc;
If (mixergetlinecontrols (hmixerobj) hmixer, & mxlc, mixer_getlinecontrolsf_onebytype ))
Return 0;
Else
Return 1;
}
Return 0;
}
//---------------------------------------------------------------------------
Long cgtvolumemute: getmutevalue (hmixer, mixercontrol * mxc)
{
Mixercontroldetails mxcd;
Mixercontroldetails_boolean mxcdmute;
Mxcd. hwndowner = 0;
Mxcd. cbstruct = sizeof (mxcd );
Mxcd. dwcontrolid = mxc-> dwcontrolid;
Mxcd. cbdetails = sizeof (mxcdmute );
Mxcd. padetails = & mxcdmute;
Mxcd. cchannels = 1;
Mxcd. cmultipleitems = 0;
If (mixergetcontroldetails (hmixerobj) hmixer, & mxcd, mixer_objectf_hmixer | mixer_getcontroldetailsf_value ))
Return-1;
Return mxcdmute. fvalue;
}
//---------------------------------------------------------------------------
Unsigned cgtvolumemute: getvolumevalue (hmixer, mixercontrol * mxc)
{
Mixercontroldetails mxcd;
Mixercontroldetails_unsigned vol; vol. dwvalue = 0;
Mxcd. hwndowner = 0;
Mxcd. cbstruct = sizeof (mxcd );
Mxcd. dwcontrolid = mxc-> dwcontrolid;
Mxcd. cbdetails = sizeof (VOL );
Mxcd. padetails = & Vol;
Mxcd. cchannels = 1;
If (mixergetcontroldetails (hmixerobj) hmixer, & mxcd, mixer_objectf_hmixer | mixer_getcontroldetailsf_value ))
Return-1;
Return vol. dwvalue;
}
//---------------------------------------------------------------------------
Bool cgtvolumemute: setmutevalue (hmixer, mixercontrol * mxc, bool mute)
{
Mixercontroldetails mxcd;
Mixercontroldetails_boolean mxcdmute; mxcdmute. fvalue = mute;
Mxcd. hwndowner = 0;
Mxcd. dwcontrolid = mxc-> dwcontrolid;
Mxcd. cbstruct = sizeof (mxcd );
Mxcd. cbdetails = sizeof (mxcdmute );
Mxcd. padetails = & mxcdmute;
Mxcd. cchannels = 1;
Mxcd. cmultipleitems = 0;
If (mixersetcontroldetails (hmixerobj) hmixer, & mxcd, mixer_objectf_hmixer | mixer_setcontroldetailsf_value ))
Return 0;
Return 1;
}
//---------------------------------------------------------------------------
Bool cgtvolumemute: setvolumevalue (hmixer, mixercontrol * mxc, long volume)
{
Mixercontroldetails mxcd;
Mixercontroldetails_unsigned vol; vol. dwvalue = volume;
Mxcd. hwndowner = 0;
Mxcd. dwcontrolid = mxc-> dwcontrolid;
Mxcd. cbstruct = sizeof (mxcd );
Mxcd. cbdetails = sizeof (VOL );
Mxcd. padetails = & Vol;
Mxcd. cchannels = 1;
If (mixersetcontroldetails (hmixerobj) hmixer, & mxcd, mixer_objectf_hmixer | mixer_setcontroldetailsf_value ))
Return 0;
Return 1;
}
//---------------------------------------------------------------------------
Unsigned winapi cgtvolumemute: getvolume (INT Dev) // & micro; & atilde; & micro; & frac12; & eacute; è ± & cedil; & micro; & auml; & ograve; & ocirc; & aacute; & iquest; Dev = 0 & ouml; Role & ograve; & ocirc; & aacute; & iquest; & pound; & not; 1 wave, 2 Midi, 3 line in
{
Long device; unsigned RT = 0;
Mixercontrol volctrl;
Hmixer;
Switch (Dev)
{
Case 1:
Device = mixerline_componenttype_src_waveout; break;
Case 2:
Device = mixerline_componenttype_src_synthesizer; break;
Case 3:
// Device = mixerline_componenttype_src_compactdisc; break; // CD & ograve; & ocirc; & aacute; & iquest;
// Device = mixerline_componenttype_src_microphone; break; // & acirc; ó & iquest; & euml; · & ccedil; & ograve; & ocirc; & aacute; & iquest;
// Device = mixerline_componenttype_src_line; break; // PC & ntilde; & iuml; & eacute; Role & aelig; Role & ograve; & ocirc; & aacute; & iquest;
Device = mixerline_componenttype_src_compactdisc; break;
Case 4:
Device = mixerline_componenttype_src_microphone; break;
Default:
Device = mixerline_componenttype_dst_speakers;
}
If (mixeropen (& hmixer, 0, 0, 0, 0) return 0;
If (! Getvolumecontrol (hmixer, device, mixercontrol_controltype_volume, & volctrl ))
Return 0;
RT = getvolumevalue (hmixer, & volctrl) * 100/volctrl. bounds. lmaximum;
Mixerclose (hmixer );
Return RT;
}
//---------------------------------------------------------------------------
Bool winapi cgtvolumemute: setvolume (long Dev, long vol)
{
// Dev = 0, 1, 2 · & ouml; ± & ETH; ± í & ecirc; & frac34; & ouml; Role & ograve; & ocirc; & aacute; & iquest ;, & sup2; Evaluate & ETH; & icirc;, Midi, line in
// Vol = 0-100 ±í & ecirc; & frac34; & ograve; & ocirc; & aacute; & iquest; & micro; & auml; & acute; ó & ETH; & iexcl;, & eacute; è & ouml; & atilde; & oacute; & euml; · & micro; & raquo; & Oslash; & ograve; & ocirc; & aacute; & iquest; & micro; & auml; & ouml; & micro; & oacute; & atilde; & micro; & auml; & ecirc; & ccedil; ° & ugrave; · & ouml; ± & egrave; & pound; & not; & frac14; & acute; & ograve; & ocirc; & aacute; & iquest; & acute; & oacute; 0-100 & pound; & not; & para; & Oslash; & sup2; & raquo; & ecirc; & ccedil; & eacute; è ± & cedil; & micro; & auml; & frac34; & Oslash; & para; & ocirc; & ouml; & micro;
// Retrun false ± í & ecirc; & frac34; & eacute; è & ouml; & atilde; & ograve; & ocirc; & aacute; & iquest; & micro; & auml; & acute; ó & ETH; & iexcl; & micro; & auml; & sup2; & ugrave; × orders & sup2; & raquo; & sup3; & eacute; & sup1; & brvbar;
// Retrun true ± í & ecirc; & frac34; & eacute; è & ouml; & atilde; & ograve; & ocirc; & aacute; & iquest; & micro; & auml; & acute; ó & ETH; & iexcl; & micro; & auml; & sup2; & ugrave; × region & sup3; & eacute; & sup1; & brvbar;
Long device;
Bool rc = false;
Mixercontrol volctrl;
Hmixer;
Switch (Dev)
{
Case 1:
Device = mixerline_componenttype_src_waveout; break;
Case 2:
Device = mixerline_componenttype_src_synthesizer; break;
Case 3:
Device = mixerline_componenttype_src_compactdisc; break;
Case 4:
Device = mixerline_componenttype_src_microphone; break;
Default:
Device = mixerline_componenttype_dst_speakers;
}
If (mixeropen (& hmixer, 0, 0, 0, 0) return 0;
If (getvolumecontrol (hmixer, device, mixercontrol_controltype_volume, & volctrl ))
{
Vol = vol * volctrl. bounds. lmaximum/100;
If (setvolumevalue (hmixer, & volctrl, vol ))
Rc = true;
}
Mixerclose (hmixer );
Return RC;
}
//---------------------------------------------------------------------------
Bool winapi cgtvolumemute: setmute (long Dev, bool vol) // & eacute; è & ouml; & atilde; & eacute; è ± & cedil; & frac34; & sup2; & ograve; & ocirc;
{
// Dev = 0, 1, 2 · & ouml; ± & ETH; ± í & ecirc; & frac34; & ouml; Role & ograve; & ocirc; & aacute; & iquest ;, & sup2; Evaluate & ETH; & icirc;, Midi, line in
// Vol = 0, 1 · & ouml; ± & ETH; ± í & ecirc; & frac34; & egrave; & iexcl; & iuml; & ucirc; & frac34; & sup2; & ograve; & ocirc;, & eacute; è & ouml; & atilde; & frac34; & sup2; & ograve; & ocirc;
// Retrun false ±í & ecirc; & frac34; & egrave; & iexcl; & iuml; & ucirc; & raquo; Limit & eacute; è & ouml; & atilde; & frac34; & sup2; & ograve; & ocirc; & sup2; & ugrave; × region & sup2; & raquo; & sup3; & eacute; & sup1; & brvbar;
// Retrun true ± í & ecirc; & frac34; & egrave; & iexcl; & iuml; & ucirc; & raquo; Limit & eacute; è & ouml; & atilde; & frac34; & sup2; & ograve; & ocirc; & sup2; & ugrave; × region & sup3; & eacute; & sup1; & brvbar;
Long device;
Bool rc = false;
Mixercontrol volctrl;
Hmixer;
Switch (Dev)
{
Case 1:
Device = mixerline_componenttype_src_waveout; break;
Case 2:
Device = mixerline_componenttype_src_synthesizer; break;
Case 3:
Device = mixerline_componenttype_src_compactdisc; break;
Case 4:
Device = mixerline_componenttype_src_microphone; break;
Default:
Device = mixerline_componenttype_dst_speakers;
}
If (mixeropen (& hmixer, 0, 0, 0, 0) return 0;
If (getvolumecontrol (hmixer, device, mixercontrol_controltype_mute, & volctrl ))
If (setmutevalue (hmixer, & volctrl, (bool) vol ))
Rc = true;
Mixerclose (hmixer );
Return RC;
}
//---------------------------------------------------------------------------
Bool winapi cgtvolumemute: getmute (long Dev)
{
// Dev = 0, 1, 2 · & ouml; ± & ETH; ± í & ecirc; & frac34; & ouml; Role & ograve; & ocirc; & aacute; & iquest; & pound; & not; & sup2; Evaluate & ETH; & icirc;, Midi, line in
// Retrun false ± í & ecirc; & frac34; & atilde; & raquo; & oacute; & ETH; & frac34; & sup2; & ograve; & ocirc;
// Retrun true ± í & ecirc; & frac34; & frac34; & sup2; & ograve; & ocirc;
Long device;
Bool rc = false;
Mixercontrol volctrl;
Hmixer;
Switch (Dev)
{
Case 1:
Device = mixerline_componenttype_src_waveout; break;
Case 2:
Device = mixerline_componenttype_src_synthesizer; break;
Case 3:
Device = mixerline_componenttype_src_compactdisc; break;
Case 4:
Device = mixerline_componenttype_src_microphone; break;
Default:
Device = mixerline_componenttype_dst_speakers;
}
If (mixeropen (& hmixer, 0, 0, 0, 0) return 0;
If (getvolumecontrol (hmixer, device, mixercontrol_controltype_mute, & volctrl ))
Rc = getmutevalue (hmixer, & volctrl) = 0? False: true;
Mixerclose (hmixer );
Return RC;
}