得到声卡输入的peak值(75分)

  • 主题发起人 主题发起人 andyyan
  • 开始时间 开始时间
A

andyyan

Unregistered / Unconfirmed
GUEST, unregistred user!
小弟参考mixer函数编写了一段代码,想得到声音的peak值,但就是有点问题,希望高手指点
procedure TForm1.Button1Click(Sender: TObject);
var
MixerControl: TMixerControl;

MixerControlDetails: TMixerControlDetails;

MixerControlDetailsSigned: TMixerControlDetailsSigned;

Mixer: THandle;
MixerLine: TMixerLine;
MixerLineControls: TMixerLineControls;

PeakMeter: DWORD;

Rslt: DWORD;

SourceCount: Cardinal;

WaveOut: DWORD;

I: Integer;

X: Integer;

Y: Integer;

begin

Rslt := mixerOpen(@Mixer, 0, 0, 0, 0);

if Rslt <> 0 then

raise Exception.CreateFmt('Can''t open mixer (%d)', [Rslt]);

FillChar(MixerLine, SizeOf(MixerLine), 0);

MixerLine.cbStruct := SizeOf(MixerLine);
MixerLine.dwComponentType := MIXERLINE_COMPONENTTYPE_DST_SPEAKERS;
Rslt := mixerGetLineInfo(Mixer, @MixerLine,
MIXER_GETLINEINFOF_COMPONENTTYPE);

if Rslt <> 0 then

raise Exception.CreateFmt('Can''t find speaker line (%d)', [Rslt]);

SourceCount := MixerLine.cConnections;

WaveOut := $FFFFFFFF;

for I := 0 to SourceCount - 1do

begin

MixerLine.dwSource := I;

Rslt := mixerGetLineInfo(Mixer, @MixerLine,
MIXER_GETLINEINFOF_SOURCE);

if Rslt <> 0 then

raise Exception.CreateFmt('Can''t get source line (%d)', [Rslt]);
//MIXERLINE_COMPONENTTYPE_SRC_WAVEOUT
if MixerLine.dwComponentType = MIXERLINE_COMPONENTTYPE_SRC_LINE then

begin

WaveOut := MixerLine.dwLineId;

Break;

end;


end;


if WaveOut = $FFFFFFFF then

raise Exception.Create('Can''t find wave out device');
FillChar(MixerLineControls, SizeOf(MixerLineControls), 0);
with MixerLineControlsdo

begin

cbStruct := SizeOf(MixerLineControls);
dwLineId := WaveOut;
dwControlType := MIXERCONTROL_CONTROLTYPE_PEAKMETER;
cControls := 1;

cbmxctrl := SizeOf(TMixerControl);

pamxctrl := @MixerControl;

end;


Rslt := mixerGetLineControls(Mixer, @MixerLineControls,
MIXER_GETLINECONTROLSF_ONEBYTYPE);
if Rslt <> 0 then

raise Exception.CreateFmt('Can''t find peak meter control (%d)',
[Rslt]);

PeakMeter := MixerControl.dwControlID;

FillChar(MixerControlDetails, SizeOf(MixerControlDetails), 0);

with MixerControlDetailsdo

begin

cbStruct := SizeOf(MixerControlDetails);

dwControlId := PeakMeter;

cChannels := 1;

cbDetails := SizeOf(MixerControlDetailsSigned);

paDetails := @MixerControlDetailsSigned;
end;


Rslt := mixerClose(Mixer);

if Rslt <> 0 then

raise Exception.CreateFmt('Can''t close mixer (%d)', [Rslt]);

end;

但老是提示说:'Can''t find peak meter control,不知道为什么呢?难道声卡上没有meter 的控制器???????高手指点啊
 
我的qq是78498929,欢迎高手前来指点,谢谢
 
后退
顶部