请问怎样控制音量及左右声道???(50分)

  • 主题发起人 主题发起人 乐子
  • 开始时间 开始时间
这个我明白,可我也找不到
 
在win32中的啊
是在工具栏的
就是第三页面上的啊
 
:乐子
我试过了你的那个程序是对的, 如果有mmsystem 的但不会来可能是你的系统出了问题我昨天不会来但今天我重装系统就会来了啊,
v:=$ffff //这好像是右声道
v:=$ffff0000 //这好像是左声道
v:=$ffffffff //这好像是立体声啊你试试就知道了
 
哈哈!有分拿了!
我以前也碰到过控制不了声卡的问题,是这样解决的:
waveoutgetvolume(WaveOutGetNumDevs,v);//要用WaveOutGetNumDevs取声卡设备号,不一定都是“0”!!
 
闈炲父鎰熻阿澶у?
 
许多控件或者方法在win2k,winxp下都不好用了.由于我要使用,不得不自己做了一个.
你看看吧
//=================================================================
unit MixerCtrl;

interface
uses windows,mmsystem,Sysutils;
{
creator: guan qing gang 关庆罡
http://pcauto.3322.net
email:gqg@21cn.com
}


{ About parameter :DST ,SCR referrence to mmsystem.pas
for example:
Dst=MIXERLINE_COMPONENTTYPE_DST_SPEAKERS
Src=MIXERLINE_COMPONENTTYPE_SRC_WAVEOUT
is waveout speaker volume


Dst=MIXERLINE_COMPONENTTYPE_DST_WAVEIN
Src=MIXERLINE_COMPONENTTYPE_SRC_MICROPHONE
is microphone inpute volume


}


//mute:1 unmute:0 ignore:other
procedure SetMute(Dst:longword;Src:longword;MasterMute:integer;Mute:integer);

//mastvol,vol: 0 to 1000 ,other: ignore
procedure SetVolume(Dst:longword;Src:longword;MasterVol:longint;Vol:longint);

//N:the number of chars to compare
Procedure SelectInputDevice(DeviceName:pchar;N :integer);


Procedure GetSelectedInputDevice(var DeviceName :Pchar);

procedure GetVolume(Dst:longword;Src:longword;var MasterVol:longint;var Vol:longint);
//vol: 0 to 1000

procedure GetMute(Dst:longword;Src:longword;var MasterMute:integer;var Mute:integer);

implementation

//-------------------------------------------------------------------------------------------
//-----------------------------------------------------------------------------------------------------
Procedure SelectInputDevice(DeviceName:pchar;N :integer);
var
hmx:HMIXER;
mxl:MIXERLINE

j:longword;
cChannels:longword;
cMultipleItems:longword;
pmxctrl:array of MIXERCONTROL;
///////////////////
mxlctrl: MIXERLINECONTROLS;
///////////////
mxcd:TMIXERCONTROLDETAILS;
bOneItemOnly : boolean;
plisttext : array of MIXERCONTROLDETAILS_LISTTEXT;
plistbool : array of MIXERCONTROLDETAILS_BOOLEAN;

i:longint;
ret:longint;
begin

//Open the mixer device
mixerOpen(@hmx, 0, 0, 0, 0);

// Get the line info for the wave in destination line
mxl.cbStruct:= sizeof(mxl);
mxl.dwComponentType:=MIXERLINE_COMPONENTTYPE_DST_WAVEIN;
ret:= mixerGetLineInfo(hmx, @mxl,MIXER_GETLINEINFOF_COMPONENTTYPE);
if ret=0 then


// Find a LIST control, if any, for the wave in line
setlength(pmxctrl,mxl.cControls);

mxlctrl.cbStruct := sizeof (mxlctrl);
mxlctrl.dwLineID := mxl.dwLineID;
mxlctrl.dwControlType := 0;
mxlctrl.cControls :=mxl.cControls;
mxlctrl.cbmxctrl := sizeof (MIXERCONTROL);
mxlctrl.pamxctrl := @Pmxctrl[0];

ret:=mixerGetLineControls(hmx, @mxlctrl,MIXER_GETLINECONTROLSF_ALL);
if ret=0 then
;
// Now walk through each control to find a type of LIST control. This
// can be either Mux, Single-select, Mixer or Multiple-select.

for i:=0 to mxl.cControls-1do

if (MIXERCONTROL_CT_CLASS_LIST =(pmxctrl.dwControlType and MIXERCONTROL_CT_CLASS_MASK)) then
break;

