MMDSMIX.INT 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  1. {========================================================================}
  2. {= (c) 1995-98 SwiftSoft Ronald Dittrich =}
  3. {========================================================================}
  4. {= All Rights Reserved =}
  5. {========================================================================}
  6. {= D 01099 Dresden = Tel.: +0351-8012255 =}
  7. {= Loewenstr.7a = info@swiftsoft.de =}
  8. {========================================================================}
  9. {= Actual versions on http://www.swiftsoft.de/mmtools.html =}
  10. {========================================================================}
  11. {= This code is for reference purposes only and may not be copied or =}
  12. {= distributed in any format electronic or otherwise except one copy =}
  13. {= for backup purposes. =}
  14. {= =}
  15. {= No Delphi Component Kit or Component individually or in a collection=}
  16. {= subclassed or otherwise from the code in this unit, or associated =}
  17. {= .pas, .dfm, .dcu, .asm or .obj files may be sold or distributed =}
  18. {= without express permission from SwiftSoft. =}
  19. {= =}
  20. {= For more licence informations please refer to the associated =}
  21. {= HelpFile. =}
  22. {========================================================================}
  23. {= $Date: 20.01.1998 - 18:00:00 $ =}
  24. {========================================================================}
  25. unit MMDSMix;
  26. {$I COMPILER.INC}
  27. interface
  28. uses
  29. Windows,
  30. OLE2,
  31. Messages,
  32. SysUtils,
  33. Classes,
  34. Graphics,
  35. Controls,
  36. Dialogs,
  37. Forms,
  38. DsgnIntf,
  39. MMSystem,
  40. MMObj,
  41. MMUtils,
  42. MMDSound,
  43. MMD3DTyp,
  44. MM3D,
  45. MMRegs,
  46. MMWave,
  47. MMPCMSup,
  48. MMACMSup;
  49. type
  50. EMMDSWaveMixError = class(Exception);
  51. TMMDSSpeakerConfig = (scHeadphone,scMono,scQuad,scStereo,scSurround);
  52. TMMDSLevel = (prNormal, prPriority, prExclusive);
  53. TMMDS3DBufferMode = (bmNormal,bmHeadRelative,bmNo3D);
  54. const
  55. defMaxDistance = 1e+09; {? Should be inf}
  56. defMinDistance = 1.0;
  57. defMode = bmNormal;
  58. defPosX = 0; {?}
  59. defPosY = 0; {?}
  60. defPosZ = 0; {?}
  61. defInsideConeAngle = 360;
  62. defOutsideConeAngle = 360;
  63. defConeOrientX = 0;
  64. defConeOrientY = 0;
  65. defConeOrientZ = 1;
  66. defConeOutsideVolume = 0; {?}
  67. defVelX = 0; {?}
  68. defVelY = 0; {?}
  69. defVelZ = 0; {?}
  70. defDistanceFactor = DS3D_DEFAULTDISTANCEFACTOR;
  71. defDopplerFactor = DS3D_DEFAULTDOPPLERFACTOR;
  72. defOrientFrontX = 0;
  73. defOrientFrontY = 0;
  74. defOrientFrontZ = 1;
  75. defOrientTopX = 0;
  76. defOrientTopY = 1;
  77. defOrientTopZ = 0;
  78. defPositionX = 0; {?}
  79. defPositionY = 0; {?}
  80. defPositionZ = 0; {?}
  81. defRollOffFactor = DS3D_DEFAULTROLLOFFFACTOR;
  82. defVelocityX = 0; {?}
  83. defVelocityY = 0; {?}
  84. defVelocityZ = 0; {?}
  85. type
  86. {-- TMMDS3DControl -----------------------------------------------------}
  87. TMMDS3DControl = class(TMMObject)
  88. public
  89. procedure BeginUpdate;
  90. procedure EndUpdate;
  91. published
  92. property Deferred: Boolean read FDeferred write SetDeferred;
  93. end;
  94. {-- TMMDS3DBuffer ------------------------------------------------------}
  95. TMMDS3DBuffer = class(TMMDS3DControl)
  96. public
  97. constructor Create(Loading: Boolean);
  98. destructor Destroy; override;
  99. procedure Assign(Source: TPersistent); override;
  100. published
  101. property MaxDistance: D3DVALUE read GetMaxDistance write SetMaxDistance;
  102. property MinDistance: D3DVALUE read GetMinDistance write SetMinDistance;
  103. property Mode: TMMDS3DBufferMode read GetMode write SetMode default defMode;
  104. property Position: TMMVector3D read GetPosition write SetPosition;
  105. property InsideConeAngle: LongInt read GetInsideConeAngle write SetInsideConeAngle default defInsideConeAngle;
  106. property OutsideConeAngle: LongInt read GetOutsideConeAngle write SetOutsideConeAngle default defOutsideConeAngle;
  107. property ConeOrientation: TMMVector3D read GetConeOrientation write SetConeOrientation;
  108. property ConeOutsideVolume: LongInt read GetConeOutsideVolume write SetConeOutsideVolume default defConeOutsideVolume;
  109. property Velocity: TMMVector3D read GetVelocity write SetVelocity;
  110. end;
  111. {-- TMMDS3DListener ----------------------------------------------------}
  112. TMMDS3DListener = class(TMMDS3DControl)
  113. public
  114. constructor Create(Loading: Boolean);
  115. destructor Destroy; override;
  116. procedure Assign(Source: TPersistent); override;
  117. procedure Commit;
  118. published
  119. property DistanceFactor: D3DVALUE read GetDistanceFactor write SetDistanceFactor;
  120. property DopplerFactor: D3DVALUE read GetDopplerFactor write SetDopplerFactor;
  121. property OrientFront: TMMVector3D read GetOrientFront write SetOrientFront;
  122. property OrientTop: TMMVector3D read GetOrientTop write SetOrientTop;
  123. property Position: TMMVector3D read GetPosition write SetPosition;
  124. property RollOffFactor: D3DVALUE read GetRollOffFactor write SetRollOffFactor;
  125. property Velocity: TMMVector3D read GetVelocity write SetVelocity;
  126. end;
  127. {-- TMMDSSoundBuffer ---------------------------------------------------}
  128. TMMDSSoundBuffer = class(TMMObject)
  129. public
  130. constructor Create; virtual;
  131. property Caps: TDSBCAPS read GetCaps;
  132. property Wave: TMMWave read FWave;
  133. property Name: string read FName;
  134. property BufferSize: Longint read GetBufferSize;
  135. property Playing: Boolean read GetPlaying;
  136. property Paused: Boolean read FPaused;
  137. property Muted: Boolean read FMuted write SetMuted default False;
  138. property Volume: Longint read GetVolume write SetVolume default 0;
  139. property Panning: Longint read GetPanning write SetPanning default 0;
  140. property Frequency: Longint read GetFrequency write SetFrequency default 0;
  141. property Position: Longint read GetPosition write SetPosition default 0;
  142. property Looping: Boolean read GetLooping write SetLooping default False;
  143. end;
  144. {-- TMMDSSoundCaps ----------------------------------------------------}
  145. TMMDSSoundCaps = class(TMMObject)
  146. published
  147. property ContinuousRate: Boolean read FContinuousRate write FBDummy stored False;
  148. property EmulDriver: Boolean read FEmulDriver write FBDummy stored False;
  149. property Certified: Boolean read FCertified write FBDummy stored False;
  150. property Primary16Bit: Boolean read FPrimary16Bit write FBDummy stored False;
  151. property Primary8Bit: Boolean read FPrimary8Bit write FBDummy stored False;
  152. property PrimaryMono: Boolean read FPrimaryMono write FBDummy stored False;
  153. property PrimaryStereo: Boolean read FPrimaryStereo write FBDummy stored False;
  154. property Secondary16Bit: Boolean read FSecondary16Bit write FBDummy stored False;
  155. property Secondary8Bit: Boolean read FSecondary8Bit write FBDummy stored False;
  156. property SecondaryMono: Boolean read FSecondaryMono write FBDummy stored False;
  157. property SecondaryStereo: Boolean read FSecondaryStero write FBDummy stored False;
  158. property MinSecondarySampleRate: DWORD read FMin2Sample write FLDummy stored False;
  159. property MaxSecondarySampleRate: DWORD read FMax2Sample write FLDummy stored False;
  160. property PrimaryBuffers: DWORD read FPrimaryBuffers write FLDummy stored False;
  161. property MaxHWMixingAllBuffers: DWORD read FMaxHWAll write FLDummy stored False;
  162. property MaxHWMixingStaticBuffers: DWORD read FMaxHWStatic write FLDummy stored False;
  163. property MaxHWMixingStreamingBuffers: DWORD read FMaxHWStream write FLDummy stored False;
  164. property FreeHWMixingAllBuffers: DWORD read FFreeHWAlls write FLDummy stored False;
  165. property FreeHWMixingStaticBuffers: DWORD read FFreeHWStatic write FLDummy stored False;
  166. property FreeHWMixingStreamingBuffers: DWORD read FFreeHWStream write FLDummy stored False;
  167. property MaxHW3DAllBuffers: DWORD read FMaxHW3All write FLDummy stored False;
  168. property MaxHW3DStaticBuffers: DWORD read FMaxHW3Static write FLDummy stored False;
  169. property MaxHW3DStreamingBuffers: DWORD read FMaxHW3Stream write FLDummy stored False;
  170. property FreeHW3DAllBuffers: DWORD read FFreeHW3Alls write FLDummy stored False;
  171. property FreeHW3DStaticBuffers: DWORD read FFreeHW3Static write FLDummy stored False;
  172. property FreeHW3DStreamingBuffers: DWORD read FFreeHW3Stream write FLDummy stored False;
  173. property TotalHWMemBytes: DWORD read FTotalHWMemBytes write FLDummy stored False;
  174. property FreeHWMemBytes: DWORD read FFreeHWMemBytes write FLDummy stored False;
  175. property MaxContigFreeHWMemBytes: DWORD read FMaxContigFree write FLDummy stored False;
  176. property UnlockTransferRateHWBuffers: DWORD read FUnlockRate write FLDummy stored False;
  177. property PlayCPUOverheadSWBuffers: DWORD read FPlayCPU write FLDummy stored False;
  178. end;
  179. TMMDSBufferLostEvent = procedure(Sender: TObject; Buffer: TMMDSSoundBuffer; var Abort: Boolean) of object;
  180. TMMDSBufferEndEvent = procedure(Sender: TObject; Buffer: TMMDSSoundBuffer) of object;
  181. {-- TMMDSWaveMixer ----------------------------------------------------}
  182. TMMDSWaveMixer = class(TMMComponent)
  183. public
  184. constructor Create(AOwner: TComponent); override;
  185. destructor Destroy; override;
  186. procedure Open;
  187. procedure Close;
  188. procedure CooperateWith(Handle: THandle);
  189. function AddBuffer(var aName: string; aWave: TMMWave): TMMDSSoundBuffer;
  190. function DuplicateBuffer(var aName: string; Buffer: TMMDSSoundBuffer): TMMDSSoundBuffer;
  191. procedure RemoveBuffer(Buffer: TMMDSSoundBuffer);
  192. procedure PlayBuffer(Buffer: TMMDSSoundBuffer);
  193. procedure PauseBuffer(Buffer: TMMDSSoundBuffer);
  194. procedure StopBuffer(Buffer: TMMDSSoundBuffer);
  195. procedure FreeBuffers;
  196. procedure OpenInDesignTime;
  197. procedure CloseInDesignTime;
  198. property PCMWaveFormat: TPCMWaveFormat read GetPCMWaveFormat write SetPCMWaveFormat;
  199. property Buffer[Index: integer]: TMMDSSoundBuffer read GetBuffer;
  200. property BufferByName[aName: string]: TMMDSSoundBuffer read GetBufferName;
  201. property BufferCount: integer read GetBufferCount;
  202. property NumDevs: integer read GetNumDevs;
  203. property Devices[Index: integer]: PDSDRIVERDESC read GetDevices;
  204. property Muted: Boolean read FMuted write SetMuted default False;
  205. property Volume: Longint read GetVolume write SetVolume default 0;
  206. property Panning: Longint read GetPanning write SetPanning default 0;
  207. property Opened: Boolean read GetOpened;
  208. published
  209. property OnBufferLost: TMMDSBufferLostEvent read FOnBufferLost write FOnBufferLost;
  210. property OnBufferEnd: TMMDSBufferEndEvent read FOnBufferEnd write FOnBufferEnd;
  211. property Level: TMMDSLevel read FLevel write SetLevel default prPriority;
  212. property SoundCaps: TMMDSSoundCaps read GetCaps write SetCaps;
  213. property SpeakerConfiguration: TMMDSSpeakerConfig read GetSpeaker write SetSpeaker default scStereo;
  214. property DeviceID: TMMDeviceID read FDeviceID write SetDeviceID default 0;
  215. property ProductName: String read FProductName write SetProductName stored False;
  216. property BitLength: TMMBits read FBits write SetBits default b8bit;
  217. property SampleRate: Longint read FSampleRate write SetSampleRate default 11025;
  218. property Mode: TMMMode read FMode write SetMode default mMono;
  219. property Use3D: Boolean read FUse3D write SetUse3D default False;
  220. property Sound3D: TMMDS3DListener read F3DListener write Set3DListener;
  221. end;
  222. {-- TMMDSMixChannel ---------------------------------------------------}
  223. TMMDSMixChannel = class(TMMCustomMemoryWave)
  224. public
  225. constructor Create(aOwner: TComponent); override;
  226. destructor Destroy; override;
  227. procedure Init;
  228. procedure Play;
  229. procedure Pause;
  230. procedure Stop;
  231. property SoundBuffer: TMMDSSoundBuffer read FSoundBuffer;
  232. property BufferSize: Longint read GetBufferSize;
  233. property Position: Longint read GetPosition write SetPosition;
  234. property Playing: Boolean read GetPlaying;
  235. {$WARNINGS OFF}
  236. property Paused: Boolean read GetPaused;
  237. {$WARNINGS ON}
  238. published
  239. property OnPlayEnd: TNotifyEvent read FOnPlayEnd write FOnPlayEnd;
  240. property Mixer: TMMDSWaveMixer read FMixer write FMixer;
  241. property Muted: Boolean read GetMuted write SetMuted default False;
  242. property Volume: Longint read GetVolume write SetVolume default 0;
  243. property Panning: Longint read GetPanning write SetPanning default 0;
  244. property Frequency: Longint read GetFrequency write SetFrequency default 0;
  245. property Looping: Boolean read GetLooping write SetLooping default False;
  246. property Sound3D: TMMDS3DBuffer read F3DBuffer write Set3DBuffer;
  247. end;
  248. {-- EDSMixError -------------------------------------------------------}
  249. EDSMixError = class(Exception)
  250. end;
  251. {-- EDirectSoundError -------------------------------------------------}
  252. EDirectSoundError = class(EDSMixError)
  253. private
  254. FResult : HRESULT;
  255. public
  256. constructor CreateRes(Code: HRESULT);
  257. property Result: HRESULT read FResult;
  258. end;
  259. procedure DSCheck(Res: HRESULT);
  260. function DSCheckExcl(Res: HRESULT; Excl: array of HRESULT): HRESULT;
  261. implementation