{========================================================================} {= (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 MMDSMix; {$I COMPILER.INC} interface uses Windows, OLE2, Messages, SysUtils, Classes, Graphics, Controls, Dialogs, Forms, DsgnIntf, MMSystem, MMObj, MMUtils, MMDSound, MMD3DTyp, MM3D, MMRegs, MMWave, MMPCMSup, MMACMSup; type EMMDSWaveMixError = class(Exception); TMMDSSpeakerConfig = (scHeadphone,scMono,scQuad,scStereo,scSurround); TMMDSLevel = (prNormal, prPriority, prExclusive); TMMDS3DBufferMode = (bmNormal,bmHeadRelative,bmNo3D); const defMaxDistance = 1e+09; {? Should be inf} defMinDistance = 1.0; defMode = bmNormal; defPosX = 0; {?} defPosY = 0; {?} defPosZ = 0; {?} defInsideConeAngle = 360; defOutsideConeAngle = 360; defConeOrientX = 0; defConeOrientY = 0; defConeOrientZ = 1; defConeOutsideVolume = 0; {?} defVelX = 0; {?} defVelY = 0; {?} defVelZ = 0; {?} defDistanceFactor = DS3D_DEFAULTDISTANCEFACTOR; defDopplerFactor = DS3D_DEFAULTDOPPLERFACTOR; defOrientFrontX = 0; defOrientFrontY = 0; defOrientFrontZ = 1; defOrientTopX = 0; defOrientTopY = 1; defOrientTopZ = 0; defPositionX = 0; {?} defPositionY = 0; {?} defPositionZ = 0; {?} defRollOffFactor = DS3D_DEFAULTROLLOFFFACTOR; defVelocityX = 0; {?} defVelocityY = 0; {?} defVelocityZ = 0; {?} type {-- TMMDS3DControl -----------------------------------------------------} TMMDS3DControl = class(TMMObject) public procedure BeginUpdate; procedure EndUpdate; published property Deferred: Boolean read FDeferred write SetDeferred; end; {-- TMMDS3DBuffer ------------------------------------------------------} TMMDS3DBuffer = class(TMMDS3DControl) public constructor Create(Loading: Boolean); destructor Destroy; override; procedure Assign(Source: TPersistent); override; published property MaxDistance: D3DVALUE read GetMaxDistance write SetMaxDistance; property MinDistance: D3DVALUE read GetMinDistance write SetMinDistance; property Mode: TMMDS3DBufferMode read GetMode write SetMode default defMode; property Position: TMMVector3D read GetPosition write SetPosition; property InsideConeAngle: LongInt read GetInsideConeAngle write SetInsideConeAngle default defInsideConeAngle; property OutsideConeAngle: LongInt read GetOutsideConeAngle write SetOutsideConeAngle default defOutsideConeAngle; property ConeOrientation: TMMVector3D read GetConeOrientation write SetConeOrientation; property ConeOutsideVolume: LongInt read GetConeOutsideVolume write SetConeOutsideVolume default defConeOutsideVolume; property Velocity: TMMVector3D read GetVelocity write SetVelocity; end; {-- TMMDS3DListener ----------------------------------------------------} TMMDS3DListener = class(TMMDS3DControl) public constructor Create(Loading: Boolean); destructor Destroy; override; procedure Assign(Source: TPersistent); override; procedure Commit; published property DistanceFactor: D3DVALUE read GetDistanceFactor write SetDistanceFactor; property DopplerFactor: D3DVALUE read GetDopplerFactor write SetDopplerFactor; property OrientFront: TMMVector3D read GetOrientFront write SetOrientFront; property OrientTop: TMMVector3D read GetOrientTop write SetOrientTop; property Position: TMMVector3D read GetPosition write SetPosition; property RollOffFactor: D3DVALUE read GetRollOffFactor write SetRollOffFactor; property Velocity: TMMVector3D read GetVelocity write SetVelocity; end; {-- TMMDSSoundBuffer ---------------------------------------------------} TMMDSSoundBuffer = class(TMMObject) public constructor Create; virtual; property Caps: TDSBCAPS read GetCaps; property Wave: TMMWave read FWave; property Name: string read FName; property BufferSize: Longint read GetBufferSize; property Playing: Boolean read GetPlaying; property Paused: Boolean read FPaused; property Muted: Boolean read FMuted write SetMuted default False; property Volume: Longint read GetVolume write SetVolume default 0; property Panning: Longint read GetPanning write SetPanning default 0; property Frequency: Longint read GetFrequency write SetFrequency default 0; property Position: Longint read GetPosition write SetPosition default 0; property Looping: Boolean read GetLooping write SetLooping default False; end; {-- TMMDSSoundCaps ----------------------------------------------------} TMMDSSoundCaps = class(TMMObject) published property ContinuousRate: Boolean read FContinuousRate write FBDummy stored False; property EmulDriver: Boolean read FEmulDriver write FBDummy stored False; property Certified: Boolean read FCertified write FBDummy stored False; property Primary16Bit: Boolean read FPrimary16Bit write FBDummy stored False; property Primary8Bit: Boolean read FPrimary8Bit write FBDummy stored False; property PrimaryMono: Boolean read FPrimaryMono write FBDummy stored False; property PrimaryStereo: Boolean read FPrimaryStereo write FBDummy stored False; property Secondary16Bit: Boolean read FSecondary16Bit write FBDummy stored False; property Secondary8Bit: Boolean read FSecondary8Bit write FBDummy stored False; property SecondaryMono: Boolean read FSecondaryMono write FBDummy stored False; property SecondaryStereo: Boolean read FSecondaryStero write FBDummy stored False; property MinSecondarySampleRate: DWORD read FMin2Sample write FLDummy stored False; property MaxSecondarySampleRate: DWORD read FMax2Sample write FLDummy stored False; property PrimaryBuffers: DWORD read FPrimaryBuffers write FLDummy stored False; property MaxHWMixingAllBuffers: DWORD read FMaxHWAll write FLDummy stored False; property MaxHWMixingStaticBuffers: DWORD read FMaxHWStatic write FLDummy stored False; property MaxHWMixingStreamingBuffers: DWORD read FMaxHWStream write FLDummy stored False; property FreeHWMixingAllBuffers: DWORD read FFreeHWAlls write FLDummy stored False; property FreeHWMixingStaticBuffers: DWORD read FFreeHWStatic write FLDummy stored False; property FreeHWMixingStreamingBuffers: DWORD read FFreeHWStream write FLDummy stored False; property MaxHW3DAllBuffers: DWORD read FMaxHW3All write FLDummy stored False; property MaxHW3DStaticBuffers: DWORD read FMaxHW3Static write FLDummy stored False; property MaxHW3DStreamingBuffers: DWORD read FMaxHW3Stream write FLDummy stored False; property FreeHW3DAllBuffers: DWORD read FFreeHW3Alls write FLDummy stored False; property FreeHW3DStaticBuffers: DWORD read FFreeHW3Static write FLDummy stored False; property FreeHW3DStreamingBuffers: DWORD read FFreeHW3Stream write FLDummy stored False; property TotalHWMemBytes: DWORD read FTotalHWMemBytes write FLDummy stored False; property FreeHWMemBytes: DWORD read FFreeHWMemBytes write FLDummy stored False; property MaxContigFreeHWMemBytes: DWORD read FMaxContigFree write FLDummy stored False; property UnlockTransferRateHWBuffers: DWORD read FUnlockRate write FLDummy stored False; property PlayCPUOverheadSWBuffers: DWORD read FPlayCPU write FLDummy stored False; end; TMMDSBufferLostEvent = procedure(Sender: TObject; Buffer: TMMDSSoundBuffer; var Abort: Boolean) of object; TMMDSBufferEndEvent = procedure(Sender: TObject; Buffer: TMMDSSoundBuffer) of object; {-- TMMDSWaveMixer ----------------------------------------------------} TMMDSWaveMixer = class(TMMComponent) public constructor Create(AOwner: TComponent); override; destructor Destroy; override; procedure Open; procedure Close; procedure CooperateWith(Handle: THandle); function AddBuffer(var aName: string; aWave: TMMWave): TMMDSSoundBuffer; function DuplicateBuffer(var aName: string; Buffer: TMMDSSoundBuffer): TMMDSSoundBuffer; procedure RemoveBuffer(Buffer: TMMDSSoundBuffer); procedure PlayBuffer(Buffer: TMMDSSoundBuffer); procedure PauseBuffer(Buffer: TMMDSSoundBuffer); procedure StopBuffer(Buffer: TMMDSSoundBuffer); procedure FreeBuffers; procedure OpenInDesignTime; procedure CloseInDesignTime; property PCMWaveFormat: TPCMWaveFormat read GetPCMWaveFormat write SetPCMWaveFormat; property Buffer[Index: integer]: TMMDSSoundBuffer read GetBuffer; property BufferByName[aName: string]: TMMDSSoundBuffer read GetBufferName; property BufferCount: integer read GetBufferCount; property NumDevs: integer read GetNumDevs; property Devices[Index: integer]: PDSDRIVERDESC read GetDevices; property Muted: Boolean read FMuted write SetMuted default False; property Volume: Longint read GetVolume write SetVolume default 0; property Panning: Longint read GetPanning write SetPanning default 0; property Opened: Boolean read GetOpened; published property OnBufferLost: TMMDSBufferLostEvent read FOnBufferLost write FOnBufferLost; property OnBufferEnd: TMMDSBufferEndEvent read FOnBufferEnd write FOnBufferEnd; property Level: TMMDSLevel read FLevel write SetLevel default prPriority; property SoundCaps: TMMDSSoundCaps read GetCaps write SetCaps; property SpeakerConfiguration: TMMDSSpeakerConfig read GetSpeaker write SetSpeaker default scStereo; property DeviceID: TMMDeviceID read FDeviceID write SetDeviceID default 0; property ProductName: String read FProductName write SetProductName stored False; property BitLength: TMMBits read FBits write SetBits default b8bit; property SampleRate: Longint read FSampleRate write SetSampleRate default 11025; property Mode: TMMMode read FMode write SetMode default mMono; property Use3D: Boolean read FUse3D write SetUse3D default False; property Sound3D: TMMDS3DListener read F3DListener write Set3DListener; end; {-- TMMDSMixChannel ---------------------------------------------------} TMMDSMixChannel = class(TMMCustomMemoryWave) public constructor Create(aOwner: TComponent); override; destructor Destroy; override; procedure Init; procedure Play; procedure Pause; procedure Stop; property SoundBuffer: TMMDSSoundBuffer read FSoundBuffer; property BufferSize: Longint read GetBufferSize; property Position: Longint read GetPosition write SetPosition; property Playing: Boolean read GetPlaying; {$WARNINGS OFF} property Paused: Boolean read GetPaused; {$WARNINGS ON} published property OnPlayEnd: TNotifyEvent read FOnPlayEnd write FOnPlayEnd; property Mixer: TMMDSWaveMixer read FMixer write FMixer; property Muted: Boolean read GetMuted write SetMuted default False; property Volume: Longint read GetVolume write SetVolume default 0; property Panning: Longint read GetPanning write SetPanning default 0; property Frequency: Longint read GetFrequency write SetFrequency default 0; property Looping: Boolean read GetLooping write SetLooping default False; property Sound3D: TMMDS3DBuffer read F3DBuffer write Set3DBuffer; end; {-- EDSMixError -------------------------------------------------------} EDSMixError = class(Exception) end; {-- EDirectSoundError -------------------------------------------------} EDirectSoundError = class(EDSMixError) private FResult : HRESULT; public constructor CreateRes(Code: HRESULT); property Result: HRESULT read FResult; end; procedure DSCheck(Res: HRESULT); function DSCheckExcl(Res: HRESULT; Excl: array of HRESULT): HRESULT; implementation