if (i < mxl.cControls) then

begin

// Found a LIST control
// Check if the LIST control is a Mux or Single-select type
bOneItemOnly:= FALSE;
case (pmxctrl.dwControlType) of
MIXERCONTROL_CONTROLTYPE_MUX: bOneItemOnly := TRUE;
MIXERCONTROL_CONTROLTYPE_SINGLESELECT: bOneItemOnly := TRUE;
end;


cChannels := mxl.cChannels;
cMultipleItems := 0;
if (MIXERCONTROL_CONTROLF_UNIFORM and pmxctrl.fdwControl)<>0 then

cChannels := 1;

if (MIXERCONTROL_CONTROLF_MULTIPLE and pmxctrl.fdwControl)<>0 then

cMultipleItems := pmxctrl.cMultipleItems;

// Get the text description of each item
setlength(plisttext,cChannels * cMultipleItems );

mxcd.cbStruct:=sizeof(mxcd);
mxcd.dwControlID:= pmxctrl.dwControlID;
mxcd.cChannels :=cchannels;
mxcd.hwndOwner :=0;
mxcd.cMultipleItems:=cMultipleItems;
mxcd.cbDetails :=sizeof (MIXERCONTROLDETAILS_LISTTEXT);
mxcd.paDetails :=@plisttext[0];


ret:= mixerGetControlDetails(hmx, @mxcd,MIXER_GETCONTROLDETAILSF_LISTTEXT);
if ret=0 then
;

// Now get the value for each item
setlength(plistbool,cChannels * cMultipleItems+10);

mxcd.cbDetails := sizeof(MIXERCONTROLDETAILS_BOOLEAN);
mxcd.paDetails := @(plistbool[0]);

ret:=mixerGetControlDetails(hmx, @mxcd,MIXER_GETCONTROLDETAILSF_VALUE);
if ret=0 then
;
// Select the "Microphone" item
for j:=0 to cMultipleItemsdo

if (0 = strlicomp(plisttext[j*cChannels].szName,DeviceName,N)) then

begin

// Select it for both left and right channels
plistbool[j*cChannels].fValue :=1;
plistbool[j*cChannels+ cChannels -1].fValue := 1;
end
else
if (bOneItemOnly) then

begin

// Mux or Single-select allows only one item to be selected
// so clear other items as necessary
plistbool[j*cChannels].fValue :=0;
plistbool[j*cChannels+ cChannels - 1].fValue := 0;
end;


// Now actually set the new values in
ret:=mixerSetControlDetails(hmx, @mxcd,MIXER_SETCONTROLDETAILSF_VALUE);
if ret=0 then

end;

mixerClose(hmx);

end;



//---------------------------------------------------------------------------------
procedure SetMute(Dst:longword;Src:longword;MasterMute:integer;Mute:integer);
var
hmx:HMIXER;
mxl:MIXERLINE
cConnections:longword;
j:longword;
cChannels:longword;
pmxctrl:PMIXERCONTROL;
///////////////////
mxlctrl: MIXERLINECONTROLS;
///////////////
mxcd:TMIXERCONTROLDETAILS;
pbool:array of MIXERCONTROLDETAILS_BOOLEAN;

ret:longint;
begin

// Open the mixer device
mixerOpen(@hmx, 0, 0, 0, 0);

// Get the line info for the wave in destination line

mxl.cbStruct := sizeof(mxl);
mxl.dwComponentType := Dst;
mixerGetLineInfo(hmx, @mxl, MIXER_GETLINEINFOF_COMPONENTTYPE);

getmem(pmxctrl,sizeof(MIXERCONTROL));

//******************Master Mute******************************************************
if (mastermute=0) or (mastermute=1) then

begin

mxlctrl.cbStruct := sizeof (mxlctrl);
mxlctrl.dwLineID := mxl.dwLineID;
mxlctrl.dwControlType := MIXERCONTROL_CONTROLTYPE_MUTE;
mxlctrl.cControls :=1;
mxlctrl.cbmxctrl := sizeof (MIXERCONTROL);
mxlctrl.pamxctrl := pmxctrl;
ret:=mixerGetLineControls(hmx, @mxlctrl,MIXER_GETLINECONTROLSF_ONEBYTYPE)
if(ret = MMSYSERR_NOERROR ) then

begin

// Found, so proceed
cChannels := mxl.cChannels;

setlength(pbool, cChannels);

if (MIXERCONTROL_CONTROLF_UNIFORM and pmxctrl.fdwControl)<>0 then
cChannels := 1;

mxcd.cbStruct:=sizeof(mxcd);
mxcd.dwControlID:= pmxctrl.dwControlID;
mxcd.cChannels :=cchannels;
mxcd.hwndOwner :=0;
mxcd.cbDetails := sizeof (MIXERCONTROLDETAILS_BOOLEAN);
mxcd.paDetails :=pbool;

mixerGetControlDetails(hmx, @mxcd,MIXER_SETCONTROLDETAILSF_VALUE);

// Unmute the microphone line (for both channels)
pbool[0].fValue :=MasterMute;
pbool[cChannels - 1].fValue :=MasterMute;

mixerSetControlDetails(hmx, @mxcd, MIXER_SETCONTROLDETAILSF_VALUE);
end;

end;

//*****************Master Mute end*******************************************************
// Now find the microphone source line connected to this wave in
// destination
if (mute=0) or (mute=1) then

begin

cConnections := mxl.cConnections;
for j:=0 to cConnections-1do

begin

mxl.dwSource := j;
mixerGetLineInfo(hmx, @mxl, MIXER_GETLINEINFOF_SOURCE);
if (Src = mxl.dwComponentType) then
break;
end;



// Find a mute control, if any, of the microphone line


mxlctrl.cbStruct := sizeof (mxlctrl);
mxlctrl.dwLineID := mxl.dwLineID;
mxlctrl.dwControlType := MIXERCONTROL_CONTROLTYPE_MUTE;
mxlctrl.cControls :=1;
mxlctrl.cbmxctrl := sizeof (MIXERCONTROL);
mxlctrl.pamxctrl := pmxctrl;
ret:=mixerGetLineControls(hmx, @mxlctrl,MIXER_GETLINECONTROLSF_ONEBYTYPE)
if(ret = MMSYSERR_NOERROR ) then

begin

// Found, so proceed
cChannels := mxl.cChannels;

setlength(pbool, cChannels);

if (MIXERCONTROL_CONTROLF_UNIFORM and pmxctrl.fdwControl)<>0 then
cChannels := 1;

mxcd.cbStruct:=sizeof(mxcd);
mxcd.dwControlID:= pmxctrl.dwControlID;
mxcd.cChannels :=cchannels;
mxcd.hwndOwner :=0;
mxcd.cbDetails := sizeof (MIXERCONTROLDETAILS_BOOLEAN);
mxcd.paDetails :=pbool;

mixerGetControlDetails(hmx, @mxcd,MIXER_SETCONTROLDETAILSF_VALUE);

// Unmute the microphone line (for both channels)
pbool[0].fValue :=Mute;
pbool[cChannels - 1].fValue :=Mute;

mixerSetControlDetails(hmx, @mxcd, MIXER_SETCONTROLDETAILSF_VALUE);

end;

end;

freemem(pmxctrl);
mixerClose(hmx);
end;

//-------------------------------------------------------------------------------------------


//-------------------------------------------------------------------------------------------
procedure SetVolume(Dst:longword;Src:longword;MasterVol:longint;Vol:longint);
//vol: 0 to 1000
var
hmx:HMIXER;
mxl:MIXERLINE
cConnections:longword;
j:longword;
cChannels:longword;
pmxctrl:pMIXERCONTROL;
///////////////////
mxlctrl: MIXERLINECONTROLS;
///////////////
mxcd:TMIXERCONTROLDETAILS;

pUnsigned :array of MIXERCONTROLDETAILS_UNSIGNED;
ret:longint;
begin

// Open the mixer device
mixerOpen(@hmx, 0, 0, 0, 0);

// Get the line info for the wave in destination line
mxl.cbStruct := sizeof(mxl);
mxl.dwComponentType := Dst;
mixerGetLineInfo(hmx, @mxl,MIXER_GETLINEINFOF_COMPONENTTYPE);


getmem(pmxctrl,sizeof(MIXERCONTROL));
//*********************Master volume begin
**********************************************************
if (MasterVol>=0) and (MasterVol<=1000) then

begin

mxlctrl.cbStruct := sizeof (mxlctrl);
mxlctrl.dwLineID := mxl.dwLineID;
mxlctrl.dwControlType := MIXERCONTROL_CONTROLTYPE_VOLUME;
mxlctrl.cControls :=1;
mxlctrl.cbmxctrl := sizeof (MIXERCONTROL);
mxlctrl.pamxctrl := pmxctrl;

ret:=mixerGetLineControls(hmx, @mxlctrl,MIXER_GETLINECONTROLSF_ONEBYTYPE)
if ret=0 then
;
if(ret = MMSYSERR_NOERROR ) then

begin

// Found!
cChannels := mxl.cChannels;

setlength(pUnsigned,cChannels);

if (MIXERCONTROL_CONTROLF_UNIFORM and pmxctrl.fdwControl)<>0 then
cChannels := 1;

mxcd.cbStruct:=sizeof(mxcd);
mxcd.dwControlID:= pmxctrl.dwControlID;
mxcd.cChannels :=cchannels;
mxcd.hwndOwner :=0;

mxcd.cbDetails := sizeof (MIXERCONTROLDETAILS_UNSIGNED);
mxcd.paDetails :=pUnsigned;


ret:=mixerGetControlDetails(hmx, @mxcd,MIXER_SETCONTROLDETAILSF_VALUE);
if ret=0 then

begin

// Set the volume to the middle (for both channels as needed)
pUnsigned[cChannels - 1].dwValue :=round(MasterVol*(pmxctrl.Bounds.dwMinimum+pmxctrl.Bounds.dwMaximum)/1000);
pUnsigned[0].dwValue := pUnsigned[cChannels - 1].dwValue;
ret:=mixerSetControlDetails(hmx, @mxcd,MIXER_SETCONTROLDETAILSF_VALUE);
if ret=0 then
;
end;


end


end;


//*******************************Master volume end************************************************
// Now find the microphone source line connected to this wave in
// destination
if (Vol>=0) and (Vol<=1000) then

begin

cConnections := mxl.cConnections;
for j:=0 to cConnections-1do

begin

mxl.dwSource := j;
mixerGetLineInfo(hmx, @mxl, MIXER_GETLINEINFOF_SOURCE);
if (Src = mxl.dwComponentType) then
break;
end;

// Find a volume control, if any, of the microphone line


mxlctrl.cbStruct := sizeof (mxlctrl);
mxlctrl.dwLineID := mxl.dwLineID;
mxlctrl.dwControlType := MIXERCONTROL_CONTROLTYPE_VOLUME;
mxlctrl.cControls :=1;
mxlctrl.cbmxctrl := sizeof (MIXERCONTROL);
mxlctrl.pamxctrl := pmxctrl;

ret:=mixerGetLineControls(hmx, @mxlctrl,MIXER_GETLINECONTROLSF_ONEBYTYPE)
if ret=0 then
;
if(ret = MMSYSERR_NOERROR ) then

begin

// Found!
cChannels := mxl.cChannels;

setlength(pUnsigned,cChannels);

if (MIXERCONTROL_CONTROLF_UNIFORM and pmxctrl.fdwControl)<>0 then
cChannels := 1;
mxcd.cbStruct:=sizeof(mxcd);
mxcd.dwControlID:= pmxctrl.dwControlID;
mxcd.cChannels :=cchannels;
mxcd.hwndOwner :=0;

mxcd.cbDetails := sizeof (MIXERCONTROLDETAILS_UNSIGNED);
mxcd.paDetails :=pUnsigned;

ret:=mixerGetControlDetails(hmx, @mxcd,MIXER_SETCONTROLDETAILSF_VALUE);
if ret=0 then

begin

pUnsigned[cChannels - 1].dwValue :=round(vol*(pmxctrl.Bounds.dwMinimum+pmxctrl.Bounds.dwMaximum)/1000);
pUnsigned[0].dwValue := pUnsigned[cChannels - 1].dwValue;
ret:=mixerSetControlDetails(hmx, @mxcd,MIXER_SETCONTROLDETAILSF_VALUE);
if ret=0 then
;
end;


end;

end;


freemem(pmxctrl);


mixerClose(hmx);
end;

//-------------------------------------------------------------------------------------------
procedure GetMute(Dst:longword;Src:longword;var MasterMute:integer;var Mute:integer);
var
hmx:HMIXER;
mxl:MIXERLINE
cConnections:longword;
j:longword;
cChannels:longword;
pmxctrl:pMIXERCONTROL;
///////////////////
mxlctrl: MIXERLINECONTROLS;
///////////////
mxcd:TMIXERCONTROLDETAILS;
pbool:array of MIXERCONTROLDETAILS_BOOLEAN;

