----------------------------------------
-- Microsoft DirectX Ada binding lib --
-- File : XAudio2fx.ads --
-- Translator:Dongfeng.Gu,2018/11/16 --
-- Mail: 515639@qq.com --
-- Progress:100% --
----------------------------------------
with Ada.Unchecked_Conversion;
with Win32; use win32;
with win32.rpcdce;
with win32.Objbase; use win32.Objbase;
with Interfaces.C;
package XAudio2fx is
CLSID_AudioVolumeMeter:constant win32.rpcdce.GUID:=(16#2139e6da#,16#c341#,16#4774#,(16#9a#,16#c3#,16#b4#,16#e0#,16#26#,16#34#,16#7f#,16#64#));
CLSID_AudioVolumeMeter_Debug:constant win32.rpcdce.GUID:=(16#a5cc4e13#,16#ca00#,16#416b#,(16#a6#,16#ee#,16#49#,16#fe#,16#e7#,16#b5#,16#43#,16#d0#));
CLSID_AudioReverb:constant win32.rpcdce.GUID:=(16#d06df0d0#,16#8518#,16#441e#,(16#82#,16#2f#,16#54#,16#51#,16#d5#,16#c5#,16#95#,16#b8#));
CLSID_AudioReverb_Debug:constant win32.rpcdce.GUID:=(16#613604ec#,16#304c#,16#45ec#,(16#a4#,16#ed#,16#7a#,16#1c#,16#61#,16#2e#,16#9e#,16#72#));
XAUDIO2FX_DEBUG : constant := 1; -- To select the debug version of an effect;
type LPIUNKNOWN is access all IUnknown;
type LPLPIUNKNOWN is access all LPIUNKNOWN;
function CreateAudioVolumeMeter(ppApo:LPLPIUnknown) return HRESULT with Import,Convention=>stdcall,external_name=>"CreateAudioVolumeMeter";
function CreateAudioReverb(ppApo:LPLPIUnknown) return HRESULT with Import,Convention=>stdcall,external_name=>"CreateAudioReverb";
-- FOR XBOX
function XBOX_XAudio2CreateVolumeMeter(ppApo:LPLPIUNKNOWN;Flags:UINT32:=0) return HRESULT is (CreateAudioVolumeMeter(ppApo)) with Inline;
function XBOX_XAudio2CreateReverb(ppApo:LPLPIUNKNOWN;Flags:UINT32:=0) return HRESULT is (CreateAudioReverb(ppApo)) with Inline;
-- FOR WINDOWS
use type Interfaces.C.unsigned;
type TagLPVOID is access all PVOID;
function AsPPVOID is new Ada.Unchecked_Conversion(LPLPIUNKNOWN,TagLPVOID);
function XAudio2CreateVolumeMeter(ppApo:LPLPIUNKNOWN;Flags:UINT32:=0) return HRESULT is (CoCreateInstance((if (Flags and XAUDIO2FX_DEBUG) /=0 then CLSID_AudioVolumeMeter_Debug'Unrestricted_Access else CLSID_AudioVolumeMeter'Unrestricted_Access),
Null,
1,
IID_IUnknown'Unrestricted_Access,
AsPPVOID(ppApo)
)) with Inline;
function XAudio2CreateReverb(ppApo:LPLPIUNKNOWN;Flags:UINT32:=0) return HRESULT is (CoCreateInstance((if (Flags and XAUDIO2FX_DEBUG) /=0 then CLSID_AudioReverb_Debug'Unrestricted_Access else CLSID_AudioReverb'Unrestricted_Access),
Null,
1,
IID_IUnknown'Unrestricted_Access,
AsPPVOID(ppApo)
)) with Inline;
type XAUDIO2FX_VOLUMEMETER_LEVELS is record
pPeakLevels:LPfloat;
pRMSLevels:LPfloat;
ChannelCount: UINT32;
end record with Pack;
type LPXAUDIO2FX_VOLUMEMETER_LEVELS is access all XAUDIO2FX_VOLUMEMETER_LEVELS;
XAUDIO2FX_REVERB_MIN_FRAMERATE : constant := 20000;
XAUDIO2FX_REVERB_MAX_FRAMERATE : constant := 48000;
type XAUDIO2FX_REVERB_PARAMETERS is record
WetDryMix: float;
ReflectionsDelay: UINT32;
ReverbDelay: BYTE;
RearDelay: BYTE;
PositionLeft: BYTE;
PositionRight: BYTE;
PositionMatrixLeft: BYTE;
PositionMatrixRight: BYTE;
EarlyDiffusion: BYTE;
LateDiffusion: BYTE;
LowEQGain: BYTE;
LowEQCutoff: BYTE;
HighEQGain: BYTE;
HighEQCutoff: BYTE;
RoomFilterFreq: float;
RoomFilterMain: float;
RoomFilterHF: float;
ReflectionsGain: float;
ReverbGain: float;
DecayTime: float;
Density: float;
RoomSize: float;
end record with Pack;
type LPXAUDIO2FX_REVERB_PARAMETERS is access all XAUDIO2FX_REVERB_PARAMETERS;
XAUDIO2FX_REVERB_MIN_WET_DRY_MIX : constant := 0.0;
XAUDIO2FX_REVERB_MIN_REFLECTIONS_DELAY : constant := 0;
XAUDIO2FX_REVERB_MIN_REVERB_DELAY : constant := 0;
XAUDIO2FX_REVERB_MIN_REAR_DELAY : constant := 0;
XAUDIO2FX_REVERB_MIN_POSITION : constant := 0;
XAUDIO2FX_REVERB_MIN_DIFFUSION : constant := 0;
XAUDIO2FX_REVERB_MIN_LOW_EQ_GAIN : constant := 0;
XAUDIO2FX_REVERB_MIN_LOW_EQ_CUTOFF : constant := 0;
XAUDIO2FX_REVERB_MIN_HIGH_EQ_GAIN : constant := 0;
XAUDIO2FX_REVERB_MIN_HIGH_EQ_CUTOFF : constant := 0;
XAUDIO2FX_REVERB_MIN_ROOM_FILTER_FREQ : constant := 20.0;
XAUDIO2FX_REVERB_MIN_ROOM_FILTER_MAIN : constant := -100.0;
XAUDIO2FX_REVERB_MIN_ROOM_FILTER_HF : constant := -100.0;
XAUDIO2FX_REVERB_MIN_REFLECTIONS_GAIN : constant := -100.0;
XAUDIO2FX_REVERB_MIN_REVERB_GAIN : constant := -100.0;
XAUDIO2FX_REVERB_MIN_DECAY_TIME : constant := 0.1;
XAUDIO2FX_REVERB_MIN_DENSITY : constant := 0.0;
XAUDIO2FX_REVERB_MIN_ROOM_SIZE : constant := 0.0;
XAUDIO2FX_REVERB_MAX_WET_DRY_MIX : constant := 100.0;
XAUDIO2FX_REVERB_MAX_REFLECTIONS_DELAY : constant := 300;
XAUDIO2FX_REVERB_MAX_REVERB_DELAY : constant := 85;
XAUDIO2FX_REVERB_MAX_REAR_DELAY : constant := 5;
XAUDIO2FX_REVERB_MAX_POSITION : constant := 30;
XAUDIO2FX_REVERB_MAX_DIFFUSION : constant := 15;
XAUDIO2FX_REVERB_MAX_LOW_EQ_GAIN : constant := 12;
XAUDIO2FX_REVERB_MAX_LOW_EQ_CUTOFF : constant := 9;
XAUDIO2FX_REVERB_MAX_HIGH_EQ_GAIN : constant := 8;
XAUDIO2FX_REVERB_MAX_HIGH_EQ_CUTOFF : constant := 14;
XAUDIO2FX_REVERB_MAX_ROOM_FILTER_FREQ : constant := 20000.0;
XAUDIO2FX_REVERB_MAX_ROOM_FILTER_MAIN : constant := 0.0;
XAUDIO2FX_REVERB_MAX_ROOM_FILTER_HF : constant := 0.0;
XAUDIO2FX_REVERB_MAX_REFLECTIONS_GAIN : constant := 20.0;
XAUDIO2FX_REVERB_MAX_REVERB_GAIN : constant := 20.0;
XAUDIO2FX_REVERB_MAX_DENSITY : constant := 100.0;
XAUDIO2FX_REVERB_MAX_ROOM_SIZE : constant := 100.0;
XAUDIO2FX_REVERB_DEFAULT_WET_DRY_MIX : constant := 100.0;
XAUDIO2FX_REVERB_DEFAULT_REFLECTIONS_DELAY : constant := 5;
XAUDIO2FX_REVERB_DEFAULT_REVERB_DELAY : constant := 5;
XAUDIO2FX_REVERB_DEFAULT_REAR_DELAY : constant := 5;
XAUDIO2FX_REVERB_DEFAULT_POSITION : constant := 6;
XAUDIO2FX_REVERB_DEFAULT_POSITION_MATRIX : constant := 27;
XAUDIO2FX_REVERB_DEFAULT_EARLY_DIFFUSION : constant := 8;
XAUDIO2FX_REVERB_DEFAULT_LATE_DIFFUSION : constant := 8;
XAUDIO2FX_REVERB_DEFAULT_LOW_EQ_GAIN : constant := 8;
XAUDIO2FX_REVERB_DEFAULT_LOW_EQ_CUTOFF : constant := 4;
XAUDIO2FX_REVERB_DEFAULT_HIGH_EQ_GAIN : constant := 8;
XAUDIO2FX_REVERB_DEFAULT_HIGH_EQ_CUTOFF : constant := 4;
XAUDIO2FX_REVERB_DEFAULT_ROOM_FILTER_FREQ : constant := 5000.0;
XAUDIO2FX_REVERB_DEFAULT_ROOM_FILTER_MAIN : constant := 0.0;
XAUDIO2FX_REVERB_DEFAULT_ROOM_FILTER_HF : constant := 0.0;
XAUDIO2FX_REVERB_DEFAULT_REFLECTIONS_GAIN : constant := 0.0;
XAUDIO2FX_REVERB_DEFAULT_REVERB_GAIN : constant := 0.0;
XAUDIO2FX_REVERB_DEFAULT_DECAY_TIME : constant := 1.0;
XAUDIO2FX_REVERB_DEFAULT_DENSITY : constant := 100.0;
XAUDIO2FX_REVERB_DEFAULT_ROOM_SIZE : constant := 100.0;
type XAUDIO2FX_REVERB_I3DL2_PARAMETERS is record
WetDryMix: float;
Room: INT32;
RoomHF: INT32;
RoomRolloffFactor: float;
DecayTime: float;
DecayHFRatio: float;
Reflections: INT32;
ReflectionsDelay: float;
Reverb: INT32;
ReverbDelay: float;
Diffusion: float;
Density: float;
HFReference: float;
end record with Pack;
type LPXAUDIO2FX_REVERB_I3DL2_PARAMETERS is access all XAUDIO2FX_REVERB_I3DL2_PARAMETERS;
procedure ReverbConvertI3DL2ToNative(pI3DL2:access constant XAUDIO2FX_REVERB_I3DL2_PARAMETERS;pNative:access XAUDIO2FX_REVERB_PARAMETERS) with Inline;
use type Interfaces.C.int;
XAUDIO2FX_I3DL2_PRESET_DEFAULT : constant XAUDIO2FX_REVERB_I3DL2_PARAMETERS := (100.0,-10000, 0,0.0, 1.00,0.50,-10000,0.020,-10000,0.040,100.0,100.0,5000.0);
XAUDIO2FX_I3DL2_PRESET_GENERIC : constant XAUDIO2FX_REVERB_I3DL2_PARAMETERS := (100.0, -1000, -100,0.0, 1.49,0.83, -2602,0.007, 200,0.011,100.0,100.0,5000.0);
XAUDIO2FX_I3DL2_PRESET_PADDEDCELL : constant XAUDIO2FX_REVERB_I3DL2_PARAMETERS := (100.0, -1000,-6000,0.0, 0.17,0.10, -1204,0.001, 207,0.002,100.0,100.0,5000.0);
XAUDIO2FX_I3DL2_PRESET_ROOM : constant XAUDIO2FX_REVERB_I3DL2_PARAMETERS := (100.0, -1000, -454,0.0, 0.40,0.83, -1646,0.002, 53,0.003,100.0,100.0,5000.0);
XAUDIO2FX_I3DL2_PRESET_BATHROOM : constant XAUDIO2FX_REVERB_I3DL2_PARAMETERS := (100.0, -1000,-1200,0.0, 1.49,0.54, -370,0.007, 1030,0.011,100.0, 60.0,5000.0);
XAUDIO2FX_I3DL2_PRESET_LIVINGROOM : constant XAUDIO2FX_REVERB_I3DL2_PARAMETERS := (100.0, -1000,-6000,0.0, 0.50,0.10, -1376,0.003, -1104,0.004,100.0,100.0,5000.0);
XAUDIO2FX_I3DL2_PRESET_STONEROOM : constant XAUDIO2FX_REVERB_I3DL2_PARAMETERS := (100.0, -1000, -300,0.0, 2.31,0.64, -711,0.012, 83,0.017,100.0,100.0,5000.0);
XAUDIO2FX_I3DL2_PRESET_AUDITORIUM : constant XAUDIO2FX_REVERB_I3DL2_PARAMETERS := (100.0, -1000, -476,0.0, 4.32,0.59, -789,0.020, -289,0.030,100.0,100.0,5000.0);
XAUDIO2FX_I3DL2_PRESET_CONCERTHALL : constant XAUDIO2FX_REVERB_I3DL2_PARAMETERS := (100.0, -1000, -500,0.0, 3.92,0.70, -1230,0.020, -2,0.029,100.0,100.0,5000.0);
XAUDIO2FX_I3DL2_PRESET_CAVE : constant XAUDIO2FX_REVERB_I3DL2_PARAMETERS := (100.0, -1000, 0,0.0, 2.91,1.30, -602,0.015, -302,0.022,100.0,100.0,5000.0);
XAUDIO2FX_I3DL2_PRESET_ARENA : constant XAUDIO2FX_REVERB_I3DL2_PARAMETERS := (100.0, -1000, -698,0.0, 7.24,0.33, -1166,0.020, 16,0.030,100.0,100.0,5000.0);
XAUDIO2FX_I3DL2_PRESET_HANGAR : constant XAUDIO2FX_REVERB_I3DL2_PARAMETERS := (100.0, -1000,-1000,0.0,10.05,0.23, -602,0.020, 198,0.030,100.0,100.0,5000.0);
XAUDIO2FX_I3DL2_PRESET_CARPETEDHALLWAY : constant XAUDIO2FX_REVERB_I3DL2_PARAMETERS := (100.0, -1000,-4000,0.0, 0.30,0.10, -1831,0.002, -1630,0.030,100.0,100.0,5000.0);
XAUDIO2FX_I3DL2_PRESET_HALLWAY : constant XAUDIO2FX_REVERB_I3DL2_PARAMETERS := (100.0, -1000, -300,0.0, 1.49,0.59, -1219,0.007, 441,0.011,100.0,100.0,5000.0);
XAUDIO2FX_I3DL2_PRESET_STONECORRIDOR : constant XAUDIO2FX_REVERB_I3DL2_PARAMETERS := (100.0, -1000, -237,0.0, 2.70,0.79, -1214,0.013, 395,0.020,100.0,100.0,5000.0);
XAUDIO2FX_I3DL2_PRESET_ALLEY : constant XAUDIO2FX_REVERB_I3DL2_PARAMETERS := (100.0, -1000, -270,0.0, 1.49,0.86, -1204,0.007, -4,0.011,100.0,100.0,5000.0);
XAUDIO2FX_I3DL2_PRESET_FOREST : constant XAUDIO2FX_REVERB_I3DL2_PARAMETERS := (100.0, -1000,-3300,0.0, 1.49,0.54, -2560,0.162, -613,0.088, 79.0,100.0,5000.0);
XAUDIO2FX_I3DL2_PRESET_CITY : constant XAUDIO2FX_REVERB_I3DL2_PARAMETERS := (100.0, -1000, -800,0.0, 1.49,0.67, -2273,0.007, -2217,0.011, 50.0,100.0,5000.0);
XAUDIO2FX_I3DL2_PRESET_MOUNTAINS : constant XAUDIO2FX_REVERB_I3DL2_PARAMETERS := (100.0, -1000,-2500,0.0, 1.49,0.21, -2780,0.300, -2014,0.100, 27.0,100.0,5000.0);
XAUDIO2FX_I3DL2_PRESET_QUARRY : constant XAUDIO2FX_REVERB_I3DL2_PARAMETERS := (100.0, -1000,-1000,0.0, 1.49,0.83,-10000,0.061, 500,0.025,100.0,100.0,5000.0);
XAUDIO2FX_I3DL2_PRESET_PLAIN : constant XAUDIO2FX_REVERB_I3DL2_PARAMETERS := (100.0, -1000,-2000,0.0, 1.49,0.50, -2466,0.179, -2514,0.100, 21.0,100.0,5000.0);
XAUDIO2FX_I3DL2_PRESET_PARKINGLOT : constant XAUDIO2FX_REVERB_I3DL2_PARAMETERS := (100.0, -1000, 0,0.0, 1.65,1.50, -1363,0.008, -1153,0.012,100.0,100.0,5000.0);
XAUDIO2FX_I3DL2_PRESET_SEWERPIPE : constant XAUDIO2FX_REVERB_I3DL2_PARAMETERS := (100.0, -1000,-1000,0.0, 2.81,0.14, 429,0.014, 648,0.021, 80.0, 60.0,5000.0);
XAUDIO2FX_I3DL2_PRESET_UNDERWATER : constant XAUDIO2FX_REVERB_I3DL2_PARAMETERS := (100.0, -1000,-4000,0.0, 1.49,0.10, -449,0.007, 1700,0.011,100.0,100.0,5000.0);
XAUDIO2FX_I3DL2_PRESET_SMALLROOM : constant XAUDIO2FX_REVERB_I3DL2_PARAMETERS := (100.0, -1000, -600,0.0, 1.10,0.83, -400,0.005, 500,0.010,100.0,100.0,5000.0);
XAUDIO2FX_I3DL2_PRESET_MEDIUMROOM : constant XAUDIO2FX_REVERB_I3DL2_PARAMETERS := (100.0, -1000, -600,0.0, 1.30,0.83, -1000,0.010, -200,0.020,100.0,100.0,5000.0);
XAUDIO2FX_I3DL2_PRESET_LARGEROOM : constant XAUDIO2FX_REVERB_I3DL2_PARAMETERS := (100.0, -1000, -600,0.0, 1.50,0.83, -1600,0.020, -1000,0.040,100.0,100.0,5000.0);
XAUDIO2FX_I3DL2_PRESET_MEDIUMHALL : constant XAUDIO2FX_REVERB_I3DL2_PARAMETERS := (100.0, -1000, -600,0.0, 1.80,0.70, -1300,0.015, -800,0.030,100.0,100.0,5000.0);
XAUDIO2FX_I3DL2_PRESET_LARGEHALL : constant XAUDIO2FX_REVERB_I3DL2_PARAMETERS := (100.0, -1000, -600,0.0, 1.80,0.70, -2000,0.030, -1400,0.060,100.0,100.0,5000.0);
XAUDIO2FX_I3DL2_PRESET_PLATE : constant XAUDIO2FX_REVERB_I3DL2_PARAMETERS := (100.0, -1000, -200,0.0, 1.30,0.90, 0,0.002, 0,0.010,100.0, 75.0,5000.0);
--
-- THE END.
--
end XAudio2fx;
----------------------------------------
-- Microsoft DirectX Ada binding lib --
-- File : XAudio2fx.adb --
-- Translator:Dongfeng.Gu,2018/11/16 --
-- Mail: 515639@qq.com --
-- Progress:100% --
----------------------------------------
package body XAudio2fx is
function log10(f:float) return float with Import,external_name=>"log10f";
procedure ReverbConvertI3DL2ToNative(pI3DL2:access constant XAUDIO2FX_REVERB_I3DL2_PARAMETERS;pNative:access XAUDIO2FX_REVERB_PARAMETERS) is
reflectionsDelay,reverbDelay:FLOAT;
begin
pNative.RearDelay := XAUDIO2FX_REVERB_DEFAULT_REAR_DELAY; -- 5
pNative.PositionLeft := XAUDIO2FX_REVERB_DEFAULT_POSITION; -- 6
pNative.PositionRight := XAUDIO2FX_REVERB_DEFAULT_POSITION; -- 6
pNative.PositionMatrixLeft := XAUDIO2FX_REVERB_DEFAULT_POSITION_MATRIX; -- 27
pNative.PositionMatrixRight := XAUDIO2FX_REVERB_DEFAULT_POSITION_MATRIX; -- 27
pNative.RoomSize := XAUDIO2FX_REVERB_DEFAULT_ROOM_SIZE; -- 100
pNative.LowEQCutoff := 4;
pNative.HighEQCutoff := 6;
pNative.RoomFilterMain := float(pI3DL2.Room) / 100.0;
pNative.RoomFilterHF := float(pI3DL2.RoomHF) / 100.0;
if (pI3DL2.DecayHFRatio >= 1.0) then
declare
index:int32:=int32(-4.0 * log10(pI3DL2.DecayHFRatio));
begin
if index < (-8) then
index:=-8;
end if;
pNative.LowEQGain:=BYTE(if index<0 then index+8 else 8);
pNative.HighEQGain := 8;
pNative.DecayTime := pI3DL2.DecayTime * pI3DL2.DecayHFRatio;
end;
else
declare
index:int32:=int32(4.0 * log10(pI3DL2.DecayHFRatio));
begin
if index < (-8) then
index:=-8;
end if;
pNative.LowEQGain:=BYTE(if index<0 then index+8 else 8);
pNative.HighEQGain := 8;
pNative.DecayTime := pI3DL2.DecayTime;
end;
end if;
reflectionsDelay := pI3DL2.ReflectionsDelay * 1000.0;
if (reflectionsDelay >= FLOAT(XAUDIO2FX_REVERB_MAX_REFLECTIONS_DELAY)) then
reflectionsDelay := float(XAUDIO2FX_REVERB_MAX_REFLECTIONS_DELAY - 1);
elsif reflectionsDelay <= 1.0 then
reflectionsDelay := 1.0;
end if;
pNative.ReflectionsDelay := UINT32(reflectionsDelay);
reverbDelay := pI3DL2.ReverbDelay * 1000.0;
if (reverbDelay >= FLOAT(XAUDIO2FX_REVERB_MAX_REVERB_DELAY)) then
reverbDelay := float(XAUDIO2FX_REVERB_MAX_REVERB_DELAY - 1);
end if;
pNative.ReverbDelay := BYTE(reverbDelay);
pNative.ReflectionsGain := float(pI3DL2.Reflections) / 100.0;
pNative.ReverbGain := float(pI3DL2.Reverb) / 100.0;
pNative.EarlyDiffusion := BYTE(15.0 * pI3DL2.Diffusion / 100.0);
pNative.LateDiffusion := pNative.EarlyDiffusion;
pNative.Density := pI3DL2.Density;
pNative.RoomFilterFreq := pI3DL2.HFReference;
pNative.WetDryMix := pI3DL2.WetDryMix;
end;
--
-- THE END.
--
end XAudio2fx;