MMSlow.pas
上传用户:hylc_2004
上传日期:2014-01-23
资源大小:46800k
文件大小:7k
- {========================================================================}
- {= (c) 1995-98 SwiftSoft Ronald Dittrich =}
- {========================================================================}
- {= All Rights Reserved =}
- {========================================================================}
- {= D 01099 Dresden = Tel.: +0351-8012255 =}
- {= Loewenstr.7a = info@swiftsoft.de =}
- {========================================================================}
- {= Actual versions on http://www.swiftsoft.de/mmtools.html =}
- {========================================================================}
- {= This code is for reference purposes only and may not be copied or =}
- {= distributed in any format electronic or otherwise except one copy =}
- {= for backup purposes. =}
- {= =}
- {= No Delphi Component Kit or Component individually or in a collection=}
- {= subclassed or otherwise from the code in this unit, or associated =}
- {= .pas, .dfm, .dcu, .asm or .obj files may be sold or distributed =}
- {= without express permission from SwiftSoft. =}
- {= =}
- {= For more licence informations please refer to the associated =}
- {= HelpFile. =}
- {========================================================================}
- {= $Date: 20.01.1998 - 18:00:00 $ =}
- {========================================================================}
- unit MMSLow;
- {$I COMPILER.INC}
- interface
- uses
- {$IFDEF WIN32}
- Windows,
- {$ELSE}
- WinTypes,
- WinProcs,
- {$ENDIF}
- SysUtils,
- Classes,
- Controls,
- MMSystem,
- MMRegs,
- MMObj,
- MMDSPObj,
- MMUtils,
- MMPCMSup,
- MMFX;
- type
- EMMSimpleLowPassError = class(Exception);
- TMMFilterType = (ftNone,ftSoftLowPass,ftLowPass);
- {-- TMMSimpleLowPass -------------------------------------------------}
- TMMSimpleLowPass = class(TMMDSPComponent)
- private
- FEnabled : Boolean;
- FOpen : Boolean;
- FPFilter : PSimpleFilter;
- FFilterType: TMMFilterType;
- procedure SetEnabled(aValue: Boolean);
- procedure SetFilterType(aValue: TMMFilterType);
- protected
- procedure SetPWaveFormat(aValue: PWaveFormatEx); override;
- procedure Update; virtual;
- procedure Opened; override;
- procedure Closed; override;
- procedure Started; override;
- procedure BufferReady(lpwh: PWaveHdr); override;
- procedure BufferLoad(lpwh: PWaveHdr; var MoreBuffers: Boolean); override;
- public
- constructor Create(aOwner: TComponent); override;
- destructor Destroy; override;
- procedure Open;
- procedure Close;
- procedure Process(Buffer: PChar; Length: integer);
- published
- property Input;
- property Output;
- property Enabled: Boolean read FEnabled write SetEnabled default True;
- property FilterType: TMMFilterType read FFilterType write SetFilterType default ftNone;
- end;
- implementation
- {== TMMSimpleLowPass ====================================================}
- constructor TMMSimpleLowPass.Create(aOwner: TComponent);
- begin
- inherited Create(aOwner);
- FEnabled := True;
- FOpen := False;
- FPFilter := nil;
- FFilterType := ftNone;
- end;
- {-- TMMSimpleLowPass ----------------------------------------------------}
- destructor TMMSimpleLowPass.Destroy;
- begin
- Close;
- inherited Destroy;
- end;
- {-- TMMSimpleLowPass ----------------------------------------------------}
- procedure TMMSimpleLowPass.SetEnabled(aValue: Boolean);
- begin
- if (aValue <> FEnabled) then
- begin
- FEnabled := aValue;
- if FEnabled then Update;
- end;
- end;
- {-- TMMSimpleLowPass ----------------------------------------------------}
- procedure TMMSimpleLowPass.SetFilterType(aValue: TMMFilterType);
- begin
- if (aValue <> FFilterType) then
- begin
- FFilterType := aValue;
- Update;
- end;
- end;
- {-- TMMSimpleLowPass ----------------------------------------------------}
- procedure TMMSimpleLowPass.SetPWaveFormat(aValue: PWaveFormatEx);
- begin
- if (aValue <> nil) then
- begin
- if not (csDesigning in ComponentState) then
- if not pcmIsValidFormat(aValue) then
- raise EMMSimpleLowPassError.Create(LoadResStr(IDS_INVALIDFORMAT));
- end;
- inherited SetPWaveFormat(aValue);
- end;
- {-- TMMSimpleLowPass ----------------------------------------------------}
- procedure TMMSimpleLowPass.Open;
- begin
- if not FOpen then
- begin
- if pcmIsValidFormat(PWaveFormat) then
- begin
- FPFilter := InitSimpleLowPass(PWaveFormat);
- if (FPFilter = nil) then OutOfMemoryError
- else
- begin
- FOpen := True;
- Update;
- end;
- end;
- end;
- end;
- {-- TMMSimpleLowPass ----------------------------------------------------}
- procedure TMMSimpleLowPass.Close;
- begin
- if FOpen then
- begin
- FOpen := False;
- DoneSimpleLowPass(FPFilter);
- end;
- end;
- {-- TMMSimpleLowPass ----------------------------------------------------}
- procedure TMMSimpleLowPass.Process(Buffer: PChar; Length: integer);
- begin
- { process the buffer trough the filter }
- if (FPFilter <> nil) then DoSimpleLowPass(FPFilter, Buffer, Length);
- end;
- {-- TMMSimpleLowPass ----------------------------------------------------}
- procedure TMMSimpleLowPass.Update;
- begin
- { setup the filter with the params }
- if FOpen then
- begin
- SetSimpleLowPass(FPFilter, Ord(FFilterType));
- end;
- end;
- {-- TMMSimpleLowPass ----------------------------------------------------}
- procedure TMMSimpleLowPass.Opened;
- begin
- Open;
- inherited Opened;
- end;
- {-- TMMSimpleLowPass ----------------------------------------------------}
- procedure TMMSimpleLowPass.Closed;
- begin
- Close;
- inherited Closed;
- end;
- {-- TMMSimpleLowPass ----------------------------------------------------}
- procedure TMMSimpleLowPass.Started;
- begin
- Update;
- inherited Started;
- end;
- {-- TMMSimpleLowPass ----------------------------------------------------}
- procedure TMMSimpleLowPass.BufferReady(lpwh: PWaveHdr);
- begin
- if Enabled and FOpen then
- begin
- Process(lpwh^.lpData, lpwh^.dwBytesRecorded);
- end;
- inherited BufferReady(lpwh);
- end;
- {-- TMMSimpleLowPass ----------------------------------------------------}
- procedure TMMSimpleLowPass.BufferLoad(lpwh: PWaveHdr; var MoreBuffers: Boolean);
- begin
- inherited BufferLoad(lpwh, MoreBuffers);
- if Enabled and FOpen then
- begin
- Process(lpwh^.lpData, lpwh^.dwBytesRecorded);
- end;
- end;
- end.