ret:longint;
begin

// Open the mixer device
mixerOpen(@hmx, 0, 0, 0, 0);

// Get the line info for the wave in destination line

mxl.cbStruct := sizeof(mxl);
mxl.dwComponentType := Dst;
mixerGetLineInfo(hmx, @mxl, MIXER_GETLINEINFOF_COMPONENTTYPE);

getmem(pmxctrl,sizeof(MIXERCONTROL));

//******************Master Mute******************************************************


mxlctrl.cbStruct := sizeof (mxlctrl);
mxlctrl.dwLineID := mxl.dwLineID;
mxlctrl.dwControlType := MIXERCONTROL_CONTROLTYPE_MUTE;
mxlctrl.cControls :=1;
mxlctrl.cbmxctrl := sizeof (MIXERCONTROL);
mxlctrl.pamxctrl := pmxctrl;
ret:=mixerGetLineControls(hmx, @mxlctrl,MIXER_GETLINECONTROLSF_ONEBYTYPE)
if(ret = MMSYSERR_NOERROR ) then

begin

// Found, so proceed
cChannels := mxl.cChannels;

setlength(pbool, cChannels);

if (MIXERCONTROL_CONTROLF_UNIFORM and pmxctrl.fdwControl)<>0 then
cChannels := 1;

mxcd.cbStruct:=sizeof(mxcd);
mxcd.dwControlID:= pmxctrl.dwControlID;
mxcd.cChannels :=cchannels;
mxcd.hwndOwner :=0;
mxcd.cbDetails := sizeof (MIXERCONTROLDETAILS_BOOLEAN);
mxcd.paDetails :=pbool;

mixerGetControlDetails(hmx, @mxcd,MIXER_SETCONTROLDETAILSF_VALUE);

// Unmute the microphone line (for both channels)
MasterMute:=pbool[0].fValue

end;


//*****************Master Mute end*******************************************************
// Now find the microphone source line connected to this wave in
// destination

cConnections := mxl.cConnections;
for j:=0 to cConnections-1do

begin

mxl.dwSource := j;
mixerGetLineInfo(hmx, @mxl, MIXER_GETLINEINFOF_SOURCE);
if (Src = mxl.dwComponentType) then
break;
end;



// Find a mute control, if any, of the microphone line


mxlctrl.cbStruct := sizeof (mxlctrl);
mxlctrl.dwLineID := mxl.dwLineID;
mxlctrl.dwControlType := MIXERCONTROL_CONTROLTYPE_MUTE;
mxlctrl.cControls :=1;
mxlctrl.cbmxctrl := sizeof (MIXERCONTROL);
mxlctrl.pamxctrl := pmxctrl;
ret:=mixerGetLineControls(hmx, @mxlctrl,MIXER_GETLINECONTROLSF_ONEBYTYPE)
if(ret = MMSYSERR_NOERROR ) then

begin

// Found, so proceed
cChannels := mxl.cChannels;

setlength(pbool, cChannels);

if (MIXERCONTROL_CONTROLF_UNIFORM and pmxctrl.fdwControl)<>0 then
cChannels := 1;

mxcd.cbStruct:=sizeof(mxcd);
mxcd.dwControlID:= pmxctrl.dwControlID;
mxcd.cChannels :=cchannels;
mxcd.hwndOwner :=0;
mxcd.cbDetails := sizeof (MIXERCONTROLDETAILS_BOOLEAN);
mxcd.paDetails :=pbool;

mixerGetControlDetails(hmx, @mxcd,MIXER_SETCONTROLDETAILSF_VALUE);

// Unmute the microphone line (for both channels)
Mute := pbool[0].fValue
end;


freemem(pmxctrl);


mixerClose(hmx);
end;

//-----------------------------------------------------------------------------------------------------
Procedure GetSelectedInputDevice(var DeviceName :Pchar);
var
hmx:HMIXER;
mxl:MIXERLINE

j:longword;
cChannels:longword;
cMultipleItems:longword;
pmxctrl:array of MIXERCONTROL;
///////////////////
mxlctrl: MIXERLINECONTROLS;
///////////////
mxcd:TMIXERCONTROLDETAILS;
bOneItemOnly : boolean;
plisttext : array of MIXERCONTROLDETAILS_LISTTEXT;
plistbool : array of MIXERCONTROLDETAILS_BOOLEAN;

i:longint;
ret:longint;
begin

//Open the mixer device
mixerOpen(@hmx, 0, 0, 0, 0);

// Get the line info for the wave in destination line
mxl.cbStruct:= sizeof(mxl);
mxl.dwComponentType:=MIXERLINE_COMPONENTTYPE_DST_WAVEIN;
ret:= mixerGetLineInfo(hmx, @mxl,MIXER_GETLINEINFOF_COMPONENTTYPE);
if ret=0 then


// Find a LIST control, if any, for the wave in line
setlength(pmxctrl,mxl.cControls);

mxlctrl.cbStruct := sizeof (mxlctrl);
mxlctrl.dwLineID := mxl.dwLineID;
mxlctrl.dwControlType := 0;
mxlctrl.cControls :=mxl.cControls;
mxlctrl.cbmxctrl := sizeof (MIXERCONTROL);
mxlctrl.pamxctrl := @Pmxctrl[0];

ret:=mixerGetLineControls(hmx, @mxlctrl,MIXER_GETLINECONTROLSF_ALL);
if ret=0 then
;
// Now walk through each control to find a type of LIST control. This
// can be either Mux, Single-select, Mixer or Multiple-select.

for i:=0 to mxl.cControls-1do

if (MIXERCONTROL_CT_CLASS_LIST =(pmxctrl.dwControlType and MIXERCONTROL_CT_CLASS_MASK)) then
break;

if (i < mxl.cControls) then

begin

// Found a LIST control
// Check if the LIST control is a Mux or Single-select type
bOneItemOnly:= FALSE;
case (pmxctrl.dwControlType) of
MIXERCONTROL_CONTROLTYPE_MUX: bOneItemOnly := TRUE;
MIXERCONTROL_CONTROLTYPE_SINGLESELECT: bOneItemOnly := TRUE;
end;


cChannels := mxl.cChannels;
cMultipleItems := 0;
if (MIXERCONTROL_CONTROLF_UNIFORM and pmxctrl.fdwControl)<>0 then

cChannels := 1;

if (MIXERCONTROL_CONTROLF_MULTIPLE and pmxctrl.fdwControl)<>0 then

cMultipleItems := pmxctrl.cMultipleItems;

// Get the text description of each item
setlength(plisttext,cChannels * cMultipleItems );

mxcd.cbStruct:=sizeof(mxcd);
mxcd.dwControlID:= pmxctrl.dwControlID;
mxcd.cChannels :=cchannels;
mxcd.hwndOwner :=0;
mxcd.cMultipleItems:=cMultipleItems;
mxcd.cbDetails :=sizeof (MIXERCONTROLDETAILS_LISTTEXT);
mxcd.paDetails :=@plisttext[0];


ret:= mixerGetControlDetails(hmx, @mxcd,MIXER_GETCONTROLDETAILSF_LISTTEXT);
if ret=0 then
;

// Now get the value for each item
setlength(plistbool,cChannels * cMultipleItems+10);

mxcd.cbDetails := sizeof(MIXERCONTROLDETAILS_BOOLEAN);
mxcd.paDetails := @(plistbool[0]);

ret:=mixerGetControlDetails(hmx, @mxcd,MIXER_GETCONTROLDETAILSF_VALUE);
if ret=0 then
;

//
for j:=0 to cMultipleItemsdo

if plistbool[j*cChannels].fValue=1 then

devicename:=plisttext[j*cChannels].szName;
end;


mixerClose(hmx);

end;



//---------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------
procedure GetVolume(Dst:longword;Src:longword;var MasterVol:longint;var Vol:longint);
//vol: 0 to 1000
var
hmx:HMIXER;
mxl:MIXERLINE
cConnections:longword;
j:longword;
cChannels:longword;
pmxctrl:pMIXERCONTROL;
///////////////////
mxlctrl: MIXERLINECONTROLS;
///////////////
mxcd:TMIXERCONTROLDETAILS;

pUnsigned :array of MIXERCONTROLDETAILS_UNSIGNED;
ret:longint;
begin

// Open the mixer device
mixerOpen(@hmx, 0, 0, 0, 0);

// Get the line info for the wave in destination line
mxl.cbStruct := sizeof(mxl);
mxl.dwComponentType := Dst;
mixerGetLineInfo(hmx, @mxl,MIXER_GETLINEINFOF_COMPONENTTYPE);


