📄 directsound.pas
字号:
var lplpvAudioPtr2: Pointer; var lpdwAudioBytes2: DWORD;
dwFlags: DWORD) : HResult; stdcall;
function Start(dwFlags: DWORD) : HResult; stdcall;
function Stop: HResult; stdcall;
function Unlock(lpvAudioPtr1: Pointer; dwAudioBytes1: DWORD;
lpvAudioPtr2: Pointer; dwAudioBytes2: DWORD) : HResult; stdcall;
end;
//
// IDirectSoundNotify
//
IDirectSoundNotify = interface (IUnknown)
['{b0210783-89cd-11d0-af08-00a0c925cd16}']
// IDirectSoundNotify methods
function SetNotificationPositions(cPositionNotifies: DWORD;
const lpcPositionNotifies: TDSBPositionNotify) : HResult; stdcall;
end;
//
// IKsPropertySet
//
IKsPropertySet = interface (IUnknown)
['{31efac30-515c-11d0-a9aa-00aa0061be93}']
// IKsPropertySet methods
function Get(const rguidPropSet: TGUID; ulId: DWORD; var pInstanceData;
ulInstanceLength: DWORD; var pPropertyData; ulDataLength: DWORD;
var pulBytesReturned: DWORD) : HResult; stdcall;
// Warning: The following method is defined as Set() in DirectX
// which is a reserved word in Delphi!
function SetProperty(const rguidPropSet: TGUID; ulId: DWORD;
var pInstanceData; ulInstanceLength: DWORD;
var pPropertyData; pulDataLength: DWORD) : HResult; stdcall;
function QuerySupport(const rguidPropSet: TGUID; ulId: DWORD;
var pulTypeSupport: DWORD) : HResult; stdcall;
end;
const
KSPROPERTY_SUPPORT_GET = $00000001;
KSPROPERTY_SUPPORT_SET = $00000002;
//
// GUID's for all the objects
//
type
IID_IDirectSound = IDirectSound;
IID_IDirectSoundBuffer = IDirectSoundBuffer;
IID_IDirectSound3DListener = IDirectSound3DListener;
IID_IDirectSound3DBuffer = IDirectSound3DBuffer;
IID_IDirectSoundCapture = IDirectSoundCapture;
IID_IDirectSoundCaptureBuffer = IDirectSoundCaptureBuffer;
IID_IDirectSoundNotify = IDirectSoundNotify;
IID_IKsPropertySet = IKsPropertySet;
//
// Creation Routines
//
var
DirectSoundCreate : function ( lpGuid: PGUID; out ppDS: IDirectSound;
pUnkOuter: IUnknown) : HResult; stdcall;
DirectSoundEnumerateW : function (lpDSEnumCallback: TDSEnumCallbackW;
lpContext: Pointer) : HResult; stdcall;
DirectSoundEnumerateA : function (lpDSEnumCallback: TDSEnumCallbackA;
lpContext: Pointer) : HResult; stdcall;
DirectSoundEnumerate : function (lpDSEnumCallback: TDSEnumCallback;
lpContext: Pointer) : HResult; stdcall;
DirectSoundCaptureCreate : function (lpGUID: PGUID;
out lplpDSC: IDirectSoundCapture;
pUnkOuter: IUnknown) : HResult; stdcall;
DirectSoundCaptureEnumerateW : function (lpDSEnumCallback: TDSEnumCallbackW;
lpContext: Pointer) : HResult; stdcall;
DirectSoundCaptureEnumerateA : function (lpDSEnumCallback: TDSEnumCallbackA;
lpContext: Pointer) : HResult; stdcall;
DirectSoundCaptureEnumerate : function(lpDSEnumCallback: TDSEnumCallback;
lpContext: Pointer) : HResult; stdcall;
//
// Return Codes
//
const
MAKE_DSHRESULT_ = HResult($88780000);
DS_OK = 0;
// The function completed successfully, but we had to substitute the 3D algorithm
DS_NO_VIRTUALIZATION = MAKE_DSHRESULT_ + 10;
// The call failed because resources (such as a priority level)
// were already being used by another caller.
DSERR_ALLOCATED = MAKE_DSHRESULT_ + 10;
// The control (vol,pan,etc.) requested by the caller is not available.
DSERR_CONTROLUNAVAIL = MAKE_DSHRESULT_ + 30;
// An invalid parameter was passed to the returning function
DSERR_INVALIDPARAM = E_INVALIDARG;
// This call is not valid for the current state of this object
DSERR_INVALIDCALL = MAKE_DSHRESULT_ + 50;
// An undetermined error occured inside the DirectSound subsystem
DSERR_GENERIC = E_FAIL;
// The caller does not have the priority level required for the function to
// succeed.
DSERR_PRIOLEVELNEEDED = MAKE_DSHRESULT_ + 70;
// Not enough free memory is available to complete the operation
DSERR_OUTOFMEMORY = E_OUTOFMEMORY;
// The specified WAVE format is not supported
DSERR_BADFORMAT = MAKE_DSHRESULT_ + 100;
// The function called is not supported at this time
DSERR_UNSUPPORTED = E_NOTIMPL;
// No sound driver is available for use
DSERR_NODRIVER = MAKE_DSHRESULT_ + 120;
// This object is already initialized
DSERR_ALREADYINITIALIZED = MAKE_DSHRESULT_ + 130;
// This object does not support aggregation
DSERR_NOAGGREGATION = CLASS_E_NOAGGREGATION;
// The buffer memory has been lost, and must be restored.
DSERR_BUFFERLOST = MAKE_DSHRESULT_ + 150;
// Another app has a higher priority level, preventing this call from
// succeeding.
DSERR_OTHERAPPHASPRIO = MAKE_DSHRESULT_ + 160;
// This object has not been initialized
DSERR_UNINITIALIZED = MAKE_DSHRESULT_ + 170;
// The requested COM interface is not available
DSERR_NOINTERFACE = E_NOINTERFACE;
// Access is denied
DSERR_ACCESSDENIED = E_ACCESSDENIED;
//
// Flags
//
DSCAPS_PRIMARYMONO = $00000001;
DSCAPS_PRIMARYSTEREO = $00000002;
DSCAPS_PRIMARY8BIT = $00000004;
DSCAPS_PRIMARY16BIT = $00000008;
DSCAPS_CONTINUOUSRATE = $00000010;
DSCAPS_EMULDRIVER = $00000020;
DSCAPS_CERTIFIED = $00000040;
DSCAPS_SECONDARYMONO = $00000100;
DSCAPS_SECONDARYSTEREO = $00000200;
DSCAPS_SECONDARY8BIT = $00000400;
DSCAPS_SECONDARY16BIT = $00000800;
DSSCL_NORMAL = $00000001;
DSSCL_PRIORITY = $00000002;
DSSCL_EXCLUSIVE = $00000003;
DSSCL_WRITEPRIMARY = $00000004;
DSSPEAKER_HEADPHONE = $00000001;
DSSPEAKER_MONO = $00000002;
DSSPEAKER_QUAD = $00000003;
DSSPEAKER_STEREO = $00000004;
DSSPEAKER_SURROUND = $00000005;
DSSPEAKER_5POINT1 = $00000006;
DSSPEAKER_GEOMETRY_MIN = $00000005; // 5 degrees
DSSPEAKER_GEOMETRY_NARROW = $0000000A; // 10 degrees
DSSPEAKER_GEOMETRY_WIDE = $00000014; // 20 degrees
DSSPEAKER_GEOMETRY_MAX = $000000B4; // 180 degrees
function DSSPEAKER_COMBINED(c, g: variant) : DWORD;
function DSSPEAKER_CONFIG(a: variant) : byte;
function DSSPEAKER_GEOMETRY(a: variant) : byte;
const
DSBCAPS_PRIMARYBUFFER = $00000001;
DSBCAPS_STATIC = $00000002;
DSBCAPS_LOCHARDWARE = $00000004;
DSBCAPS_LOCSOFTWARE = $00000008;
DSBCAPS_CTRL3D = $00000010;
DSBCAPS_CTRLFREQUENCY = $00000020;
DSBCAPS_CTRLPAN = $00000040;
DSBCAPS_CTRLVOLUME = $00000080;
DSBCAPS_CTRLPOSITIONNOTIFY = $00000100;
DSBCAPS_STICKYFOCUS = $00004000;
DSBCAPS_GLOBALFOCUS = $00008000;
DSBCAPS_GETCURRENTPOSITION2 = $00010000;
DSBCAPS_MUTE3DATMAXDISTANCE = $00020000;
DSBCAPS_LOCDEFER = $00040000;
DSBPLAY_LOOPING = $00000001;
DSBPLAY_LOCHARDWARE = $00000002;
DSBPLAY_LOCSOFTWARE = $00000004;
DSBPLAY_TERMINATEBY_TIME = $00000008;
DSBPLAY_TERMINATEBY_DISTANCE = $000000010;
DSBPLAY_TERMINATEBY_PRIORITY = $000000020;
DSBSTATUS_PLAYING = $00000001;
DSBSTATUS_BUFFERLOST = $00000002;
DSBSTATUS_LOOPING = $00000004;
DSBSTATUS_LOCHARDWARE = $00000008;
DSBSTATUS_LOCSOFTWARE = $00000010;
DSBSTATUS_TERMINATED = $00000020;
DSBLOCK_FROMWRITECURSOR = $00000001;
DSBLOCK_ENTIREBUFFER = $00000002;
DSBFREQUENCY_MIN = 100;
DSBFREQUENCY_MAX = 100000;
DSBFREQUENCY_ORIGINAL = 0;
DSBPAN_LEFT = -10000;
DSBPAN_CENTER = 0;
DSBPAN_RIGHT = 10000;
DSBVOLUME_MIN = -10000;
DSBVOLUME_MAX = 0;
DSBSIZE_MIN = 4;
DSBSIZE_MAX = $0FFFFFFF;
DS3DMODE_NORMAL = $00000000;
DS3DMODE_HEADRELATIVE = $00000001;
DS3DMODE_DISABLE = $00000002;
DS3D_IMMEDIATE = $00000000;
DS3D_DEFERRED = $00000001;
DS3D_MINDISTANCEFACTOR = FLT_MIN;
DS3D_MAXDISTANCEFACTOR = FLT_MAX;
DS3D_DEFAULTDISTANCEFACTOR = 1.0;
DS3D_MINROLLOFFFACTOR = 0.0;
DS3D_MAXROLLOFFFACTOR = 10.0;
DS3D_DEFAULTROLLOFFFACTOR = 1.0;
DS3D_MINDOPPLERFACTOR = 0.0;
DS3D_MAXDOPPLERFACTOR = 10.0;
DS3D_DEFAULTDOPPLERFACTOR = 1.0;
DS3D_DEFAULTMINDISTANCE = 1.0;
DS3D_DEFAULTMAXDISTANCE = 1000000000.0;
DS3D_MINCONEANGLE = 0;
DS3D_MAXCONEANGLE = 360;
DS3D_DEFAULTCONEANGLE = 360;
DS3D_DEFAULTCONEOUTSIDEVOLUME = DSBVOLUME_MAX;
DSCCAPS_EMULDRIVER = $00000020;
DSCCAPS_CERTIFIED = DSCAPS_CERTIFIED;
DSCBCAPS_WAVEMAPPED = $80000000;
DSBCAPS_CTRLDEFAULT = $000000E0;
DSBCAPS_CTRLALL = $000001F0;
DSCBLOCK_ENTIREBUFFER = $00000001;
DSCBSTATUS_CAPTURING = $00000001;
DSCBSTATUS_LOOPING = $00000002;
DSCBSTART_LOOPING = $00000001;
DSBPN_OFFSETSTOP = DWORD(-1);
//
// DirectSound3D Algorithms
//
// Default DirectSound3D algorithm {00000000-0000-0000-0000-000000000000}
DS3DALG_DEFAULT: TGUID = '{00000000-0000-0000-0000-000000000000}';
// No virtualization {C241333F-1C1B-11d2-94F5-00C04FC28ACA}
DS3DALG_NO_VIRTUALIZATION: TGUID = '';
// High-quality HRTF algorithm {C2413340-1C1B-11d2-94F5-00C04FC28ACA}
DS3DALG_HRTF_FULL: TGUID = '{C2413340-1C1B-11d2-94F5-00C04FC28ACA}';
// Lower-quality HRTF algorithm {C2413342-1C1B-11d2-94F5-00C04FC28ACA}
DS3DALG_HRTF_LIGHT: TGUID = '{C2413342-1C1B-11d2-94F5-00C04FC28ACA}';
implementation
uses
DXCommon;
function MAKE_DSHRESULT(code: DWORD) : HResult;
begin
Result := HResult(1 shl 31) or HResult(_FACDS shl 16)
or HResult(code);
end;
function DSSPEAKER_COMBINED(c, g: variant) : DWORD;
begin
Result := byte(c) or (byte(g) shl 16)
end;
function DSSPEAKER_CONFIG(a: variant) : byte;
begin
Result := byte(a);
end;
function DSSPEAKER_GEOMETRY(a: variant) : byte;
begin
Result := byte(a shr 16 and $FF);
end;
function DSErrorString(Value: HResult) : string;
begin
case Value of
DS_OK: Result := 'The request completed successfully.';
DSERR_ALLOCATED: Result := 'The request failed because resources, such as a priority level, were already in use by another caller.';
DSERR_ALREADYINITIALIZED: Result := 'The object is already initialized.';
DSERR_BADFORMAT: Result := 'The specified wave format is not supported.';
DSERR_BUFFERLOST: Result := 'The buffer memory has been lost and must be restored.';
DSERR_CONTROLUNAVAIL: Result := 'The control (volume, pan, and so forth) requested by the caller is not available.';
DSERR_GENERIC: Result := 'An undetermined error occurred inside the DirectSound subsystem.';
DSERR_INVALIDCALL: Result := 'This function is not valid for the current state of this object.';
DSERR_INVALIDPARAM: Result := 'An invalid parameter was passed to the returning function.';
DSERR_NOAGGREGATION: Result := 'The object does not support aggregation.';
DSERR_NODRIVER: Result := 'No sound driver is available for use.';
DSERR_NOINTERFACE: Result := 'The requested COM interface is not available.';
DSERR_OTHERAPPHASPRIO: Result := 'Another application has a higher priority level, preventing this call from succeeding.';
DSERR_OUTOFMEMORY: Result := 'The DirectSound subsystem could not allocate sufficient memory to complete the caller磗 request.';
DSERR_PRIOLEVELNEEDED: Result := 'The caller does not have the priority level required for the function to succeed.';
DSERR_UNINITIALIZED: Result := 'The IDirectSound::Initialize method has not been called or has not been called successfully before other methods were called.';
DSERR_UNSUPPORTED: Result := 'The function called is not supported at this time.';
else Result := 'Unrecognized Error';
end;
end;
initialization
begin
if not IsNTandDelphiRunning then
begin
DSoundDLL := LoadLibrary('DSound.dll');
DirectSoundCreate := GetProcAddress(DSoundDLL,'DirectSoundCreate');
DirectSoundEnumerateW := GetProcAddress(DSoundDLL,'DirectSoundEnumerateW');
DirectSoundEnumerateA := GetProcAddress(DSoundDLL,'DirectSoundEnumerateA');
{$IFDEF UNICODE}
DirectSoundEnumerate := DirectSoundEnumerateW;
{$ELSE}
DirectSoundEnumerate := DirectSoundEnumerateA;
{$ENDIF}
DirectSoundCaptureCreate :=
GetProcAddress(DSoundDLL,'DirectSoundCaptureCreate');
DirectSoundCaptureEnumerateW :=
GetProcAddress(DSoundDLL,'DirectSoundCaptureEnumerateW');
DirectSoundCaptureEnumerateA :=
GetProcAddress(DSoundDLL,'DirectSoundCaptureEnumerateA');
{$IFDEF UNICODE}
DirectSoundCaptureEnumerate := DirectSoundCaptureEnumerateW;
{$ELSE}
DirectSoundCaptureEnumerate := DirectSoundCaptureEnumerateA;
{$ENDIF}
end;
end;
finalization
begin
FreeLibrary(DSoundDLL);
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -