home *** CD-ROM | disk | FTP | other *** search
- unit DDXDemo;
-
- {
- This unit implements a DirectX plugin (also known as DirectShow filter)
- in Delphi.
- This unit will be the main unit exported by our dll, and must use
- the DelDXBase unit.
- The associated C++ dll
- }
-
- interface
-
- uses
- Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
- StdCtrls, ComCtrls,
- DDXBase;
-
- const
- {*** change the name, short description and optional help file}
- EffectName = 'DDXDemo';
- EffectDesc = 'DDX Demo';
- EffectHelpFile = 'ddxddemo.htm'; {doesn't really matter if there isn't one}
-
- {*** change the name of the properties class}
- PropertiesName = 'DDXDemo_Settings';
-
- {*** IT IS CRUCIAL that each new project has NEW, FRESH GUIDS!!! }
- {*** DO NOT USE THESE ONES!!!}
- {*** Use the NewGUIDs utility to generate them }
- EffectGUID = '{EFD5F1C0-51AF-11D5-A607-444553540000}';
- PropertiesGUID = '{EFD5F1C1-51AF-11D5-A607-444553540000}';
-
-
- type
-
- { this form is the editor form for the plugin }
- TDDXDemoForm = class(TForm)
- TrackBar1: TTrackBar;
- Label1: TLabel;
- TrackBar2: TTrackBar;
- Label2: TLabel;
- procedure TrackBar1Change(Sender: TObject);
- procedure TrackBar2Change(Sender: TObject);
- private
- { Private declarations }
- fPlugin : TDelphiDirectXPluginBase;
- public
- { Public declarations }
- property Plugin : TDelphiDirectXPluginBase read fPlugin;
- end;
-
- { This is the actual effect class, which should be
- descended from TDelphiDirectXPluginBase }
- TMyDelphiDirectXPlugin = class (TDelphiDirectXPluginBase)
- public
- constructor create; override;
- { the reasons for overriding create:
- (a) to enforce the number of parameters (zero)
- (b) to allow you to specify the channel modes
- and sample types you are prepared to support.
- (c) and of course, you need to specify default
- starting up values for your effect's parameters
- (d) and allocate any buffers / working variables etc. }
-
- destructor destroy; override;
- { you'd override this to destroy any buffers ou allocated in create }
-
- procedure CompleteConnectEditor; override;
- { This gets called after WE have been connected to the editor form.
- But the editor form is not yet connected to US.
- So we override this to make our editor form aware of the effect. }
-
- procedure DisplaySetParameter (
- aParamNum : integer;
- aValue : single); override;
- { This gets called after the system has modified one of the parameters,
- and we override it so that we can update the associated control
- on our editor form. }
-
- function Transform (
- aInBuffer : pointer;
- aInSamples : integer;
- aOutBuffer : pointer;
- aOutSamples: integer;
- aProcessed : pInteger)
- : integer; override;
- { THis is where the audio work gets done }
-
- {here is a really cool way to access parameters from the array by name}
- property Volume : single index 0 read GetParam write SetParam;
- property Pan : single index 1 read GetParam write SetParam;
- end;
-
-
- const
- {*** You must define a class reference constant to your plugin class: }
- DelphiPluginClass : TDelphiPluginClassRef = TMyDelphiDirectXPlugin;
- DelphiEditorFormClass : TDelphiEditorFormClassRef = TDDXDemoForm;
-
- var
- DDXDemoForm: TDDXDemoForm;
-
- implementation
-
- {$R *.DFM}
-
-
- constructor TMyDelphiDirectXPlugin.create;
- begin
- inherited create;
- ChannelModes := [cmMonoToMono, cmMonoToStereo, cmStereoToStereo];
-
- SampleTypes := [stFloat32, stInteger16];
-
- Volume := 0.7;
- Pan := 0.5;
- end;
-
- destructor TMyDelphiDirectXPlugin.destroy;
- begin
- inherited destroy;
- end;
-
- procedure TMyDelphiDirectXPlugin.CompleteConnectEditor;
- begin
- inherited CompleteConnectEditor;
- TDDXDemoForm(fEditorForm).fPlugin := self;
- TDDXDemoForm(fEditorForm).TrackBar1.position := round (10 * Volume);
- TDDXDemoForm(fEditorForm).TrackBar2.position := round (10 * Pan);
- end;
-
- procedure TMyDelphiDirectXPlugin.DisplaySetParameter (
- aParamNum : integer;
- aValue : single);
- begin
- case aParamNum of
- 0 : TDDXDemoForm(fEditorForm).TrackBar1.position := round (10 * Volume);
- 1 : TDDXDemoForm(fEditorForm).TrackBar2.position := round (10 * Pan);
- {for as many parameters as you are have, up to a max of 15}
- end;
- end;
-
-
- function TMyDelphiDirectXPlugin.Transform (
- aInBuffer : pointer;
- aInSamples : integer;
- aOutBuffer : pointer;
- aOutSamples: integer;
- aProcessed : pInteger)
- : integer;
- var
- inbufstep : ^single;
- outbufstep : ^single;
-
- inbufstepI : ^smallint;
- outbufstepI: ^smallint;
-
- sctr : integer;
- value : single;
-
- doPan : boolean;
- begin
- { mono-mono, stereo-stereo: aProcessed is the same as aInSamples
- mono-stereo: aProcessed is 2 * aInSamples }
- aProcessed^ := aInSamples * OutputChannels div InputChannels;
-
- result := 0;
- inbufstep := aInBuffer;
- outbufstep := aOutBuffer;
- inbufstepI := aInBuffer;
- outbufstepI:= aOutBuffer;
-
- doPan := OutputChannels = 2;
-
- sctr := aInSamples;
-
- while sctr > 0 do begin
-
- if SampleType = stFloat32 then begin
- value := Volume * inbufstep^;
- if DoPan
- then outbufstep^ := (1-pan) * value
- else outbufstep^ := value;
- inc (inbufstep); inc (outbufstep);
- end else begin
- value := Volume * inbufstepI^;
- if DoPan
- then outbufstep^ := round ((1-pan) * value)
- else outbufstep^ := round (value);
- inc (inbufstepI); inc (outbufstepI);
- end;
- dec (sctr);
-
- if InputChannels = 2 then begin
- if SampleType = stFloat32 then begin
- value := Volume * inbufstep^;
- inc (inbufstep);
- end else begin
- value := Volume * inbufstepI^;
- inc (inbufstepI);
- end;
- {we do NOT dec the counter again - nSamples is number or mono OR stereo samples}
- end;
-
- if OutputChannels = 2 then begin
- if SampleType = stFloat32 then begin
- outbufstep^ := pan * value;
- inc (outbufstep);
- end else begin
- outbufstepI^ := round (pan * value);
- inc (outbufstepI);
- end;
- end;
-
- end;
- end;
-
- procedure TDDXDemoForm.TrackBar1Change(Sender: TObject);
- begin
- TMyDelphiDirectXPlugin (fPlugin).Volume := TrackBar1.position / 10;
- end;
-
-
- procedure TDDXDemoForm.TrackBar2Change(Sender: TObject);
- begin
- TMyDelphiDirectXPlugin (fPlugin).Pan := TrackBar2.position / 10;
- end;
-
- function GetClsNam (aWindow : HWND) : string;
- var buff : array [0..127] of char;
- begin
- GetClassName(aWindow, buff, 127);
- result := StrPas (buff);
- end;
- function RectToStr(aRect : trect) : string;
- begin
- result :=
- inttostr (aRect.left) + ',' +
- inttostr (aRect.top) + ',' +
- inttostr (aRect.right) + ',' +
- inttostr (aRect.bottom);
- end;
-
- initialization
- { you MUST call this to load some global variables
- used by the procedural dll interface }
- RegisterEffect (
- EffectName,
- EffectDesc,
- EffectHelpFile,
- PropertiesName,
- EffectGUID,
- PropertiesGUID,
- DelphiPluginClass,
- DelphiEditorFormClass);
- end.
-
-