getmem(pmxctrl,sizeof(MIXERCONTROL));
//*********************Master volume begin
**********************************************************
mxlctrl.cbStruct := sizeof (mxlctrl);
mxlctrl.dwLineID := mxl.dwLineID;
mxlctrl.dwControlType := MIXERCONTROL_CONTROLTYPE_VOLUME;
mxlctrl.cControls :=1;
mxlctrl.cbmxctrl := sizeof (MIXERCONTROL);
mxlctrl.pamxctrl := pmxctrl;

ret:=mixerGetLineControls(hmx, @mxlctrl,MIXER_GETLINECONTROLSF_ONEBYTYPE)
if ret=0 then
;
if(ret = MMSYSERR_NOERROR ) then

begin

// Found!
cChannels := mxl.cChannels;

setlength(pUnsigned,cChannels);

if (MIXERCONTROL_CONTROLF_UNIFORM and pmxctrl.fdwControl)<>0 then
cChannels := 1;

mxcd.cbStruct:=sizeof(mxcd);
mxcd.dwControlID:= pmxctrl.dwControlID;
mxcd.cChannels :=cchannels;
mxcd.hwndOwner :=0;

mxcd.cbDetails := sizeof (MIXERCONTROLDETAILS_UNSIGNED);
mxcd.paDetails :=pUnsigned;


ret:=mixerGetControlDetails(hmx, @mxcd,MIXER_SETCONTROLDETAILSF_VALUE);
if ret=0 then

begin

// Set the volume to the middle (for both channels as needed)
MasterVol:= round(pUnsigned[0].dwValue/((pmxctrl.Bounds.dwMinimum+pmxctrl.Bounds.dwMaximum)/1000));
end;


end;





//*******************************Master volume end************************************************
// Now find the microphone source line connected to this wave in
// destination
cConnections := mxl.cConnections;
for j:=0 to cConnections-1do

begin

mxl.dwSource := j;
mixerGetLineInfo(hmx, @mxl, MIXER_GETLINEINFOF_SOURCE);
if (Src = mxl.dwComponentType) then
break;
end;

// Find a volume control, if any, of the microphone line


mxlctrl.cbStruct := sizeof (mxlctrl);
mxlctrl.dwLineID := mxl.dwLineID;
mxlctrl.dwControlType := MIXERCONTROL_CONTROLTYPE_VOLUME;
mxlctrl.cControls :=1;
mxlctrl.cbmxctrl := sizeof (MIXERCONTROL);
mxlctrl.pamxctrl := pmxctrl;

ret:=mixerGetLineControls(hmx, @mxlctrl,MIXER_GETLINECONTROLSF_ONEBYTYPE)
if ret=0 then
;
if(ret = MMSYSERR_NOERROR ) then

begin

// Found!
cChannels := mxl.cChannels;

setlength(pUnsigned,cChannels);

if (MIXERCONTROL_CONTROLF_UNIFORM and pmxctrl.fdwControl)<>0 then
cChannels := 1;
mxcd.cbStruct:=sizeof(mxcd);
mxcd.dwControlID:= pmxctrl.dwControlID;
mxcd.cChannels :=cchannels;
mxcd.hwndOwner :=0;

mxcd.cbDetails := sizeof (MIXERCONTROLDETAILS_UNSIGNED);
mxcd.paDetails :=pUnsigned;

ret:=mixerGetControlDetails(hmx, @mxcd,MIXER_SETCONTROLDETAILSF_VALUE);
if ret=0 then

begin

Vol:= round(pUnsigned[0].dwValue/((pmxctrl.Bounds.dwMinimum+pmxctrl.Bounds.dwMaximum)/1000));
end;


end;



freemem(pmxctrl);


mixerClose(hmx);
end;


end.

//================================例子==========================================
//================================例子==========================================

//================================例子==========================================

//================================例子==========================================

//================================例子==========================================

//================================例子==========================================
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls,mixerctrl,mmsystem;

