{相关结构:} TDSFXFlanger = packed recordfWetDryMix: Single; // 0 .. 100 : 50 (%)fDepth: Single; // 0 .. 100 : 100 (%)fFeedback: Single; //-99 .. 99 : -50 (%)fFrequency: Single; // 0 .. 10 : 0.25lWaveform: Longint; // 0 .. 1 : 1fDelay: Single; // 0 .. 4 : 2 (ms)lPhase: Longint; // 0 .. 4 : 2 end;//该结构相关常量: DSFXFLANGER_WETDRYMIX_MIN = 0.0; DSFXFLANGER_WETDRYMIX_MAX = 100.0;DSFXFLANGER_DEPTH_MIN = 0.0; DSFXFLANGER_DEPTH_MAX = 100.0;DSFXFLANGER_FEEDBACK_MIN = -99.0; DSFXFLANGER_FEEDBACK_MAX = 99.0;DSFXFLANGER_FREQUENCY_MIN = 0.0; DSFXFLANGER_FREQUENCY_MAX = 10.0;DSFXFLANGER_WAVE_TRIANGLE = 0; DSFXFLANGER_WAVE_SIN = 1;DSFXFLANGER_PHASE_MIN = 0; DSFXFLANGER_PHASE_MAX = 4;DSFXFLANGER_DELAY_MIN = 0.0; DSFXFLANGER_DELAY_MAX = 4.0;DSFXFLANGER_PHASE_NEG_180 = 0; DSFXFLANGER_PHASE_NEG_90 = 1; DSFXFLANGER_PHASE_ZERO = 2; DSFXFLANGER_PHASE_90 = 3; DSFXFLANGER_PHASE_180 = 4;
测试代码:
unit Unit1;interfaceusesWindows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,Dialogs, StdCtrls, ExtCtrls;typeTForm1 = class(TForm)Button1: TButton;Button2: TButton;LabeledEdit1: TLabeledEdit;LabeledEdit2: TLabeledEdit;LabeledEdit3: TLabeledEdit;LabeledEdit4: TLabeledEdit;LabeledEdit5: TLabeledEdit;RadioGroup1: TRadioGroup;RadioGroup2: TRadioGroup;procedure FormCreate(Sender: TObject);procedure Button1Click(Sender: TObject);procedure Button2Click(Sender: TObject);procedure RadioGroup1Click(Sender: TObject);procedure LabeledEdit1Change(Sender: TObject);procedure FormDestroy(Sender: TObject);end;varForm1: TForm1;implementation{$R *.dfm}uses DirectSound, ReadWave2;varmyDSound: IDirectSound8;buf8: IDirectSoundBuffer8;fxFlanger: IDirectSoundFXFlanger8; //IDirectSoundFXFlanger8 效果器procedure TForm1.FormCreate(Sender: TObject); beginSystem.ReportMemoryLeaksOnShutdown := True;DirectSoundCreate8(nil, myDSound, nil);myDSound.SetCooperativeLevel(Handle, DSSCL_NORMAL);Button1.Caption := '打开并播放';Button2.Caption := '停止播放';LabeledEdit1.EditLabel.Caption := 'fWetDryMix: 0.0 - 100.0';LabeledEdit1.Text := '50.0';LabeledEdit1.Tag := 1;LabeledEdit2.EditLabel.Caption := 'fDepth: 0.0 - 100.0';LabeledEdit2.Text := '100.0';LabeledEdit2.Tag := 2;LabeledEdit3.EditLabel.Caption := 'fFeedback: -99.0 - 99.0';LabeledEdit3.Text := '-50.0';LabeledEdit3.Tag := 3;LabeledEdit4.EditLabel.Caption := 'fFrequency: 0.0 - 10.0';LabeledEdit4.Text := '1.0';LabeledEdit4.Tag := 4;LabeledEdit5.EditLabel.Caption := 'ffDelay: 0.0 - 4.0';LabeledEdit5.Text := '2.0';LabeledEdit5.Tag := 5;RadioGroup1.Caption := 'lWaveform:';RadioGroup1.Items.CommaText := 'WAVE_TRIANGLE, WAVE_SIN';RadioGroup1.ItemIndex := 1;RadioGroup2.Caption := 'lPhase:';RadioGroup2.Items.CommaText := '-180,-90,0,90,180';RadioGroup2.ItemIndex := 2;LabeledEdit2.OnChange := LabeledEdit1.OnChange;LabeledEdit3.OnChange := LabeledEdit1.OnChange;LabeledEdit4.OnChange := LabeledEdit1.OnChange;LabeledEdit5.OnChange := LabeledEdit1.OnChange;RadioGroup2.OnClick := RadioGroup1.OnClick; end;procedure TForm1.Button1Click(Sender: TObject); varbuf: IDirectSoundBuffer;bufDesc: TDSBufferDesc;rEffect: TDSEffectDesc;wav: TReadWave;p1: Pointer;n1: DWORD; beginwav := TReadWave.Create;if not wav.OpenDialog then begin wav.Free; Exit; end;ZeroMemory(@bufDesc, SizeOf(TDSBufferDesc));bufDesc.dwSize := SizeOf(TDSBufferDesc);bufDesc.dwFlags := DSBCAPS_CTRLFX;bufDesc.dwBufferBytes := wav.Size;bufDesc.lpwfxFormat := @wav.Format;myDSound.CreateSoundBuffer(bufDesc, buf, nil);buf.QueryInterface(IID_IDirectSoundBuffer8, buf8);buf8.Lock(0, 0, @p1, @n1, nil, nil, DSBLOCK_ENTIREBUFFER);wav.Read(p1, n1);wav.Free;buf8.Unlock(p1, n1, nil, 0);ZeroMemory(@rEffect, SizeOf(TDSEffectDesc));rEffect.dwSize := SizeOf(TDSEffectDesc);rEffect.dwFlags := 0;rEffect.guidDSFXClass := GUID_DSFX_STANDARD_FLANGER;buf8.SetFX(1, @rEffect, nil);buf8.GetObjectInPath(GUID_DSFX_STANDARD_FLANGER, 0, IID_IDirectSoundFXFlanger8, fxFlanger);buf8.Play(0, 0, DSBPLAY_LOOPING); end;procedure TForm1.Button2Click(Sender: TObject); beginif Assigned(buf8) then buf8.Stop; end;procedure TForm1.RadioGroup1Click(Sender: TObject); varrFlanger: TDSFXFlanger; beginif buf8 = nil then Exit;rFlanger.fWetDryMix := StrToFloat(LabeledEdit1.Text);rFlanger.fDepth := StrToFloat(LabeledEdit2.Text);rFlanger.fFeedback := StrToFloat(LabeledEdit3.Text);rFlanger.fFrequency := StrToFloat(LabeledEdit4.Text);rFlanger.lWaveform := RadioGroup1.ItemIndex;rFlanger.fDelay := StrToFloat(LabeledEdit5.Text);rFlanger.lPhase := RadioGroup2.ItemIndex;fxFlanger.SetAllParameters(rFlanger); end;procedure TForm1.LabeledEdit1Change(Sender: TObject); varf: Single;obj: TLabeledEdit; beginobj := Sender as TLabeledEdit;if obj.Text = '-' then Exit;f := StrToFloatDef(obj.Text, MaxInt);case obj.Tag of1: if (f < 0) or (f > 100) then obj.Text := '50.0';2: if (f < 0) or (f > 100) then obj.Text := '100.0';3: if (f < -99) or (f > 99) then obj.Text := '-50.0';4: if (f < 0) or (f > 10) then obj.Text := '0.25';5: if (f < 0) or (f > 20) then obj.Text := '2';end;RadioGroup1.OnClick(nil); end;procedure TForm1.FormDestroy(Sender: TObject); beginbuf8 := nil;myDSound := nil; end;end.
窗体设计:
object Form1: TForm1Left = 0Top = 0Caption = 'Form1'ClientHeight = 287ClientWidth = 314Color = clBtnFaceFont.Charset = DEFAULT_CHARSETFont.Color = clWindowTextFont.Height = -11Font.Name = 'Tahoma'Font.Style = []OldCreateOrder = FalseOnCreate = FormCreateOnDestroy = FormDestroyPixelsPerInch = 96TextHeight = 13object Button1: TButtonLeft = 24Top = 18Width = 75Height = 25Caption = 'Button1'TabOrder = 0OnClick = Button1Clickendobject Button2: TButtonLeft = 120Top = 18Width = 75Height = 25Caption = 'Button2'TabOrder = 1OnClick = Button2Clickendobject LabeledEdit1: TLabeledEditLeft = 24Top = 72Width = 138Height = 21EditLabel.Width = 61EditLabel.Height = 13EditLabel.Caption = 'LabeledEdit1'TabOrder = 2OnChange = LabeledEdit1Changeendobject LabeledEdit2: TLabeledEditLeft = 24Top = 115Width = 138Height = 21EditLabel.Width = 61EditLabel.Height = 13EditLabel.Caption = 'LabeledEdit2'TabOrder = 3endobject LabeledEdit3: TLabeledEditLeft = 24Top = 160Width = 138Height = 21EditLabel.Width = 61EditLabel.Height = 13EditLabel.Caption = 'LabeledEdit3'TabOrder = 4endobject LabeledEdit4: TLabeledEditLeft = 24Top = 208Width = 138Height = 21EditLabel.Width = 61EditLabel.Height = 13EditLabel.Caption = 'LabeledEdit4'TabOrder = 5endobject LabeledEdit5: TLabeledEditLeft = 24Top = 253Width = 138Height = 21EditLabel.Width = 61EditLabel.Height = 13EditLabel.Caption = 'LabeledEdit5'TabOrder = 6endobject RadioGroup1: TRadioGroupLeft = 177Top = 56Width = 129Height = 64Caption = 'RadioGroup1'TabOrder = 7OnClick = RadioGroup1Clickendobject RadioGroup2: TRadioGroupLeft = 176Top = 136Width = 129Height = 138Caption = 'RadioGroup2'TabOrder = 8end end
运行效果图: