我是想实时获得MP3音乐的振幅(声强)
unit Unit1;interfaceuses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ComCtrls, mmsystem, ExtCtrls;type
  TForm1 = class(TForm)
    pb1: TProgressBar;
    tmr1: TTimer;
    procedure tmr1Timer(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    Function GetVolume:Integer;
  end;var
  Form1: TForm1;
  rc: MMRESULT ;              // Return code.
  hMixer: PHMIXER ;            // Mixer handle used in mixer API calls.
  mxc: PMIXERCONTROL ;         // Holds the mixer control data.
  mxl: PMIXERLINE ;            // Holds the mixer line data.
  mxlc: PMIXERLINECONTROLS ;   // Obtains the mixer control.
implementation{$R *.dfm}
procedure testpeakmeter;begin
    // Open the mixer. This opens the mixer with a deviceID of 0. If you
    // have a single sound card/mixer, then this will open it. If you have
    // multiple sound cards/mixers, the deviceIDs will be 0, 1, 2, and
    // so on.
    rc := mixerOpen(hMixer, 0,0,0,0);
    if MMSYSERR_NOERROR <> rc then begin
       showmessage('Couldn t open the mixer.')
    end;    // Initialize MIXERLINE structure.
    ZeroMemory(mxl,sizeof(mxl));
    mxl.cbStruct := sizeof(mxl);    // Specify the line you want to get. You are getting the input line
    // here. If you want to get the output line, you need to use
    // MIXERLINE_COMPONENTTYPE_SRC_WAVEOUT.
    mxl.dwComponentType := MIXERLINE_COMPONENTTYPE_DST_WAVEIN;    rc := mixerGetLineInfo(HMIXEROBJ(hMixer), mxl,
                           MIXER_GETLINEINFOF_COMPONENTTYPE);
    if (MMSYSERR_NOERROR = rc) then begin
        showmessage( 'Couldn t get the mixer line.');
        exit
    end;
    // Get the control.
    ZeroMemory(mxlc, sizeof(mxlc));
    mxlc.cbStruct := sizeof(mxlc);
    mxlc.dwLineID := mxl.dwLineID;
    mxlc.dwControlType := MIXERCONTROL_CONTROLTYPE_PEAKMETER;
    mxlc.cControls := 1;
    mxlc.cbmxctrl := sizeof(mxc);
    mxlc.pamxctrl := mxc;
    ZeroMemory(mxc, sizeof(mxc));
    mxc.cbStruct := sizeof(mxc);
    rc := mixerGetLineControls(HMIXEROBJ(hMixer),mxlc,
                               MIXER_GETLINECONTROLSF_ONEBYTYPE);
    if (MMSYSERR_NOERROR <> rc) then begin
       showmessage('Couldn t get the control.')
    end;
end;Function TForm1.GetVolume:Integer;
var
  mxcd:PMIXERCONTROLDETAILS;             // Gets the control values.
  volStruct:^MIXERCONTROLDETAILS_SIGNED ; // Gets the control values.
  volume:integer ;                          // Holds the final volume value.begin    // After successfully getting the peakmeter control, the volume range
    // will be specified by mxc.Bounds.lMinimum to mxc.Bounds.lMaximum.    // Initialize the MIXERCONTROLDETAILS structure
    ZeroMemory(mxcd, sizeof(mxcd));
    mxcd.cbStruct := sizeof(mxcd);
    mxcd.cbDetails := sizeof(volStruct);
    mxcd.dwControlID := mxc.dwControlID;
    mxcd.paDetails := volStruct;
    mxcd.cChannels := 1;    // Get the current value of the peakmeter control. Typically, you
    // would set a timer in your program to query the volume every 10th
    // of a second or so.
    rc := mixerGetControlDetails(HMIXEROBJ(hMixer), mxcd,
                                 MIXER_GETCONTROLDETAILSF_VALUE);
    if (MMSYSERR_NOERROR = rc) then begin
        showmessage(' Couldn t get the current volume.')
    end;
    volume := volStruct.lValue;    // Get the absolute value of the volume.
    if (volume < 0) then
        volume := -volume;
    result:=volume;
end;
procedure TForm1.tmr1Timer(Sender: TObject);
begin
   testpeakmeter;
   pb1.Position:=GetVolume;
end;end.

解决方案 »

  1.   

    ZeroMemory(mxlc, sizeof(mxlc));
    ZeroMemory(mxcd, sizeof(mxcd));
    这两处大家可以把这段代码直接粘贴到一个单元调试.
    在窗体上放timer控件,命名为tmr1 
    progressbar 命名为pb1
      

  2.   

    mxcd你把它设置为全局变量
    mxlc上面的exit加个';'
      

  3.   

    不会吧 海龙兄弟 begin end 语句断的最后一个语句可以不加‘;’都不知道啊
    另外应该跟mxcd是不是全局变量没多大的关系
      

  4.   

    mmtools非常好,基本不用写什么代码
    用WaveInOpen或WaveOutOpen API函数也可以