type
TForm1 = class(TForm)
GroupBox1: TGroupBox;
CheckBox1: TCheckBox;
CheckBox2: TCheckBox;
GroupBox2: TGroupBox;
ScrollBar1: TScrollBar;
ScrollBar2: TScrollBar;
GroupBox3: TGroupBox;
Button3: TButton;
Edit1: TEdit;
Button1: TButton;
Label1: TLabel;
Label2: TLabel;
ScrollBar3: TScrollBar;
Label3: TLabel;
Label4: TLabel;
procedure CheckBox1Click(Sender: TObject);
procedure CheckBox2Click(Sender: TObject);
procedure ScrollBar1Scroll(Sender: TObject;
ScrollCode: TScrollCode;
var ScrollPos: Integer);
procedure ScrollBar2Scroll(Sender: TObject;
ScrollCode: TScrollCode;
var ScrollPos: Integer);
procedure Button3Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure ScrollBar3Scroll(Sender: TObject;
ScrollCode: TScrollCode;
var ScrollPos: Integer);
private
{ Private declarations }
public
{ Public declarations }
end;


var
Form1: TForm1;

implementation

{$R *.DFM}
procedure TForm1.CheckBox1Click(Sender: TObject);
begin

if checkbox1.Checked then

SetMute(MIXERLINE_COMPONENTTYPE_DST_SPEAKERS,MIXERLINE_COMPONENTTYPE_SRC_WAVEOUT,1,-1)
else

SetMute(MIXERLINE_COMPONENTTYPE_DST_SPEAKERS,MIXERLINE_COMPONENTTYPE_SRC_WAVEOUT,0,-1)
end;


procedure TForm1.CheckBox2Click(Sender: TObject);
begin

if checkbox2.Checked then

SetMute(MIXERLINE_COMPONENTTYPE_DST_SPEAKERS,MIXERLINE_COMPONENTTYPE_SRC_WAVEOUT,-1,1)
else

SetMute(MIXERLINE_COMPONENTTYPE_DST_SPEAKERS,MIXERLINE_COMPONENTTYPE_SRC_WAVEOUT,-1,0)
end;


procedure TForm1.ScrollBar1Scroll(Sender: TObject;
ScrollCode: TScrollCode;
var ScrollPos: Integer);
begin

SetVolume(MIXERLINE_COMPONENTTYPE_DST_SPEAKERS,MIXERLINE_COMPONENTTYPE_SRC_WAVEOUT,ScrollBar1.Position ,-1);
//vol: 0 to 1000
end;


procedure TForm1.ScrollBar2Scroll(Sender: TObject;
ScrollCode: TScrollCode;
var ScrollPos: Integer);
begin

SetVolume(MIXERLINE_COMPONENTTYPE_DST_SPEAKERS,MIXERLINE_COMPONENTTYPE_SRC_WAVEOUT,-1,ScrollBar2.Position );
//vol: 0 to 1000
end;


procedure TForm1.Button3Click(Sender: TObject);
var
s:pchar;
begin

s:=pchar(edit1.text);
SelectInputDevice(s,3);
end;


procedure TForm1.FormCreate(Sender: TObject);
var
mv,v :longint;
mm,m :longint;
s:pchar;
begin

getvolume(MIXERLINE_COMPONENTTYPE_DST_SPEAKERS,MIXERLINE_COMPONENTTYPE_SRC_WAVEOUT,mv,v);
scrollbar1.Position:=mv;
scrollbar2.Position :=v;

getvolume(MIXERLINE_COMPONENTTYPE_DST_WAVEIN,MIXERLINE_COMPONENTTYPE_SRC_MICROPHONE,mv,v);
scrollbar3.Position :=v;

getmute(MIXERLINE_COMPONENTTYPE_DST_SPEAKERS,MIXERLINE_COMPONENTTYPE_SRC_WAVEOUT,mm,m);

if mm=1 then

checkbox1.Checked:=true
else

checkbox1.Checked:=false;

if m=1 then

checkbox2.Checked:=true
else

checkbox2.Checked:=false;

getselectedinputdevice(s);
edit1.Text :=s;

end;


procedure TForm1.Button1Click(Sender: TObject);
begin

close;
end;


procedure TForm1.ScrollBar3Scroll(Sender: TObject;
ScrollCode: TScrollCode;
var ScrollPos: Integer);
begin

SetVolume(MIXERLINE_COMPONENTTYPE_DST_WAVEIN,MIXERLINE_COMPONENTTYPE_SRC_MICROPHONE,-1,ScrollBar3.Position );
//vol: 0 to 1000
end;


end.



 
If you want the full source code ,contact me.
qq:57177681
 
这些代码根本解决不了左右声道的问题,只要一设置左声道,右边的那个音箱就没戏了,还是用mciSendString()吧,可以根本性的解决问题,要的话发邮件到pc-bird@vip.sina.com
 
后退
顶部