MMConect.pas
上传用户:hylc_2004
上传日期:2014-01-23
资源大小:46800k
文件大小:53k
- {========================================================================}
- {= (c) 1995-98 SwiftSoft Ronald Dittrich =}
- {========================================================================}
- {= All Rights Reserved =}
- {========================================================================}
- {= D 01099 Dresden = Fax.: +49(0)351-8037944 =}
- {= Loewenstr.7a = info@swiftsoft.de =}
- {========================================================================}
- {= Actual versions on http://www.swiftsoft.de/index.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: 05.10.98 - 17:53:10 $ =}
- {========================================================================}
- unit MMConect;
- {$I COMPILER.INC}
- {.$DEFINE _MMDEBUG}
- {$C FIXED PRELOAD PERMANENT}
- interface
- uses
- {$IFDEF WIN32}
- Windows,
- {$ELSE}
- WinTypes,
- WinProcs,
- {$ENDIF}
- SysUtils,
- Messages,
- Classes,
- Controls,
- Forms,
- MMSystem,
- MMObj,
- MMDSPObj,
- MMTimer,
- MMUtils,
- MMString,
- MMMulDiv,
- MMRegs,
- MMPCMSup,
- MMWaveIO,
- MMLevel,
- {$IFNDEF LEVEL_ONLY}
- MMMeter,
- MMOscope,
- MMSpectr,
- MMSpGram,
- MMLight,
- {$ENDIF}
- MMACMSup
- {$IFDEF _MMDEBUG}
- ,MMDebug
- {$ENDIF};
- const
- { set this to true if you have problems with hints or flat buttons }
- ENTER_IDLE_MODE : Boolean = False;
- {$IFDEF CBUILDER3} {$EXTERNALSYM MAXSPEED} {$ENDIF}
- MAXSPEED = 5000;
- type
- TMMTriggerMode = (tmNone, tmUpFlank, tmDownFlank);
- EMMConnectorError = class(Exception);
- {-- TMMConnector ------------------------------------------------------}
- TMMConnector = class(TMMDSPComponent)
- private
- {$IFDEF WIN32}
- FDataSection : TRtlCriticalSection;
- {$ENDIF}
- FTimerID : integer;
- FEnabled : Boolean;
- FRestoreIdle : Boolean;
- FAutoTrigger : Boolean;
- FTriggerMode : TMMTriggerMode;
- FTriggerLevel : integer;
- FSynchronize : Boolean;
- FSilence : integer;
- FStarted : Boolean;
- FRunning : Boolean;
- FPaused : Boolean;
- FConvert : PACMConvert;
- FDstWaveFormat : PWaveFormatEx;
- FDstBufferSize : Longint;
- FRealBufferSize: Longint;
- FSrcData : PChar;
- FDstData : PChar;
- FAutoConvert : Boolean;
- FIsPCMFormat : Boolean;
- FCanConvert : Boolean;
- FSpeed : integer;
- FRefresh : Boolean;
- FInHandler : integer;
- FRealTime : Boolean;
- FLevel1 : TMMLevel;
- FLevel2 : TMMLevel;
- {$IFNDEF LEVEL_ONLY}
- FMeter1 : TMMMeter;
- FMeter2 : TMMMeter;
- FOscope1 : TMMOscope;
- FOscope2 : TMMOscope;
- FLight1 : TMMLight;
- FLight2 : TMMLight;
- FSpectrum1 : TMMSpectrum;
- FSpectrum2 : TMMSpectrum;
- FSpectrum3 : TMMSpectrum;
- FSpectrum4 : TMMSpectrum;
- FSpectrogram1 : TMMSpectrogram;
- FSpectrogram2 : TMMSpectrogram;
- {$ENDIF}
- FIndexLevel : Longint;
- {$IFNDEF LEVEL_ONLY}
- FIndexMeter : Longint;
- FIndexScope : Longint;
- FIndexLight : Longint;
- FIndexSpectrum : Longint;
- FIndexSpectrogram1 : Longint;
- FIndexSpectrogram2 : Longint;
- {$ENDIF}
- FRefreshLevel : Boolean;
- {$IFNDEF LEVEL_ONLY}
- FRefreshMeter : Boolean;
- FRefreshScope : Boolean;
- FRefreshLight : Boolean;
- FRefreshSpectrum : Boolean;
- FRefreshSpectrogram: Boolean;
- {$ENDIF}
- FLevelRefresh : Longint;
- {$IFNDEF LEVEL_ONLY}
- FMeterRefresh : Longint;
- FOscopeRefresh : Longint;
- FLightRefresh : Longint;
- FSpectrumRefresh : Longint;
- FSpectrogramRefresh: Longint;
- {$ENDIF}
- FBufTime : Int64;
- FStepTime : Int64;
- FOnTrigger : TNotifyEvent;
- procedure SetEnabled(aValue: Boolean);
- procedure SetAutoTrigger(aValue: Boolean);
- procedure SetSpeed(aValue: integer);
- procedure SetTriggerMode(aValue: TMMTriggerMode);
- procedure SetTriggerLevel(aValue: integer);
- procedure SetRealTime(aValue: Boolean);
- procedure SetLevel(index: integer; aValue: TMMLevel);
- {$IFNDEF LEVEL_ONLY}
- procedure SetMeter(index: integer; aValue: TMMMeter);
- procedure SetOscope(index: integer; aValue: TMMOscope);
- procedure SetLight(index: integer; aValue: TMMLight);
- procedure SetSpectrum(index: integer; aValue: TMMSpectrum);
- procedure SetSpectrogram(index: integer; aValue: TMMSpectrogram);
- {$ENDIF}
- procedure SetEnterIdle(aValue: Boolean);
- function GetEnterIdle: Boolean;
- procedure SetWaveParams;
- procedure ProcessData;
- procedure UpdateTimer(Enabled: Boolean);
- protected
- procedure ChangeDesigning(aValue: Boolean); override;
- procedure Notification(AComponent: TComponent; Operation: TOperation); override;
- procedure SetPWaveFormat(aValue: PWaveFormatEx); override;
- procedure Started; override;
- procedure Paused; override;
- procedure Restarted; override;
- procedure Stopped; override;
- procedure Reseting; override;
- procedure BufferReady(lpwh: PWaveHdr); override;
- procedure BufferLoad(lpwh: PWaveHdr; var MoreBuffers: Boolean); override;
- public
- constructor Create(AOwner: TComponent); override;
- destructor Destroy; override;
- procedure NewBuffer(lpData: PChar; dwLength: DWORD); virtual;
- property IsPaused: Boolean read FPaused;
- property IsStarted: Boolean read FStarted;
-
- procedure Trigger; virtual;
- property RefreshCountLevel: Longint read FLevelRefresh write FLevelRefresh;
- {$IFNDEF LEVEL_ONLY}
- property RefreshCountMeter: Longint read FMeterRefresh write FMeterRefresh;
- property RefreshCountOscope: Longint read FOscopeRefresh write FOscopeRefresh;
- property RefreshCountLight: Longint read FLightRefresh write FLightRefresh;
- property RefreshCountSpectrum: Longint read FSpectrumRefresh write FSpectrumRefresh;
- property RefreshCountSpectrogram: Longint read FSpectrogramRefresh write FSpectrogramRefresh;
- {$ENDIF}
- procedure GetPeak(var PeakL, PeakR: Smallint);
- published
- property OnTrigger: TNotifyEvent read FOnTrigger write FOnTrigger;
- property Enabled: Boolean read FEnabled write SetEnabled default True;
- property AutoConvert: Boolean read FAutoConvert write FAutoConvert default True;
- property AutoTrigger: Boolean read FAutoTrigger write SetAutoTrigger default True;
- property Synchronize: Boolean read FSynchronize write FSynchronize default True;
- property Speed: integer read FSpeed write SetSpeed default MAXSPEED;
- property TriggerMode: TMMTriggerMode read FTriggerMode write SetTriggerMode default tmNone;
- property TriggerLevel: integer read FTriggerLevel write SetTriggerLevel default 0;
- property RefreshOnStop: Boolean read FRefresh write FRefresh default True;
- property RealTime: Boolean read FRealTime write SetRealTime default True;
- property EnterIdle: Boolean read GetEnterIdle write SetEnterIdle;
- property Input;
- property Output;
- property Level1: TMMLevel index 0 read FLevel1 write SetLevel;
- property Level2: TMMLevel index 1 read FLevel2 write SetLevel;
- {$IFNDEF LEVEL_ONLY}
- property Meter1: TMMMeter index 0 read FMeter1 write SetMeter;
- property Meter2: TMMMeter index 1 read FMeter2 write SetMeter;
- property Oscope1: TMMOscope index 0 read FOscope1 write SetOscope;
- property Oscope2: TMMOscope index 1 read FOscope2 write SetOscope;
- property Light1: TMMLight index 0 read FLight1 write SetLight;
- property Light2: TMMLight index 1 read FLight2 write SetLight;
- property Spectrum1: TMMSpectrum index 0 read FSpectrum1 write SetSpectrum;
- property Spectrum2: TMMSpectrum index 1 read FSpectrum2 write SetSpectrum;
- property Spectrum3: TMMSpectrum index 2 read FSpectrum3 write SetSpectrum;
- property Spectrum4: TMMSpectrum index 3 read FSpectrum4 write SetSpectrum;
- property Spectrogram1: TMMSpectrogram index 0 read FSpectrogram1 write SetSpectrogram;
- property Spectrogram2: TMMSpectrogram index 1 read FSpectrogram2 write SetSpectrogram;
- {$ENDIF}
- end;
- implementation
- uses Consts;
- type
- TIdleHandler = class
- procedure Idle(Sender: TObject; var Done: Boolean);
- end;
- const
- CM_CON_START = CM_BASE + 501;
- CM_CON_TRIGGER = CM_BASE + 502;
- CM_CON_AUTOTRIGGER = CM_BASE + 503;
- const
- ConnectorWindow: HWND = 0;
- ConnectorCount : Longint = 0;
- ConnectorList : TList = nil;
- LoopStarted : integer = 0;
- LoopSpeed : integer = 0;
- RestoreIdle : Boolean = False;
- IdleHandler : TIdleHandler = nil;
- {-------------------------------------------------------------------------}
- procedure DebugStr(s: String);
- begin
- {$IFDEF _MMDEBUG}
- if (s <> ' ') then s := 'Trigger: '+s;
- DB_WriteStrLn(0,s);
- {$ENDIF}
- end;
- {-- TIdleHandler --------------------------------------------------------}
- procedure TIdleHandler.Idle(Sender: TObject; var Done: Boolean);
- begin
- Done := False;
- end;
- {------------------------------------------------------------------------}
- procedure ProcessConnectors;
- var
- i: integer;
- begin
- { let windows have some time }
- for i := 0 to MAXSPEED-LoopSpeed do Application.ProcessMessages;
- { now go trough all connectors in the list }
- if (LoopStarted > 0) and (not Application.Terminated) and
- (ConnectorList.Count > 0) then
- begin
- for i := 0 to ConnectorList.Count-1 do
- with TMMConnector(ConnectorList.Items[i]) do
- begin
- if FAutoTrigger and FEnabled and FRunning then ProcessData;
- end;
- end;
- end;
- {------------------------------------------------------------------------}
- function ConnectorWndProc(Window: HWND; Message, wParam: UINT; lParam: Longint): Longint;
- export;{$IFDEF WIN32}stdcall;{$ENDIF}
- begin
- if (ConnectorList <> nil) then
- try
- case Message of
- CM_CON_START:
- if (lParam <> 0) then
- with TMMConnector(lParam) do
- begin
- if FStarted then
- begin
- FInHandler := 0;
- FRunning := True;
- if FAutoTrigger then
- begin
- inc(LoopStarted);
- PostMessage(ConnectorWindow,CM_CON_AUTOTRIGGER,0,0);
- end;
- end;
- exit;
- end;
- CM_CON_TRIGGER:
- if (lParam <> 0) then
- with TMMConnector(lParam) do
- begin
- if FEnabled and FRunning then
- begin
- { process the controls }
- ProcessData;
- {$IFDEF WIN32}
- InterlockedDecrement(FInHandler);
- {$ENDIF}
- end;
- exit;
- end;
- CM_CON_AUTOTRIGGER:
- begin
- { go trough all connectors }
- ProcessConnectors;
- { decide if we need a new loop }
- if (LoopStarted > 0) and (not Application.Terminated) and
- (ConnectorList.Count > 0) then
- begin
- {$IFDEF WIN32}
- Sleep(1);
- {$ENDIF}
- { give the app a chance }
- if ENTER_IDLE_MODE then
- Application.HandleMessage;
- PostMessage(ConnectorWindow,CM_CON_AUTOTRIGGER,0,0);
- end;
- exit;
- end;
- end;
- except
- Application.HandleException(nil);
- end;
- Result := DefWindowProc(Window, Message, wParam, lParam);
- end;
- {------------------------------------------------------------------------}
- const
- TMMConnectorWindowClass: TWndClass = (
- style: 0;
- lpfnWndProc: @ConnectorWndProc;
- cbClsExtra: 0;
- cbWndExtra: 0;
- hInstance: 0;
- hIcon: 0;
- hCursor: 0;
- hbrBackground: 0;
- lpszMenuName: nil;
- lpszClassName: 'TMMConnectorWindow');
- {------------------------------------------------------------------------}
- function AllocateConnectorWindow: HWND;
- var
- TempClass: TWndClass;
- ClassRegistered: Boolean;
- begin
- TMMConnectorWindowClass.hInstance := HInstance;
- ClassRegistered := GetClassInfo(HInstance,
- TMMConnectorWindowClass.lpszClassName, TempClass);
- if not ClassRegistered or (TempClass.lpfnWndProc <> @ConnectorWndProc) then
- begin
- {$IFDEF WIN32}
- if ClassRegistered then
- Windows.UnregisterClass(TMMConnectorWindowClass.lpszClassName, HInstance);
- Windows.RegisterClass(TMMConnectorWindowClass);
- {$ELSE}
- if ClassRegistered then
- WinProcs.UnregisterClass(TMMConnectorWindowClass.lpszClassName, HInstance);
- WinProcs.RegisterClass(TMMConnectorWindowClass);
- {$ENDIF}
- end;
- Result := CreateWindow(TMMConnectorWindowClass.lpszClassName, '', 0,
- 0, 0, 0, 0, 0, 0, HInstance, nil);
- end;
- {------------------------------------------------------------------------}
- procedure UpdateSpeed(Connector: TMMConnector);
- var
- i: integer;
- begin
- LoopSpeed := 0;
- if (ConnectorList <> nil) then
- for i := 0 to ConnectorList.Count-1 do
- with TMMConnector(ConnectorList.Items[i]) do
- begin
- if FSpeed > LoopSpeed then LoopSpeed := FSpeed;
- end;
- end;
- {------------------------------------------------------------------------}
- procedure AddConnector(Connector: TMMConnector);
- begin
- inc(ConnectorCount);
- if (ConnectorCount = 1) then
- begin
- ConnectorList := TList.Create;
- ConnectorWindow := AllocateConnectorWindow;
- end;
- ConnectorList.Add(Connector);
- UpdateSpeed(Connector);
- end;
- {------------------------------------------------------------------------}
- procedure RemoveConnector(Connector: TMMConnector);
- begin
- if (ConnectorList = nil) or (ConnectorList.indexOf(Connector) = -1) then exit;
- ConnectorList.Remove(Connector);
- ConnectorList.Pack;
- dec(ConnectorCount);
- if (ConnectorCount = 0) then
- begin
- ConnectorList.Free;
- ConnectorList := nil;
- DestroyWindow(ConnectorWindow);
- ConnectorWindow := 0;
- end;
- end;
- {------------------------------------------------------------------------}
- procedure TimeCallBack(uTimerID, dwUser: Longint);
- begin
- if (dwUser <> 0) then
- with TMMConnector(dwUser) do
- begin
- if FPaused then
- begin
- FBufTime := TimeGetExactTime;
- if assigned(FLevel1) or assigned(FLevel2) then
- begin
- FRefreshLevel := True;
- FIndexLevel := 0;
- end;
- {$IFNDEF LEVEL_ONLY}
- if assigned(FMeter1) or assigned(FMeter2) then
- begin
- FRefreshMeter := True;
- FIndexMeter := 0;
- end;
- if assigned(FOscope1) or assigned(FOscope2) then
- begin
- FRefreshScope := True;
- FIndexScope := 0;
- end;
- if assigned(FLight1) or assigned(FLight2) then
- begin
- FRefreshLight := True;
- FIndexLight := 0;
- end;
- if assigned(FSpectrum1) or assigned(FSpectrum2) or
- assigned(FSpectrum3) or assigned(FSpectrum4) then
- begin
- FRefreshSpectrum := True;
- FIndexSpectrum := 0;
- end;
- if assigned(FSpectrogram1) or assigned(FSpectrogram2) then
- begin
- FRefreshSpectrogram := True;
- FIndexSpectrogram1 := 0;
- FIndexSpectrogram2 := 0;
- end;
- {$ENDIF}
- end;
- end;
- end;
- {== TMMConnector ========================================================}
- constructor TMMConnector.Create(AOwner: TComponent);
- begin
- inherited Create(AOwner);
- FTimerID := 0;
- FEnabled := True;
- FRestoreIdle:= False;
- FAutoConvert:= True;
- FAutoTrigger:= True;
- FTriggerMode:= tmNone;
- FTriggerLevel := 0;
- FSynchronize := True;
- FSpeed := MAXSPEED;
- FStarted := False;
- FRunning := False;
- FPaused := False;
- FSrcData := nil;
- FDstData := nil;
- FDstBufferSize:= 0;
- FRealBufferSize:= 0;
- FIsPCMFormat := False;
- FCanConvert := False;
- FRefresh := True;
- FRealTime := True;
- FLevel1 := nil;
- FLevel2 := nil;
- {$IFNDEF LEVEL_ONLY}
- FMeter1 := nil;
- FMeter2 := nil;
- FOscope1 := nil;
- FOscope2 := nil;
- FLight1 := nil;
- FLight2 := nil;
- FSpectrum1 := nil;
- FSpectrum2 := nil;
- FSpectrum3 := nil;
- FSpectrum4 := nil;
- FSpectrogram1 := nil;
- FSpectrogram2 := nil;
- {$ENDIF}
- FIndexLevel := 0;
- {$IFNDEF LEVEL_ONLY}
- FIndexMeter := 0;
- FIndexScope := 0;
- FIndexLight := 0;
- FIndexSpectrum := 0;
- FIndexSpectrogram1:= 0;
- FIndexSpectrogram2:= 0;
- {$ENDIF}
- FRefreshLevel := False;
- {$IFNDEF LEVEL_ONLY}
- FRefreshMeter := False;
- FRefreshScope := False;
- FRefreshSpectrum := False;
- FRefreshSpectrogram:= False;
- {$ENDIF}
- FLevelRefresh := 0;
- {$IFNDEF LEVEL_ONLY}
- FMeterRefresh := 0;
- FOscopeRefresh := 0;
- FSpectrumRefresh := 0;
- FSpectrogramRefresh:= 0;
- {$ENDIF}
- if not (csDesigning in ComponentState) then
- begin
- TimeBeginPeriod(1);
- { update the connector list }
- AddConnector(Self);
- end;
- ErrorCode := ComponentRegistered(InitCode, Self, ClassName);
- if (ErrorCode <> 0) then RegisterFailed(InitCode, Self , ClassName);
- end;
- {-- TMMConnector --------------------------------------------------------}
- destructor TMMConnector.Destroy;
- var
- Msg: TMsg;
- begin
- Stopped;
- if not (csDesigning in ComponentState) then
- begin
- TimeEndPeriod(1);
- { remove pending messages }
- while PeekMessage(Msg, ConnectorWindow, CM_CON_START, CM_CON_AUTOTRIGGER, PM_REMOVE) do;
- { update the connector list }
- RemoveConnector(Self);
- end;
- inherited destroy;
- end;
- {-- TMMConnector --------------------------------------------------------}
- procedure TMMConnector.ChangeDesigning(aValue: Boolean);
- begin
- inherited ChangeDesigning(aValue);
- if not (csDesigning in ComponentState) then
- begin
- TimeBeginPeriod(1);
- { update the connector list }
- AddConnector(Self);
- end;
- end;
- {-- TMMConnector --------------------------------------------------------}
- procedure TMMConnector.Notification(aComponent: TComponent; Operation: TOperation);
- begin
- inherited Notification(aComponent, Operation);
- if (Operation = opRemove) then
- begin
- if (aComponent = FLevel1) then FLevel1 := nil;
- if (aComponent = FLevel2) then FLevel2 := nil;
- {$IFNDEF LEVEL_ONLY}
- if (aComponent = FMeter1) then FMeter1 := nil;
- if (aComponent = FMeter2) then FMeter2 := nil;
- if (aComponent = FOscope1) then FOscope1 := nil;
- if (aComponent = FOscope2) then FOscope2 := nil;
- if (aComponent = FLight1) then FLight1 := nil;
- if (aComponent = FLight2) then FLight2 := nil;
- if (aComponent = FSpectrum1) then FSpectrum1 := nil;
- if (aComponent = FSpectrum2) then FSpectrum2 := nil;
- if (aComponent = FSpectrum3) then FSpectrum3 := nil;
- if (aComponent = FSpectrum4) then FSpectrum4 := nil;
- if (aComponent = FSpectrogram1) then FSpectrogram1 := nil;
- if (aComponent = FSpectrogram2) then FSpectrogram2 := nil;
- {$ENDIF}
- end;
- end;
- {-- TMMConnector --------------------------------------------------------}
- procedure TMMConnector.UpdateTimer(Enabled: Boolean);
- var
- {$IFNDEF WIN32}
- TimeCB: TTimeCallBack;
- {$ENDIF}
- Time: integer;
- begin
- FRefreshLevel := False;
- {$IFNDEF LEVEL_ONLY}
- FRefreshMeter := False;
- FRefreshScope := False;
- FRefreshLight := False;
- FRefreshSpectrum := False;
- FRefreshSpectrogram:= False;
- {$ENDIF}
- if (FTimerID <> 0) then
- begin
- MMTimeKillEvent(FTimerID);
- FTimerID := 0;
- end;
- if Enabled then
- begin
- if (BufferSize < 8192) then
- Time := wioBytesToTime(PWaveFormat,BufferSize)
- else
- Time := 25;
- FTimerID := MMTimeSetEvent(Time, False, @TimeCallBack, Longint(Self));
- if (FTimerID = 0) then
- raise EOutOfResources.Create({$IFDEF DELPHI3}SNoTimers{$ELSE}LoadStr(SNoTimers){$ENDIF});
- end;
- end;
- {-- TMMConnector --------------------------------------------------------}
- procedure TMMConnector.SetEnterIdle(aValue: Boolean);
- begin
- ENTER_IDLE_MODE := aValue;
- end;
- {-- TMMConnector --------------------------------------------------------}
- function TMMConnector.GetEnterIdle: Boolean;
- begin
- Result := ENTER_IDLE_MODE;
- end;
- {-- TMMConnector --------------------------------------------------------}
- procedure TMMConnector.SetEnabled(aValue: Boolean);
- begin
- if (aValue <> FEnabled) then
- begin
- FEnabled := aValue;
- if not (csDesigning in ComponentState) then
- begin
- if not FEnabled then
- begin
- if FRunning then
- begin
- FRunning := False;
- if FAutoTrigger then dec(LoopStarted);
- end;
- if (LoopStarted = 0) and RestoreIdle then
- begin
- Application.OnIdle := nil;
- IdleHandler.Free;
- IdleHandler := nil;
- RestoreIdle := False;
- end;
- if assigned(FLevel1) then FLevel1.ResetData;
- if assigned(FLevel2) then FLevel2.ResetData;
- {$IFNDEF LEVEL_ONLY}
- if assigned(FMeter1) then FMeter1.ResetData;
- if assigned(FMeter2) then FMeter2.ResetData;
- if assigned(FOscope1) then FOscope1.ResetData;
- if assigned(FOscope2) then FOscope2.ResetData;
- if assigned(FLight1) then FLight1.ResetData;
- if assigned(FLight2) then FLight2.ResetData;
- if assigned(FSpectrum1) then FSpectrum1.ResetData;
- if assigned(FSpectrum2) then FSpectrum2.ResetData;
- if assigned(FSpectrum3) then FSpectrum3.ResetData;
- if assigned(FSpectrum4) then FSpectrum4.ResetData;
- if assigned(FSpectrogram1) then FSpectrogram1.ResetData;
- if assigned(FSpectrogram2) then FSpectrogram2.ResetData;
- {$ENDIF}
- end
- else if FStarted and FRealTime then
- begin
- if FAutoTrigger and ENTER_IDLE_MODE then
- begin
- {$IFDEF WIN32}
- if not assigned(Application.OnIdle) and (IdleHandler = nil) then
- begin
- IdleHandler := TIdleHandler.Create;
- Application.OnIdle := IdleHandler.Idle;
- RestoreIdle := True;
- end;
- {$ENDIF}
- end;
- PostMessage(ConnectorWindow,CM_CON_START,0,Longint(Self));
- end;
- end;
- end;
- end;
- {-- TMMConnector --------------------------------------------------------}
- procedure TMMConnector.SetRealTime(aValue: Boolean);
- begin
- if (aValue <> FRealTime) then
- begin
- if isOpen then
- raise EMMConnectorError.Create(LoadResStr(IDS_PROPERTYOPEN));
- FRealTime := aValue;
- end;
- end;
- {-- TMMConnector --------------------------------------------------------}
- procedure TMMConnector.SetSpeed(aValue: integer);
- begin
- if (aValue <> FSpeed) then
- begin
- FSpeed := MinMax(aValue,1,MAXSPEED);
- if not (csDesigning in ComponentState) then UpdateSpeed(Self);
- end;
- end;
- {-- TMMConnector --------------------------------------------------------}
- procedure TMMConnector.SetTriggerMode(aValue: TMMTriggerMode);
- begin
- if (aValue <> FTriggerMode) then
- begin
- FTriggerMode := aValue;
- end;
- end;
- {-- TMMConnector --------------------------------------------------------}
- procedure TMMConnector.SetTriggerLevel(aValue: integer);
- begin
- if (aValue <> FTriggerLevel) then
- begin
- FTriggerLevel := aValue;
- end;
- end;
- {-- TMMConnector --------------------------------------------------------}
- procedure TMMConnector.SetLevel(index: integer; aValue: TMMLevel);
- begin
- { bug fix for AXControl under VB }
- if Longint(Self) = Longint(aValue) then exit;
- case index of
- 0: if (FLevel1 = aValue) or ((aValue <> nil) and (FLevel2 = aValue)) then exit
- else FLevel1 := aValue;
- 1: if (FLevel2 = aValue) or ((aValue <> nil) and (FLevel1 = aValue)) then exit
- else FLevel2 := aValue;
- end;
- FRefreshLevel := False;
- if aValue <> nil then SetWaveParams;
- {$IFDEF WIN32}
- {$IFDEF TRIAL}
- {$DEFINE _HACK2}
- {$I MMHACK.INC}
- {$ENDIF}
- {$ENDIF}
- end;
- {$IFNDEF LEVEL_ONLY}
- {-- TMMConnector --------------------------------------------------------}
- procedure TMMConnector.SetMeter(index: integer; aValue: TMMMeter);
- begin
- { bug fix for AXControl under VB }
- if Longint(Self) = Longint(aValue) then exit;
- case index of
- 0: if (FMeter1 = aValue) or ((aValue <> nil) and (FMeter2 = aValue)) then exit
- else FMeter1 := aValue;
- 1: if (FMeter2 = aValue) or ((aValue <> nil) and (FMeter1 = aValue)) then exit
- else FMeter2 := aValue;
- end;
- FRefreshMeter := False;
- if aValue <> nil then SetWaveParams;
- end;
- {-- TMMConnector --------------------------------------------------------}
- procedure TMMConnector.SetOscope(index: integer; aValue: TMMOscope);
- begin
- { bug fix for AXControl under VB }
- if Longint(Self) = Longint(aValue) then exit;
- case index of
- 0: if (FOscope1 = aValue) or ((aValue <> nil) and (FOscope2 = aValue)) then exit
- else FOscope1 := aValue;
- 1: if (FOscope2 = aValue) or ((aValue <> nil) and (FOscope1 = aValue)) then exit
- else FOscope2 := aValue;
- end;
- FRefreshScope := False;
- if aValue <> nil then SetWaveParams;
- end;
- {-- TMMConnector --------------------------------------------------------}
- procedure TMMConnector.SetLight(index: integer; aValue: TMMLight);
- begin
- { bug fix for AXControl under VB }
- if Longint(Self) = Longint(aValue) then exit;
- case index of
- 0: if (FLight1 = aValue) or ((aValue <> nil) and (FLight2 = aValue)) then exit
- else FLight1 := aValue;
- 1: if (FLight2 = aValue) or ((aValue <> nil) and (FLight1 = aValue)) then exit
- else FLight2 := aValue;
- end;
- FRefreshLight := False;
- if aValue <> nil then SetWaveParams;
- end;
- {-- TMMConnector --------------------------------------------------------}
- procedure TMMConnector.SetSpectrum(index: integer; aValue: TMMSpectrum);
- begin
- { bug fix for AXControl under VB }
- if Longint(Self) = Longint(aValue) then exit;
- case index of
- 0: if (FSpectrum1 = aValue) then exit else FSpectrum1 := aValue;
- 1: if (FSpectrum2 = aValue) then exit else FSpectrum2 := aValue;
- 2: if (FSpectrum3 = aValue) then exit else FSpectrum3 := aValue;
- 3: if (FSpectrum4 = aValue) then exit else FSpectrum4 := aValue;
- end;
- FRefreshSpectrum := False;
- if aValue <> nil then SetWaveParams;
- {$IFDEF WIN32}
- {$IFDEF TRIAL}
- {$DEFINE _HACK3}
- {$I MMHACK.INC}
- {$ENDIF}
- {$ENDIF}
- end;
- {-- TMMConnector --------------------------------------------------------}
- procedure TMMConnector.SetSpectrogram(index: integer; aValue: TMMSpectrogram);
- begin
- { bug fix for AXControl under VB }
- if Longint(Self) = Longint(aValue) then exit;
- case index of
- 0: if (FSpectrogram1 = aValue) or ((aValue <> nil) and (FSpectrogram2 = aValue)) then exit
- else FSpectrogram1 := aValue;
- 1: if (FSpectrogram2 = aValue) or ((aValue <> nil) and (FSpectrogram1 = aValue)) then exit
- else FSpectrogram2 := aValue;
- end;
- FRefreshSpectrogram := False;
- if aValue <> nil then SetWaveParams;
- end;
- {$ENDIF}
- {-- TMMConnector --------------------------------------------------------}
- procedure TMMConnector.SetPWaveFormat(aValue: PWaveFormatEx);
- begin
- inherited SetPWaveFormat(aValue);
- SetWaveParams;
- end;
- {-- TMMConnector --------------------------------------------------------}
- procedure TMMConnector.SetWaveParams;
- var
- wfx: TWaveFormatEx;
- begin
- if (PWaveFormat <> nil) then
- begin
- if not FStarted then
- begin
- FCanConvert := False;
- if (PWaveFormat^.wFormatTag = WAVE_FORMAT_PCM) then
- begin
- FIsPCMFormat := True;
- wfx := PWaveFormat^;
- end
- else
- begin
- FIsPCMFormat := False;
- if FAutoConvert then
- begin
- wfx := acmSuggestPCMFormat(PWaveFormat);
- if (wfx.wFormatTag <> 0) then
- FCanConvert := acmQueryConvert(PWaveFormat,@wfx,True);
- end;
- end;
- end
- else wfx := FDstWaveFormat^;
- if (FIsPCMFormat or FCanConvert) then
- begin
- if wfx.wBitsPerSample = 8 then
- FSilence := 128
- else
- FSilence := 0;
- if assigned(FLevel1) then
- FLevel1.PCMWaveFormat := PPCMWaveFormat(@wfx)^;
- if assigned(FLevel2) then
- FLevel2.PCMWaveFormat := PPCMWaveFormat(@wfx)^;
- {$IFNDEF LEVEL_ONLY}
- if assigned(FMeter1) then
- FMeter1.PCMWaveFormat := PPCMWaveFormat(@wfx)^;
- if assigned(FMeter2) then
- FMeter2.PCMWaveFormat := PPCMWaveFormat(@wfx)^;
- if assigned(FOscope1) then
- FOscope1.PCMWaveFormat := PPCMWaveFormat(@wfx)^;
- if assigned(FOscope2) then
- FOscope2.PCMWaveFormat := PPCMWaveFormat(@wfx)^;
- if assigned(FLight1) then
- FLight1.PCMWaveFormat := PPCMWaveFormat(@wfx)^;
- if assigned(FLight2) then
- FLight2.PCMWaveFormat := PPCMWaveFormat(@wfx)^;
- if assigned(FSpectrum1) then
- FSpectrum1.PCMWaveFormat := PPCMWaveFormat(@wfx)^;
- if assigned(FSpectrum2) then
- FSpectrum2.PCMWaveFormat := PPCMWaveFormat(@wfx)^;
- if assigned(FSpectrum3) then
- FSpectrum3.PCMWaveFormat := PPCMWaveFormat(@wfx)^;
- if assigned(FSpectrum4) then
- FSpectrum4.PCMWaveFormat := PPCMWaveFormat(@wfx)^;
- if assigned(FSpectrogram1) then
- FSpectrogram1.PCMWaveFormat := PPCMWaveFormat(@wfx)^;
- if assigned(FSpectrogram2) then
- FSpectrogram2.PCMWaveFormat := PPCMWaveFormat(@wfx)^;
- {$ENDIF}
- end;
- end;
- end;
- {-- TMMConnector --------------------------------------------------------}
- procedure TMMConnector.Started;
- var
- wfx: TWaveFormatEx;
- begin
- inherited Started;
- if not (csDesigning in ComponentState) and
- (PWaveFormat <> nil) and not FStarted then
- begin
- FSrcData := nil;
- FDstData := nil;
- if (PWaveFormat^.wFormatTag = WAVE_FORMAT_PCM) then
- begin
- FIsPCMFormat := True;
- FCanConvert := False;
- FDstWaveFormat := PWaveFormat;
- FDstBufferSize := BufferSize;
- FSrcData := GlobalAllocMem(BufferSize);
- FDstData := FSrcData;
- end
- else
- begin
- FIsPCMFormat := False;
- FCanConvert := False;
- if FAutoConvert then
- begin
- wfx := acmSuggestPCMFormat(PWaveFormat);
- FDstWaveFormat := wioCopyWaveFormat(@wfx);
- FSrcData := GlobalAllocMem(BufferSize);
- FConvert := acmBeginConvert(PWaveFormat,FDstWaveFormat,FSrcData,BufferSize,True);
- if (FConvert <> nil) then
- begin
- FCanConvert := True;
- FDstData := FConvert^.lpDstBuffer;
- FDstBufferSize := FConvert^.dwDstBufferSize;
- end
- else
- begin
- GlobalFreeMem(Pointer(FSrcData));
- GlobalFreeMem(Pointer(FDstWaveFormat));
- FDstBufferSize := 0;
- end;
- end;
- end;
- FRefreshLevel := False;
- {$IFNDEF LEVEL_ONLY}
- FRefreshMeter := False;
- FRefreshScope := False;
- FRefreshLight := False;
- FRefreshSpectrum := False;
- FRefreshSpectrogram := False;
- {$ENDIF}
- FLevelRefresh := 0;
- {$IFNDEF LEVEL_ONLY}
- FMeterRefresh := 0;
- FOscopeRefresh := 0;
- FLightRefresh := 0;
- FSpectrumRefresh := 0;
- FSpectrogramRefresh := 0;
- {$ENDIF}
- if (FIsPCMFormat or FCanConvert) and (FDstData <> nil) then
- begin
- {$IFDEF WIN32}
- FillChar(FDataSection, SizeOf(FDataSection), 0);
- InitializeCriticalSection(FDataSection);
- {$ENDIF}
- UpdateSpeed(Self);
- FStarted := True;
- SetWaveParams;
- if FEnabled and FRealTime then
- begin
- if FAutoTrigger and ENTER_IDLE_MODE then
- begin
- {$IFDEF WIN32}
- if not assigned(Application.OnIdle) and (IdleHandler = nil) then
- begin
- IdleHandler := TIdleHandler.Create;
- Application.OnIdle := IdleHandler.Idle;
- RestoreIdle := True;
- end;
- {$ENDIF}
- end;
- PostMessage(ConnectorWindow,CM_CON_START,0,Longint(Self));
- end;
- end;
- end;
- end;
- {-- TMMConnector --------------------------------------------------------}
- procedure TMMConnector.Paused;
- begin
- if not (csDesigning in ComponentState) and FStarted and not FPaused then
- begin
- FPaused := True;
- if (FDstData <> nil) and (FIsPCMFormat or FCanConvert) then
- GlobalFillMem(FDstData^, FDstBufferSize, FSilence);
- if FRealTime then UpdateTimer(True);
- end;
- inherited Paused;
- end;
- {-- TMMConnector --------------------------------------------------------}
- procedure TMMConnector.Restarted;
- begin
- if not (csDesigning in ComponentState) and FPaused then
- begin
- FPaused := False;
- if FRealTime then UpdateTimer(False);
- end;
- inherited Restarted;
- end;
- {-- TMMConnector --------------------------------------------------------}
- procedure TMMConnector.Stopped;
- begin
- if not (csDesigning in ComponentState) and FStarted then
- begin
- FStarted := False;
- if FRunning then
- begin
- FRunning := False;
- if FAutoTrigger then dec(LoopStarted);
- if (LoopStarted = 0) and RestoreIdle then
- begin
- Application.OnIdle := nil;
- IdleHandler.Free;
- IdleHandler := nil;
- RestoreIdle := False;
- end;
- end;
- FPaused := False;
- UpdateTimer(False);
- if FCanConvert and (FConvert <> nil) then
- begin
- acmDoneConvert(FConvert);
- FDstData := nil;
- GlobalFreeMem(Pointer(FDstWaveFormat));
- end;
- GlobalFreeMem(Pointer(FSrcData));
- {$IFDEF WIN32}
- DeleteCriticalSection(FDataSection);
- {$ENDIF}
- if FRefresh then
- begin
- if assigned(FLevel1) then FLevel1.ResetData;
- if assigned(FLevel2) then FLevel2.ResetData;
- {$IFNDEF LEVEL_ONLY}
- if assigned(FMeter1) then FMeter1.ResetData;
- if assigned(FMeter2) then FMeter2.ResetData;
- if assigned(FOscope1) then FOscope1.ResetData;
- if assigned(FOscope2) then FOscope2.ResetData;
- if assigned(FLight1) then FLight1.ResetData;
- if assigned(FLight2) then FLight2.ResetData;
- if assigned(FSpectrum1) then FSpectrum1.ResetData;
- if assigned(FSpectrum2) then FSpectrum2.ResetData;
- if assigned(FSpectrum3) then FSpectrum3.ResetData;
- if assigned(FSpectrum4) then FSpectrum4.ResetData;
- if assigned(FSpectrogram1) then FSpectrogram1.ResetData;
- if assigned(FSpectrogram2) then FSpectrogram2.ResetData;
- {$ENDIF}
- end;
- end;
- inherited Stopped;
- end;
- {-- TMMConnector --------------------------------------------------------}
- procedure TMMConnector.Reseting;
- begin
- if not (csDesigning in ComponentState) and FStarted then
- begin
- if (FDstData <> nil) and (FIsPCMFormat or FCanConvert) then
- GlobalFillMem(FDstData^, FDstBufferSize, FSilence);
- end;
- inherited Reseting;
- end;
- {-- TMMConnector --------------------------------------------------------}
- procedure TMMConnector.ProcessData;
- var
- Offset: Longint;
- DataPtr,DataPtr2: PChar;
- Size,Size2: integer;
- TimeOK,Time2OK: Boolean;
- {$IFNDEF LEVEL_ONLY}
- Scope: TMMOscope;
- {$ENDIF}
- begin
- if FEnabled and (FRunning or (not FRealtime and FStarted)) and (FDstData <> nil) then
- begin
- {$IFDEF WIN32}
- EnterCriticalSection(FDataSection);
- try
- {$ENDIF}
- if FRefreshLevel then
- begin
- Size := 0;
- DataPtr := FDstData;
- TimeOK := True;
- if assigned(FLevel1) then Size := FLevel1.BytesPerLevel;
- if assigned(FLevel2) then Size := Max(Size,FLevel2.BytesPerLevel);
- if Synchronize then
- begin
- FStepTime := 1000000;
- FStepTime := Trunc(FStepTime*FIndexLevel/FDstWaveFormat^.nAvgBytesPerSec);
- if (TimeGetExactTime-FBufTime < FStepTime) then
- begin
- TimeOK := False;
- end;
- end;
- if TimeOK then
- begin
- inc(DataPtr,FIndexLevel);
- inc(FIndexLevel,Size);
- if (DataPtr + Size <= FDstData + FRealBufferSize) then
- begin
- { paint the level. }
- if assigned(FLevel1) then FLevel1.RefreshPCMData(DataPtr);
- if assigned(FLevel2) then FLevel2.RefreshPCMData(DataPtr);
- inc(FLevelRefresh);
- end
- else FRefreshLevel := False;
- end;
- end;
- {$IFNDEF LEVEL_ONLY}
- if FRefreshMeter then
- begin
- Size := 0;
- DataPtr := FDstData;
- TimeOK := True;
- if assigned(FMeter1) then Size := FMeter1.BytesPerMeter;
- if assigned(FMeter2) then Size := Max(Size,FMeter2.BytesPerMeter);
- if FSynchronize then
- begin
- FStepTime := 1000000;
- FStepTime := Trunc(FStepTime*FIndexMeter/FDstWaveFormat^.nAvgBytesPerSec);
- if (TimeGetExactTime-FBufTime < FStepTime) then TimeOK := False;
- end;
- if TimeOK then
- begin
- inc(DataPtr,FIndexMeter);
- inc(FIndexMeter,Size);
- if (DataPtr + Size <= FDstData + FRealBufferSize) then
- begin
- { paint the meter. }
- if assigned(FMeter1) then FMeter1.RefreshPCMData(DataPtr);
- if assigned(FMeter2) then FMeter2.RefreshPCMData(DataPtr);
- inc(FMeterRefresh);
- end
- else FRefreshMeter := False;
- end;
- end;
- if FRefreshScope then
- begin
- Size := 0;
- Offset := -1;
- DataPtr := FDstData;
- TimeOK := True;
- if assigned(FOscope2) then
- begin
- Size := FOscope2.BytesPerScope;
- Scope := FOscope2;
- end;
- if assigned(FOscope1) then
- begin
- Size := Max(Size,FOscope1.BytesPerScope);
- Scope := FOscope1;
- end;
- inc(DataPtr, FIndexScope);
- if (FTriggerMode <> tmNone) and not FPaused then
- begin
- Offset := pcmFindZeroCross(FDstWaveFormat, DataPtr,
- FRealBufferSize-FIndexScope,
- 0, Byte(FTriggerMode), FTriggerLevel);
- end;
- if FSynchronize then
- begin
- FStepTime := 1000000;
- FStepTime := Trunc(FStepTime*FIndexScope/FDstWaveFormat^.nAvgBytesPerSec);
- if (TimeGetExactTime-FBufTime < FStepTime) then TimeOK := False;
- end;
- if TimeOK then
- with Scope do
- begin
- if (Offset > 0) then
- begin
- inc(FIndexScope,Offset);
- inc(DataPtr, Offset);
- end;
- if Scroll and Accelerate then
- inc(FIndexScope, FFTLength div 4 * (Ord(BitLength)+1)*(Ord(Mode)+1))
- else
- inc(FIndexScope, Size);
- if (DataPtr + Size <= FDstData + FRealBufferSize) then
- begin
- { paint the scope. }
- if assigned(FOscope1) then FOscope1.RefreshPCMData(DataPtr);
- if assigned(FOscope2) then FOscope2.RefreshPCMData(DataPtr);
- inc(FOscopeRefresh);
- end
- else FRefreshScope := False;
- end;
- end;
- if FRefreshLight then
- begin
- Size := 0;
- DataPtr := FDstData;
- TimeOK := True;
- if assigned(FLight1) then Size := FLight1.BytesPerLight;
- if assigned(FLight2) then Size := Max(Size,FLight2.BytesPerLight);
- if FSynchronize then
- begin
- FStepTime := 1000000;
- FStepTime := Trunc(FStepTime*FIndexLight/FDstWaveFormat^.nAvgBytesPerSec);
- if (TimeGetExactTime-FBufTime < FStepTime) then TimeOK := False;
- end;
- if TimeOK then
- begin
- inc(DataPtr,FIndexLight);
- inc(FIndexLight,Size);
- if (DataPtr + Size <= FDstData + FRealBufferSize) then
- begin
- { paint the light. }
- if assigned(FLight1) then FLight1.RefreshPCMData(DataPtr);
- if assigned(FLight2) then FLight2.RefreshPCMData(DataPtr);
- inc(FLightRefresh);
- end
- else FRefreshLight := False;
- end;
- end;
- if FRefreshSpectrum then
- begin
- Size := 0;
- DataPtr := FDstData;
- TimeOK := True;
- if assigned(FSpectrum1) then Size := FSpectrum1.BytesPerSpectrum;
- if assigned(FSpectrum2) then Size := Max(Size,FSpectrum2.BytesPerSpectrum);
- if assigned(FSpectrum3) then Size := Max(Size,FSpectrum3.BytesPerSpectrum);
- if assigned(FSpectrum4) then Size := Max(Size,FSpectrum4.BytesPerSpectrum);
- if FSynchronize then
- begin
- FStepTime := 1000000;
- FStepTime := Trunc(FStepTime*FIndexSpectrum/FDstWaveFormat^.nAvgBytesPerSec);
- if (TimeGetExactTime-FBufTime < FStepTime) then TimeOK := False;
- end;
- if TimeOK then
- begin
- inc(DataPtr,FIndexSpectrum);
- inc(FIndexSpectrum,Size);
- if (DataPtr + Size <= FDstData + FRealBufferSize) then
- begin
- { paint the spectrum. }
- if assigned(FSpectrum1) then FSpectrum1.RefreshPCMData(DataPtr);
- if assigned(FSpectrum2) then FSpectrum2.RefreshPCMData(DataPtr);
- if assigned(FSpectrum3) then FSpectrum3.RefreshPCMData(DataPtr);
- if assigned(FSpectrum4) then FSpectrum4.RefreshPCMData(DataPtr);
- inc(FSpectrumRefresh);
- end
- else
- begin
- FRefreshSpectrum := False;
- end;
- end;
- end;
- if FRefreshSpectrogram then
- begin
- Size := 0;
- Size2:= 0;
- DataPtr := nil;
- DataPtr2 := nil;
- TimeOK := False;
- Time2OK := False;
- if assigned(FSpectrogram1) then
- with FSpectrogram1 do
- begin
- DataPtr := FDstData;
- Size := BytesPerSpectrogram;
- if FSynchronize then
- begin
- FStepTime := 1000000;
- FStepTime := Trunc(FStepTime*FIndexSpectrogram1/FDstWaveFormat^.nAvgBytesPerSec);
- if (TimeGetExactTime-FBufTime >= FStepTime) then TimeOK := True;
- end
- else TimeOK := True;
- if TimeOK then
- begin
- inc(DataPtr,FIndexSpectrogram1);
- if Accelerate then
- inc(FIndexSpectrogram1, Size div 4)
- else
- inc(FIndexSpectrogram1, Size);
- end;
- end;
- if assigned(FSpectrogram2) then
- with FSpectrogram2 do
- begin
- DataPtr2 := FDstData;
- Size2 := BytesPerSpectrogram;
- if FSynchronize then
- begin
- FStepTime := 1000000;
- FStepTime := Trunc(FStepTime*FIndexSpectrogram2/FDstWaveFormat^.nAvgBytesPerSec);
- if (TimeGetExactTime-FBufTime >= FStepTime) then Time2OK := True;
- end
- else Time2OK := True;
- if Time2OK then
- begin
- inc(DataPtr2,FIndexSpectrogram2);
- if Accelerate then
- inc(FIndexSpectrogram2, Size div 4)
- else
- inc(FIndexSpectrogram2, Size2);
- end;
- end;
- if TimeOK or Time2OK then
- begin
- if ((DataPtr <> nil) and (DataPtr + Size <= FDstData + FRealBufferSize)) or
- ((DataPtr2 <> nil) and (DataPtr2 + Size2 <= FDstData + FRealBufferSize)) then
- begin
- { paint the spectrogram. }
- if assigned(FSpectrogram1) and TimeOK and
- (DataPtr + Size <= FDstData + FRealBufferSize) then
- FSpectrogram1.RefreshPCMData(DataPtr);
- if assigned(FSpectrogram2) and Time2OK and
- (DataPtr2 + Size2 <= FDstData + FRealBufferSize) then
- FSpectrogram2.RefreshPCMData(DataPtr2);
- inc(FSpectrogramRefresh);
- end
- else FRefreshSpectrogram := False;
- end;
- end;
- {$ENDIF}
- {$IFDEF WIN32}
- finally
- LeaveCriticalSection(FDataSection);
- end;
- {$ENDIF}
- if assigned(FOnTrigger) then FOnTrigger(Self);
- end;
- end;
- {-- TMMConnector --------------------------------------------------------}
- procedure TMMConnector.NewBuffer(lpData: PChar; dwLength: DWORD);
- begin
- if FEnabled and not FPaused and (FIsPCMFormat or FCanConvert) then
- begin
- if (lpData <> nil) then
- begin
- FBufTime := TimeGetExactTime;
- {$IFDEF WIN32}
- EnterCriticalSection(FDataSection);
- try
- {$ENDIF}
- FRealBufferSize := Min(dwLength,BufferSize);
- GlobalMoveMem(lpData^,FSrcData^,FRealBufferSize);
- { if we have a compressed format try to convert the format }
- if not FIsPCMFormat and FCanConvert then
- begin
- FRealBufferSize := acmDoConvert(FConvert,FRealBufferSize);
- if FRealBufferSize <= 0 then exit;
- end;
- {$IFDEF WIN32}
- finally
- LeaveCriticalSection(FDataSection);
- end;
- {$ENDIF}
- if assigned(FLevel1) or assigned(FLevel2) then
- begin
- FRefreshLevel := True;
- FIndexLevel := 0;
- end;
- {$IFNDEF LEVEL_ONLY}
- if assigned(FMeter1) or assigned(FMeter2) then
- begin
- FRefreshMeter := True;
- FIndexMeter := 0;
- end;
- if assigned(FOscope1) or assigned(FOscope2) then
- begin
- FRefreshScope := True;
- FIndexScope := 0;
- end;
- if assigned(FLight1) or assigned(FLight2) then
- begin
- FRefreshLight := True;
- FIndexLight := 0;
- end;
- if assigned(FSpectrum1) or assigned(FSpectrum2) or
- assigned(FSpectrum3) or assigned(FSpectrum4) then
- begin
- FRefreshSpectrum := True;
- FIndexSpectrum := 0;
- end;
- if assigned(FSpectrogram1) or assigned(FSpectrogram2) then
- begin
- FRefreshSpectrogram := True;
- FIndexSpectrogram1 := 0;
- FIndexSpectrogram2 := 0;
- end;
- {$ENDIF}
- if not FRealTime and FAutoTrigger then ProcessData;
- end;
- end;
- end;
- {-- TMMConnector --------------------------------------------------------}
- procedure TMMConnector.BufferReady(lpwh: PWaveHdr);
- var
- p: PWaveHdr;
- begin
- if FSynchronize and (PMMWaveHdr(lpwh)^.lpNext <> nil) and (PMMWaveHdr(lpwh)^.wh.dwBytesRecorded > 0) then
- p := PMMWaveHdr(lpwh)^.lpNext
- else
- p := lpwh;
- if (p <> nil) then
- NewBuffer(p^.lpData,p^.dwBytesRecorded);
- inherited BufferReady(lpwh);
- end;
- {-- TMMConnector --------------------------------------------------------}
- procedure TMMConnector.BufferLoad(lpwh: PWaveHdr; var MoreBuffers: Boolean);
- begin
- inherited BufferLoad(lpwh, MoreBuffers);
- NewBuffer(lpwh^.lpData,lpwh.dwBytesRecorded);
- end;
- {-- TMMConnector --------------------------------------------------------}
- procedure TMMConnector.GetPeak(var PeakL, PeakR: Smallint);
- begin
- if (FIsPCMFormat or FCanConvert) and (FDstData <> nil) then
- begin
- pcmFindPeak(FDstWaveFormat,
- FDstData, FRealBufferSize,
- PeakL, PeakR);
- end
- else
- begin
- PeakL := FSilence;
- PeakR := FSilence;
- end;
- end;
- {-- TMMConnector --------------------------------------------------------}
- procedure TMMConnector.SetAutoTrigger(aValue: Boolean);
- begin
- if (aValue <> FAutoTrigger) then
- begin
- FAutoTrigger := aValue;
- if not (csDesigning in ComponentState) then
- begin
- if not FAutoTrigger then
- begin
- if FRunning then
- begin
- dec(LoopStarted);
- FRunning := False;
- end;
- if (LoopStarted = 0) and RestoreIdle then
- begin
- Application.OnIdle := nil;
- IdleHandler.Free;
- IdleHandler := nil;
- RestoreIdle := False;
- end;
- end
- else if FStarted and FEnabled and FRealTime then
- begin
- if FAutoTrigger and ENTER_IDLE_MODE then
- begin
- {$IFDEF WIN32}
- if not assigned(Application.OnIdle) and (IdleHandler = nil) then
- begin
- IdleHandler := TIdleHandler.Create;
- Application.OnIdle := IdleHandler.Idle;
- RestoreIdle := True;
- end;
- {$ENDIF}
- end;
- PostMessage(ConnectorWindow,CM_CON_START,0,Longint(Self));
- end;
- end;
- end;
- {$IFDEF WIN32}
- {$IFDEF TRIAL}
- {$DEFINE _HACK1}
- {$I MMHACK.INC}
- {$ENDIF}
- {$ENDIF}
- end;
- {-- TMMConnector --------------------------------------------------------}
- procedure TMMConnector.Trigger;
- begin
- if FEnabled and (FRunning or (not FRealtime and FStarted)) and not FAutoTrigger then
- begin
- {$IFDEF WIN32}
- if (FInHandler = 0) then
- begin
- if (GetCurrentThreadID <> MainThreadID) then
- begin
- {$IFDEF WIN32}
- InterlockedIncrement(FInHandler);
- {$ENDIF}
- PostMessage(ConnectorWindow,CM_CON_TRIGGER,0,Longint(Self));
- end
- else ProcessData;
- end;
- {$ELSE}
- ProcessData;
- {$ENDIF}
- end;
- end;
- end.