中国程序员联盟 正在重新改版中ing 不便之处还请见谅 改版后将内容涉及java delphi .net php
 
  首页 | 数据库开发 | 网络通讯 | 多线程 | 多媒体开发 | 图像处理 | 程序人生 | 系统函数 | 控件开发 | Web服务
 
  当前位置:笨鱼delphi技术网>多媒体开发>文章内容

delphi 音量输出仪表

来源:国外 关于:Tomas Rutkauskas 发布时间:2007-07-15   [收藏] [推荐]
Is there a way, like the Windows Volume Control, to get the current
volume output... not the Volume settings (loudness), but how "loud" the
playing sound is? The Volume Control has a "red-to-green" bar that show
the volume output... how could this be done?
Here's some code that will retrieve a handle to the meter attached to
the WaveOut source of the speaker line, if there is one:
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 - 1 do
  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]);
    if MixerLine.dwComponentType = MIXERLINE_COMPONENTTYPE_SRC_WAVEOUT 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 MixerLineControls do
  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;
  // at this point, I have the meter control ID, so I can
  // repeatedly query its value and plot the resulting data
  // on a canvas
  X := 0;
  FillChar(MixerControlDetails, SizeOf(MixerControlDetails), 0);
  with MixerControlDetails do
  begin
    cbStruct := SizeOf(MixerControlDetails);
    dwControlId := PeakMeter;
    cChannels := 1;
    cbDetails := SizeOf(MixerControlDetailsSigned);
    paDetails := @MixerControlDetailsSigned;
  end;
  repeat
    Sleep(10);
    Rslt := mixerGetControlDetails(Mixer, @MixerControlDetails,
      MIXER_GETCONTROLDETAILSF_VALUE);
    if Rslt <> 0 then
      raise Exception.CreateFmt('Can''t get control details (%d)',
        [Rslt]);
    Application.ProcessMessages;
    Inc(X);
    Y := 300 - Round(300 * Abs(MixerControlDetailsSigned.lValue) /
      32768);
    with Canvas do
    begin
      MoveTo(X, 0);
      Pen.Color := clBtnFace;
      LineTo(X, 300);
      Pen.Color := clWindowText;
      LineTo(X, Y);
    end;
  until X > 500;
  // don't forget to close the mixer handle when you're done
  Rslt := mixerClose(Mixer);
  if Rslt <> 0 then
    raise Exception.CreateFmt('Can''t close mixer (%d)', [Rslt]);
end;

[浏览: 次]   
上一篇:delphi 音乐播放器扬声器类   下一篇:delphi 音乐播放器信号显示组件
[收藏] [推荐] [返回顶部] [打印本页] [关闭窗口]  
    评论加载中…
google adsense热点文章
·delphi 播放wav文件
·delphi 设置声卡音量
·delphi 多媒体wave文件写盘
·delphi 多媒体音量调节
·delphi 如何将.wav多媒体文件加载到可
·delphi 多媒体wave文件CD音频
·delphi 分析多媒体波频文件
·delphi 音乐播放器信号显示组件
·delphi 音乐播放器扬声器类
·delphi 如何处理wave多媒体文件的split
·delphi 如何处理扩展名为.avi的audio流
     delphi技术网 | firefox 下载 | Avant Browser下载 | dedecms 技术网 | drupal 爱好者 | php 技术网
  Copyright@www.delphichm.com,2006-2009.All Rights Reserved.
 
程序员联盟 | delphi Java .net|QQ:707102932