Rev 1 | Rev 16 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1 | Rev 4 | ||
---|---|---|---|
Line 3... | Line 3... | ||
3 | interface |
3 | interface |
4 | 4 | ||
5 | {$INCLUDE DelphiXcfg.inc} |
5 | {$INCLUDE DelphiXcfg.inc} |
6 | 6 | ||
7 | uses |
7 | uses |
8 | Windows, Messages, SysUtils, Classes, Controls, Forms, ExtCtrls, MMSystem, |
8 | Windows, Messages, SysUtils, Classes, Controls, Forms, ExtCtrls, MMSystem, ActiveX, |
- | 9 | DXClass, DXWave, D3DUtils, {$IFDEF VER17UP} Types, {$ENDIF} |
|
- | 10 | {$IFDEF StandardDX} |
|
9 | DirectX, DXClass, Wave; |
11 | DirectSound, DirectMusic; |
- | 12 | {$ELSE} |
|
- | 13 | DirectX; |
|
- | 14 | {$ENDIF} |
|
10 | 15 | ||
11 | type |
16 | type |
12 | 17 | ||
13 | { EDirectSoundError } |
18 | { EDirectSoundError } |
14 | 19 | ||
Line 28... | Line 33... | ||
28 | FStickyFocus: Boolean; |
33 | FStickyFocus: Boolean; |
29 | function GetBuffer(Index: Integer): TDirectSoundBuffer; |
34 | function GetBuffer(Index: Integer): TDirectSoundBuffer; |
30 | function GetBufferCount: Integer; |
35 | function GetBufferCount: Integer; |
31 | function GetIDSound: IDirectSound; |
36 | function GetIDSound: IDirectSound; |
32 | function GetISound: IDirectSound; |
37 | function GetISound: IDirectSound; |
33 | protected |
38 | protected |
34 | procedure CheckBuffer(Buffer: TDirectSoundBuffer); |
39 | procedure CheckBuffer(Buffer: TDirectSoundBuffer); |
35 | procedure DoRestoreBuffer; virtual; |
40 | procedure DoRestoreBuffer; virtual; |
36 | public |
41 | public |
37 | constructor Create(GUID: PGUID); |
42 | constructor Create(GUID: PGUID); |
38 | destructor Destroy; override; |
43 | destructor Destroy; override; |
Line 41... | Line 46... | ||
41 | property Buffers[Index: Integer]: TDirectSoundBuffer read GetBuffer; |
46 | property Buffers[Index: Integer]: TDirectSoundBuffer read GetBuffer; |
42 | property IDSound: IDirectSound read GetIDSound; |
47 | property IDSound: IDirectSound read GetIDSound; |
43 | property ISound: IDirectSound read GetISound; |
48 | property ISound: IDirectSound read GetISound; |
44 | end; |
49 | end; |
45 | 50 | ||
- | 51 | { TD3DSParams } |
|
- | 52 | ||
- | 53 | TConeAngle = record |
|
- | 54 | Inside,Outside:DWord; |
|
- | 55 | end; |
|
- | 56 | TD3DSParams = class |
|
- | 57 | private |
|
- | 58 | FOwner: TDirectSoundBuffer; |
|
- | 59 | ||
- | 60 | FDsb: TDS3DBUFFER; |
|
- | 61 | ||
- | 62 | function GetPosition: TD3DVector; |
|
- | 63 | function GetVelocity: TD3DVector; |
|
- | 64 | function GetConeOrientation: TD3DVector; |
|
- | 65 | function GetConeAngle: TConeAngle; |
|
- | 66 | function GetConeOutsideVolume: Integer; |
|
- | 67 | function GetMinDistance: TD3DValue; |
|
- | 68 | function GetMaxDistance: TD3DValue; |
|
- | 69 | function GetRaw: TDS3DBuffer; |
|
- | 70 | ||
- | 71 | procedure SetPosition(const v: TD3DVector); |
|
- | 72 | procedure SetVelocity(const v: TD3DVector); |
|
- | 73 | procedure SetConeOrientation(const v: TD3DVector); |
|
- | 74 | procedure SetConeAngle(const v: TConeAngle); |
|
- | 75 | procedure SetConeOutsideVolume(const v: Integer); |
|
- | 76 | procedure SetMinDistance(const v: TD3DValue); |
|
- | 77 | procedure SetMaxDistance(const v: TD3DValue); |
|
- | 78 | procedure SetRaw(const v: TDS3DBuffer); |
|
- | 79 | ||
- | 80 | function CheckValidity: Boolean; |
|
- | 81 | public |
|
- | 82 | constructor Create(Owner: TDirectSoundBuffer); |
|
- | 83 | destructor Destroy; override; |
|
- | 84 | property Position: TD3DVector read getPosition write setPosition; |
|
- | 85 | property Velocity: TD3DVector read getVelocity write setVelocity; |
|
- | 86 | property ConeOrientation: TD3DVector read getConeOrientation write setConeOrientation; |
|
- | 87 | property ConeAngle: TConeAngle read getConeAngle write setConeAngle; |
|
- | 88 | property ConeOutsideVolume: Integer read getConeOutsideVolume write setConeOutsideVolume; |
|
- | 89 | property MinDistance: TD3DValue read getMinDistance write setMinDistance; |
|
- | 90 | property MaxDistance: TD3DValue read getMaxDistance write setMaxDistance; |
|
- | 91 | property RawParams: TDS3DBuffer read getRaw write setRaw; |
|
- | 92 | procedure Assign(Prms: TD3DSParams); |
|
- | 93 | end; |
|
- | 94 | ||
46 | { TDirectSoundBuffer } |
95 | { TDirectSoundBuffer } |
47 | 96 | ||
48 | TDirectSoundBuffer = class(TDirectX) |
97 | TDirectSoundBuffer = class(TDirectX) |
49 | private |
98 | private |
50 | FDSound: TDirectSound; |
99 | FDSound: TDirectSound; |
51 | FIDSBuffer: IDirectSoundBuffer; |
100 | FIDSBuffer: IDirectSoundBuffer; |
- | 101 | FIDS3DBuffer:IDirectSound3DBuffer; |
|
- | 102 | FD3DSParams: TD3DSParams; |
|
52 | FCaps: TDSBCaps; |
103 | FCaps: TDSBCaps; |
53 | FFormat: PWaveFormatEx; |
104 | FFormat: PWaveFormatEx; |
54 | FFormatSize: Integer; |
105 | FFormatSize: Integer; |
55 | FLockAudioPtr1, FLockAudioPtr2: array[0..0] of Pointer; |
106 | FLockAudioPtr1, FLockAudioPtr2: array[0..0] of Pointer; |
56 | FLockAudioSize1, FLockAudioSize2: array[0..0] of DWORD; |
107 | FLockAudioSize1, FLockAudioSize2: array[0..0] of DWORD; |
57 | FLockCount: Integer; |
108 | FLockCount: Integer; |
- | 109 | FIsD3D: Boolean; |
|
58 | function GetBitCount: Longint; |
110 | function GetBitCount: Longint; |
59 | function GetFormat: PWaveFormatEx; |
111 | function GetFormat: PWaveFormatEx; |
60 | function GetFrequency: Integer; |
112 | function GetFrequency: Integer; |
61 | function GetIDSBuffer: IDirectSoundBuffer; |
113 | function GetIDSBuffer: IDirectSoundBuffer; |
62 | function GetIBuffer: IDirectSoundBuffer; |
114 | function GetIBuffer: IDirectSoundBuffer; |
Line 69... | Line 121... | ||
69 | procedure SetFrequency(Value: Integer); |
121 | procedure SetFrequency(Value: Integer); |
70 | procedure SetIDSBuffer(Value: IDirectSoundBuffer); |
122 | procedure SetIDSBuffer(Value: IDirectSoundBuffer); |
71 | procedure SetPan(Value: Integer); |
123 | procedure SetPan(Value: Integer); |
72 | procedure SetPosition(Value: Longint); |
124 | procedure SetPosition(Value: Longint); |
73 | procedure SetVolume(Value: Integer); |
125 | procedure SetVolume(Value: Integer); |
- | 126 | function GetIDS3DBuffer: IDirectSound3DBuffer; |
|
- | 127 | procedure SetIDS3DBuffer(const Value: IDirectSound3DBuffer); |
|
- | 128 | procedure SetD3DSParams(const Value: TD3DSParams); |
|
74 | protected |
129 | protected |
75 | procedure Check; override; |
130 | procedure Check; override; |
76 | public |
131 | public |
77 | constructor Create(ADirectSound: TDirectSound); |
132 | constructor Create(ADirectSound: TDirectSound); |
78 | destructor Destroy; override; |
133 | destructor Destroy; override; |
Line 84... | Line 139... | ||
84 | procedure LoadFromStream(Stream: TStream); |
139 | procedure LoadFromStream(Stream: TStream); |
85 | procedure LoadFromWave(Wave: TWave); |
140 | procedure LoadFromWave(Wave: TWave); |
86 | function Lock(LockPosition, LockSize: Longint; |
141 | function Lock(LockPosition, LockSize: Longint; |
87 | var AudioPtr1: Pointer; var AudioSize1: Longint; |
142 | var AudioPtr1: Pointer; var AudioSize1: Longint; |
88 | var AudioPtr2: Pointer; var AudioSize2: Longint): Boolean; |
143 | var AudioPtr2: Pointer; var AudioSize2: Longint): Boolean; |
89 | function Play(Loop: Boolean{$IFNDEF VER100}=False{$ENDIF}): Boolean; |
144 | function Play(Loop: Boolean{$IFNDEF VER100} = False{$ENDIF}): Boolean; |
90 | function Restore: Boolean; |
145 | function Restore: Boolean; |
91 | function SetFormat(const Format: TWaveFormatEx): Boolean; |
146 | function SetFormat(const Format: TWaveFormatEx): Boolean; |
92 | procedure SetSize(const Format: TWaveFormatEx; Size: Integer); |
147 | procedure SetSize(const Format: TWaveFormatEx; Size: Integer; D3D: Boolean {$IFNDEF VER100}= False{$ENDIF}); |
93 | procedure Stop; |
148 | procedure Stop; |
94 | procedure UnLock; |
149 | procedure UnLock; |
95 | property BitCount: Longint read GetBitCount; |
150 | property BitCount: Longint read GetBitCount; |
96 | property DSound: TDirectSound read FDSound; |
151 | property DSound: TDirectSound read FDSound; |
97 | property Format: PWaveFormatEx read GetFormat; |
152 | property Format: PWaveFormatEx read GetFormat; |
98 | property FormatSize: Integer read FFormatSize; |
153 | property FormatSize: Integer read FFormatSize; |
99 | property Frequency: Integer read GetFrequency write SetFrequency; |
154 | property Frequency: Integer read GetFrequency write SetFrequency; |
100 | property IBuffer: IDirectSoundBuffer read GetIBuffer; |
155 | property IBuffer: IDirectSoundBuffer read GetIBuffer; |
101 | property IDSBuffer: IDirectSoundBuffer read GetIDSBuffer write SetIDSBuffer; |
156 | property IDSBuffer: IDirectSoundBuffer read GetIDSBuffer write SetIDSBuffer; |
- | 157 | property IDS3DBuffer: IDirectSound3DBuffer read GetIDS3DBuffer write SetIDS3DBuffer; |
|
102 | property Playing: Boolean read GetPlaying; |
158 | property Playing: Boolean read GetPlaying; |
103 | property Pan: Integer read GetPan write SetPan; |
159 | property Pan: Integer read GetPan write SetPan; |
- | 160 | property D3DSParams: TD3DSParams read FD3DSParams write SetD3DSParams; |
|
- | 161 | property IsD3D: Boolean read FIsD3D write FIsD3D default False; |
|
104 | property Position: Longint read GetPosition write SetPosition; |
162 | property Position: Longint read GetPosition write SetPosition; |
105 | property Size: Integer read GetSize; |
163 | property Size: Integer read GetSize; |
106 | property Volume: Integer read GetVolume write SetVolume; |
164 | property Volume: Integer read GetVolume write SetVolume; |
107 | end; |
165 | end; |
108 | 166 | ||
Line 168... | Line 226... | ||
168 | property Looped: Boolean read FLooped write SetLooped; |
226 | property Looped: Boolean read FLooped write SetLooped; |
169 | property Size: Integer read GetSize; |
227 | property Size: Integer read GetSize; |
170 | property Volume: Integer read GetVolume write SetVolume; |
228 | property Volume: Integer read GetVolume write SetVolume; |
171 | property WaveStream: TCustomWaveStream read FWaveStream write SetWaveStream; |
229 | property WaveStream: TCustomWaveStream read FWaveStream write SetWaveStream; |
172 | end; |
230 | end; |
173 | 231 | ||
174 | { TAudioFileStream } |
232 | { TAudioFileStream } |
175 | 233 | ||
176 | TAudioFileStream = class(TAudioStream) |
234 | TAudioFileStream = class(TAudioStream) |
177 | private |
235 | private |
178 | FFileName: string; |
236 | FFileName: string; |
Line 375... | Line 433... | ||
375 | procedure SetLooped(Value: Boolean); |
433 | procedure SetLooped(Value: Boolean); |
376 | procedure SetMaxPlayingCount(Value: Integer); |
434 | procedure SetMaxPlayingCount(Value: Integer); |
377 | procedure SetPan(Value: Integer); |
435 | procedure SetPan(Value: Integer); |
378 | procedure SetVolume(Value: Integer); |
436 | procedure SetVolume(Value: Integer); |
379 | procedure SetWave(Value: TWave); |
437 | procedure SetWave(Value: TWave); |
- | 438 | protected |
|
- | 439 | function GetPlaying: boolean; |
|
380 | public |
440 | public |
381 | constructor Create(Collection: TCollection); override; |
441 | constructor Create(Collection: TCollection); override; |
382 | destructor Destroy; override; |
442 | destructor Destroy; override; |
383 | procedure Assign(Source: TPersistent); override; |
443 | procedure Assign(Source: TPersistent); override; |
384 | procedure Play(Wait: Boolean); |
444 | procedure Play(Wait: Boolean); |
Line 387... | Line 447... | ||
387 | property Frequency: Integer read FFrequency write SetFrequency; |
447 | property Frequency: Integer read FFrequency write SetFrequency; |
388 | property Initialized: Boolean read FInitialized; |
448 | property Initialized: Boolean read FInitialized; |
389 | property Pan: Integer read FPan write SetPan; |
449 | property Pan: Integer read FPan write SetPan; |
390 | property Volume: Integer read FVolume write SetVolume; |
450 | property Volume: Integer read FVolume write SetVolume; |
391 | property WaveCollection: TWaveCollection read GetWaveCollection; |
451 | property WaveCollection: TWaveCollection read GetWaveCollection; |
- | 452 | ||
- | 453 | property Playing: boolean read GetPlaying; |
|
392 | published |
454 | published |
393 | property Looped: Boolean read FLooped write SetLooped; |
455 | property Looped: Boolean read FLooped write SetLooped; |
394 | property MaxPlayingCount: Integer read FMaxPlayingCount write SetMaxPlayingCount; |
456 | property MaxPlayingCount: Integer read FMaxPlayingCount write SetMaxPlayingCount; |
395 | property Wave: TWave read FWave write SetWave; |
457 | property Wave: TWave read FWave write SetWave; |
396 | end; |
458 | end; |
Line 443... | Line 505... | ||
443 | published |
505 | published |
444 | property DXSound; |
506 | property DXSound; |
445 | property Items; |
507 | property Items; |
446 | end; |
508 | end; |
447 | 509 | ||
- | 510 | { EDXMusicError } |
|
- | 511 | ||
- | 512 | EDXMusicError = class(Exception); |
|
- | 513 | ||
- | 514 | TMusicListCollection = class; |
|
- | 515 | ||
- | 516 | { TMusicListCollectionItem } |
|
- | 517 | ||
- | 518 | TMusicDataProp = class(TPersistent) |
|
- | 519 | private |
|
- | 520 | FMusicData: string; |
|
- | 521 | FMidiname: string; |
|
- | 522 | function GetMusicData: string; |
|
- | 523 | procedure SetMusicData(const Value: string); |
|
- | 524 | protected |
|
- | 525 | procedure DefineProperties(Filer: TFiler); override; |
|
- | 526 | procedure ReadMidiData(Stream: TStream); |
|
- | 527 | procedure WriteMidiData(Stream: TStream); |
|
- | 528 | public |
|
- | 529 | property MusicData: string read GetMusicData write SetMusicData; |
|
- | 530 | published |
|
- | 531 | property MidiName: string read FMidiname write FMidiname; |
|
- | 532 | end; |
|
- | 533 | ||
- | 534 | TMusicListCollectionItem = class(THashCollectionItem) |
|
- | 535 | private |
|
- | 536 | { Private declarations } |
|
- | 537 | FDirectMusicPerformance: IDirectMusicPerformance; |
|
- | 538 | FDirectSound: IDirectSound; |
|
- | 539 | FDirectMusic: IDirectMusic; |
|
- | 540 | FDirectMusicLoader: IDirectMusicLoader; |
|
- | 541 | FDirectMusicSegment: IDirectMusicSegment; |
|
- | 542 | FMusicObjDesc: TDMus_ObjectDesc; |
|
- | 543 | FDirectMusicSegmentState: IDirectMusicSegmentState; |
|
- | 544 | FRepeats: Cardinal; |
|
- | 545 | FStartpoint: Integer; |
|
- | 546 | FDuration: Integer; |
|
- | 547 | // startpoint props in seconds these used to hold millisecond value |
|
- | 548 | FActualDuration: Integer; |
|
- | 549 | FActualStartPoint: Integer; |
|
- | 550 | FIsInitialized: Boolean; |
|
- | 551 | FMusicDataProp: TMusicDataProp; |
|
- | 552 | procedure SetDuration(const Value: integer); |
|
- | 553 | procedure SetRepeats(const Value: Cardinal); |
|
- | 554 | procedure SetStartPoint(const Value: integer); |
|
- | 555 | function GetMusicListCollection: TMusicListCollection; |
|
- | 556 | protected |
|
- | 557 | function GetDisplayName: string; override; |
|
- | 558 | public |
|
- | 559 | constructor Create(Collection: TCollection); override; |
|
- | 560 | destructor Destroy; override; |
|
- | 561 | function Size: Integer; |
|
- | 562 | procedure Play; |
|
- | 563 | function IsPlaying: Boolean; |
|
- | 564 | procedure Stop; |
|
- | 565 | procedure Load; |
|
- | 566 | procedure Init; |
|
- | 567 | procedure LoadFromFile(const MidiFileName: string); |
|
- | 568 | procedure SaveToFile(const MidiFileName: string); |
|
- | 569 | property MusicCollection: TMusicListCollection read GetMusicListCollection; |
|
- | 570 | property IsInitialized: Boolean read FIsInitialized write FIsInitialized; |
|
- | 571 | published |
|
- | 572 | property Name; |
|
- | 573 | property Repeats: Cardinal read Frepeats write SetRepeats; |
|
- | 574 | property Duration: integer read FDuration write SetDuration; |
|
- | 575 | property StartPoint: integer read FStartPoint write SetStartPoint; |
|
- | 576 | property Midi: TMusicDataProp read FMusicDataProp write FMusicDataProp; |
|
- | 577 | end; |
|
- | 578 | ||
- | 579 | { TMusicListCollection } |
|
- | 580 | ||
- | 581 | TMusicListCollection = class(THashCollection) |
|
- | 582 | private |
|
- | 583 | FOwner: TPersistent; |
|
- | 584 | FDirectSound: IDirectSound; |
|
- | 585 | protected |
|
- | 586 | function GetItem(Index: Integer): TMusicListCollectionItem; |
|
- | 587 | procedure SetItem(Index: Integer; Value: TMusicListCollectionItem); |
|
- | 588 | procedure Update(Item: TCollectionItem); override; |
|
- | 589 | function GetOwner: TPersistent; override; |
|
- | 590 | public |
|
- | 591 | constructor Create(AOwner: TComponent); |
|
- | 592 | function Add: TMusicListCollectionItem; |
|
- | 593 | function Find(const Name: string): TMusicListCollectionItem; |
|
- | 594 | procedure Restore; |
|
- | 595 | procedure LoadFromFile(const FileName: string); |
|
- | 596 | procedure LoadFromStream(Stream: TStream); |
|
- | 597 | procedure SaveToFile(const FileName: string); |
|
- | 598 | procedure SaveToStream(Stream: TStream); |
|
- | 599 | {$IFDEF VER4UP} |
|
- | 600 | function Insert(Index: Integer): TMusicListCollectionItem; |
|
- | 601 | {$ENDIF} |
|
- | 602 | property Items[Index: Integer]: TMusicListCollectionItem read GetItem write SetItem; |
|
- | 603 | published |
|
- | 604 | end; |
|
- | 605 | ||
- | 606 | { TDXMusic } |
|
- | 607 | ||
- | 608 | TDXMusic = class(TComponent) |
|
- | 609 | private |
|
- | 610 | FDXSound: TDXSound; |
|
- | 611 | FMidis: TMusicListCollection; |
|
- | 612 | procedure SetMidis(const value: TMusicListCollection); |
|
- | 613 | procedure SetDXSound(const Value: TDXSound); |
|
- | 614 | public |
|
- | 615 | constructor Create(AOwner: TComponent); override; |
|
- | 616 | destructor Destroy; override; |
|
- | 617 | published |
|
- | 618 | property DXSound: TDXSound read FDXSound write SetDXSound; |
|
- | 619 | property Midis: TMusicListCollection read FMidis write SetMidis; |
|
- | 620 | end; |
|
- | 621 | ||
448 | implementation |
622 | implementation |
449 | 623 | ||
450 | uses DXConsts; |
624 | uses DXConsts; |
451 | 625 | ||
- | 626 | const |
|
- | 627 | dm_OK = 0; |
|
- | 628 | ||
452 | function DXDirectSoundCreate(lpGUID: PGUID; out lpDS: IDirectSound; |
629 | function DXDirectSoundCreate(lpGUID: PGUID; out lpDS: IDirectSound; |
453 | pUnkOuter: IUnknown): HRESULT; |
630 | pUnkOuter: IUnknown): HRESULT; |
454 | type |
631 | type |
455 | TDirectSoundCreate = function(lpGUID: PGUID; out lplpDD: IDirectSound; |
632 | TDirectSoundCreate = function(lpGUID: PGUID; out lplpDD: IDirectSound; |
456 | pUnkOuter: IUnknown): HRESULT; stdcall; |
633 | pUnkOuter: IUnknown): HRESULT; stdcall; |
Line 458... | Line 635... | ||
458 | Result := TDirectSoundCreate(DXLoadLibrary('DSound.dll', 'DirectSoundCreate')) |
635 | Result := TDirectSoundCreate(DXLoadLibrary('DSound.dll', 'DirectSoundCreate')) |
459 | (lpGUID, lpDS, pUnkOuter); |
636 | (lpGUID, lpDS, pUnkOuter); |
460 | end; |
637 | end; |
461 | 638 | ||
462 | function DXDirectSoundEnumerate(lpCallback: TDSEnumCallbackA; |
639 | function DXDirectSoundEnumerate(lpCallback: TDSEnumCallbackA; |
463 | lpContext: Pointer): HRESULT; |
640 | lpContext: Pointer): HRESULT; |
464 | type |
641 | type |
465 | TDirectSoundEnumerate = function(lpCallback: TDSEnumCallbackA; |
642 | TDirectSoundEnumerate = function(lpCallback: TDSEnumCallbackA; |
466 | lpContext: Pointer): HRESULT; stdcall; |
643 | lpContext: Pointer): HRESULT; stdcall; |
467 | begin |
644 | begin |
468 | Result := TDirectSoundEnumerate(DXLoadLibrary('DSound.dll', 'DirectSoundEnumerateA')) |
645 | Result := TDirectSoundEnumerate(DXLoadLibrary('DSound.dll', 'DirectSoundEnumerateA')) |
Line 482... | Line 659... | ||
482 | raise EDirectXError.Create(SSinceDirectX5); |
659 | raise EDirectXError.Create(SSinceDirectX5); |
483 | end; |
660 | end; |
484 | end; |
661 | end; |
485 | 662 | ||
486 | function DXDirectSoundCaptureEnumerate(lpCallback: TDSEnumCallbackA; |
663 | function DXDirectSoundCaptureEnumerate(lpCallback: TDSEnumCallbackA; |
487 | lpContext: Pointer): HRESULT; |
664 | lpContext: Pointer): HRESULT; |
488 | type |
665 | type |
489 | TDirectSoundCaptureEnumerate = function(lpCallback: TDSEnumCallbackA; |
666 | TDirectSoundCaptureEnumerate = function(lpCallback: TDSEnumCallbackA; |
490 | lpContext: Pointer): HRESULT; stdcall; |
667 | lpContext: Pointer): HRESULT; stdcall; |
491 | begin |
668 | begin |
492 | try |
669 | try |
Line 499... | Line 676... | ||
499 | 676 | ||
500 | var |
677 | var |
501 | DirectSoundDrivers: TDirectXDrivers; |
678 | DirectSoundDrivers: TDirectXDrivers; |
502 | DirectSoundCaptureDrivers: TDirectXDrivers; |
679 | DirectSoundCaptureDrivers: TDirectXDrivers; |
503 | 680 | ||
504 | function EnumDirectSoundDrivers_DSENUMCALLBACK(lpGuid: PGUID; lpstrDescription: LPCSTR; |
681 | function EnumDirectSoundDrivers_DSENUMCALLBACK(lpGuid: PGUID; lpstrDescription: {$IFDEF UNICODE}LPCTSTR{$ELSE}LPCSTR{$ENDIF}; |
505 | lpstrModule: LPCSTR; lpContext: Pointer): BOOL; stdcall; |
682 | lpstrModule: {$IFDEF UNICODE}LPCTSTR{$ELSE}LPCSTR{$ENDIF}; lpContext: Pointer): BOOL; stdcall; |
506 | begin |
683 | begin |
507 | Result := True; |
684 | Result := True; |
508 | with TDirectXDriver.Create(TDirectXDrivers(lpContext)) do |
685 | with TDirectXDriver.Create(TDirectXDrivers(lpContext)) do |
509 | begin |
686 | begin |
510 | Guid := lpGuid; |
687 | Guid := lpGuid; |
Line 513... | Line 690... | ||
513 | end; |
690 | end; |
514 | end; |
691 | end; |
515 | 692 | ||
516 | function EnumDirectSoundDrivers: TDirectXDrivers; |
693 | function EnumDirectSoundDrivers: TDirectXDrivers; |
517 | begin |
694 | begin |
518 | if DirectSoundDrivers=nil then |
695 | if DirectSoundDrivers = nil then |
519 | begin |
696 | begin |
520 | DirectSoundDrivers := TDirectXDrivers.Create; |
697 | DirectSoundDrivers := TDirectXDrivers.Create; |
521 | try |
698 | try |
522 | DXDirectSoundEnumerate(@EnumDirectSoundDrivers_DSENUMCALLBACK, DirectSoundDrivers); |
699 | DXDirectSoundEnumerate(@EnumDirectSoundDrivers_DSENUMCALLBACK, DirectSoundDrivers); |
523 | except |
700 | except |
Line 529... | Line 706... | ||
529 | Result := DirectSoundDrivers; |
706 | Result := DirectSoundDrivers; |
530 | end; |
707 | end; |
531 | 708 | ||
532 | function EnumDirectSoundCaptureDrivers: TDirectXDrivers; |
709 | function EnumDirectSoundCaptureDrivers: TDirectXDrivers; |
533 | begin |
710 | begin |
534 | if DirectSoundCaptureDrivers=nil then |
711 | if DirectSoundCaptureDrivers = nil then |
535 | begin |
712 | begin |
536 | DirectSoundCaptureDrivers := TDirectXDrivers.Create; |
713 | DirectSoundCaptureDrivers := TDirectXDrivers.Create; |
537 | try |
714 | try |
538 | DXDirectSoundCaptureEnumerate(@EnumDirectSoundDrivers_DSENUMCALLBACK, DirectSoundCaptureDrivers); |
715 | DXDirectSoundCaptureEnumerate(@EnumDirectSoundDrivers_DSENUMCALLBACK, DirectSoundCaptureDrivers); |
539 | except |
716 | except |
Line 550... | Line 727... | ||
550 | constructor TDirectSound.Create(GUID: PGUID); |
727 | constructor TDirectSound.Create(GUID: PGUID); |
551 | begin |
728 | begin |
552 | inherited Create; |
729 | inherited Create; |
553 | FBufferList := TList.Create; |
730 | FBufferList := TList.Create; |
554 | 731 | ||
555 | if DXDirectSoundCreate(GUID, FIDSound, nil)<>DS_OK then |
732 | if DXDirectSoundCreate(GUID, FIDSound, nil) <> DS_OK then |
556 | raise EDirectSoundError.CreateFmt(SCannotInitialized, [SDirectSound]); |
733 | raise EDirectSoundError.CreateFmt(SCannotInitialized, [SDirectSound]); |
557 | end; |
734 | end; |
558 | 735 | ||
559 | destructor TDirectSound.Destroy; |
736 | destructor TDirectSound.Destroy; |
560 | begin |
737 | begin |
561 | while BufferCount>0 do |
738 | while BufferCount > 0 do |
562 | Buffers[BufferCount-1].Free; |
739 | Buffers[BufferCount - 1].Free; |
563 | FBufferList.Free; |
740 | FBufferList.Free; |
564 | 741 | ||
565 | FIDSound := nil; |
742 | FIDSound := nil; |
566 | inherited Destroy; |
743 | inherited Destroy; |
567 | end; |
744 | end; |
Line 603... | Line 780... | ||
603 | Result := FBufferList.Count; |
780 | Result := FBufferList.Count; |
604 | end; |
781 | end; |
605 | 782 | ||
606 | function TDirectSound.GetIDSound: IDirectSound; |
783 | function TDirectSound.GetIDSound: IDirectSound; |
607 | begin |
784 | begin |
608 | if Self<>nil then |
785 | if Self <> nil then |
609 | Result := FIDSound |
786 | Result := FIDSound |
610 | else |
787 | else |
611 | Result := nil; |
788 | Result := nil; |
612 | end; |
789 | end; |
613 | 790 | ||
614 | function TDirectSound.GetISound: IDirectSound; |
791 | function TDirectSound.GetISound: IDirectSound; |
615 | begin |
792 | begin |
616 | Result := IDSound; |
793 | Result := IDSound; |
617 | if Result=nil then |
794 | if Result = nil then |
618 | raise EDirectSoundError.CreateFmt(SNotMade, ['IDirectSound']); |
795 | raise EDirectSoundError.CreateFmt(SNotMade, ['IDirectSound']); |
619 | end; |
796 | end; |
620 | 797 | ||
621 | { TDirectSoundBuffer } |
798 | { TDirectSoundBuffer } |
622 | 799 | ||
623 | constructor TDirectSoundBuffer.Create(ADirectSound: TDirectSound); |
800 | constructor TDirectSoundBuffer.Create(ADirectSound: TDirectSound); |
624 | begin |
801 | begin |
625 | inherited Create; |
802 | inherited Create; |
- | 803 | FIsD3D := False; |
|
626 | FDSound := ADirectSound; |
804 | FDSound := ADirectSound; |
- | 805 | FIDS3DBuffer := nil; |
|
627 | FDSound.FBufferList.Add(Self); |
806 | FDSound.FBufferList.Add(Self); |
628 | end; |
807 | end; |
629 | 808 | ||
630 | destructor TDirectSoundBuffer.Destroy; |
809 | destructor TDirectSoundBuffer.Destroy; |
631 | begin |
810 | begin |
632 | IDSBuffer := nil; |
811 | IDSBuffer := nil; |
- | 812 | IDS3DBuffer := nil; |
|
633 | FDSound.FBufferList.Remove(Self); |
813 | FDSound.FBufferList.Remove(Self); |
634 | inherited Destroy; |
814 | inherited Destroy; |
635 | end; |
815 | end; |
636 | 816 | ||
637 | procedure TDirectSoundBuffer.Assign(Source: TPersistent); |
817 | procedure TDirectSoundBuffer.Assign(Source: TPersistent); |
638 | var |
818 | var |
639 | TempBuffer: IDirectSoundBuffer; |
819 | TempBuffer: IDirectSoundBuffer; |
640 | begin |
820 | begin |
641 | if Source=nil then |
821 | if Source = nil then |
642 | IDSBuffer := nil |
822 | IDSBuffer := nil |
- | 823 | else |
|
643 | else if Source is TWave then |
824 | if Source is TWave then |
644 | LoadFromWave(TWave(Source)) |
825 | LoadFromWave(TWave(Source)) |
- | 826 | else |
|
645 | else if Source is TDirectSoundBuffer then |
827 | if Source is TDirectSoundBuffer then |
646 | begin |
828 | begin |
647 | if TDirectSoundBuffer(Source).IDSBuffer=nil then |
829 | if TDirectSoundBuffer(Source).IDSBuffer = nil then |
648 | IDSBuffer := nil |
830 | IDSBuffer := nil |
- | 831 | else |
|
649 | else begin |
832 | begin |
650 | FDSound.DXResult := FDSound.ISound.DuplicateSoundBuffer(TDirectSoundBuffer(Source).IDSBuffer, |
833 | FDSound.DXResult := FDSound.ISound.DuplicateSoundBuffer(TDirectSoundBuffer(Source).IDSBuffer, TempBuffer); |
651 | TempBuffer); |
- | |
652 | if FDSound.DXResult=0 then |
834 | if FDSound.DXResult = DS_OK then |
653 | begin |
835 | begin |
654 | IDSBuffer := TempBuffer; |
836 | IDSBuffer := TempBuffer; |
655 | end; |
837 | end; |
656 | end; |
838 | end; |
- | 839 | ||
- | 840 | if FIsD3D then |
|
- | 841 | if TDirectSoundBuffer(Source).IDS3DBuffer = nil then |
|
- | 842 | IDS3DBuffer := nil |
|
657 | end else |
843 | else |
- | 844 | begin |
|
- | 845 | FDSound.DXResult := FDSound.ISound.QueryInterface(IID_IDirectSound3DBuffer, FIDS3DBuffer); |
|
- | 846 | if FDSound.DXResult = DS_OK then |
|
- | 847 | FD3DSParams := TDirectSoundBuffer(Source).FD3DSParams; |
|
- | 848 | end; |
|
- | 849 | ||
- | 850 | end |
|
- | 851 | else |
|
658 | inherited Assign(Source); |
852 | inherited Assign(Source); |
659 | end; |
853 | end; |
660 | 854 | ||
661 | procedure TDirectSoundBuffer.Check; |
855 | procedure TDirectSoundBuffer.Check; |
662 | begin |
856 | begin |
Line 669... | Line 863... | ||
669 | begin |
863 | begin |
670 | IDSBuffer := nil; |
864 | IDSBuffer := nil; |
671 | 865 | ||
672 | FDSound.DXResult := FDSound.ISound.CreateSoundBuffer(BufferDesc, TempBuffer, nil); |
866 | FDSound.DXResult := FDSound.ISound.CreateSoundBuffer(BufferDesc, TempBuffer, nil); |
673 | FDXResult := FDSound.DXResult; |
867 | FDXResult := FDSound.DXResult; |
674 | Result := DXResult=DS_OK; |
868 | Result := DXResult = DS_OK; |
675 | if Result then |
869 | if Result then |
676 | IDSBuffer := TempBuffer; |
870 | IDSBuffer := TempBuffer; |
677 | end; |
871 | end; |
678 | 872 | ||
679 | function TDirectSoundBuffer.GetBitCount: Longint; |
873 | function TDirectSoundBuffer.GetBitCount: Longint; |
Line 690... | Line 884... | ||
690 | function TDirectSoundBuffer.GetFrequency: Integer; |
884 | function TDirectSoundBuffer.GetFrequency: Integer; |
691 | begin |
885 | begin |
692 | DXResult := IBuffer.GetFrequency(DWORD(Result)); |
886 | DXResult := IBuffer.GetFrequency(DWORD(Result)); |
693 | end; |
887 | end; |
694 | 888 | ||
- | 889 | function TDirectSoundBuffer.GetIDS3DBuffer: IDirectSound3DBuffer; |
|
- | 890 | begin |
|
- | 891 | if Self <> nil then |
|
- | 892 | Result := FIDS3DBuffer |
|
- | 893 | else |
|
- | 894 | Result := nil; |
|
- | 895 | end; |
|
- | 896 | ||
695 | function TDirectSoundBuffer.GetIDSBuffer: IDirectSoundBuffer; |
897 | function TDirectSoundBuffer.GetIDSBuffer: IDirectSoundBuffer; |
696 | begin |
898 | begin |
697 | if Self<>nil then |
899 | if Self <> nil then |
698 | Result := FIDSBuffer |
900 | Result := FIDSBuffer |
699 | else |
901 | else |
700 | Result := nil; |
902 | Result := nil; |
701 | end; |
903 | end; |
702 | 904 | ||
703 | function TDirectSoundBuffer.GetIBuffer: IDirectSoundBuffer; |
905 | function TDirectSoundBuffer.GetIBuffer: IDirectSoundBuffer; |
704 | begin |
906 | begin |
705 | Result := IDSBuffer; |
907 | Result := IDSBuffer; |
706 | if Result=nil then |
908 | if Result = nil then |
707 | raise EDirectSoundBufferError.CreateFmt(SNotMade, ['IDirectSoundBuffer']); |
909 | raise EDirectSoundBufferError.CreateFmt(SNotMade, ['IDirectSoundBuffer']); |
708 | end; |
910 | end; |
709 | 911 | ||
710 | function TDirectSoundBuffer.GetPlaying: Boolean; |
912 | function TDirectSoundBuffer.GetPlaying: Boolean; |
711 | begin |
913 | begin |
712 | Result := (GetStatus and (DSBSTATUS_PLAYING or DSBSTATUS_LOOPING))<>0; |
914 | Result := (GetStatus and (DSBSTATUS_PLAYING or DSBSTATUS_LOOPING)) <> 0; |
713 | end; |
915 | end; |
714 | 916 | ||
715 | function TDirectSoundBuffer.GetPan: Integer; |
917 | function TDirectSoundBuffer.GetPan: Integer; |
716 | begin |
918 | begin |
717 | DXResult := IBuffer.GetPan(Longint(Result)); |
919 | DXResult := IBuffer.GetPan(Longint(Result)); |
718 | end; |
920 | end; |
719 | 921 | ||
720 | function TDirectSoundBuffer.GetPosition: Longint; |
922 | function TDirectSoundBuffer.GetPosition: Longint; |
721 | var |
923 | var |
722 | dwCurrentWriteCursor: Longint; |
924 | dwCurrentWriteCursor: Longint; |
723 | begin |
925 | begin |
724 | IBuffer.GetCurrentPosition(DWORD(Result), DWORD(dwCurrentWriteCursor)); |
926 | IBuffer.GetCurrentPosition(@DWORD(Result), @DWORD(dwCurrentWriteCursor)); |
725 | end; |
927 | end; |
726 | 928 | ||
727 | function TDirectSoundBuffer.GetSize: Integer; |
929 | function TDirectSoundBuffer.GetSize: Integer; |
728 | begin |
930 | begin |
729 | Result := FCaps.dwBufferBytes; |
931 | Result := FCaps.dwBufferBytes; |
Line 739... | Line 941... | ||
739 | DXResult := IBuffer.GetVolume(Longint(Result)); |
941 | DXResult := IBuffer.GetVolume(Longint(Result)); |
740 | end; |
942 | end; |
741 | 943 | ||
742 | procedure TDirectSoundBuffer.LoadFromFile(const FileName: string); |
944 | procedure TDirectSoundBuffer.LoadFromFile(const FileName: string); |
743 | var |
945 | var |
744 | Stream : TFileStream; |
946 | Stream: TFileStream; |
745 | begin |
947 | begin |
746 | Stream := TFileStream.Create(FileName, fmOpenRead); |
948 | Stream := TFileStream.Create(FileName, fmOpenRead); |
747 | try |
949 | try |
748 | LoadFromStream(Stream); |
950 | LoadFromStream(Stream); |
749 | finally |
951 | finally |
Line 755... | Line 957... | ||
755 | Data: Pointer; Size: Integer); |
957 | Data: Pointer; Size: Integer); |
756 | var |
958 | var |
757 | Data1, Data2: Pointer; |
959 | Data1, Data2: Pointer; |
758 | Data1Size, Data2Size: Longint; |
960 | Data1Size, Data2Size: Longint; |
759 | begin |
961 | begin |
760 | SetSize(Format, Size); |
962 | SetSize(Format, Size, FIsD3D); |
761 | 963 | ||
762 | if Data<>nil then |
964 | if Data <> nil then |
763 | begin |
965 | begin |
764 | if Lock(0, Size, Data1, Data1Size, Data2, Data2Size) then |
966 | if Lock(0, Size, Data1, Data1Size, Data2, Data2Size) then |
765 | begin |
967 | begin |
766 | try |
968 | try |
767 | Move(Data^, Data1^, Data1Size); |
969 | Move(Data^, Data1^, Data1Size); |
768 | if Data2<>nil then |
970 | if Data2 <> nil then |
769 | Move(Pointer(Longint(Data)+Data1Size)^, Data2^, Data2Size); |
971 | Move(Pointer(Longint(Data) + Data1Size)^, Data2^, Data2Size); |
770 | finally |
972 | finally |
771 | UnLock; |
973 | UnLock; |
772 | end; |
974 | end; |
- | 975 | end |
|
773 | end else |
976 | else |
774 | begin |
977 | begin |
775 | FIDSBuffer := nil; |
978 | FIDSBuffer := nil; |
- | 979 | FIDS3DBuffer := nil; |
|
776 | raise EDirectSoundBufferError.CreateFmt(SCannotLock, [SDirectSoundBuffer]); |
980 | raise EDirectSoundBufferError.CreateFmt(SCannotLock, [SDirectSoundBuffer]); |
777 | end; |
981 | end; |
778 | end; |
982 | end; |
779 | end; |
983 | end; |
780 | 984 | ||
781 | procedure TDirectSoundBuffer.LoadFromStream(Stream: TStream); |
985 | procedure TDirectSoundBuffer.LoadFromStream(Stream: TStream); |
782 | var |
986 | var |
783 | Wave: TWave; |
987 | Wave: TWave; |
784 | begin |
988 | begin |
785 | Wave := TWave.Create; |
989 | Wave := TWave.Create; |
786 | try |
990 | try |
787 | Wave.LoadFromStream(Stream); |
991 | Wave.LoadFromStream(Stream); |
Line 799... | Line 1003... | ||
799 | function TDirectSoundBuffer.Lock(LockPosition, LockSize: Longint; |
1003 | function TDirectSoundBuffer.Lock(LockPosition, LockSize: Longint; |
800 | var AudioPtr1: Pointer; var AudioSize1: Longint; |
1004 | var AudioPtr1: Pointer; var AudioSize1: Longint; |
801 | var AudioPtr2: Pointer; var AudioSize2: Longint): Boolean; |
1005 | var AudioPtr2: Pointer; var AudioSize2: Longint): Boolean; |
802 | begin |
1006 | begin |
803 | Result := False; |
1007 | Result := False; |
804 | if IDSBuffer=nil then Exit; |
1008 | if IDSBuffer = nil then Exit; |
805 | - | ||
806 | if FLockCount>High(FLockAudioPtr1) then Exit; |
- | |
807 | 1009 | ||
- | 1010 | if FLockCount > High(FLockAudioPtr1) then Exit; |
|
808 | DXResult := IBuffer.Lock(LockPosition, LockSize, |
1011 | DXResult := IBuffer.Lock(LockPosition, LockSize, |
809 | FLockAudioPtr1[FLockCount], FLockAudioSize1[FLockCount], |
1012 | {$IFNDEF DX7}@{$ENDIF}FLockAudioPtr1[FLockCount], {$IFNDEF DX7}@{$ENDIF}FLockAudioSize1[FLockCount], |
810 | FLockAudioPtr2[FLockCount], FLockAudioSize2[FLockCount], 0); |
1013 | {$IFNDEF DX7}@{$ENDIF}FLockAudioPtr2[FLockCount], {$IFNDEF DX7}@{$ENDIF}FLockAudioSize2[FLockCount], 0); |
811 | Result := DXResult=DS_OK; |
1014 | Result := DXResult = DS_OK; |
812 | 1015 | ||
813 | if Result then |
1016 | if Result then |
814 | begin |
1017 | begin |
815 | AudioPtr1 := FLockAudioPtr1[FLockCount]; |
1018 | AudioPtr1 := FLockAudioPtr1[FLockCount]; |
816 | AudioPtr2 := FLockAudioPtr2[FLockCount]; |
1019 | AudioPtr2 := FLockAudioPtr2[FLockCount]; |
Line 824... | Line 1027... | ||
824 | begin |
1027 | begin |
825 | if Loop then |
1028 | if Loop then |
826 | DXResult := IBuffer.Play(0, 0, DSBPLAY_LOOPING) |
1029 | DXResult := IBuffer.Play(0, 0, DSBPLAY_LOOPING) |
827 | else |
1030 | else |
828 | DXResult := IBuffer.Play(0, 0, 0); |
1031 | DXResult := IBuffer.Play(0, 0, 0); |
829 | Result := DXResult=DS_OK; |
1032 | Result := DXResult = DS_OK; |
830 | end; |
1033 | end; |
831 | 1034 | ||
832 | function TDirectSoundBuffer.Restore: Boolean; |
1035 | function TDirectSoundBuffer.Restore: Boolean; |
833 | begin |
1036 | begin |
834 | DXResult := IBuffer.Restore; |
1037 | DXResult := IBuffer.Restore; |
835 | Result := DXResult=DS_OK; |
1038 | Result := DXResult = DS_OK; |
- | 1039 | end; |
|
- | 1040 | ||
- | 1041 | procedure TDirectSoundBuffer.SetD3DSParams(const Value: TD3DSParams); |
|
- | 1042 | begin |
|
- | 1043 | FD3DSParams.Assign(Value); |
|
836 | end; |
1044 | end; |
837 | 1045 | ||
838 | function TDirectSoundBuffer.SetFormat(const Format: TWaveFormatEx): Boolean; |
1046 | function TDirectSoundBuffer.SetFormat(const Format: TWaveFormatEx): Boolean; |
839 | begin |
1047 | begin |
840 | DXResult := IBuffer.SetFormat(Format); |
1048 | DXResult := IBuffer.SetFormat(FFormat{$IFDEF DX7}^{$ENDIF}); |
841 | Result := DXResult=DS_OK; |
1049 | Result := DXResult = DS_OK; |
842 | 1050 | ||
843 | if Result then |
1051 | if Result then |
844 | begin |
1052 | begin |
845 | FreeMem(FFormat); |
1053 | FreeMem(FFormat); |
846 | FFormat := nil; |
1054 | FFormat := nil; |
847 | FFormatSize := 0; |
1055 | FFormatSize := 0; |
848 | if IBuffer.GetFormat(PWaveFormatEx(nil)^, 0, DWORD(FFormatSize))=DS_OK then |
1056 | if IBuffer.GetFormat(PWaveFormatEx(nil), 0, @DWORD(FFormatSize)) = DS_OK then |
849 | begin |
1057 | begin |
850 | GetMem(FFormat, FFormatSize); |
1058 | GetMem(FFormat, FFormatSize); |
851 | IBuffer.GetFormat(FFormat^, FFormatSize, PDWORD(nil)^); |
1059 | IBuffer.GetFormat(FFormat, FFormatSize, nil); |
852 | end; |
1060 | end; |
853 | end; |
1061 | end; |
854 | end; |
1062 | end; |
855 | 1063 | ||
856 | procedure TDirectSoundBuffer.SetFrequency(Value: Integer); |
1064 | procedure TDirectSoundBuffer.SetFrequency(Value: Integer); |
857 | begin |
1065 | begin |
858 | DXResult := IBuffer.SetFrequency(Value); |
1066 | DXResult := IBuffer.SetFrequency(Value); |
859 | end; |
1067 | end; |
860 | 1068 | ||
- | 1069 | procedure TDirectSoundBuffer.SetIDS3DBuffer(const Value: IDirectSound3DBuffer); |
|
- | 1070 | begin |
|
- | 1071 | if FIDS3DBuffer = Value then Exit; |
|
- | 1072 | ||
- | 1073 | FIDS3DBuffer := Value; |
|
- | 1074 | FillChar(FCaps, SizeOf(FCaps), 0); |
|
- | 1075 | FreeMem(FFormat); |
|
- | 1076 | FFormat := nil; |
|
- | 1077 | FFormatSize := 0; |
|
- | 1078 | FLockCount := 0; |
|
- | 1079 | ||
- | 1080 | if FIDS3DBuffer <> nil then |
|
- | 1081 | begin |
|
- | 1082 | FCaps.dwSize := SizeOf(FCaps); |
|
- | 1083 | IBuffer.GetCaps(FCaps); |
|
- | 1084 | ||
- | 1085 | if IBuffer.GetFormat(PWaveFormatEx(nil), 0, @DWORD(FFormatSize)) = DS_OK then |
|
- | 1086 | begin |
|
- | 1087 | GetMem(FFormat, FFormatSize); |
|
- | 1088 | IBuffer.GetFormat(FFormat, FFormatSize, nil); |
|
- | 1089 | end; |
|
- | 1090 | end; |
|
- | 1091 | end; |
|
- | 1092 | ||
861 | procedure TDirectSoundBuffer.SetIDSBuffer(Value: IDirectSoundBuffer); |
1093 | procedure TDirectSoundBuffer.SetIDSBuffer(Value: IDirectSoundBuffer); |
862 | begin |
1094 | begin |
863 | if FIDSBuffer=Value then Exit; |
1095 | if FIDSBuffer = Value then Exit; |
864 | 1096 | ||
865 | FIDSBuffer := Value; |
1097 | FIDSBuffer := Value; |
866 | FillChar(FCaps, SizeOf(FCaps), 0); |
1098 | FillChar(FCaps, SizeOf(FCaps), 0); |
867 | FreeMem(FFormat); |
1099 | FreeMem(FFormat); |
868 | FFormat := nil; |
1100 | FFormat := nil; |
869 | FFormatSize := 0; |
1101 | FFormatSize := 0; |
870 | FLockCount := 0; |
1102 | FLockCount := 0; |
871 | 1103 | ||
872 | if FIDSBuffer<>nil then |
1104 | if FIDSBuffer <> nil then |
873 | begin |
1105 | begin |
874 | FCaps.dwSize := SizeOf(FCaps); |
1106 | FCaps.dwSize := SizeOf(FCaps); |
875 | IBuffer.GetCaps(FCaps); |
1107 | IBuffer.GetCaps(FCaps); |
876 | 1108 | ||
877 | if IBuffer.GetFormat(PWaveFormatEx(nil)^, 0, DWORD(FFormatSize))=DS_OK then |
1109 | if IBuffer.GetFormat(PWaveFormatEx(nil), 0, @DWORD(FFormatSize)) = DS_OK then |
878 | begin |
1110 | begin |
879 | GetMem(FFormat, FFormatSize); |
1111 | GetMem(FFormat, FFormatSize); |
880 | IBuffer.GetFormat(FFormat^, FFormatSize, PDWORD(nil)^); |
1112 | IBuffer.GetFormat(FFormat, FFormatSize, nil); |
881 | end; |
1113 | end; |
882 | end; |
1114 | end; |
883 | end; |
1115 | end; |
884 | 1116 | ||
885 | procedure TDirectSoundBuffer.SetPan(Value: Integer); |
1117 | procedure TDirectSoundBuffer.SetPan(Value: Integer); |
886 | begin |
1118 | begin |
Line 889... | Line 1121... | ||
889 | 1121 | ||
890 | procedure TDirectSoundBuffer.SetPosition(Value: Longint); |
1122 | procedure TDirectSoundBuffer.SetPosition(Value: Longint); |
891 | begin |
1123 | begin |
892 | DXResult := IBuffer.SetCurrentPosition(Value); |
1124 | DXResult := IBuffer.SetCurrentPosition(Value); |
893 | end; |
1125 | end; |
- | 1126 | {$IFNDEF DX7} |
|
- | 1127 | const |
|
- | 1128 | DSBCAPS_CTRLDEFAULT = DSBCAPS_CTRLFREQUENCY or DSBCAPS_CTRLPAN or DSBCAPS_CTRLVOLUME; |
|
- | 1129 | {$ENDIF} |
|
894 | 1130 | ||
895 | procedure TDirectSoundBuffer.SetSize(const Format: TWaveFormatEx; Size: Integer); |
1131 | procedure TDirectSoundBuffer.SetSize(const Format: TWaveFormatEx; Size: Integer; D3D: Boolean {$IFNDEF VER100}= False{$ENDIF}); |
896 | var |
1132 | var |
897 | BufferDesc: TDSBufferDesc; |
1133 | BufferDesc: TDSBufferDesc; |
898 | begin |
1134 | begin |
899 | { IDirectSoundBuffer made. } |
1135 | { IDirectSoundBuffer made. } |
900 | FillChar(BufferDesc, SizeOf(BufferDesc), 0); |
1136 | FillChar(BufferDesc, SizeOf(BufferDesc), 0); |
901 | 1137 | ||
902 | with BufferDesc do |
1138 | with BufferDesc do |
903 | begin |
1139 | begin |
904 | dwSize := SizeOf(TDSBufferDesc); |
1140 | dwSize := SizeOf(TDSBufferDesc); |
905 | dwFlags := DSBCAPS_CTRLDEFAULT; |
1141 | dwFlags := DSBCAPS_CTRLDEFAULT; |
906 | if DSound.FStickyFocus then |
1142 | if DSound.FStickyFocus then |
907 | dwFlags := dwFlags or DSBCAPS_STICKYFOCUS |
1143 | dwFlags := dwFlags or DSBCAPS_STICKYFOCUS |
908 | else if DSound.FGlobalFocus then |
1144 | else if DSound.FGlobalFocus then |
909 | dwFlags := dwFlags or DSBCAPS_GLOBALFOCUS; |
1145 | dwFlags := dwFlags or DSBCAPS_GLOBALFOCUS; |
- | 1146 | if D3D then |
|
- | 1147 | dwFlags := DSBCAPS_STATIC + DSBCAPS_CTRLDEFAULT + DSBCAPS_CTRL3D - DSBCAPS_CTRLPAN; |
|
910 | dwBufferBytes := Size; |
1148 | dwBufferBytes := Size; |
911 | lpwfxFormat := @Format; |
1149 | lpwfxFormat := @Format; |
912 | end; |
1150 | end; |
913 | 1151 | ||
914 | if not CreateBuffer(BufferDesc) then |
1152 | if not CreateBuffer(BufferDesc) then |
Line 925... | Line 1163... | ||
925 | DXResult := IBuffer.Stop; |
1163 | DXResult := IBuffer.Stop; |
926 | end; |
1164 | end; |
927 | 1165 | ||
928 | procedure TDirectSoundBuffer.Unlock; |
1166 | procedure TDirectSoundBuffer.Unlock; |
929 | begin |
1167 | begin |
930 | if IDSBuffer=nil then Exit; |
1168 | if IDSBuffer = nil then Exit; |
931 | if FLockCount=0 then Exit; |
1169 | if FLockCount = 0 then Exit; |
932 | 1170 | ||
933 | Dec(FLockCount); |
1171 | Dec(FLockCount); |
934 | DXResult := IBuffer.UnLock(FLockAudioPtr1[FLockCount], FLockAudioSize1[FLockCount], |
1172 | DXResult := IBuffer.UnLock(FLockAudioPtr1[FLockCount], FLockAudioSize1[FLockCount], |
935 | FLockAudioPtr2[FLockCount], FLockAudioSize2[FLockCount]); |
1173 | FLockAudioPtr2[FLockCount], FLockAudioSize2[FLockCount]); |
936 | end; |
1174 | end; |
937 | 1175 | ||
- | 1176 | { TD3DSParams } |
|
- | 1177 | ||
- | 1178 | function TD3DSParams.CheckValidity: Boolean; |
|
- | 1179 | begin |
|
- | 1180 | Result := (FOwner <> nil) and (TDirectSoundBuffer(FOwner).IDS3DBuffer <> nil) |
|
- | 1181 | end; |
|
- | 1182 | ||
- | 1183 | constructor TD3DSParams.Create(Owner: TDirectSoundBuffer); |
|
- | 1184 | {$IFDEF VER14UP} |
|
- | 1185 | function MakeD3DVector(x, y, z: TD3DValue): TD3DVector; {$IFDEF VER9UP}inline; {$ENDIF} |
|
- | 1186 | begin |
|
- | 1187 | Result.x := x; |
|
- | 1188 | Result.y := y; |
|
- | 1189 | Result.z := z; |
|
- | 1190 | end; |
|
- | 1191 | {$ENDIF} |
|
- | 1192 | begin |
|
- | 1193 | inherited Create; |
|
- | 1194 | FOwner := Owner; |
|
- | 1195 | with FDsb do |
|
- | 1196 | begin |
|
- | 1197 | dwSize := SizeOf(TDS3DBuffer); |
|
- | 1198 | vPosition := MakeD3DVector(0, 0, 0); |
|
- | 1199 | vVelocity := MakeD3DVector(0, 0, 0); |
|
- | 1200 | dwInsideConeAngle := DS3D_DEFAULTCONEANGLE; |
|
- | 1201 | dwOutsideConeAngle := DS3D_DEFAULTCONEANGLE; |
|
- | 1202 | vConeOrientation := MakeD3DVector(0, 0, 0); |
|
- | 1203 | lConeoutsideVolume := DS3D_DEFAULTCONEOUTSIDEVOLUME; |
|
- | 1204 | flMinDistance := 5; |
|
- | 1205 | flMaxDistance := 100.0; |
|
- | 1206 | dwMode := DS3DMODE_NORMAL; |
|
- | 1207 | end; |
|
- | 1208 | end; |
|
- | 1209 | ||
- | 1210 | destructor TD3DSParams.destroy; |
|
- | 1211 | begin |
|
- | 1212 | inherited destroy; |
|
- | 1213 | end; |
|
- | 1214 | ||
- | 1215 | function TD3DSParams.getPosition: TD3DVector; |
|
- | 1216 | begin |
|
- | 1217 | if CheckValidity then |
|
- | 1218 | begin |
|
- | 1219 | FOwner.IDS3DBuffer.GetPosition(FDsb.vPosition); |
|
- | 1220 | end; |
|
- | 1221 | result := FDsb.vPosition; |
|
- | 1222 | end; |
|
- | 1223 | ||
- | 1224 | function TD3DSParams.getVelocity: TD3DVector; |
|
- | 1225 | begin |
|
- | 1226 | if CheckValidity then |
|
- | 1227 | begin |
|
- | 1228 | FOwner.IDS3DBuffer.GetVelocity(FDsb.vVelocity); |
|
- | 1229 | end; |
|
- | 1230 | result := FDsb.vVelocity; |
|
- | 1231 | end; |
|
- | 1232 | ||
- | 1233 | function TD3DSParams.getConeOrientation: TD3DVector; |
|
- | 1234 | begin |
|
- | 1235 | if CheckValidity then |
|
- | 1236 | begin |
|
- | 1237 | FOwner.IDS3DBuffer.GetConeOrientation(FDsb.vConeOrientation); |
|
- | 1238 | end; |
|
- | 1239 | result := FDsb.vConeOrientation; |
|
- | 1240 | end; |
|
- | 1241 | ||
- | 1242 | function TD3DSParams.getConeAngle: TConeAngle; |
|
- | 1243 | begin |
|
- | 1244 | if CheckValidity then |
|
- | 1245 | begin |
|
- | 1246 | FOwner.IDS3DBuffer.GetConeAngles(FDsb.dwInsideConeAngle, FDsb.dwOutsideConeAngle); |
|
- | 1247 | end; |
|
- | 1248 | with result do |
|
- | 1249 | begin |
|
- | 1250 | Inside := FDsb.dwInsideConeAngle; |
|
- | 1251 | OutSide := FDsb.dwOutsideConeAngle; |
|
- | 1252 | end; |
|
- | 1253 | end; |
|
- | 1254 | ||
- | 1255 | function TD3DSParams.getConeOutsideVolume: Integer; |
|
- | 1256 | begin |
|
- | 1257 | if CheckValidity then |
|
- | 1258 | begin |
|
- | 1259 | FOwner.IDS3DBuffer.GetConeOutsideVolume(FDsb.lConeOutsideVolume); |
|
- | 1260 | end; |
|
- | 1261 | result := FDsb.lConeOutsideVolume; |
|
- | 1262 | end; |
|
- | 1263 | ||
- | 1264 | function TD3DSParams.getMinDistance: TD3DValue; |
|
- | 1265 | begin |
|
- | 1266 | if CheckValidity then |
|
- | 1267 | begin |
|
- | 1268 | FOwner.IDS3DBuffer.GetMinDistance(FDsb.flMinDistance); |
|
- | 1269 | end; |
|
- | 1270 | result := FDsb.flMinDistance; |
|
- | 1271 | end; |
|
- | 1272 | ||
- | 1273 | function TD3DSParams.getMaxDistance: TD3DValue; |
|
- | 1274 | begin |
|
- | 1275 | if CheckValidity then |
|
- | 1276 | begin |
|
- | 1277 | FOwner.IDS3DBuffer.GetMaxDistance(FDsb.flMaxDistance); |
|
- | 1278 | end; |
|
- | 1279 | result := FDsb.flMaxDistance; |
|
- | 1280 | end; |
|
- | 1281 | ||
- | 1282 | function TD3DSParams.getRaw: TDS3DBuffer; |
|
- | 1283 | begin |
|
- | 1284 | if CheckValidity then |
|
- | 1285 | begin |
|
- | 1286 | FOwner.IDS3DBuffer.GetAllParameters(FDsb); |
|
- | 1287 | end; |
|
- | 1288 | result := FDsb; |
|
- | 1289 | end; |
|
- | 1290 | ||
- | 1291 | ||
- | 1292 | procedure TD3DSParams.setPosition(const v: TD3DVector); |
|
- | 1293 | begin |
|
- | 1294 | if CheckValidity then |
|
- | 1295 | begin |
|
- | 1296 | FOwner.IDS3DBuffer.SetPosition(v.x, v.y, v.z, DS3D_IMMEDIATE); |
|
- | 1297 | end; |
|
- | 1298 | FDsb.vPosition := v; |
|
- | 1299 | end; |
|
- | 1300 | ||
- | 1301 | procedure TD3DSParams.setVelocity(const v: TD3DVector); |
|
- | 1302 | begin |
|
- | 1303 | if CheckValidity then |
|
- | 1304 | begin |
|
- | 1305 | FOwner.IDS3DBuffer.SetVelocity(v.x, v.y, v.z, DS3D_IMMEDIATE); |
|
- | 1306 | end; |
|
- | 1307 | FDsb.vVelocity := v; |
|
- | 1308 | end; |
|
- | 1309 | ||
- | 1310 | procedure TD3DSParams.setConeOrientation(const v: TD3DVector); |
|
- | 1311 | begin |
|
- | 1312 | if CheckValidity then |
|
- | 1313 | begin |
|
- | 1314 | FOwner.IDS3DBuffer.SetConeOrientation(v.x, v.y, v.z, DS3D_IMMEDIATE); |
|
- | 1315 | end; |
|
- | 1316 | FDsb.vConeOrientation := v; |
|
- | 1317 | end; |
|
- | 1318 | ||
- | 1319 | procedure TD3DSParams.setConeAngle(const v: TConeAngle); |
|
- | 1320 | begin |
|
- | 1321 | if CheckValidity then |
|
- | 1322 | begin |
|
- | 1323 | FOwner.IDS3DBuffer.SetConeAngles(v.Inside, v.Outside, DS3D_IMMEDIATE); |
|
- | 1324 | end; |
|
- | 1325 | FDsb.dwInsideConeAngle := v.Inside; |
|
- | 1326 | FDsb.dwInsideConeAngle := v.Outside; |
|
- | 1327 | end; |
|
- | 1328 | ||
- | 1329 | procedure TD3DSParams.setConeOutsideVolume(const v: Integer); |
|
- | 1330 | begin |
|
- | 1331 | if CheckValidity then |
|
- | 1332 | begin |
|
- | 1333 | FOwner.IDS3DBuffer.SetConeOutsideVolume(v, DS3D_IMMEDIATE); |
|
- | 1334 | end; |
|
- | 1335 | FDsb.lConeOutsideVolume := v; |
|
- | 1336 | end; |
|
- | 1337 | ||
- | 1338 | procedure TD3DSParams.setMinDistance(const v: TD3DValue); |
|
- | 1339 | begin |
|
- | 1340 | if CheckValidity then |
|
- | 1341 | begin |
|
- | 1342 | FOwner.IDS3DBuffer.SetMinDistance(v, DS3D_IMMEDIATE); |
|
- | 1343 | end; |
|
- | 1344 | FDsb.flMinDistance := v; |
|
- | 1345 | end; |
|
- | 1346 | ||
- | 1347 | procedure TD3DSParams.setMaxDistance(const v: TD3DValue); |
|
- | 1348 | begin |
|
- | 1349 | if CheckValidity then |
|
- | 1350 | begin |
|
- | 1351 | FOwner.IDS3DBuffer.SetMaxDistance(v, DS3D_IMMEDIATE); |
|
- | 1352 | end; |
|
- | 1353 | FDsb.flMaxDistance := v; |
|
- | 1354 | end; |
|
- | 1355 | ||
- | 1356 | procedure TD3DSParams.setRaw(const v: TDS3DBuffer); |
|
- | 1357 | begin |
|
- | 1358 | if CheckValidity then |
|
- | 1359 | begin |
|
- | 1360 | if FOwner.IDS3DBuffer.SetAllParameters(v, DS3D_IMMEDIATE) <> DS_OK then |
|
- | 1361 | {'Parameter is invalid for Params3D'}; |
|
- | 1362 | end; |
|
- | 1363 | FDsb := v; |
|
- | 1364 | end; |
|
- | 1365 | ||
- | 1366 | procedure TD3DSParams.Assign(Prms: TD3DSParams); |
|
- | 1367 | begin |
|
- | 1368 | FDsb := Prms.RawParams; |
|
- | 1369 | ||
- | 1370 | if CheckValidity then |
|
- | 1371 | begin |
|
- | 1372 | if FOwner.IDS3DBuffer.SetAllParameters(FDsb, DS3D_IMMEDIATE) <> DS_OK then |
|
- | 1373 | {'Parameter is invalid for Params3D'}; |
|
- | 1374 | end; |
|
- | 1375 | end; |
|
- | 1376 | ||
938 | { TAudioStream } |
1377 | { TAudioStream } |
939 | 1378 | ||
940 | type |
1379 | type |
941 | TAudioStreamNotify = class(TThread) |
1380 | TAudioStreamNotify = class(TThread) |
942 | private |
1381 | private |
Line 983... | Line 1422... | ||
983 | if FStopOnTerminate then FAudio.Stop; |
1422 | if FStopOnTerminate then FAudio.Stop; |
984 | end; |
1423 | end; |
985 | 1424 | ||
986 | procedure TAudioStreamNotify.Execute; |
1425 | procedure TAudioStreamNotify.Execute; |
987 | begin |
1426 | begin |
988 | while WaitForSingleObject(FAudio.FNotifyEvent, FSleepTime)=WAIT_TIMEOUT do |
1427 | while WaitForSingleObject(FAudio.FNotifyEvent, FSleepTime) = WAIT_TIMEOUT do |
989 | Synchronize(Update); |
1428 | Synchronize(Update); |
990 | end; |
1429 | end; |
991 | 1430 | ||
992 | procedure TAudioStreamNotify.Update; |
1431 | procedure TAudioStreamNotify.Update; |
993 | begin |
1432 | begin |
Line 1025... | Line 1464... | ||
1025 | inherited Destroy; |
1464 | inherited Destroy; |
1026 | end; |
1465 | end; |
1027 | 1466 | ||
1028 | function TAudioStream.GetFormat: PWaveFormatEX; |
1467 | function TAudioStream.GetFormat: PWaveFormatEX; |
1029 | begin |
1468 | begin |
1030 | if WaveStream=nil then |
1469 | if WaveStream = nil then |
1031 | raise EAudioStreamError.Create(SWaveStreamNotSet); |
1470 | raise EAudioStreamError.Create(SWaveStreamNotSet); |
1032 | Result := WaveStream.Format; |
1471 | Result := WaveStream.Format; |
1033 | end; |
1472 | end; |
1034 | 1473 | ||
1035 | function TAudioStream.GetFormatSize: Integer; |
1474 | function TAudioStream.GetFormatSize: Integer; |
1036 | begin |
1475 | begin |
1037 | if WaveStream=nil then |
1476 | if WaveStream = nil then |
1038 | raise EAudioStreamError.Create(SWaveStreamNotSet); |
1477 | raise EAudioStreamError.Create(SWaveStreamNotSet); |
1039 | Result := WaveStream.FormatSize; |
1478 | Result := WaveStream.FormatSize; |
1040 | end; |
1479 | end; |
1041 | 1480 | ||
1042 | function TAudioStream.GetFrequency: Integer; |
1481 | function TAudioStream.GetFrequency: Integer; |
Line 1055... | Line 1494... | ||
1055 | Result := FPlayedSize; |
1494 | Result := FPlayedSize; |
1056 | end; |
1495 | end; |
1057 | 1496 | ||
1058 | function TAudioStream.GetSize: Integer; |
1497 | function TAudioStream.GetSize: Integer; |
1059 | begin |
1498 | begin |
1060 | if WaveStream<>nil then |
1499 | if WaveStream <> nil then |
1061 | Result := WaveStream.Size |
1500 | Result := WaveStream.Size |
1062 | else |
1501 | else |
1063 | Result := 0; |
1502 | Result := 0; |
1064 | end; |
1503 | end; |
1065 | 1504 | ||
Line 1101... | Line 1540... | ||
1101 | begin |
1540 | begin |
1102 | Result := PlayPosition + (FBufferSize - FBufferPos); |
1541 | Result := PlayPosition + (FBufferSize - FBufferPos); |
1103 | end; |
1542 | end; |
1104 | 1543 | ||
1105 | i := WaveStream.FilledSize; |
1544 | i := WaveStream.FilledSize; |
1106 | if i>=0 then Result := Min(Result, i); |
1545 | if i >= 0 then Result := Min(Result, i); |
1107 | end; |
1546 | end; |
1108 | 1547 | ||
1109 | procedure TAudioStream.Play; |
1548 | procedure TAudioStream.Play; |
1110 | begin |
1549 | begin |
1111 | if not FPlaying then |
1550 | if not FPlaying then |
1112 | begin |
1551 | begin |
1113 | if WaveStream=nil then |
1552 | if WaveStream = nil then |
1114 | raise EAudioStreamError.Create(SWaveStreamNotSet); |
1553 | raise EAudioStreamError.Create(SWaveStreamNotSet); |
1115 | 1554 | ||
1116 | if Size=0 then Exit; |
1555 | if Size = 0 then Exit; |
1117 | 1556 | ||
1118 | FPlaying := True; |
1557 | FPlaying := True; |
1119 | try |
1558 | try |
1120 | SetPosition(FPosition); |
1559 | SetPosition(FPosition); |
1121 | if FAutoUpdate then |
1560 | if FAutoUpdate then |
Line 1134... | Line 1573... | ||
1134 | AFrequency: Integer; |
1573 | AFrequency: Integer; |
1135 | APan: Integer; |
1574 | APan: Integer; |
1136 | AVolume: Integer; |
1575 | AVolume: Integer; |
1137 | begin |
1576 | begin |
1138 | APlaying := Playing; |
1577 | APlaying := Playing; |
1139 | 1578 | ||
1140 | APosition := Position; |
1579 | APosition := Position; |
1141 | AFrequency := Frequency; |
1580 | AFrequency := Frequency; |
1142 | APan := Pan; |
1581 | APan := Pan; |
1143 | AVolume := Volume; |
1582 | AVolume := Volume; |
1144 | - | ||
- | 1583 | ||
1145 | SetWaveStream(WaveStream); |
1584 | SetWaveStream(WaveStream); |
1146 | 1585 | ||
1147 | Position := APosition; |
1586 | Position := APosition; |
1148 | Frequency := AFrequency; |
1587 | Frequency := AFrequency; |
1149 | Pan := APan; |
1588 | Pan := APan; |
1150 | Volume := AVolume; |
1589 | Volume := AVolume; |
1151 | - | ||
- | 1590 | ||
1152 | if APlaying then Play; |
1591 | if APlaying then Play; |
1153 | end; |
1592 | end; |
1154 | 1593 | ||
1155 | procedure TAudioStream.SetAutoUpdate(Value: Boolean); |
1594 | procedure TAudioStream.SetAutoUpdate(Value: Boolean); |
1156 | begin |
1595 | begin |
1157 | if FAutoUpdate<>Value then |
1596 | if FAutoUpdate <> Value then |
1158 | begin |
1597 | begin |
1159 | FAutoUpdate := Value; |
1598 | FAutoUpdate := Value; |
1160 | if FPlaying then |
1599 | if FPlaying then |
1161 | begin |
1600 | begin |
1162 | if FNotifyThread<>nil then |
1601 | if FNotifyThread <> nil then |
1163 | begin |
1602 | begin |
1164 | (FNotifyThread as TAudioStreamNotify).FStopOnTerminate := False; |
1603 | (FNotifyThread as TAudioStreamNotify).FStopOnTerminate := False; |
1165 | FNotifyThread.Free; |
1604 | FNotifyThread.Free; |
1166 | end; |
1605 | end; |
1167 | 1606 | ||
Line 1171... | Line 1610... | ||
1171 | end; |
1610 | end; |
1172 | end; |
1611 | end; |
1173 | 1612 | ||
1174 | procedure TAudioStream.SetBufferLength(Value: Integer); |
1613 | procedure TAudioStream.SetBufferLength(Value: Integer); |
1175 | begin |
1614 | begin |
1176 | if Value<10 then Value := 10; |
1615 | if Value < 10 then Value := 10; |
1177 | if FBufferLength<>Value then |
1616 | if FBufferLength <> Value then |
1178 | begin |
1617 | begin |
1179 | FBufferLength := Value; |
1618 | FBufferLength := Value; |
1180 | if WaveStream<>nil then RecreateBuf; |
1619 | if WaveStream <> nil then RecreateBuf; |
1181 | end; |
1620 | end; |
1182 | end; |
1621 | end; |
1183 | 1622 | ||
1184 | procedure TAudioStream.SetFrequency(Value: Integer); |
1623 | procedure TAudioStream.SetFrequency(Value: Integer); |
1185 | begin |
1624 | begin |
1186 | FBuffer.Frequency := Value; |
1625 | FBuffer.Frequency := Value; |
1187 | end; |
1626 | end; |
1188 | 1627 | ||
1189 | procedure TAudioStream.SetLooped(Value: Boolean); |
1628 | procedure TAudioStream.SetLooped(Value: Boolean); |
1190 | begin |
1629 | begin |
1191 | if FLooped<>Value then |
1630 | if FLooped <> Value then |
1192 | begin |
1631 | begin |
1193 | FLooped := Value; |
1632 | FLooped := Value; |
1194 | Position := Position; |
1633 | Position := Position; |
1195 | end; |
1634 | end; |
1196 | end; |
1635 | end; |
Line 1206... | Line 1645... | ||
1206 | FPlayedSize := Value; |
1645 | FPlayedSize := Value; |
1207 | end; |
1646 | end; |
1208 | 1647 | ||
1209 | procedure TAudioStream.SetPosition(Value: Integer); |
1648 | procedure TAudioStream.SetPosition(Value: Integer); |
1210 | begin |
1649 | begin |
1211 | if WaveStream=nil then |
1650 | if WaveStream = nil then |
1212 | raise EAudioStreamError.Create(SWaveStreamNotSet); |
1651 | raise EAudioStreamError.Create(SWaveStreamNotSet); |
1213 | 1652 | ||
1214 | Value := Max(Min(Value, Size-1), 0); |
1653 | Value := Max(Min(Value, Size - 1), 0); |
1215 | Value := Value div Format^.nBlockAlign * Format^.nBlockAlign; |
1654 | Value := Value div Format^.nBlockAlign * Format^.nBlockAlign; |
1216 | 1655 | ||
1217 | FPosition := Value; |
1656 | FPosition := Value; |
1218 | 1657 | ||
1219 | if Playing then |
1658 | if Playing then |
Line 1250... | Line 1689... | ||
1250 | FWaveStream := nil; |
1689 | FWaveStream := nil; |
1251 | FBufferPos := 0; |
1690 | FBufferPos := 0; |
1252 | FPosition := 0; |
1691 | FPosition := 0; |
1253 | FWritePosition := 0; |
1692 | FWritePosition := 0; |
1254 | 1693 | ||
1255 | if (Value<>nil) and (FBufferLength>0) then |
1694 | if (Value <> nil) and (FBufferLength > 0) then |
1256 | begin |
1695 | begin |
1257 | FBufferSize := FBufferLength * Integer(Value.Format^.nAvgBytesPerSec) div 1000; |
1696 | FBufferSize := FBufferLength * Integer(Value.Format^.nAvgBytesPerSec) div 1000; |
1258 | 1697 | ||
1259 | FillChar(BufferDesc, SizeOf(BufferDesc), 0); |
1698 | FillChar(BufferDesc, SizeOf(BufferDesc), 0); |
1260 | with BufferDesc do |
1699 | with BufferDesc do |
Line 1302... | Line 1741... | ||
1302 | if not FPlaying then Exit; |
1741 | if not FPlaying then Exit; |
1303 | 1742 | ||
1304 | try |
1743 | try |
1305 | UpdatePlayedSize; |
1744 | UpdatePlayedSize; |
1306 | 1745 | ||
1307 | if Size<0 then |
1746 | if Size < 0 then |
1308 | begin |
1747 | begin |
1309 | WriteSize := GetWriteSize; |
1748 | WriteSize := GetWriteSize; |
1310 | if WriteSize>0 then |
1749 | if WriteSize > 0 then |
1311 | begin |
1750 | begin |
1312 | WriteSize := WriteWave(WriteSize); |
1751 | WriteSize := WriteWave(WriteSize); |
1313 | FPosition := FPosition + WriteSize; |
1752 | FPosition := FPosition + WriteSize; |
1314 | end; |
1753 | end; |
1315 | end else |
1754 | end else |
1316 | begin |
1755 | begin |
1317 | if FLooped then |
1756 | if FLooped then |
1318 | begin |
1757 | begin |
1319 | WriteSize := GetWriteSize; |
1758 | WriteSize := GetWriteSize; |
1320 | if WriteSize>0 then |
1759 | if WriteSize > 0 then |
1321 | begin |
1760 | begin |
1322 | WriteWave(WriteSize); |
1761 | WriteWave(WriteSize); |
1323 | FPosition := (FPosition + WriteSize) mod Size; |
1762 | FPosition := (FPosition + WriteSize) mod Size; |
1324 | end; |
1763 | end; |
1325 | end else |
1764 | end else |
1326 | begin |
1765 | begin |
1327 | if FPosition<Size then |
1766 | if FPosition < Size then |
1328 | begin |
1767 | begin |
1329 | WriteSize := GetWriteSize; |
1768 | WriteSize := GetWriteSize; |
1330 | if WriteSize>0 then |
1769 | if WriteSize > 0 then |
1331 | begin |
1770 | begin |
1332 | WriteWave(WriteSize); |
1771 | WriteWave(WriteSize); |
1333 | FPosition := FPosition + WriteSize; |
1772 | FPosition := FPosition + WriteSize; |
1334 | if FPosition>Size then FPosition := Size; |
1773 | if FPosition > Size then FPosition := Size; |
1335 | end; |
1774 | end; |
1336 | end else |
1775 | end else |
1337 | begin |
1776 | begin |
1338 | if InThread then |
1777 | if InThread then |
1339 | SetEvent(FNotifyEvent) |
1778 | SetEvent(FNotifyEvent) |
Line 1363... | Line 1802... | ||
1363 | try |
1802 | try |
1364 | FWaveStream.Position := FWritePosition; |
1803 | FWaveStream.Position := FWritePosition; |
1365 | FWaveStream.ReadBuffer(Data1^, Data1Size); |
1804 | FWaveStream.ReadBuffer(Data1^, Data1Size); |
1366 | FWritePosition := FWritePosition + Data1Size; |
1805 | FWritePosition := FWritePosition + Data1Size; |
1367 | 1806 | ||
1368 | if Data2<>nil then |
1807 | if Data2 <> nil then |
1369 | begin |
1808 | begin |
1370 | FWaveStream.ReadBuffer(Data2^, Data2Size); |
1809 | FWaveStream.ReadBuffer(Data2^, Data2Size); |
1371 | FWritePosition := FWritePosition + Data2Size; |
1810 | FWritePosition := FWritePosition + Data2Size; |
1372 | end; |
1811 | end; |
1373 | 1812 | ||
Line 1390... | Line 1829... | ||
1390 | s1 := FWaveStream.Read(Data1^, Data1Size); |
1829 | s1 := FWaveStream.Read(Data1^, Data1Size); |
1391 | FWritePosition := FWritePosition + s1; |
1830 | FWritePosition := FWritePosition + s1; |
1392 | FBufferPos := (FBufferPos + DWORD(s1)) mod FBufferSize; |
1831 | FBufferPos := (FBufferPos + DWORD(s1)) mod FBufferSize; |
1393 | Inc(Result, s1); |
1832 | Inc(Result, s1); |
1394 | 1833 | ||
1395 | if (Data2<>nil) and (s1=Data1Size) then |
1834 | if (Data2 <> nil) and (s1 = Data1Size) then |
1396 | begin |
1835 | begin |
1397 | s2 := FWaveStream.Read(Data2^, Data2Size); |
1836 | s2 := FWaveStream.Read(Data2^, Data2Size); |
1398 | FWritePosition := FWritePosition + s2; |
1837 | FWritePosition := FWritePosition + s2; |
1399 | FBufferPos := (FBufferPos + DWORD(s2)) mod FBufferSize; |
1838 | FBufferPos := (FBufferPos + DWORD(s2)) mod FBufferSize; |
1400 | Inc(Result, s2); |
1839 | Inc(Result, s2); |
Line 1409... | Line 1848... | ||
1409 | var |
1848 | var |
1410 | C: Byte; |
1849 | C: Byte; |
1411 | Data1, Data2: Pointer; |
1850 | Data1, Data2: Pointer; |
1412 | Data1Size, Data2Size: Longint; |
1851 | Data1Size, Data2Size: Longint; |
1413 | begin |
1852 | begin |
1414 | if Format^.wBitsPerSample=8 then C := $80 else C := 0; |
1853 | if Format^.wBitsPerSample = 8 then C := $80 else C := 0; |
1415 | 1854 | ||
1416 | if FBuffer.Lock(FBufferPos, Size, Data1, Data1Size, Data2, Data2Size) then |
1855 | if FBuffer.Lock(FBufferPos, Size, Data1, Data1Size, Data2, Data2Size) then |
1417 | begin |
1856 | begin |
1418 | try |
1857 | try |
1419 | FillChar(Data1^, Data1Size, C); |
1858 | FillChar(Data1^, Data1Size, C); |
1420 | 1859 | ||
1421 | if Data2<>nil then |
1860 | if Data2 <> nil then |
1422 | FillChar(Data2^, Data2Size, C); |
1861 | FillChar(Data2^, Data2Size, C); |
1423 | finally |
1862 | finally |
1424 | FBuffer.UnLock; |
1863 | FBuffer.UnLock; |
1425 | end; |
1864 | end; |
1426 | FBufferPos := (FBufferPos + DWORD(Data1Size) + DWORD(Data2Size)) mod FBufferSize; |
1865 | FBufferPos := (FBufferPos + DWORD(Data1Size) + DWORD(Data2Size)) mod FBufferSize; |
Line 1429... | Line 1868... | ||
1429 | end; |
1868 | end; |
1430 | 1869 | ||
1431 | var |
1870 | var |
1432 | DataSize: Integer; |
1871 | DataSize: Integer; |
1433 | begin |
1872 | begin |
1434 | if Size>=0 then |
1873 | if Size >= 0 then |
1435 | begin |
1874 | begin |
1436 | Result := WriteSize; |
1875 | Result := WriteSize; |
1437 | if FLooped then |
1876 | if FLooped then |
1438 | begin |
1877 | begin |
1439 | while WriteSize>0 do |
1878 | while WriteSize > 0 do |
1440 | begin |
1879 | begin |
1441 | DataSize := Min(Size-FWritePosition, WriteSize); |
1880 | DataSize := Min(Size - FWritePosition, WriteSize); |
1442 | 1881 | ||
1443 | WriteData(DataSize); |
1882 | WriteData(DataSize); |
1444 | FWritePosition := FWritePosition mod Size; |
1883 | FWritePosition := FWritePosition mod Size; |
1445 | 1884 | ||
1446 | Dec(WriteSize, DataSize); |
1885 | Dec(WriteSize, DataSize); |
1447 | end; |
1886 | end; |
1448 | end else |
1887 | end else |
1449 | begin |
1888 | begin |
1450 | DataSize := Size-FWritePosition; |
1889 | DataSize := Size - FWritePosition; |
1451 | 1890 | ||
1452 | if DataSize<=0 then |
1891 | if DataSize <= 0 then |
1453 | begin |
1892 | begin |
1454 | WriteSilence(WriteSize); |
1893 | WriteSilence(WriteSize); |
1455 | end else |
1894 | end else |
1456 | if DataSize>=WriteSize then |
1895 | if DataSize >= WriteSize then |
1457 | begin |
1896 | begin |
1458 | WriteData(WriteSize); |
1897 | WriteData(WriteSize); |
1459 | end else |
1898 | end else |
1460 | begin |
1899 | begin |
1461 | WriteData(DataSize); |
1900 | WriteData(DataSize); |
1462 | WriteSilence(WriteSize-DataSize); |
1901 | WriteSilence(WriteSize - DataSize); |
1463 | end; |
1902 | end; |
1464 | end; |
1903 | end; |
1465 | end else |
1904 | end else |
1466 | begin |
1905 | begin |
1467 | Result := 0; |
1906 | Result := 0; |
1468 | WriteData2(WriteSize); |
1907 | WriteData2(WriteSize); |
Line 1477... | Line 1916... | ||
1477 | FWaveFileStream.Free; |
1916 | FWaveFileStream.Free; |
1478 | end; |
1917 | end; |
1479 | 1918 | ||
1480 | procedure TAudioFileStream.SetFileName(const Value: string); |
1919 | procedure TAudioFileStream.SetFileName(const Value: string); |
1481 | begin |
1920 | begin |
1482 | if FFileName=Value then Exit; |
1921 | if FFileName = Value then Exit; |
1483 | 1922 | ||
1484 | FFileName := Value; |
1923 | FFileName := Value; |
1485 | 1924 | ||
1486 | if FWaveFileStream<>nil then |
1925 | if FWaveFileStream <> nil then |
1487 | begin |
1926 | begin |
1488 | WaveStream := nil; |
1927 | WaveStream := nil; |
1489 | FWaveFileStream.Free; |
1928 | FWaveFileStream.Free; |
1490 | FWaveFileStream := nil; |
1929 | FWaveFileStream := nil; |
1491 | end; |
1930 | end; |
1492 | 1931 | ||
1493 | if Value<>'' then |
1932 | if Value <> '' then |
1494 | begin |
1933 | begin |
1495 | try |
1934 | try |
1496 | FWaveFileStream := TWaveFileStream.Create(Value, fmOpenRead or fmShareDenyWrite); |
1935 | FWaveFileStream := TWaveFileStream.Create(Value, fmOpenRead or fmShareDenyWrite); |
1497 | FWaveFileStream.Open(False); |
1936 | FWaveFileStream.Open(False); |
1498 | WaveStream := FWaveFileStream; |
1937 | WaveStream := FWaveFileStream; |
Line 1519... | Line 1958... | ||
1519 | function TSoundCaptureFormats.IndexOf(ASamplesPerSec, ABitsPerSample, AChannels: Integer): Integer; |
1958 | function TSoundCaptureFormats.IndexOf(ASamplesPerSec, ABitsPerSample, AChannels: Integer): Integer; |
1520 | var |
1959 | var |
1521 | i: Integer; |
1960 | i: Integer; |
1522 | begin |
1961 | begin |
1523 | Result := -1; |
1962 | Result := -1; |
1524 | for i:=0 to Count-1 do |
1963 | for i := 0 to Count - 1 do |
1525 | with Items[i] do |
1964 | with Items[i] do |
1526 | if (FSamplesPerSec=ASamplesPerSec) and (FBitsPerSample=ABitsPerSample) and (FChannels=AChannels) then |
1965 | if (FSamplesPerSec = ASamplesPerSec) and (FBitsPerSample = ABitsPerSample) and (FChannels = AChannels) then |
1527 | begin |
1966 | begin |
1528 | Result := i; |
1967 | Result := i; |
1529 | Break; |
1968 | Break; |
1530 | end; |
1969 | end; |
1531 | end; |
1970 | end; |
Line 1567... | Line 2006... | ||
1567 | if Assigned(FCapture.FOnFilledBuffer) then FCapture.Stop; |
2006 | if Assigned(FCapture.FOnFilledBuffer) then FCapture.Stop; |
1568 | end; |
2007 | end; |
1569 | 2008 | ||
1570 | procedure TSoundCaptureStreamNotify.Execute; |
2009 | procedure TSoundCaptureStreamNotify.Execute; |
1571 | begin |
2010 | begin |
1572 | while WaitForSingleObject(FCapture.FNotifyEvent, FSleepTime)=WAIT_TIMEOUT do |
2011 | while WaitForSingleObject(FCapture.FNotifyEvent, FSleepTime) = WAIT_TIMEOUT do |
1573 | begin |
2012 | begin |
1574 | Synchronize(Update); |
2013 | Synchronize(Update); |
1575 | end; |
2014 | end; |
1576 | end; |
2015 | end; |
1577 | 2016 | ||
1578 | procedure TSoundCaptureStreamNotify.Update; |
2017 | procedure TSoundCaptureStreamNotify.Update; |
1579 | begin |
2018 | begin |
1580 | if FCapture.FilledSize>0 then |
2019 | if FCapture.FilledSize > 0 then |
1581 | begin |
2020 | begin |
1582 | try |
2021 | try |
1583 | FCapture.DoFilledBuffer; |
2022 | FCapture.DoFilledBuffer; |
1584 | except |
2023 | except |
1585 | on E: Exception do |
2024 | on E: Exception do |
Line 1604... | Line 2043... | ||
1604 | begin |
2043 | begin |
1605 | inherited Create; |
2044 | inherited Create; |
1606 | FBufferLength := 1000; |
2045 | FBufferLength := 1000; |
1607 | FSupportedFormats := TSoundCaptureFormats.Create; |
2046 | FSupportedFormats := TSoundCaptureFormats.Create; |
1608 | 2047 | ||
1609 | if DXDirectSoundCaptureCreate(GUID, FCapture, nil)<>DS_OK then |
2048 | if DXDirectSoundCaptureCreate(GUID, FCapture, nil) <> DS_OK then |
1610 | raise ESoundCaptureStreamError.CreateFmt(SCannotInitialized, [SDirectSoundCapture]); |
2049 | raise ESoundCaptureStreamError.CreateFmt(SCannotInitialized, [SDirectSoundCapture]); |
1611 | 2050 | ||
1612 | { The supported format list is acquired. } |
2051 | { The supported format list is acquired. } |
1613 | for ASamplesPerSec:=Low(SamplesPerSecList) to High(SamplesPerSecList) do |
2052 | for ASamplesPerSec := Low(SamplesPerSecList) to High(SamplesPerSecList) do |
1614 | for ABitsPerSample:=Low(BitsPerSampleList) to High(BitsPerSampleList) do |
2053 | for ABitsPerSample := Low(BitsPerSampleList) to High(BitsPerSampleList) do |
1615 | for AChannels:=Low(ChannelsList) to High(ChannelsList) do |
2054 | for AChannels := Low(ChannelsList) to High(ChannelsList) do |
1616 | begin |
2055 | begin |
1617 | { Test } |
2056 | { Test } |
1618 | MakePCMWaveFormatEx(Format, SamplesPerSecList[ASamplesPerSec], BitsPerSampleList[ABitsPerSample], ChannelsList[AChannels]); |
2057 | MakePCMWaveFormatEx(Format, SamplesPerSecList[ASamplesPerSec], BitsPerSampleList[ABitsPerSample], ChannelsList[AChannels]); |
1619 | 2058 | ||
1620 | FillChar(dscbd, SizeOf(dscbd), 0); |
2059 | FillChar(dscbd, SizeOf(dscbd), 0); |
1621 | dscbd.dwSize := SizeOf(dscbd); |
2060 | dscbd.dwSize := SizeOf(dscbd); |
1622 | dscbd.dwBufferBytes := Format.nAvgBytesPerSec; |
2061 | dscbd.dwBufferBytes := Format.nAvgBytesPerSec; |
1623 | dscbd.lpwfxFormat := @Format; |
2062 | dscbd.lpwfxFormat := @Format; |
1624 | 2063 | ||
1625 | { If the buffer can be made, the format of present can be used. } |
2064 | { If the buffer can be made, the format of present can be used. } |
1626 | if FCapture.CreateCaptureBuffer(dscbd, TempBuffer, nil)=DS_OK then |
2065 | if FCapture.CreateCaptureBuffer(dscbd, TempBuffer, nil) = DS_OK then |
1627 | begin |
2066 | begin |
1628 | TempBuffer := nil; |
2067 | TempBuffer := nil; |
1629 | with TSoundCaptureFormat.Create(FSupportedFormats) do |
2068 | with TSoundCaptureFormat.Create(FSupportedFormats) do |
1630 | begin |
2069 | begin |
1631 | FSamplesPerSec := Format.nSamplesPerSec; |
2070 | FSamplesPerSec := Format.nSamplesPerSec; |
Line 1660... | Line 2099... | ||
1660 | 2099 | ||
1661 | function TSoundCaptureStream.GetReadSize: Integer; |
2100 | function TSoundCaptureStream.GetReadSize: Integer; |
1662 | var |
2101 | var |
1663 | CapturePosition, ReadPosition: DWORD; |
2102 | CapturePosition, ReadPosition: DWORD; |
1664 | begin |
2103 | begin |
1665 | if FBuffer.GetCurrentPosition(CapturePosition, ReadPosition)=DS_OK then |
2104 | if FBuffer.GetCurrentPosition(@DWORD(CapturePosition), @DWORD(ReadPosition)) = DS_OK then |
1666 | begin |
2105 | begin |
1667 | if FBufferPos<=ReadPosition then |
2106 | if FBufferPos <= ReadPosition then |
1668 | Result := ReadPosition - FBufferPos |
2107 | Result := ReadPosition - FBufferPos |
1669 | else |
2108 | else |
1670 | Result := FBufferSize - FBufferPos + ReadPosition; |
2109 | Result := FBufferSize - FBufferPos + ReadPosition; |
1671 | end else |
2110 | end else |
1672 | Result := 0; |
2111 | Result := 0; |
Line 1679... | Line 2118... | ||
1679 | Data1Size, Data2Size: DWORD; |
2118 | Data1Size, Data2Size: DWORD; |
1680 | C: Byte; |
2119 | C: Byte; |
1681 | begin |
2120 | begin |
1682 | if not FCapturing then |
2121 | if not FCapturing then |
1683 | Start; |
2122 | Start; |
- | 2123 | Data1 := nil; |
|
1684 | 2124 | Data2 := nil; |
|
1685 | Result := 0; |
2125 | Result := 0; |
1686 | while Result<Count do |
2126 | while Result < Count do |
1687 | begin |
2127 | begin |
1688 | Size := Min(Count-Result, GetReadSize); |
2128 | Size := Min(Count - Result, GetReadSize); |
1689 | if Size>0 then |
2129 | if Size > 0 then |
1690 | begin |
2130 | begin |
1691 | if FBuffer.Lock(FBufferPos, Size, Data1, Data1Size, Data2, Data2Size, 0)=DS_OK then |
2131 | if FBuffer.Lock(FBufferPos, Size, Data1, {$IFNDEF DX7}@{$ENDIF}Data1Size, |
- | 2132 | Data2, {$IFNDEF DX7}@{$ENDIF}Data2Size, 0) = DS_OK then |
|
1692 | begin |
2133 | begin |
1693 | Move(Data1^, Pointer(Integer(@Buffer)+Result)^, Data1Size); |
2134 | Move(Data1^, Pointer(Integer(@Buffer) + Result)^, Data1Size); |
1694 | Result := Result + Integer(Data1Size); |
2135 | Result := Result + Integer(Data1Size); |
1695 | 2136 | ||
1696 | if Data2<>nil then |
2137 | if Data2 <> nil then |
1697 | begin |
2138 | begin |
1698 | Move(Data2^, Pointer(Integer(@Buffer)+Result)^, Data2Size); |
2139 | Move(Data2^, Pointer(Integer(@Buffer) + Result)^, Data2Size); |
1699 | Result := Result + Integer(Data1Size); |
2140 | Result := Result + Integer(Data1Size); |
1700 | end; |
2141 | end; |
1701 | 2142 | ||
1702 | FBuffer.UnLock(Data1, Data1Size, Data2, Data2Size); |
2143 | FBuffer.UnLock(Data1, Data1Size, Data2, Data2Size); |
1703 | FBufferPos := (FBufferPos + Data1Size + Data2Size) mod FBufferSize; |
2144 | FBufferPos := (FBufferPos + Data1Size + Data2Size) mod FBufferSize; |
1704 | end else |
2145 | end else |
1705 | Break; |
2146 | Break; |
1706 | end; |
2147 | end; |
1707 | if Result<Count then Sleep(50); |
2148 | if Result < Count then Sleep(50); |
1708 | end; |
2149 | end; |
1709 | 2150 | ||
1710 | case Format^.wBitsPerSample of |
2151 | case Format^.wBitsPerSample of |
1711 | 8: C := $80; |
2152 | 8: C := $80; |
1712 | 16: C := $00; |
2153 | 16: C := $00; |
1713 | else |
2154 | else |
1714 | C := $00; |
2155 | C := $00; |
1715 | end; |
2156 | end; |
1716 | 2157 | ||
1717 | FillChar(Pointer(Integer(@Buffer)+Result)^, Count-Result, C); |
2158 | FillChar(Pointer(Integer(@Buffer) + Result)^, Count - Result, C); |
1718 | Result := Count; |
2159 | Result := Count; |
1719 | end; |
2160 | end; |
1720 | 2161 | ||
1721 | procedure TSoundCaptureStream.SetBufferLength(Value: Integer); |
2162 | procedure TSoundCaptureStream.SetBufferLength(Value: Integer); |
1722 | begin |
2163 | begin |
Line 1760... | Line 2201... | ||
1760 | FillChar(dscbd, SizeOf(dscbd), 0); |
2201 | FillChar(dscbd, SizeOf(dscbd), 0); |
1761 | dscbd.dwSize := SizeOf(dscbd); |
2202 | dscbd.dwSize := SizeOf(dscbd); |
1762 | dscbd.dwBufferBytes := FBufferSize; |
2203 | dscbd.dwBufferBytes := FBufferSize; |
1763 | dscbd.lpwfxFormat := Format; |
2204 | dscbd.lpwfxFormat := Format; |
1764 | 2205 | ||
1765 | if FCapture.CreateCaptureBuffer(dscbd, FBuffer, nil)<>DS_OK then |
2206 | if FCapture.CreateCaptureBuffer(dscbd, FBuffer, nil) <> DS_OK then |
1766 | raise ESoundCaptureStreamError.CreateFmt(SCannotMade, [SDirectSoundCaptureBuffer]); |
2207 | raise ESoundCaptureStreamError.CreateFmt(SCannotMade, [SDirectSoundCaptureBuffer]); |
1767 | 2208 | ||
1768 | FBufferPos := 0; |
2209 | FBufferPos := 0; |
1769 | 2210 | ||
1770 | FBuffer.Start(DSCBSTART_LOOPING); |
2211 | FBuffer.Start(DSCBSTART_LOOPING); |
Line 1784... | Line 2225... | ||
1784 | begin |
2225 | begin |
1785 | if FCapturing then |
2226 | if FCapturing then |
1786 | begin |
2227 | begin |
1787 | FNotifyThread.Free; |
2228 | FNotifyThread.Free; |
1788 | FCapturing := False; |
2229 | FCapturing := False; |
1789 | if FBuffer<>nil then |
2230 | if FBuffer <> nil then |
1790 | FBuffer.Stop; |
2231 | FBuffer.Stop; |
1791 | FBuffer := nil; |
2232 | FBuffer := nil; |
1792 | end; |
2233 | end; |
1793 | end; |
2234 | end; |
1794 | 2235 | ||
Line 1798... | Line 2239... | ||
1798 | begin |
2239 | begin |
1799 | inherited Create; |
2240 | inherited Create; |
1800 | FDSound := ADSound; |
2241 | FDSound := ADSound; |
1801 | FEnabled := True; |
2242 | FEnabled := True; |
1802 | 2243 | ||
1803 | - | ||
1804 | FEffectList := TList.Create; |
2244 | FEffectList := TList.Create; |
1805 | FTimer := TTimer.Create(nil); |
2245 | FTimer := TTimer.Create(nil); |
1806 | FTimer.Interval := 500; |
2246 | FTimer.Interval := 500; |
1807 | FTimer.OnTimer := TimerEvent; |
2247 | FTimer.OnTimer := TimerEvent; |
1808 | end; |
2248 | end; |
Line 1817... | Line 2257... | ||
1817 | 2257 | ||
1818 | procedure TSoundEngine.Clear; |
2258 | procedure TSoundEngine.Clear; |
1819 | var |
2259 | var |
1820 | i: Integer; |
2260 | i: Integer; |
1821 | begin |
2261 | begin |
1822 | for i:=EffectCount-1 downto 0 do |
2262 | for i := EffectCount - 1 downto 0 do |
1823 | Effects[i].Free; |
2263 | Effects[i].Free; |
1824 | FEffectList.Clear; |
2264 | FEffectList.Clear; |
1825 | end; |
2265 | end; |
1826 | 2266 | ||
1827 | procedure TSoundEngine.EffectFile(const Filename: string; Loop, Wait: Boolean); |
2267 | procedure TSoundEngine.EffectFile(const Filename: string; Loop, Wait: Boolean); |
1828 | var |
2268 | var |
1829 | Stream : TFileStream; |
2269 | Stream: TFileStream; |
1830 | begin |
2270 | begin |
1831 | Stream :=TFileStream.Create(Filename, fmOpenRead); |
2271 | Stream := TFileStream.Create(Filename, fmOpenRead); |
1832 | try |
2272 | try |
1833 | EffectStream(Stream, Loop, Wait); |
2273 | EffectStream(Stream, Loop, Wait); |
1834 | finally |
2274 | finally |
1835 | Stream.Free; |
2275 | Stream.Free; |
1836 | end; |
2276 | end; |
Line 1892... | Line 2332... | ||
1892 | 2332 | ||
1893 | procedure TSoundEngine.SetEnabled(Value: Boolean); |
2333 | procedure TSoundEngine.SetEnabled(Value: Boolean); |
1894 | var |
2334 | var |
1895 | i: Integer; |
2335 | i: Integer; |
1896 | begin |
2336 | begin |
1897 | for i:=EffectCount-1 downto 0 do |
2337 | for i := EffectCount - 1 downto 0 do |
1898 | Effects[i].Free; |
2338 | Effects[i].Free; |
1899 | FEffectList.Clear; |
2339 | FEffectList.Clear; |
1900 | 2340 | ||
1901 | FEnabled := Value; |
2341 | FEnabled := Value; |
1902 | FTimer.Enabled := Value; |
2342 | FTimer.Enabled := Value; |
Line 1904... | Line 2344... | ||
1904 | 2344 | ||
1905 | procedure TSoundEngine.TimerEvent(Sender: TObject); |
2345 | procedure TSoundEngine.TimerEvent(Sender: TObject); |
1906 | var |
2346 | var |
1907 | i: Integer; |
2347 | i: Integer; |
1908 | begin |
2348 | begin |
1909 | for i:=EffectCount-1 downto 0 do |
2349 | for i := EffectCount - 1 downto 0 do |
1910 | if not TDirectSoundBuffer(FEffectList[i]).Playing then |
2350 | if not TDirectSoundBuffer(FEffectList[i]).Playing then |
1911 | begin |
2351 | begin |
1912 | TDirectSoundBuffer(FEffectList[i]).Free; |
2352 | TDirectSoundBuffer(FEffectList[i]).Free; |
1913 | FEffectList.Delete(i); |
2353 | FEffectList.Delete(i); |
1914 | end; |
2354 | end; |
Line 1969... | Line 2409... | ||
1969 | procedure TCustomDXSound.UnRegisterNotifyEvent(NotifyEvent: TDXSoundNotifyEvent); |
2409 | procedure TCustomDXSound.UnRegisterNotifyEvent(NotifyEvent: TDXSoundNotifyEvent); |
1970 | var |
2410 | var |
1971 | Event: PDXSoundNotifyEvent; |
2411 | Event: PDXSoundNotifyEvent; |
1972 | i: Integer; |
2412 | i: Integer; |
1973 | begin |
2413 | begin |
1974 | for i:=0 to FNotifyEventList.Count-1 do |
2414 | for i := 0 to FNotifyEventList.Count - 1 do |
1975 | begin |
2415 | begin |
1976 | Event := FNotifyEventList[i]; |
2416 | Event := FNotifyEventList[i]; |
1977 | if (TMethod(Event^).Code = TMethod(NotifyEvent).Code) and |
2417 | if (TMethod(Event^).Code = TMethod(NotifyEvent).Code) and |
1978 | (TMethod(Event^).Data = TMethod(NotifyEvent).Data) then |
2418 | (TMethod(Event^).Data = TMethod(NotifyEvent).Data) then |
1979 | begin |
2419 | begin |
Line 1990... | Line 2430... | ||
1990 | 2430 | ||
1991 | procedure TCustomDXSound.NotifyEventList(NotifyType: TDXSoundNotifyType); |
2431 | procedure TCustomDXSound.NotifyEventList(NotifyType: TDXSoundNotifyType); |
1992 | var |
2432 | var |
1993 | i: Integer; |
2433 | i: Integer; |
1994 | begin |
2434 | begin |
1995 | for i:=FNotifyEventList.Count-1 downto 0 do |
2435 | for i := FNotifyEventList.Count - 1 downto 0 do |
1996 | PDXSoundNotifyEvent(FNotifyEventList[i])^(Self, NotifyType); |
2436 | PDXSoundNotifyEvent(FNotifyEventList[i])^(Self, NotifyType); |
1997 | end; |
2437 | end; |
1998 | 2438 | ||
1999 | procedure TCustomDXSound.FormWndProc(var Message: TMessage; DefWindowProc: TWndMethod); |
2439 | procedure TCustomDXSound.FormWndProc(var Message: TMessage; DefWindowProc: TWndMethod); |
2000 | begin |
2440 | begin |
2001 | case Message.Msg of |
2441 | case Message.Msg of |
2002 | WM_CREATE: |
2442 | WM_CREATE: |
2003 | begin |
2443 | begin |
2004 | DefWindowProc(Message); |
2444 | DefWindowProc(Message); |
2005 | SetForm(FForm); |
2445 | SetForm(FForm); |
2006 | Exit; |
2446 | Exit; |
2007 | end; |
2447 | end; |
2008 | end; |
2448 | end; |
2009 | DefWindowProc(Message); |
2449 | DefWindowProc(Message); |
2010 | end; |
2450 | end; |
2011 | 2451 | ||
2012 | class function TCustomDXSound.Drivers: TDirectXDrivers; |
2452 | class function TCustomDXSound.Drivers: TDirectXDrivers; |
Line 2055... | Line 2495... | ||
2055 | FInternalInitialized := False; |
2495 | FInternalInitialized := False; |
2056 | 2496 | ||
2057 | SetOptions(FOptions); |
2497 | SetOptions(FOptions); |
2058 | 2498 | ||
2059 | FPrimary.Free; FPrimary := nil; |
2499 | FPrimary.Free; FPrimary := nil; |
2060 | FDSound.Free; FDSound := nil; |
2500 | FDSound.Free; FDSound := nil; |
2061 | end; |
2501 | end; |
2062 | end; |
2502 | end; |
2063 | end; |
2503 | end; |
2064 | 2504 | ||
2065 | procedure TCustomDXSound.Initialize; |
2505 | procedure TCustomDXSound.Initialize; |
2066 | const |
2506 | const |
2067 | PrimaryDesc: TDSBufferDesc = ( |
2507 | PrimaryDesc: TDSBufferDesc = ( |
2068 | dwSize: SizeOf (PrimaryDesc); |
2508 | dwSize: SizeOf(PrimaryDesc); |
2069 | dwFlags: DSBCAPS_PRIMARYBUFFER); |
2509 | dwFlags: DSBCAPS_PRIMARYBUFFER); |
2070 | var |
2510 | var |
2071 | Component: TComponent; |
2511 | Component: TComponent; |
2072 | begin |
2512 | begin |
2073 | Finalize; |
2513 | Finalize; |
2074 | 2514 | ||
2075 | Component := Owner; |
2515 | Component := Owner; |
2076 | while (Component<>nil) and (not (Component is TCustomForm)) do |
2516 | while (Component <> nil) and (not (Component is TCustomForm)) do |
2077 | Component := Component.Owner; |
2517 | Component := Component.Owner; |
2078 | if Component=nil then |
2518 | if Component = nil then |
2079 | raise EDXSoundError.Create(SNoForm); |
2519 | raise EDXSoundError.Create(SNoForm); |
2080 | 2520 | ||
2081 | NotifyEventList(dsntInitializing); |
2521 | NotifyEventList(dsntInitializing); |
2082 | DoInitializing; |
2522 | DoInitializing; |
2083 | 2523 | ||
Line 2117... | Line 2557... | ||
2117 | begin |
2557 | begin |
2118 | try |
2558 | try |
2119 | Initialize; |
2559 | Initialize; |
2120 | except |
2560 | except |
2121 | on E: EDirectSoundError do ; |
2561 | on E: EDirectSoundError do ; |
2122 | else raise; |
2562 | else raise; |
2123 | end; |
2563 | end; |
2124 | end; |
2564 | end; |
2125 | end; |
2565 | end; |
2126 | 2566 | ||
2127 | procedure TCustomDXSound.Restore; |
2567 | procedure TCustomDXSound.Restore; |
Line 2221... | Line 2661... | ||
2221 | 2661 | ||
2222 | FWave.Assign(TWaveCollectionItem(Source).FWave); |
2662 | FWave.Assign(TWaveCollectionItem(Source).FWave); |
2223 | 2663 | ||
2224 | if PrevInitialized then |
2664 | if PrevInitialized then |
2225 | Restore; |
2665 | Restore; |
- | 2666 | end |
|
2226 | end else |
2667 | else |
2227 | inherited Assign(Source); |
2668 | inherited Assign(Source); |
- | 2669 | end; |
|
- | 2670 | ||
- | 2671 | function TWaveCollectionItem.GetPlaying: boolean; |
|
- | 2672 | var |
|
- | 2673 | Buffer: TDirectSoundBuffer; |
|
- | 2674 | index: integer; |
|
- | 2675 | begin |
|
- | 2676 | Result := False; |
|
- | 2677 | if not FInitialized then Exit; |
|
- | 2678 | Assert(GetBuffer <> nil); |
|
- | 2679 | Assert(FBufferList <> nil); |
|
- | 2680 | if FLooped then |
|
- | 2681 | begin |
|
- | 2682 | Buffer := GetBuffer; |
|
- | 2683 | Assert(Buffer <> nil); |
|
- | 2684 | Result := Buffer.Playing; |
|
- | 2685 | end |
|
- | 2686 | else |
|
- | 2687 | begin |
|
- | 2688 | for index := 0 to FBufferList.Count - 1 do |
|
- | 2689 | begin |
|
- | 2690 | Result := TDirectSoundBuffer(FBufferList[index]).Playing; |
|
2228 | end; |
2691 | if Result then |
- | 2692 | Break; |
|
- | 2693 | end; |
|
- | 2694 | end; |
|
- | 2695 | end; {GetPlaying} |
|
2229 | 2696 | ||
2230 | function TWaveCollectionItem.GetBuffer: TDirectSoundBuffer; |
2697 | function TWaveCollectionItem.GetBuffer: TDirectSoundBuffer; |
2231 | begin |
2698 | begin |
2232 | if FInitialized and (FBuffer=nil) then |
2699 | if FInitialized and (FBuffer = nil) then |
2233 | Restore; |
2700 | Restore; |
2234 | Result := FBuffer; |
2701 | Result := FBuffer; |
2235 | end; |
2702 | end; |
2236 | 2703 | ||
2237 | function TWaveCollectionItem.GetWaveCollection: TWaveCollection; |
2704 | function TWaveCollectionItem.GetWaveCollection: TWaveCollection; |
Line 2244... | Line 2711... | ||
2244 | i: Integer; |
2711 | i: Integer; |
2245 | begin |
2712 | begin |
2246 | if not FInitialized then Exit; |
2713 | if not FInitialized then Exit; |
2247 | FInitialized := False; |
2714 | FInitialized := False; |
2248 | 2715 | ||
2249 | for i:=0 to FBufferList.Count-1 do |
2716 | for i := 0 to FBufferList.Count - 1 do |
2250 | TDirectSoundBuffer(FBufferList[i]).Free; |
2717 | TDirectSoundBuffer(FBufferList[i]).Free; |
2251 | FBufferList.Clear; |
2718 | FBufferList.Clear; |
2252 | FBuffer.Free; FBuffer := nil; |
2719 | FBuffer.Free; FBuffer := nil; |
2253 | end; |
2720 | end; |
2254 | 2721 | ||
Line 2259... | Line 2726... | ||
2259 | end; |
2726 | end; |
2260 | 2727 | ||
2261 | function TWaveCollectionItem.CreateBuffer: TDirectSoundBuffer; |
2728 | function TWaveCollectionItem.CreateBuffer: TDirectSoundBuffer; |
2262 | begin |
2729 | begin |
2263 | Result := nil; |
2730 | Result := nil; |
2264 | if GetBuffer=nil then Exit; |
2731 | if GetBuffer = nil then Exit; |
2265 | 2732 | ||
2266 | Result := TDirectSoundBuffer.Create(WaveCollection.DXSound.DSound); |
2733 | Result := TDirectSoundBuffer.Create(WaveCollection.DXSound.DSound); |
2267 | try |
2734 | try |
2268 | Result.Assign(GetBuffer); |
2735 | Result.Assign(GetBuffer); |
2269 | except |
2736 | except |
Line 2282... | Line 2749... | ||
2282 | if FLooped then |
2749 | if FLooped then |
2283 | begin |
2750 | begin |
2284 | GetBuffer.Stop; |
2751 | GetBuffer.Stop; |
2285 | GetBuffer.Position := 0; |
2752 | GetBuffer.Position := 0; |
2286 | GetBuffer.Play(True); |
2753 | GetBuffer.Play(True); |
- | 2754 | end |
|
2287 | end else |
2755 | else |
2288 | begin |
2756 | begin |
2289 | NewBuffer := nil; |
2757 | NewBuffer := nil; |
2290 | for i:=0 to FBufferList.Count-1 do |
2758 | for i := 0 to FBufferList.Count - 1 do |
2291 | if not TDirectSoundBuffer(FBufferList[i]).Playing then |
2759 | if not TDirectSoundBuffer(FBufferList[i]).Playing then |
2292 | begin |
2760 | begin |
2293 | NewBuffer := FBufferList[i]; |
2761 | NewBuffer := FBufferList[i]; |
2294 | Break; |
2762 | Break; |
2295 | end; |
2763 | end; |
2296 | - | ||
- | 2764 | ||
2297 | if NewBuffer=nil then |
2765 | if NewBuffer = nil then |
2298 | begin |
2766 | begin |
2299 | if FMaxPlayingCount=0 then |
2767 | if FMaxPlayingCount = 0 then |
2300 | begin |
2768 | begin |
2301 | NewBuffer := CreateBuffer; |
2769 | NewBuffer := CreateBuffer; |
2302 | if NewBuffer=nil then Exit; |
2770 | if NewBuffer = nil then Exit; |
2303 | 2771 | ||
2304 | FBufferList.Add(NewBuffer); |
2772 | FBufferList.Add(NewBuffer); |
- | 2773 | end |
|
2305 | end else |
2774 | else |
2306 | begin |
2775 | begin |
2307 | if FBufferList.Count<FMaxPlayingCount then |
2776 | if FBufferList.Count < FMaxPlayingCount then |
2308 | begin |
2777 | begin |
2309 | NewBuffer := CreateBuffer; |
2778 | NewBuffer := CreateBuffer; |
2310 | if NewBuffer=nil then Exit; |
2779 | if NewBuffer = nil then Exit; |
2311 | 2780 | ||
2312 | FBufferList.Add(NewBuffer); |
2781 | FBufferList.Add(NewBuffer); |
- | 2782 | end |
|
2313 | end else |
2783 | else |
2314 | begin |
2784 | begin |
2315 | NewBuffer := FBufferList[0]; |
2785 | NewBuffer := FBufferList[0]; |
2316 | FBufferList.Move(0, FBufferList.Count-1); |
2786 | FBufferList.Move(0, FBufferList.Count - 1); |
2317 | end; |
2787 | end; |
2318 | end; |
2788 | end; |
2319 | end; |
2789 | end; |
2320 | 2790 | ||
2321 | NewBuffer.Stop; |
2791 | NewBuffer.Stop; |
Line 2333... | Line 2803... | ||
2333 | end; |
2803 | end; |
2334 | end; |
2804 | end; |
2335 | 2805 | ||
2336 | procedure TWaveCollectionItem.Restore; |
2806 | procedure TWaveCollectionItem.Restore; |
2337 | begin |
2807 | begin |
2338 | if FWave.Size=0 then Exit; |
2808 | if FWave.Size = 0 then Exit; |
2339 | 2809 | ||
2340 | if not FInitialized then |
2810 | if not FInitialized then |
2341 | begin |
2811 | begin |
2342 | if WaveCollection.Initialized then |
2812 | if WaveCollection.Initialized then |
2343 | Initialize; |
2813 | Initialize; |
2344 | if not FInitialized then Exit; |
2814 | if not FInitialized then Exit; |
2345 | end; |
2815 | end; |
2346 | 2816 | ||
2347 | if FBuffer=nil then |
2817 | if FBuffer = nil then |
2348 | FBuffer := TDirectSoundBuffer.Create(WaveCollection.DXSound.DSound); |
2818 | FBuffer := TDirectSoundBuffer.Create(WaveCollection.DXSound.DSound); |
2349 | 2819 | ||
2350 | FBuffer.LoadFromWave(FWave); |
2820 | FBuffer.LoadFromWave(FWave); |
2351 | FBuffer.Frequency := FFrequency; |
2821 | FBuffer.Frequency := FFrequency; |
2352 | FBuffer.Pan := FPan; |
2822 | FBuffer.Pan := FPan; |
Line 2358... | Line 2828... | ||
2358 | i: Integer; |
2828 | i: Integer; |
2359 | begin |
2829 | begin |
2360 | if not FInitialized then Exit; |
2830 | if not FInitialized then Exit; |
2361 | 2831 | ||
2362 | FBuffer.Stop; |
2832 | FBuffer.Stop; |
2363 | for i:=0 to FBufferList.Count-1 do |
2833 | for i := 0 to FBufferList.Count - 1 do |
2364 | TDirectSoundBuffer(FBufferList[i]).Stop; |
2834 | TDirectSoundBuffer(FBufferList[i]).Stop; |
2365 | end; |
2835 | end; |
2366 | 2836 | ||
2367 | procedure TWaveCollectionItem.SetFrequency(Value: Integer); |
2837 | procedure TWaveCollectionItem.SetFrequency(Value: Integer); |
2368 | begin |
2838 | begin |
Line 2371... | Line 2841... | ||
2371 | GetBuffer.Frequency := Value; |
2841 | GetBuffer.Frequency := Value; |
2372 | end; |
2842 | end; |
2373 | 2843 | ||
2374 | procedure TWaveCollectionItem.SetLooped(Value: Boolean); |
2844 | procedure TWaveCollectionItem.SetLooped(Value: Boolean); |
2375 | begin |
2845 | begin |
2376 | if FLooped<>Value then |
2846 | if FLooped <> Value then |
2377 | begin |
2847 | begin |
2378 | Stop; |
2848 | Stop; |
2379 | FLooped := Value; |
2849 | FLooped := Value; |
2380 | end; |
2850 | end; |
2381 | end; |
2851 | end; |
2382 | 2852 | ||
2383 | procedure TWaveCollectionItem.SetMaxPlayingCount(Value: Integer); |
2853 | procedure TWaveCollectionItem.SetMaxPlayingCount(Value: Integer); |
2384 | var |
2854 | var |
2385 | i: Integer; |
2855 | i: Integer; |
2386 | begin |
2856 | begin |
2387 | if Value<0 then Value := 0; |
2857 | if Value < 0 then Value := 0; |
2388 | 2858 | ||
2389 | if FMaxPlayingCount<>Value then |
2859 | if FMaxPlayingCount <> Value then |
2390 | begin |
2860 | begin |
2391 | FMaxPlayingCount := Value; |
2861 | FMaxPlayingCount := Value; |
2392 | 2862 | ||
2393 | if FInitialized then |
2863 | if FInitialized then |
2394 | begin |
2864 | begin |
2395 | for i:=0 to FBufferList.Count-1 do |
2865 | for i := 0 to FBufferList.Count - 1 do |
2396 | TDirectSoundBuffer(FBufferList[i]).Free; |
2866 | TDirectSoundBuffer(FBufferList[i]).Free; |
2397 | FBufferList.Clear; |
2867 | FBufferList.Clear; |
2398 | end; |
2868 | end; |
2399 | end; |
2869 | end; |
2400 | end; |
2870 | end; |
Line 2439... | Line 2909... | ||
2439 | function TWaveCollection.Find(const Name: string): TWaveCollectionItem; |
2909 | function TWaveCollection.Find(const Name: string): TWaveCollectionItem; |
2440 | var |
2910 | var |
2441 | i: Integer; |
2911 | i: Integer; |
2442 | begin |
2912 | begin |
2443 | i := IndexOf(Name); |
2913 | i := IndexOf(Name); |
2444 | if i=-1 then |
2914 | if i = -1 then |
2445 | raise EWaveCollectionError.CreateFmt(SWaveNotFound, [Name]); |
2915 | raise EWaveCollectionError.CreateFmt(SWaveNotFound, [Name]); |
2446 | Result := Items[i]; |
2916 | Result := Items[i]; |
2447 | end; |
2917 | end; |
2448 | 2918 | ||
2449 | procedure TWaveCollection.Finalize; |
2919 | procedure TWaveCollection.Finalize; |
2450 | var |
2920 | var |
2451 | i: Integer; |
2921 | i: Integer; |
2452 | begin |
2922 | begin |
2453 | for i:=0 to Count-1 do |
2923 | for i := 0 to Count - 1 do |
2454 | Items[i].Finalize; |
2924 | Items[i].Finalize; |
2455 | FDXSound := nil; |
2925 | FDXSound := nil; |
2456 | end; |
2926 | end; |
2457 | 2927 | ||
2458 | procedure TWaveCollection.Initialize(DXSound: TCustomDXSound); |
2928 | procedure TWaveCollection.Initialize(DXSound: TCustomDXSound); |
2459 | var |
2929 | var |
2460 | i: Integer; |
2930 | i: Integer; |
2461 | begin |
2931 | begin |
2462 | Finalize; |
2932 | Finalize; |
2463 | FDXSound := DXSound; |
2933 | FDXSound := DXSound; |
2464 | for i:=0 to Count-1 do |
2934 | for i := 0 to Count - 1 do |
2465 | Items[i].Initialize; |
2935 | Items[i].Initialize; |
2466 | end; |
2936 | end; |
2467 | 2937 | ||
2468 | function TWaveCollection.Initialized: Boolean; |
2938 | function TWaveCollection.Initialized: Boolean; |
2469 | begin |
2939 | begin |
2470 | Result := (FDXSound<>nil) and (FDXSound.Initialized); |
2940 | Result := (FDXSound <> nil) and (FDXSound.Initialized); |
2471 | end; |
2941 | end; |
2472 | 2942 | ||
2473 | procedure TWaveCollection.Restore; |
2943 | procedure TWaveCollection.Restore; |
2474 | var |
2944 | var |
2475 | i: Integer; |
2945 | i: Integer; |
2476 | begin |
2946 | begin |
2477 | for i:=0 to Count-1 do |
2947 | for i := 0 to Count - 1 do |
2478 | Items[i].Restore; |
2948 | Items[i].Restore; |
2479 | end; |
2949 | end; |
2480 | 2950 | ||
2481 | type |
2951 | type |
2482 | TWaveCollectionComponent = class(TComponent) |
2952 | TWaveCollectionComponent = class(TComponent) |
Line 2559... | Line 3029... | ||
2559 | end; |
3029 | end; |
2560 | 3030 | ||
2561 | procedure TCustomDXWaveList.Notification(AComponent: TComponent; Operation: TOperation); |
3031 | procedure TCustomDXWaveList.Notification(AComponent: TComponent; Operation: TOperation); |
2562 | begin |
3032 | begin |
2563 | inherited Notification(AComponent, Operation); |
3033 | inherited Notification(AComponent, Operation); |
2564 | if (Operation=opRemove) and (DXSound=AComponent) then |
3034 | if (Operation = opRemove) and (DXSound = AComponent) then |
2565 | DXSound := nil; |
3035 | DXSound := nil; |
2566 | end; |
3036 | end; |
2567 | 3037 | ||
2568 | procedure TCustomDXWaveList.DXSoundNotifyEvent(Sender: TCustomDXSound; |
3038 | procedure TCustomDXWaveList.DXSoundNotifyEvent(Sender: TCustomDXSound; |
2569 | NotifyType: TDXSoundNotifyType); |
3039 | NotifyType: TDXSoundNotifyType); |
2570 | begin |
3040 | begin |
2571 | case NotifyType of |
3041 | case NotifyType of |
2572 | dsntDestroying: DXSound := nil; |
3042 | dsntDestroying: DXSound := nil; |
2573 | dsntInitialize: FItems.Initialize(Sender); |
3043 | dsntInitialize: FItems.Initialize(Sender); |
2574 | dsntFinalize : FItems.Finalize; |
3044 | dsntFinalize: FItems.Finalize; |
2575 | dsntRestore : FItems.Restore; |
3045 | dsntRestore: FItems.Restore; |
2576 | end; |
3046 | end; |
2577 | end; |
3047 | end; |
2578 | 3048 | ||
2579 | procedure TCustomDXWaveList.SetDXSound(Value: TCustomDXSound); |
3049 | procedure TCustomDXWaveList.SetDXSound(Value: TCustomDXSound); |
2580 | begin |
3050 | begin |
2581 | if FDXSound<>nil then |
3051 | if FDXSound <> nil then |
2582 | FDXSound.UnRegisterNotifyEvent(DXSoundNotifyEvent); |
3052 | FDXSound.UnRegisterNotifyEvent(DXSoundNotifyEvent); |
2583 | 3053 | ||
2584 | FDXSound := Value; |
3054 | FDXSound := Value; |
2585 | 3055 | ||
2586 | if FDXSound<>nil then |
3056 | if FDXSound <> nil then |
2587 | FDXSound.RegisterNotifyEvent(DXSoundNotifyEvent); |
3057 | FDXSound.RegisterNotifyEvent(DXSoundNotifyEvent); |
2588 | end; |
3058 | end; |
2589 | 3059 | ||
2590 | procedure TCustomDXWaveList.SetItems(Value: TWaveCollection); |
3060 | procedure TCustomDXWaveList.SetItems(Value: TWaveCollection); |
2591 | begin |
3061 | begin |
2592 | FItems.Assign(Value); |
3062 | FItems.Assign(Value); |
2593 | end; |
3063 | end; |
2594 | 3064 | ||
- | 3065 | {(c) 2006 Jaro Benes, Play midi from memory module} |
|
- | 3066 | ||
- | 3067 | { TMusicDataProp } |
|
- | 3068 | ||
- | 3069 | type |
|
- | 3070 | TMidiDataHeader = packed record |
|
- | 3071 | Size: Integer; |
|
- | 3072 | end; |
|
- | 3073 | ||
- | 3074 | procedure TMusicDataProp.DefineProperties(Filer: TFiler); |
|
- | 3075 | begin |
|
- | 3076 | inherited DefineProperties(Filer); |
|
- | 3077 | Filer.DefineBinaryProperty('Midi', ReadMidiData, WriteMidiData, Length(Self.FMusicData) <> 0); |
|
- | 3078 | end; |
|
- | 3079 | ||
- | 3080 | function TMusicDataProp.GetMusicData: string; |
|
- | 3081 | begin |
|
- | 3082 | SetLength(Result, Length(FMusicData)); |
|
- | 3083 | if Length(FMusicData) <> 0 then |
|
- | 3084 | Move(FMusicData[1], Result[1], Length(FMusicData)); |
|
- | 3085 | end; |
|
- | 3086 | ||
- | 3087 | procedure TMusicDataProp.ReadMidiData(Stream: TStream); |
|
- | 3088 | var |
|
- | 3089 | Header: TMidiDataHeader; |
|
- | 3090 | begin |
|
- | 3091 | Stream.ReadBuffer(Header, SizeOf(Header)); |
|
- | 3092 | SetLength(FMusicData, Header.Size); |
|
- | 3093 | Stream.ReadBuffer(FMusicData[1], Header.Size); |
|
- | 3094 | end; |
|
- | 3095 | ||
- | 3096 | procedure TMusicDataProp.SetMusicData(const Value: string); |
|
- | 3097 | begin |
|
- | 3098 | SetLength(FMusicData, Length(Value)); |
|
- | 3099 | if Length(Value) <> 0 then |
|
- | 3100 | Move(Value[1], FMusicData[1], Length(Value)); |
|
- | 3101 | end; |
|
- | 3102 | ||
- | 3103 | procedure TMusicDataProp.WriteMidiData(Stream: TStream); |
|
- | 3104 | var |
|
- | 3105 | Header: TMidiDataHeader; |
|
- | 3106 | begin |
|
- | 3107 | Header.Size := Length(FMusicData); |
|
- | 3108 | Stream.WriteBuffer(Header, SizeOf(Header)); |
|
- | 3109 | Stream.WriteBuffer(FMusicData[1], Header.Size); |
|
- | 3110 | end; |
|
- | 3111 | ||
- | 3112 | { TMusicListCollectionItem } |
|
- | 3113 | ||
- | 3114 | procedure TMusicListCollectionItem.Load; |
|
- | 3115 | var |
|
- | 3116 | MidiFilelength: Integer; |
|
- | 3117 | begin |
|
- | 3118 | // kdyby nahodou uz nejaky existoval tak ho znic |
|
- | 3119 | if FDirectMusicSegment <> nil then |
|
- | 3120 | FDirectMusicSegment := nil; |
|
- | 3121 | ZeroMemory(@FMusicObjDesc, SizeOf(TDMUS_OBJECTDESC)); |
|
- | 3122 | // tohle je popisek parametru - chceme hrat z pameti |
|
- | 3123 | with FMusicObjDesc do |
|
- | 3124 | begin |
|
- | 3125 | dwsize := SizeOf(TDMUS_OBJECTDESC); |
|
- | 3126 | guidclass := CLSID_DirectMusicSegment; |
|
- | 3127 | //tohle jen pokud je to ze souboru |
|
- | 3128 | //dwvaliddata := DMUS_OBJ_CLASS or DMUS_OBJ_FULLPATH or DMUS_OBJ_FILENAME; |
|
- | 3129 | dwvaliddata := DMUS_OBJ_CLASS or DMUS_OBJ_MEMORY or DMUS_OBJ_LOADED; |
|
- | 3130 | pbMemData := @FMusicDataProp.FMusicData[1]; |
|
- | 3131 | llMemLength := Length(FMusicDataProp.FMusicData); |
|
- | 3132 | end; |
|
- | 3133 | if FDirectMusicLoader.GetObject(FMusicObjDesc, IID_IDirectMusicSegment, FDirectMusicSegment) <> dm_ok then |
|
- | 3134 | raise EDXMusicError.Create('Failed to Get object for Direct music'); ; |
|
- | 3135 | if FDirectMusicSegment.setParam(GUID_StandardMidiFile, $FFFFFFFF, 0, 0, Pointer(FDirectMusicPerformance)) <> dm_ok then |
|
- | 3136 | raise EDXMusicError.Create('Failed to Set param for Direct music'); ; |
|
- | 3137 | if FDirectMusicSegment.setParam(GUID_Download, $FFFFFFFF, 0, 0, Pointer(FDirectMusicPerformance)) <> dm_ok then |
|
- | 3138 | raise EDXMusicError.Create('Failed to Set param for Direct music'); ; |
|
- | 3139 | FDirectMusicSegment.GetLength(MidiFilelength); |
|
- | 3140 | if (FActualDuration < MidiFilelength) and (FActualDuration > 0) then |
|
- | 3141 | FDirectMusicSegment.SetLength(FActualDuration); |
|
- | 3142 | if FActualStartPoint < MidiFilelength - FActualDuration then |
|
- | 3143 | FDirectMusicSegment.SetStartpoint(FActualStartPoint); |
|
- | 3144 | // jak opakovat |
|
- | 3145 | FDirectMusicSegment.Setrepeats(repeats - 1); |
|
- | 3146 | end; |
|
- | 3147 | ||
- | 3148 | constructor TMusicListCollectionItem.Create(Collection: TCollection); |
|
- | 3149 | begin |
|
- | 3150 | inherited Create(Collection); |
|
- | 3151 | CoInitialize(nil); |
|
- | 3152 | FMusicDataProp := TMusicDataProp.Create; |
|
- | 3153 | SetLength(FMusicDataProp.FMusicData, 0); |
|
- | 3154 | FDirectMusicPerformance := nil; |
|
- | 3155 | FDirectMusic := nil; |
|
- | 3156 | FDirectSound := nil; |
|
- | 3157 | FDirectMusicSegment := nil; |
|
- | 3158 | FDirectMusicLoader := nil; |
|
- | 3159 | FIsInitialized := False; |
|
- | 3160 | end; |
|
- | 3161 | ||
- | 3162 | procedure TMusicListCollectionItem.Stop; |
|
- | 3163 | begin |
|
- | 3164 | if FDirectMusicPerformance <> nil then |
|
- | 3165 | FDirectMusicPerformance.Stop(nil, nil, 0, 0); |
|
- | 3166 | end; |
|
- | 3167 | ||
- | 3168 | function TMusicListCollectionItem.GetDisplayName: string; |
|
- | 3169 | begin |
|
- | 3170 | Result := inherited GetDisplayName |
|
- | 3171 | end; |
|
- | 3172 | ||
- | 3173 | procedure TMusicListCollectionItem.Play; |
|
- | 3174 | begin |
|
- | 3175 | if not FIsInitialized then |
|
- | 3176 | Init; |
|
- | 3177 | Load; |
|
- | 3178 | if FDirectMusicPerformance <> nil then |
|
- | 3179 | FDirectMusicPerformance.PlaySegment(FDirectMusicSegment, 0, 0, @FDirectMusicSegmentState); |
|
- | 3180 | end; |
|
- | 3181 | ||
- | 3182 | function TMusicListCollectionItem.IsPlaying: Boolean; |
|
- | 3183 | begin |
|
- | 3184 | Result := False; |
|
- | 3185 | if FDirectMusicPerformance <> nil then |
|
- | 3186 | Result := FDirectMusicPerformance.IsPlaying(FDirectMusicSegment, FDirectMusicSegmentState) = DM_OK; |
|
- | 3187 | end; |
|
- | 3188 | ||
- | 3189 | destructor TMusicListCollectionItem.Destroy; |
|
- | 3190 | begin |
|
- | 3191 | FDirectMusicPerformance := nil; |
|
- | 3192 | FDirectMusic := nil; |
|
- | 3193 | FDirectSound := nil; |
|
- | 3194 | FDirectMusicSegment := nil; |
|
- | 3195 | FDirectMusicLoader := nil; |
|
- | 3196 | FMusicDataProp.Free; |
|
- | 3197 | CoUninitialize; |
|
- | 3198 | inherited Destroy; |
|
- | 3199 | end; |
|
- | 3200 | ||
- | 3201 | procedure TMusicListCollectionItem.SetRepeats(const Value: Cardinal); |
|
- | 3202 | begin |
|
- | 3203 | Frepeats := Value; |
|
- | 3204 | end; |
|
- | 3205 | ||
- | 3206 | procedure TMusicListCollectionItem.SetStartPoint(const Value: integer); |
|
- | 3207 | begin |
|
- | 3208 | FStartPoint := Value; |
|
- | 3209 | end; |
|
- | 3210 | ||
- | 3211 | procedure TMusicListCollectionItem.SetDuration(const Value: integer); |
|
- | 3212 | begin |
|
- | 3213 | FDuration := Value; |
|
- | 3214 | end; |
|
- | 3215 | ||
- | 3216 | procedure TMusicListCollectionItem.Init; |
|
- | 3217 | var OK: Boolean; |
|
- | 3218 | begin |
|
- | 3219 | FIsInitialized := False; |
|
- | 3220 | OK := False; |
|
- | 3221 | // vytvor FDirectMusicPerformance pokud uz neni vytvoreno |
|
- | 3222 | if FDirectMusicPerformance = nil then |
|
- | 3223 | OK := CoCreateInstance(CLSID_DirectMusicPerformance, nil, CLSCTX_INPROC, |
|
- | 3224 | IID_IDirectMusicperformance, FDirectMusicPerformance) = DM_OK; |
|
- | 3225 | if not OK then Exit; |
|
- | 3226 | if FDirectSound <> nil then |
|
- | 3227 | OK := FDirectMusicPerformance.Init({$IFDEF DX7}@{$ENDIF}FDirectMusic, FDirectSound, 0) = DM_OK |
|
- | 3228 | else |
|
- | 3229 | OK := FDirectMusicPerformance.Init({$IFDEF DX7}@{$ENDIF}FDirectMusic, nil, 0) = dm_OK; |
|
- | 3230 | if not OK then Exit; |
|
- | 3231 | // vychozi midi port |
|
- | 3232 | // pridej pokud neni nastaven |
|
- | 3233 | if FDirectMusicPerformance.Addport(nil) <> DM_OK then Exit; |
|
- | 3234 | // zkus vytvorit loader |
|
- | 3235 | OK := CoCreateInstance(CLSID_DirectMusicLoader, nil, CLSCTX_Inproc, |
|
- | 3236 | IID_IDirectMusicLoader, FDirectMusicLoader) = DM_OK; |
|
- | 3237 | FIsInitialized := OK; |
|
- | 3238 | end; |
|
- | 3239 | ||
- | 3240 | function TMusicListCollectionItem.GetMusicListCollection: TMusicListCollection; |
|
- | 3241 | begin |
|
- | 3242 | Result := Collection as TMusicListCollection; |
|
- | 3243 | end; |
|
- | 3244 | ||
- | 3245 | procedure TMusicListCollectionItem.SaveToFile(const MidiFileName: string); |
|
- | 3246 | var F: file; |
|
- | 3247 | begin |
|
- | 3248 | AssignFile(F, MidiFileName); |
|
- | 3249 | Rewrite(F, 1); |
|
- | 3250 | try |
|
- | 3251 | BlockWrite(F, FMusicDataProp.FMusicData[1], Length(FMusicDataProp.FMusicData)); |
|
- | 3252 | finally |
|
- | 3253 | CloseFile(F); |
|
- | 3254 | end; |
|
- | 3255 | end; |
|
- | 3256 | ||
- | 3257 | procedure TMusicListCollectionItem.LoadFromFile(const MidiFileName: string); |
|
- | 3258 | var F: file; S: string; I: Integer; |
|
- | 3259 | begin |
|
- | 3260 | AssignFile(F, MidiFileName); |
|
- | 3261 | Reset(F, 1); |
|
- | 3262 | try |
|
- | 3263 | SetLength(FMusicDataProp.FMusicData, FileSize(F)); |
|
- | 3264 | BlockRead(F, FMusicDataProp.FMusicData[1], FileSize(F)); |
|
- | 3265 | S := ExtractFileName(MidiFileName); |
|
- | 3266 | I := Pos(ExtractFileExt(S), S); |
|
- | 3267 | if I > 0 then S := Copy(S, 1, I - 1); |
|
- | 3268 | FMusicDataProp.Midiname := S; |
|
- | 3269 | finally |
|
- | 3270 | CloseFile(F); |
|
- | 3271 | end; |
|
- | 3272 | Name := ExtractFileName(MidiFileName); |
|
- | 3273 | end; |
|
- | 3274 | ||
- | 3275 | function TMusicListCollectionItem.Size: Integer; |
|
- | 3276 | begin |
|
- | 3277 | Result := Length(FMusicDataProp.FMusicData); |
|
- | 3278 | end; |
|
- | 3279 | ||
- | 3280 | { TMusicListCollection } |
|
- | 3281 | ||
- | 3282 | constructor TMusicListCollection.Create(AOwner: TComponent); |
|
- | 3283 | begin |
|
- | 3284 | inherited Create(TMusicListCollectionItem); |
|
- | 3285 | FOwner := AOwner; |
|
- | 3286 | end; |
|
- | 3287 | ||
- | 3288 | function TMusicListCollection.Add: TMusicListCollectionItem; |
|
- | 3289 | begin |
|
- | 3290 | Result := TMusicListCollectionItem(inherited Add); |
|
- | 3291 | Result.FDirectSound := Self.FDirectSound; |
|
- | 3292 | end; |
|
- | 3293 | ||
- | 3294 | function TMusicListCollection.GetItem(Index: Integer): TMusicListCollectionItem; |
|
- | 3295 | begin |
|
- | 3296 | Result := TMusicListCollectionItem(inherited GetItem(Index)); |
|
- | 3297 | end; |
|
- | 3298 | ||
- | 3299 | procedure TMusicListCollection.SetItem(Index: Integer; |
|
- | 3300 | Value: TMusicListCollectionItem); |
|
- | 3301 | begin |
|
- | 3302 | inherited SetItem(Index, Value); |
|
- | 3303 | end; |
|
- | 3304 | ||
- | 3305 | procedure TMusicListCollection.Update(Item: TCollectionItem); |
|
- | 3306 | begin |
|
- | 3307 | inherited Update(Item); |
|
- | 3308 | end; |
|
- | 3309 | ||
- | 3310 | function TMusicListCollection.Find( |
|
- | 3311 | const Name: string): TMusicListCollectionItem; |
|
- | 3312 | var |
|
- | 3313 | i: Integer; |
|
- | 3314 | begin |
|
- | 3315 | i := IndexOf(Name); |
|
- | 3316 | if i = -1 then |
|
- | 3317 | raise EDXMusicError.CreateFmt('The midi document does not exist: %s.', [Name]); |
|
- | 3318 | Result := Items[i]; |
|
- | 3319 | end; |
|
- | 3320 | ||
- | 3321 | {$IFDEF VER4UP} |
|
- | 3322 | function TMusicListCollection.Insert(Index: Integer): TMusicListCollectionItem; |
|
- | 3323 | begin |
|
- | 3324 | Result := TMusicListCollectionItem(inherited Insert(Index)); |
|
- | 3325 | end; |
|
- | 3326 | {$ENDIF} |
|
- | 3327 | ||
- | 3328 | function TMusicListCollection.GetOwner: TPersistent; |
|
- | 3329 | begin |
|
- | 3330 | Result := FOwner; |
|
- | 3331 | end; |
|
- | 3332 | ||
- | 3333 | procedure TMusicListCollection.Restore; |
|
- | 3334 | begin |
|
- | 3335 | ||
- | 3336 | end; |
|
- | 3337 | ||
- | 3338 | procedure TMusicListCollection.SaveToFile(const FileName: string); |
|
- | 3339 | var |
|
- | 3340 | Stream: TFileStream; |
|
- | 3341 | begin |
|
- | 3342 | Stream := TFileStream.Create(FileName, fmCreate); |
|
- | 3343 | try |
|
- | 3344 | SaveToStream(Stream); |
|
- | 3345 | finally |
|
- | 3346 | Stream.Free; |
|
- | 3347 | end; |
|
- | 3348 | end; |
|
- | 3349 | ||
- | 3350 | procedure TMusicListCollection.LoadFromFile(const FileName: string); |
|
- | 3351 | var |
|
- | 3352 | Stream: TFileStream; |
|
- | 3353 | begin |
|
- | 3354 | Stream := TFileStream.Create(FileName, fmOpenRead or fmShareDenyWrite); |
|
- | 3355 | try |
|
- | 3356 | LoadFromStream(Stream); |
|
- | 3357 | finally |
|
- | 3358 | Stream.Free; |
|
- | 3359 | end; |
|
- | 3360 | end; |
|
- | 3361 | ||
- | 3362 | type |
|
- | 3363 | TMidiCollectionComponent = class(TComponent) |
|
- | 3364 | private |
|
- | 3365 | FList: TMusicListCollection; |
|
- | 3366 | published |
|
- | 3367 | property List: TMusicListCollection read FList write FList; |
|
- | 3368 | end; |
|
- | 3369 | ||
- | 3370 | procedure TMusicListCollection.SaveToStream(Stream: TStream); |
|
- | 3371 | var |
|
- | 3372 | Component: TMidiCollectionComponent; |
|
- | 3373 | begin |
|
- | 3374 | Component := TMidiCollectionComponent.Create(nil); |
|
- | 3375 | try |
|
- | 3376 | Component.FList := Self; |
|
- | 3377 | Stream.WriteComponentRes('DelphiXMidiCollection', Component); |
|
- | 3378 | finally |
|
- | 3379 | Component.Free; |
|
- | 3380 | end; |
|
- | 3381 | end; |
|
- | 3382 | ||
- | 3383 | procedure TMusicListCollection.LoadFromStream(Stream: TStream); |
|
- | 3384 | var |
|
- | 3385 | Component: TMidiCollectionComponent; |
|
- | 3386 | begin |
|
- | 3387 | Clear; |
|
- | 3388 | Component := TMidiCollectionComponent.Create(nil); |
|
- | 3389 | try |
|
- | 3390 | Component.FList := Self; |
|
- | 3391 | Stream.ReadComponentRes(Component); |
|
- | 3392 | Restore; |
|
- | 3393 | finally |
|
- | 3394 | Component.Free; |
|
- | 3395 | end; |
|
- | 3396 | end; |
|
- | 3397 | ||
- | 3398 | { TDXMusic } |
|
- | 3399 | ||
- | 3400 | constructor TDXMusic.Create(AOwner: TComponent); |
|
- | 3401 | begin |
|
- | 3402 | inherited Create(AOwner); |
|
- | 3403 | FMidis := TMusicListCollection.Create(Self); |
|
- | 3404 | if Assigned(FDXSound) then |
|
- | 3405 | FMidis.FDirectSound := FDXSound.DSound.IDSound; |
|
- | 3406 | end; |
|
- | 3407 | ||
- | 3408 | procedure TDXMusic.SetMidis(const value: TMusicListCollection); |
|
- | 3409 | begin |
|
- | 3410 | FMidis.Assign(Value); |
|
- | 3411 | end; |
|
- | 3412 | ||
- | 3413 | destructor TDXMusic.Destroy; |
|
- | 3414 | begin |
|
- | 3415 | FMidis.Free; |
|
- | 3416 | inherited Destroy; |
|
- | 3417 | end; |
|
- | 3418 | ||
- | 3419 | procedure TDXMusic.SetDXSound(const Value: TDXSound); |
|
- | 3420 | begin |
|
- | 3421 | FDXSound := Value; |
|
- | 3422 | if Assigned(FDXSound) then |
|
- | 3423 | FMidis.FDirectSound := FDXSound.DSound.IDSound; |
|
- | 3424 | end; |
|
- | 3425 | ||
2595 | initialization |
3426 | initialization |
2596 | finalization |
3427 | finalization |
2597 | DirectSoundDrivers.Free; |
3428 | DirectSoundDrivers.Free; |
2598 | DirectSoundCaptureDrivers.Free; |
3429 | DirectSoundCaptureDrivers.Free; |
2599 | end. |
3430 | end. |