1 module directx.xaudio2; 2 /************************************************************************** 3 * 4 * Copyright (c) Microsoft Corporation. All rights reserved. 5 * 6 * File: xaudio2.h 7 * Content: Declarations for the XAudio2 game audio API. 8 * 9 **************************************************************************/ 10 11 /************************************************************************** 12 * 13 * XAudio2 COM object class and interface IDs. 14 * 15 **************************************************************************/ 16 17 version(Windows): 18 19 import std.math; 20 21 import directx.com; 22 23 // oops, bad way defining it here 24 //version=DXSDK_2010_6; 25 //version=DXSDK_11_0; 26 version=XAUDIO2_HELPER_FUNCTIONS; 27 28 // it is outdated and i'm lazy, so maybe later i will upgrade it or remove at all. 29 /* 30 version(DXSDK_2008_3) 31 { 32 // XAudio 2.0 (March 2008 SDK) 33 DEFINE_CLSID!(XAudio2, fac23f48, 31f5, 45a8, b4, 9b, 52, 25, d6, 14, 01, aa); 34 DEFINE_CLSID!(XAudio2_Debug, fac23f48, 31f5, 45a8, b4, 9b, 52, 25, d6, 14, 01, db); 35 } 36 37 version(DXSDK_2008_6) 38 { 39 // XAudio 2.1 (June 2008 SDK) 40 DEFINE_CLSID!(XAudio2, e21a7345, eb21, 468e, be, 50, 80, 4d, b9, 7c, f7, 08); 41 DEFINE_CLSID!(XAudio2_Debug, f7a76c21, 53d4, 46bb, ac, 53, 8b, 45, 9c, ae, 46, bd); 42 } 43 44 version(DXSDK_2008_8) 45 { 46 // XAudio 2.2 (August 2008 SDK) 47 DEFINE_CLSID(XAudio2, b802058a, 464a, 42db, bc, 10, b6, 50, d6, f2, 58, 6a); 48 DEFINE_CLSID(XAudio2_Debug, 97dfb7e7, 5161, 4015, 87, a9, c7, 9e, 6a, 19, 52, cc); 49 } 50 51 version(DXSDK_2008_11) 52 { 53 // XAudio 2.3 (November 2008 SDK) 54 DEFINE_CLSID(XAudio2, 4c5e637a, 16c7, 4de3, 9c, 46, 5e, d2, 21, 81, 96, 2d); 55 DEFINE_CLSID(XAudio2_Debug, ef0aa05d, 8075, 4e5d, be, ad, 45, be, 0c, 3c, cb, b3); 56 } 57 58 version(DXSDK_2009_3) 59 { 60 // XAudio 2.4 (March 2009 SDK) 61 //DEFINE_CLSID(XAudio2, 03219e78, 5bc3, 44d1, b9, 2e, f6, 3d, 89, cc, 65, 26); 62 //DEFINE_CLSID(XAudio2_Debug, 4256535c, 1ea4, 4d4b, 8a, d5, f9, db, 76, 2e, ca, 9e); 63 } 64 65 version(DXSDK_2009_8) 66 { 67 // XAudio 2.5 (August 2009 SDK) 68 DEFINE_CLSID(XAudio2, 4c9b6dde, 6809, 46e6, a2, 78, 9b, 6a, 97, 58, 86, 70); 69 DEFINE_CLSID(XAudio2_Debug, 715bdd1a, aa82, 436b, b0, fa, 6a, ce, a3, 9b, d0, a1); 70 } 71 72 version(DXSDK_2010_2) 73 { 74 // XAudio 2.6 (February 2010 SDK) 75 DEFINE_CLSID(XAudio2, 3eda9b49, 2085, 498b, 9b, b2, 39, a6, 77, 84, 93, de); 76 DEFINE_CLSID(XAudio2_Debug, 47199894, 7cc2, 444d, 98, 73, ce, d2, 56, 2c, c6, 0e); 77 } 78 */ 79 80 version(DXSDK_2010_6) 81 { 82 // XAudio 2.7 (June 2010 SDK) 83 // this two should be CLSID but for now leave it as IID 84 mixin(uuid!(XAudio2,"5a508685-a254-4fba-9b82-9a24b00306af")); 85 mixin(uuid!(XAudio2_Debug, "db05ea35-0329-4d4b-a53a-6dead03d3852")); 86 87 mixin(uuid!(IXAudio2, "8bcf1f58-9fe7-4583-8ac6-e2adc465c8bb")); 88 } 89 90 version(XAUDIO_2_8) 91 { 92 // XAudio 2.8 ( Windows 8 ) 93 mixin(uuid!(IXAudio2, "60d8dac8-5aa1-4e8e-b597-2f5e2883d484")); 94 } 95 96 97 // Ignore the rest of this header if only the GUID definitions were requested 98 version(GUID_DEFS_ONLY) 99 { 100 } 101 else 102 { 103 // required for uuid template 104 interface XAudio2 : IUnknown{} 105 interface XAudio2_Debug : IUnknown{} 106 107 version(XBOX) 108 import xbox.xobjbase; // Xbox COM declarations (IUnknown, etc) 109 else 110 import directx.com; // Windows COM declarations 111 112 // All structures defined in this file use tight field packing 113 align(1): 114 115 116 /************************************************************************** 117 * 118 * XAudio2 constants, flags and error codes. 119 * 120 **************************************************************************/ 121 122 // Numeric boundary values 123 enum XAUDIO2_MAX_BUFFER_BYTES = 0x80000000; // Maximum bytes allowed in a source buffer 124 enum XAUDIO2_MAX_QUEUED_BUFFERS = 64; // Maximum buffers allowed in a voice queue 125 enum XAUDIO2_MAX_BUFFERS_SYSTEM = 2; // Maximum buffers allowed for system threads (Xbox 360 only) 126 enum XAUDIO2_MAX_AUDIO_CHANNELS = 64; // Maximum channels in an audio stream 127 enum XAUDIO2_MIN_SAMPLE_RATE = 1000; // Minimum audio sample rate supported 128 enum XAUDIO2_MAX_SAMPLE_RATE = 200000; // Maximum audio sample rate supported 129 enum XAUDIO2_MAX_VOLUME_LEVEL = 16777216.0f; // Maximum acceptable volume level (2^24) 130 enum XAUDIO2_MIN_FREQ_RATIO = (1/1024.0f); // Minimum SetFrequencyRatio argument 131 enum XAUDIO2_MAX_FREQ_RATIO = 1024.0f; // Maximum MaxFrequencyRatio argument 132 enum XAUDIO2_DEFAULT_FREQ_RATIO = 2.0f; // Default MaxFrequencyRatio argument 133 enum XAUDIO2_MAX_FILTER_ONEOVERQ = 1.5f; // Maximum XAUDIO2_FILTER_PARAMETERS.OneOverQ 134 enum XAUDIO2_MAX_FILTER_FREQUENCY = 1.0f; // Maximum XAUDIO2_FILTER_PARAMETERS.Frequency 135 enum XAUDIO2_MAX_LOOP_COUNT = 254; // Maximum non-infinite XAUDIO2_BUFFER.LoopCount 136 enum XAUDIO2_MAX_INSTANCES = 8; // Maximum simultaneous XAudio2 objects on Xbox 360 137 138 // For XMA voices on Xbox 360 there is an additional restriction on the MaxFrequencyRatio 139 // argument and the voice's sample rate: the product of these numbers cannot exceed 600000 140 // for one-channel voices or 300000 for voices with more than one channel. 141 enum XAUDIO2_MAX_RATIO_TIMES_RATE_XMA_MONO = 600000; 142 enum XAUDIO2_MAX_RATIO_TIMES_RATE_XMA_MULTICHANNEL = 300000; 143 144 // Numeric values with special meanings 145 enum XAUDIO2_COMMIT_NOW = 0; // Used as an OperationSet argument 146 enum XAUDIO2_COMMIT_ALL = 0; // Used in IXAudio2::CommitChanges 147 enum XAUDIO2_INVALID_OPSET = cast(uint)(-1); // Not allowed for OperationSet arguments 148 enum XAUDIO2_NO_LOOP_REGION = 0; // Used in XAUDIO2_BUFFER.LoopCount 149 enum XAUDIO2_LOOP_INFINITE = 255; // Used in XAUDIO2_BUFFER.LoopCount 150 enum XAUDIO2_DEFAULT_CHANNELS = 0; // Used in CreateMasteringVoice 151 enum XAUDIO2_DEFAULT_SAMPLERATE = 0; // Used in CreateMasteringVoice 152 153 // Flags 154 enum XAUDIO2_DEBUG_ENGINE = 0x0001; // Used in XAudio2Create on Windows only 155 enum XAUDIO2_VOICE_NOPITCH = 0x0002; // Used in IXAudio2::CreateSourceVoice 156 enum XAUDIO2_VOICE_NOSRC = 0x0004; // Used in IXAudio2::CreateSourceVoice 157 enum XAUDIO2_VOICE_USEFILTER = 0x0008; // Used in IXAudio2::CreateSource/SubmixVoice 158 enum XAUDIO2_VOICE_MUSIC = 0x0010; // Used in IXAudio2::CreateSourceVoice 159 enum XAUDIO2_PLAY_TAILS = 0x0020; // Used in IXAudio2SourceVoice::Stop 160 enum XAUDIO2_END_OF_STREAM = 0x0040; // Used in XAUDIO2_BUFFER.Flags 161 enum XAUDIO2_SEND_USEFILTER = 0x0080; // Used in XAUDIO2_SEND_DESCRIPTOR.Flags 162 163 // Default parameters for the built-in filter 164 enum XAUDIO2_DEFAULT_FILTER_TYPE = LowPassFilter; 165 enum XAUDIO2_DEFAULT_FILTER_FREQUENCY = XAUDIO2_MAX_FILTER_FREQUENCY; 166 enum XAUDIO2_DEFAULT_FILTER_ONEOVERQ = 1.0f; 167 168 // Internal XAudio2 constants 169 version(XBOX) 170 { 171 enum XAUDIO2_QUANTUM_NUMERATOR = 2; // On Xbox 360, XAudio2 processes audio 172 enum XAUDIO2_QUANTUM_DENOMINATOR = 375; // in 5.333ms chunks (= 2/375 seconds) 173 } 174 else 175 { 176 enum XAUDIO2_QUANTUM_NUMERATOR = 1; // On Windows, XAudio2 processes audio 177 enum XAUDIO2_QUANTUM_DENOMINATOR = 100; // in 10ms chunks (= 1/100 seconds) 178 } 179 enum XAUDIO2_QUANTUM_MS = (1000.0f * XAUDIO2_QUANTUM_NUMERATOR / XAUDIO2_QUANTUM_DENOMINATOR); 180 181 // XAudio2 error codes 182 enum FACILITY_XAUDIO2 = 0x896; 183 enum XAUDIO2_E_INVALID_CALL = 0x88960001; // An API call or one of its arguments was illegal 184 enum XAUDIO2_E_XMA_DECODER_ERROR = 0x88960002; // The XMA hardware suffered an unrecoverable error 185 enum XAUDIO2_E_XAPO_CREATION_FAILED = 0x88960003; // XAudio2 failed to initialize an XAPO effect 186 enum XAUDIO2_E_DEVICE_INVALIDATED = 0x88960004; // An audio device became unusable (unplugged, etc) 187 188 189 /************************************************************************** 190 * 191 * XAudio2 structures and enumerations. 192 * 193 **************************************************************************/ 194 195 // Used in IXAudio2::Initialize 196 version(XBOX) { 197 enum XAUDIO2_XBOX_HWTHREAD_SPECIFIER 198 { 199 XboxThread0 = 0x01, 200 XboxThread1 = 0x02, 201 XboxThread2 = 0x04, 202 XboxThread3 = 0x08, 203 XboxThread4 = 0x10, 204 XboxThread5 = 0x20, 205 XAUDIO2_ANY_PROCESSOR = XboxThread4, 206 XAUDIO2_DEFAULT_PROCESSOR = XAUDIO2_ANY_PROCESSOR 207 } 208 alias XAUDIO2_XBOX_HWTHREAD_SPECIFIER XAUDIO2_PROCESSOR; 209 } 210 else { 211 alias XAUDIO2_WINDOWS_PROCESSOR_SPECIFIER = int; 212 enum : XAUDIO2_WINDOWS_PROCESSOR_SPECIFIER 213 { 214 Processor1 = 0x00000001, 215 Processor2 = 0x00000002, 216 Processor3 = 0x00000004, 217 Processor4 = 0x00000008, 218 Processor5 = 0x00000010, 219 Processor6 = 0x00000020, 220 Processor7 = 0x00000040, 221 Processor8 = 0x00000080, 222 Processor9 = 0x00000100, 223 Processor10 = 0x00000200, 224 Processor11 = 0x00000400, 225 Processor12 = 0x00000800, 226 Processor13 = 0x00001000, 227 Processor14 = 0x00002000, 228 Processor15 = 0x00004000, 229 Processor16 = 0x00008000, 230 Processor17 = 0x00010000, 231 Processor18 = 0x00020000, 232 Processor19 = 0x00040000, 233 Processor20 = 0x00080000, 234 Processor21 = 0x00100000, 235 Processor22 = 0x00200000, 236 Processor23 = 0x00400000, 237 Processor24 = 0x00800000, 238 Processor25 = 0x01000000, 239 Processor26 = 0x02000000, 240 Processor27 = 0x04000000, 241 Processor28 = 0x08000000, 242 Processor29 = 0x10000000, 243 Processor30 = 0x20000000, 244 Processor31 = 0x40000000, 245 Processor32 = 0x80000000, 246 XAUDIO2_ANY_PROCESSOR = 0xffffffff, 247 XAUDIO2_DEFAULT_PROCESSOR = XAUDIO2_ANY_PROCESSOR 248 } 249 alias XAUDIO2_WINDOWS_PROCESSOR_SPECIFIER XAUDIO2_PROCESSOR; 250 } 251 252 253 // Used in XAUDIO2_DEVICE_DETAILS below to describe the types of applications 254 // that the user has specified each device as a default for. 0 means that the 255 // device isn't the default for any role. 256 alias DWORD XAUDIO2_DEVICE_ROLE; 257 enum : XAUDIO2_DEVICE_ROLE 258 { 259 NotDefaultDevice = 0x0, 260 DefaultConsoleDevice = 0x1, 261 DefaultMultimediaDevice = 0x2, 262 DefaultCommunicationsDevice = 0x4, 263 DefaultGameDevice = 0x8, 264 GlobalDefaultDevice = 0xf, 265 InvalidDeviceRole = ~GlobalDefaultDevice 266 } 267 268 // Returned by IXAudio2::GetDeviceDetails 269 struct XAUDIO2_DEVICE_DETAILS 270 { 271 WCHAR[256] DeviceID; // String identifier for the audio device. 272 WCHAR[256] DisplayName; // Friendly name suitable for display to a human. 273 XAUDIO2_DEVICE_ROLE Role; // Roles that the device should be used for. 274 WAVEFORMATEXTENSIBLE OutputFormat; // The device's native PCM audio output format. 275 } 276 277 // Returned by IXAudio2Voice::GetVoiceDetails 278 struct XAUDIO2_VOICE_DETAILS 279 { 280 UINT32 CreationFlags; // Flags the voice was created with. 281 UINT32 InputChannels; // Channels in the voice's input audio. 282 UINT32 InputSampleRate; // Sample rate of the voice's input audio. 283 } 284 285 // Used in XAUDIO2_VOICE_SENDS below 286 struct XAUDIO2_SEND_DESCRIPTOR 287 { 288 UINT32 Flags; // Either 0 or XAUDIO2_SEND_USEFILTER. 289 IXAudio2Voice pOutputVoice; // This send's destination voice. 290 } 291 292 // Used in the voice creation functions and in IXAudio2Voice::SetOutputVoices 293 struct XAUDIO2_VOICE_SENDS 294 { 295 UINT32 SendCount; // Number of sends from this voice. 296 XAUDIO2_SEND_DESCRIPTOR* pSends; // Array of SendCount send descriptors. 297 } 298 299 // Used in XAUDIO2_EFFECT_CHAIN below 300 struct XAUDIO2_EFFECT_DESCRIPTOR 301 { 302 IUnknown pEffect; // Pointer to the effect object's IUnknown interface. 303 BOOL InitialState; // TRUE if the effect should begin in the enabled state. 304 UINT32 OutputChannels; // How many output channels the effect should produce. 305 } 306 307 // Used in the voice creation functions and in IXAudio2Voice::SetEffectChain 308 struct XAUDIO2_EFFECT_CHAIN 309 { 310 UINT32 EffectCount; // Number of effects in this voice's effect chain. 311 XAUDIO2_EFFECT_DESCRIPTOR* pEffectDescriptors; // Array of effect descriptors. 312 } 313 314 // Used in XAUDIO2_FILTER_PARAMETERS below 315 alias XAUDIO2_FILTER_TYPE = uint; 316 enum : XAUDIO2_FILTER_TYPE 317 { 318 LowPassFilter, // Attenuates frequencies above the cutoff frequency. 319 BandPassFilter, // Attenuates frequencies outside a given range. 320 HighPassFilter, // Attenuates frequencies below the cutoff frequency. 321 NotchFilter // Attenuates frequencies inside a given range. 322 } 323 324 // Used in IXAudio2Voice::Set/GetFilterParameters and Set/GetOutputFilterParameters 325 struct XAUDIO2_FILTER_PARAMETERS 326 { 327 XAUDIO2_FILTER_TYPE Type; // Low-pass, band-pass or high-pass. 328 float Frequency; // Radian frequency (2 * sin(pi*CutoffFrequency/SampleRate)); 329 // must be >= 0 and <= XAUDIO2_MAX_FILTER_FREQUENCY 330 // (giving a maximum CutoffFrequency of SampleRate/6). 331 float OneOverQ; // Reciprocal of the filter's quality factor Q; 332 // must be > 0 and <= XAUDIO2_MAX_FILTER_ONEOVERQ. 333 } 334 335 // Used in IXAudio2SourceVoice::SubmitSourceBuffer 336 struct XAUDIO2_BUFFER 337 { 338 UINT32 Flags; // Either 0 or XAUDIO2_END_OF_STREAM. 339 UINT32 AudioBytes; // Size of the audio data buffer in bytes. 340 const (ubyte)* pAudioData; // Pointer to the audio data buffer. 341 UINT32 PlayBegin; // First sample in this buffer to be played. 342 UINT32 PlayLength; // Length of the region to be played in samples, 343 // or 0 to play the whole buffer. 344 UINT32 LoopBegin; // First sample of the region to be looped. 345 UINT32 LoopLength; // Length of the desired loop region in samples, 346 // or 0 to loop the entire buffer. 347 UINT32 LoopCount; // Number of times to repeat the loop region, 348 // or XAUDIO2_LOOP_INFINITE to loop forever. 349 void* pContext; // Context value to be passed back in callbacks. 350 } 351 352 // Used in IXAudio2SourceVoice::SubmitSourceBuffer when submitting XWMA data. 353 // NOTE: If an XWMA sound is submitted in more than one buffer, each buffer's 354 // pDecodedPacketCumulativeBytes[PacketCount-1] value must be subtracted from 355 // all the entries in the next buffer's pDecodedPacketCumulativeBytes array. 356 // And whether a sound is submitted in more than one buffer or not, the final 357 // buffer of the sound should use the XAUDIO2_END_OF_STREAM flag, or else the 358 // client must call IXAudio2SourceVoice::Discontinuity after submitting it. 359 struct XAUDIO2_BUFFER_WMA 360 { 361 const (UINT32)* pDecodedPacketCumulativeBytes; // Decoded packet's cumulative size array. 362 // Each element is the number of bytes accumulated 363 // when the corresponding XWMA packet is decoded in 364 // order. The array must have PacketCount elements. 365 UINT32 PacketCount; // Number of XWMA packets submitted. Must be >= 1 and 366 // divide evenly into XAUDIO2_BUFFER.AudioBytes. 367 } 368 369 // Returned by IXAudio2SourceVoice::GetState 370 struct XAUDIO2_VOICE_STATE 371 { 372 void* pCurrentBufferContext; // The pContext value provided in the XAUDIO2_BUFFER 373 // that is currently being processed, or NULL if 374 // there are no buffers in the queue. 375 UINT32 BuffersQueued; // Number of buffers currently queued on the voice 376 // (including the one that is being processed). 377 UINT64 SamplesPlayed; // Total number of samples produced by the voice since 378 // it began processing the current audio stream. 379 } 380 381 // Returned by IXAudio2::GetPerformanceData 382 struct XAUDIO2_PERFORMANCE_DATA 383 { 384 // CPU usage information 385 UINT64 AudioCyclesSinceLastQuery; // CPU cycles spent on audio processing since the 386 // last call to StartEngine or GetPerformanceData. 387 UINT64 TotalCyclesSinceLastQuery; // Total CPU cycles elapsed since the last call 388 // (only counts the CPU XAudio2 is running on). 389 UINT32 MinimumCyclesPerQuantum; // Fewest CPU cycles spent processing any one 390 // audio quantum since the last call. 391 UINT32 MaximumCyclesPerQuantum; // Most CPU cycles spent processing any one 392 // audio quantum since the last call. 393 394 // Memory usage information 395 UINT32 MemoryUsageInBytes; // Total heap space currently in use. 396 397 // Audio latency and glitching information 398 UINT32 CurrentLatencyInSamples; // Minimum delay from when a sample is read from a 399 // source buffer to when it reaches the speakers. 400 UINT32 GlitchesSinceEngineStarted; // Audio dropouts since the engine was started. 401 402 // Data about XAudio2's current workload 403 UINT32 ActiveSourceVoiceCount; // Source voices currently playing. 404 UINT32 TotalSourceVoiceCount; // Source voices currently existing. 405 UINT32 ActiveSubmixVoiceCount; // Submix voices currently playing/existing. 406 407 UINT32 ActiveResamplerCount; // Resample xAPOs currently active. 408 UINT32 ActiveMatrixMixCount; // MatrixMix xAPOs currently active. 409 410 // Usage of the hardware XMA decoder (Xbox 360 only) 411 UINT32 ActiveXmaSourceVoices; // Number of source voices decoding XMA data. 412 UINT32 ActiveXmaStreams; // A voice can use more than one XMA stream. 413 } 414 415 // Used in IXAudio2::SetDebugConfiguration 416 struct XAUDIO2_DEBUG_CONFIGURATION 417 { 418 UINT32 TraceMask; // Bitmap of enabled debug message types. 419 UINT32 BreakMask; // Message types that will break into the debugger. 420 BOOL LogThreadID; // Whether to log the thread ID with each message. 421 BOOL LogFileline; // Whether to log the source file and line number. 422 BOOL LogFunctionName; // Whether to log the function name. 423 BOOL LogTiming; // Whether to log message timestamps. 424 } 425 426 // Values for the TraceMask and BreakMask bitmaps. Only ERRORS and WARNINGS 427 // are valid in BreakMask. WARNINGS implies ERRORS, DETAIL implies INFO, and 428 // FUNC_CALLS implies API_CALLS. By default, TraceMask is ERRORS and WARNINGS 429 // and all the other settings are zero. 430 enum XAUDIO2_LOG_ERRORS = 0x0001; // For handled errors with serious effects. 431 enum XAUDIO2_LOG_WARNINGS = 0x0002; // For handled errors that may be recoverable. 432 enum XAUDIO2_LOG_INFO = 0x0004; // Informational chit-chat (e.g. state changes). 433 enum XAUDIO2_LOG_DETAIL = 0x0008; // More detailed chit-chat. 434 enum XAUDIO2_LOG_API_CALLS = 0x0010; // Public API function entries and exits. 435 enum XAUDIO2_LOG_FUNC_CALLS = 0x0020; // Internal function entries and exits. 436 enum XAUDIO2_LOG_TIMING = 0x0040; // Delays detected and other timing data. 437 enum XAUDIO2_LOG_LOCKS = 0x0080; // Usage of critical sections and mutexes. 438 enum XAUDIO2_LOG_MEMORY = 0x0100; // Memory heap usage information. 439 enum XAUDIO2_LOG_STREAMING = 0x1000; // Audio streaming information. 440 441 442 /************************************************************************** 443 * 444 * IXAudio2: Top-level XAudio2 COM interface. 445 * 446 **************************************************************************/ 447 interface IXAudio2 : IUnknown 448 { 449 extern(Windows): 450 version(DXSDK_2010_6) 451 { 452 // NAME: IXAudio2::GetDeviceCount 453 // DESCRIPTION: Returns the number of audio output devices available. 454 // 455 // ARGUMENTS: 456 // pCount - Returns the device count. 457 // 458 HRESULT GetDeviceCount(UINT32* pCount); 459 460 // NAME: IXAudio2::GetDeviceDetails 461 // DESCRIPTION: Returns information about the device with the given index. 462 // 463 // ARGUMENTS: 464 // Index - Index of the device to be queried. 465 // pDeviceDetails - Returns the device details. 466 // 467 HRESULT GetDeviceDetails (UINT32 Index, XAUDIO2_DEVICE_DETAILS* pDeviceDetails); 468 469 // NAME: IXAudio2::Initialize 470 // DESCRIPTION: Sets global XAudio2 parameters and prepares it for use. 471 // 472 // ARGUMENTS: 473 // Flags - Flags specifying the XAudio2 object's behavior. Currently unused. 474 // XAudio2Processor - An XAUDIO2_PROCESSOR enumeration value that specifies 475 // the hardware thread (Xbox) or processor (Windows) that XAudio2 will use. 476 // The enumeration values are platform-specific; platform-independent code 477 // can use XAUDIO2_DEFAULT_PROCESSOR to use the default on each platform. 478 // 479 HRESULT Initialize ( 480 UINT32 Flags = 0, 481 XAUDIO2_PROCESSOR XAudio2Processor = XAUDIO2_DEFAULT_PROCESSOR); // XAUDIO2_WINDOWS_PROCESSOR_SPECIFIER.XAUDIO2_DEFAULT_PROCESSOR ); 482 } 483 484 // NAME: IXAudio2::RegisterForCallbacks 485 // DESCRIPTION: Adds a new client to receive XAudio2's engine callbacks. 486 // 487 // ARGUMENTS: 488 // pCallback - Callback interface to be called during each processing pass. 489 // 490 HRESULT RegisterForCallbacks (IXAudio2EngineCallback pCallback); 491 492 // NAME: IXAudio2::UnregisterForCallbacks 493 // DESCRIPTION: Removes an existing receiver of XAudio2 engine callbacks. 494 // 495 // ARGUMENTS: 496 // pCallback - Previously registered callback interface to be removed. 497 // 498 void UnregisterForCallbacks(IXAudio2EngineCallback pCallback); 499 500 // NAME: IXAudio2::CreateSourceVoice 501 // DESCRIPTION: Creates and configures a source voice. 502 // 503 // ARGUMENTS: 504 // ppSourceVoice - Returns the new object's IXAudio2SourceVoice interface. 505 // pSourceFormat - Format of the audio that will be fed to the voice. 506 // Flags - XAUDIO2_VOICE flags specifying the source voice's behavior. 507 // MaxFrequencyRatio - Maximum SetFrequencyRatio argument to be allowed. 508 // pCallback - Optional pointer to a client-provided callback interface. 509 // pSendList - Optional list of voices this voice should send audio to. 510 // pEffectChain - Optional list of effects to apply to the audio data. 511 // 512 HRESULT CreateSourceVoice (IXAudio2SourceVoice* ppSourceVoice, 513 const (WAVEFORMATEX)* pSourceFormat, 514 UINT32 Flags = 0, 515 float MaxFrequencyRatio = XAUDIO2_DEFAULT_FREQ_RATIO, 516 IXAudio2VoiceCallback pCallback = null, 517 const (XAUDIO2_VOICE_SENDS)* pSendList = null, 518 const (XAUDIO2_EFFECT_CHAIN)* pEffectChain = null); 519 520 // NAME: IXAudio2::CreateSubmixVoice 521 // DESCRIPTION: Creates and configures a submix voice. 522 // 523 // ARGUMENTS: 524 // ppSubmixVoice - Returns the new object's IXAudio2SubmixVoice interface. 525 // InputChannels - Number of channels in this voice's input audio data. 526 // InputSampleRate - Sample rate of this voice's input audio data. 527 // Flags - XAUDIO2_VOICE flags specifying the submix voice's behavior. 528 // ProcessingStage - Arbitrary number that determines the processing order. 529 // pSendList - Optional list of voices this voice should send audio to. 530 // pEffectChain - Optional list of effects to apply to the audio data. 531 // 532 HRESULT CreateSubmixVoice (IXAudio2SubmixVoice* ppSubmixVoice, 533 UINT32 InputChannels, UINT32 InputSampleRate, 534 UINT32 Flags = 0, UINT32 ProcessingStage = 0, 535 const (XAUDIO2_VOICE_SENDS)* pSendList = null, 536 const (XAUDIO2_EFFECT_CHAIN)* pEffectChain = null); 537 538 539 // NAME: IXAudio2::CreateMasteringVoice 540 // DESCRIPTION: Creates and configures a mastering voice. 541 // 542 // ARGUMENTS: 543 // ppMasteringVoice - Returns the new object's IXAudio2MasteringVoice interface. 544 // InputChannels - Number of channels in this voice's input audio data. 545 // InputSampleRate - Sample rate of this voice's input audio data. 546 // Flags - XAUDIO2_VOICE flags specifying the mastering voice's behavior. 547 // DeviceIndex - Identifier of the device to receive the output audio. 548 // pEffectChain - Optional list of effects to apply to the audio data. 549 // 550 HRESULT CreateMasteringVoice (IXAudio2MasteringVoice* ppMasteringVoice, 551 UINT32 InputChannels = XAUDIO2_DEFAULT_CHANNELS, 552 UINT32 InputSampleRate = XAUDIO2_DEFAULT_SAMPLERATE, 553 UINT32 Flags = 0, UINT32 DeviceIndex = 0, 554 const (XAUDIO2_EFFECT_CHAIN)* pEffectChain = null); 555 556 // NAME: IXAudio2::StartEngine 557 // DESCRIPTION: Creates and starts the audio processing thread. 558 // 559 HRESULT StartEngine (); 560 561 // NAME: IXAudio2::StopEngine 562 // DESCRIPTION: Stops and destroys the audio processing thread. 563 // 564 void StopEngine (); 565 566 // NAME: IXAudio2::CommitChanges 567 // DESCRIPTION: Atomically applies a set of operations previously tagged 568 // with a given identifier. 569 // 570 // ARGUMENTS: 571 // OperationSet - Identifier of the set of operations to be applied. 572 // 573 HRESULT CommitChanges (UINT32 OperationSet); 574 575 // NAME: IXAudio2::GetPerformanceData 576 // DESCRIPTION: Returns current resource usage details: memory, CPU, etc. 577 // 578 // ARGUMENTS: 579 // pPerfData - Returns the performance data structure. 580 // 581 void GetPerformanceData (XAUDIO2_PERFORMANCE_DATA* pPerfData); 582 583 // NAME: IXAudio2::SetDebugConfiguration 584 // DESCRIPTION: Configures XAudio2's debug output (in debug builds only). 585 // 586 // ARGUMENTS: 587 // pDebugConfiguration - Structure describing the debug output behavior. 588 // pReserved - Optional parameter; must be NULL. 589 // 590 void SetDebugConfiguration (const (XAUDIO2_DEBUG_CONFIGURATION)* pDebugConfiguration, 591 void* pReserved = null); 592 } 593 594 595 /************************************************************************** 596 * 597 * IXAudio2Voice: Base voice management interface. 598 * 599 **************************************************************************/ 600 601 extern(C++) interface IXAudio2Voice 602 { 603 extern(Windows): 604 /* NAME: IXAudio2Voice::GetVoiceDetails 605 // DESCRIPTION: Returns the basic characteristics of this voice. 606 // 607 // ARGUMENTS: 608 // pVoiceDetails - Returns the voice's details. 609 */ 610 void GetVoiceDetails (XAUDIO2_VOICE_DETAILS* pVoiceDetails); 611 612 /* NAME: IXAudio2Voice::SetOutputVoices 613 // DESCRIPTION: Replaces the set of submix/mastering voices that receive 614 // this voice's output. 615 // 616 // ARGUMENTS: 617 // pSendList - Optional list of voices this voice should send audio to. 618 */ 619 HRESULT SetOutputVoices (const (XAUDIO2_VOICE_SENDS)* pSendList); 620 621 /* NAME: IXAudio2Voice::SetEffectChain 622 // DESCRIPTION: Replaces this voice's current effect chain with a new one. 623 // 624 // ARGUMENTS: 625 // pEffectChain - Structure describing the new effect chain to be used. 626 */ 627 HRESULT SetEffectChain (const (XAUDIO2_EFFECT_CHAIN)* pEffectChain); 628 629 /* NAME: IXAudio2Voice::EnableEffect 630 // DESCRIPTION: Enables an effect in this voice's effect chain. 631 // 632 // ARGUMENTS: 633 // EffectIndex - Index of an effect within this voice's effect chain. 634 // OperationSet - Used to identify this call as part of a deferred batch. 635 */ 636 HRESULT EnableEffect (UINT32 EffectIndex, 637 UINT32 OperationSet = XAUDIO2_COMMIT_NOW); 638 639 /* NAME: IXAudio2Voice::DisableEffect 640 // DESCRIPTION: Disables an effect in this voice's effect chain. 641 // 642 // ARGUMENTS: 643 // EffectIndex - Index of an effect within this voice's effect chain. 644 // OperationSet - Used to identify this call as part of a deferred batch. 645 */ 646 HRESULT DisableEffect (UINT32 EffectIndex, 647 UINT32 OperationSet = XAUDIO2_COMMIT_NOW); 648 649 /* NAME: IXAudio2Voice::GetEffectState 650 // DESCRIPTION: Returns the running state of an effect. 651 // 652 // ARGUMENTS: 653 // EffectIndex - Index of an effect within this voice's effect chain. 654 // pEnabled - Returns the enabled/disabled state of the given effect. 655 */ 656 void GetEffectState (UINT32 EffectIndex, /*out*/ BOOL* pEnabled); 657 658 /* NAME: IXAudio2Voice::SetEffectParameters 659 // DESCRIPTION: Sets effect-specific parameters. 660 // 661 // REMARKS: Unlike IXAPOParameters::SetParameters, this method may 662 // be called from any thread. XAudio2 implements 663 // appropriate synchronization to copy the parameters to the 664 // realtime audio processing thread. 665 // 666 // ARGUMENTS: 667 // EffectIndex - Index of an effect within this voice's effect chain. 668 // pParameters - Pointer to an effect-specific parameters block. 669 // ParametersByteSize - Size of the pParameters array in bytes. 670 // OperationSet - Used to identify this call as part of a deferred batch. 671 */ 672 673 HRESULT SetEffectParameters (UINT32 EffectIndex, 674 const (void)* pParameters, 675 UINT32 ParametersByteSize, 676 UINT32 OperationSet = XAUDIO2_COMMIT_NOW); 677 678 /* NAME: IXAudio2Voice::GetEffectParameters 679 // DESCRIPTION: Obtains the current effect-specific parameters. 680 // 681 // ARGUMENTS: 682 // EffectIndex - Index of an effect within this voice's effect chain. 683 // pParameters - Returns the current values of the effect-specific parameters. 684 // ParametersByteSize - Size of the pParameters array in bytes. 685 */ 686 HRESULT GetEffectParameters ( UINT32 EffectIndex, 687 void* pParameters, 688 UINT32 ParametersByteSize); 689 690 /* NAME: IXAudio2Voice::SetFilterParameters 691 // DESCRIPTION: Sets this voice's filter parameters. 692 // 693 // ARGUMENTS: 694 // pParameters - Pointer to the filter's parameter structure. 695 // OperationSet - Used to identify this call as part of a deferred batch. 696 */ 697 HRESULT SetFilterParameters ( const(XAUDIO2_FILTER_PARAMETERS)* pParameters, 698 UINT32 OperationSet = XAUDIO2_COMMIT_NOW); 699 700 /* NAME: IXAudio2Voice::GetFilterParameters 701 // DESCRIPTION: Returns this voice's current filter parameters. 702 // 703 // ARGUMENTS: 704 // pParameters - Returns the filter parameters. 705 */ 706 void GetFilterParameters (XAUDIO2_FILTER_PARAMETERS* pParameters); 707 708 /* NAME: IXAudio2Voice::SetOutputFilterParameters 709 // DESCRIPTION: Sets the filter parameters on one of this voice's sends. 710 // 711 // ARGUMENTS: 712 // pDestinationVoice - Destination voice of the send whose filter parameters will be set. 713 // pParameters - Pointer to the filter's parameter structure. 714 // OperationSet - Used to identify this call as part of a deferred batch. 715 */ 716 HRESULT SetOutputFilterParameters (IXAudio2Voice pDestinationVoice, 717 const (XAUDIO2_FILTER_PARAMETERS)* pParameters, 718 UINT32 OperationSet = XAUDIO2_COMMIT_NOW); 719 720 /* NAME: IXAudio2Voice::GetOutputFilterParameters 721 // DESCRIPTION: Returns the filter parameters from one of this voice's sends. 722 // 723 // ARGUMENTS: 724 // pDestinationVoice - Destination voice of the send whose filter parameters will be read. 725 // pParameters - Returns the filter parameters. 726 */ 727 void GetOutputFilterParameters (IXAudio2Voice pDestinationVoice, 728 XAUDIO2_FILTER_PARAMETERS* pParameters); 729 730 /* NAME: IXAudio2Voice::SetVolume 731 // DESCRIPTION: Sets this voice's overall volume level. 732 // 733 // ARGUMENTS: 734 // Volume - New overall volume level to be used, as an amplitude factor. 735 // OperationSet - Used to identify this call as part of a deferred batch. 736 */ 737 HRESULT SetVolume (float Volume, 738 UINT32 OperationSet = XAUDIO2_COMMIT_NOW); 739 740 /* NAME: IXAudio2Voice::GetVolume 741 // DESCRIPTION: Obtains this voice's current overall volume level. 742 // 743 // ARGUMENTS: 744 // pVolume: Returns the voice's current overall volume level. 745 */ 746 void GetVolume (float* pVolume); 747 748 /* NAME: IXAudio2Voice::SetChannelVolumes 749 // DESCRIPTION: Sets this voice's per-channel volume levels. 750 // 751 // ARGUMENTS: 752 // Channels - Used to confirm the voice's channel count. 753 // pVolumes - Array of per-channel volume levels to be used. 754 // OperationSet - Used to identify this call as part of a deferred batch. 755 */ 756 HRESULT SetChannelVolumes (UINT32 Channels, const (float)* pVolumes, 757 UINT32 OperationSet = XAUDIO2_COMMIT_NOW); 758 759 /* NAME: IXAudio2Voice::GetChannelVolumes 760 // DESCRIPTION: Returns this voice's current per-channel volume levels. 761 // 762 // ARGUMENTS: 763 // Channels - Used to confirm the voice's channel count. 764 // pVolumes - Returns an array of the current per-channel volume levels. 765 */ 766 void GetChannelVolumes (UINT32 Channels, float* pVolumes); 767 768 /* NAME: IXAudio2Voice::SetOutputMatrix 769 // DESCRIPTION: Sets the volume levels used to mix from each channel of this 770 // voice's output audio to each channel of a given destination 771 // voice's input audio. 772 // 773 // ARGUMENTS: 774 // pDestinationVoice - The destination voice whose mix matrix to change. 775 // SourceChannels - Used to confirm this voice's output channel count 776 // (the number of channels produced by the last effect in the chain). 777 // DestinationChannels - Confirms the destination voice's input channels. 778 // pLevelMatrix - Array of [SourceChannels * DestinationChannels] send 779 // levels. The level used to send from source channel S to destination 780 // channel D should be in pLevelMatrix[S + SourceChannels * D]. 781 // OperationSet - Used to identify this call as part of a deferred batch. 782 */ 783 HRESULT SetOutputMatrix (IXAudio2Voice pDestinationVoice, 784 UINT32 SourceChannels, UINT32 DestinationChannels, 785 const (float)* pLevelMatrix, 786 UINT32 OperationSet = XAUDIO2_COMMIT_NOW); 787 788 /* NAME: IXAudio2Voice::GetOutputMatrix 789 // DESCRIPTION: Obtains the volume levels used to send each channel of this 790 // voice's output audio to each channel of a given destination 791 // voice's input audio. 792 // 793 // ARGUMENTS: 794 // pDestinationVoice - The destination voice whose mix matrix to obtain. 795 // SourceChannels - Used to confirm this voice's output channel count 796 // (the number of channels produced by the last effect in the chain). 797 // DestinationChannels - Confirms the destination voice's input channels. 798 // pLevelMatrix - Array of send levels, as above. 799 */ 800 void GetOutputMatrix (IXAudio2Voice pDestinationVoice, 801 UINT32 SourceChannels, 802 UINT32 DestinationChannels, 803 float* pLevelMatrix); 804 805 /* NAME: IXAudio2Voice::DestroyVoice 806 // DESCRIPTION: Destroys this voice, stopping it if necessary and removing 807 // it from the XAudio2 graph. 808 */ 809 void DestroyVoice (); 810 } 811 812 813 /************************************************************************** 814 * 815 * IXAudio2SourceVoice: Source voice management interface. 816 * 817 **************************************************************************/ 818 819 extern(C++) interface IXAudio2SourceVoice : IXAudio2Voice 820 { 821 extern(Windows): 822 823 // NAME: IXAudio2SourceVoice::Start 824 // DESCRIPTION: Makes this voice start consuming and processing audio. 825 // 826 // ARGUMENTS: 827 // Flags - Flags controlling how the voice should be started. 828 // OperationSet - Used to identify this call as part of a deferred batch. 829 // 830 HRESULT Start (UINT32 Flags = 0, UINT32 OperationSet = XAUDIO2_COMMIT_NOW); 831 832 // NAME: IXAudio2SourceVoice::Stop 833 // DESCRIPTION: Makes this voice stop consuming audio. 834 // 835 // ARGUMENTS: 836 // Flags - Flags controlling how the voice should be stopped. 837 // OperationSet - Used to identify this call as part of a deferred batch. 838 // 839 HRESULT Stop (UINT32 Flags = 0, UINT32 OperationSet = XAUDIO2_COMMIT_NOW); 840 841 // NAME: IXAudio2SourceVoice::SubmitSourceBuffer 842 // DESCRIPTION: Adds a new audio buffer to this voice's input queue. 843 // 844 // ARGUMENTS: 845 // pBuffer - Pointer to the buffer structure to be queued. 846 // pBufferWMA - Additional structure used only when submitting XWMA data. 847 // 848 HRESULT SubmitSourceBuffer (const (XAUDIO2_BUFFER)* pBuffer, const (XAUDIO2_BUFFER_WMA)* pBufferWMA = null); 849 850 // NAME: IXAudio2SourceVoice::FlushSourceBuffers 851 // DESCRIPTION: Removes all pending audio buffers from this voice's queue. 852 // 853 HRESULT FlushSourceBuffers (); 854 855 // NAME: IXAudio2SourceVoice::Discontinuity 856 // DESCRIPTION: Notifies the voice of an intentional break in the stream of 857 // audio buffers (e.g. the end of a sound), to prevent XAudio2 858 // from interpreting an empty buffer queue as a glitch. 859 // 860 HRESULT Discontinuity (); 861 862 // NAME: IXAudio2SourceVoice::ExitLoop 863 // DESCRIPTION: Breaks out of the current loop when its end is reached. 864 // 865 // ARGUMENTS: 866 // OperationSet - Used to identify this call as part of a deferred batch. 867 // 868 HRESULT ExitLoop (UINT32 OperationSet = XAUDIO2_COMMIT_NOW); 869 870 // NAME: IXAudio2SourceVoice::GetState 871 // DESCRIPTION: Returns the number of buffers currently queued on this voice, 872 // the pContext value associated with the currently processing 873 // buffer (if any), and other voice state information. 874 // 875 // ARGUMENTS: 876 // pVoiceState - Returns the state information. 877 // 878 void GetState (XAUDIO2_VOICE_STATE* pVoiceState); // may differ with DirectX versions 879 880 // NAME: IXAudio2SourceVoice::SetFrequencyRatio 881 // DESCRIPTION: Sets this voice's frequency adjustment, i.e. its pitch. 882 // 883 // ARGUMENTS: 884 // Ratio - Frequency change, expressed as source frequency / target frequency. 885 // OperationSet - Used to identify this call as part of a deferred batch. 886 // 887 HRESULT SetFrequencyRatio (float Ratio, 888 UINT32 OperationSet = XAUDIO2_COMMIT_NOW); 889 890 // NAME: IXAudio2SourceVoice::GetFrequencyRatio 891 // DESCRIPTION: Returns this voice's current frequency adjustment ratio. 892 // 893 // ARGUMENTS: 894 // pRatio - Returns the frequency adjustment. 895 // 896 void GetFrequencyRatio (float* pRatio); 897 898 // NAME: IXAudio2SourceVoice::SetSourceSampleRate 899 // DESCRIPTION: Reconfigures this voice to treat its source data as being 900 // at a different sample rate than the original one specified 901 // in CreateSourceVoice's pSourceFormat argument. 902 // 903 // ARGUMENTS: 904 // UINT32 - The intended sample rate of further submitted source data. 905 // 906 HRESULT SetSourceSampleRate (UINT32 NewSourceSampleRate); 907 } 908 909 /************************************************************************** 910 * 911 * IXAudio2SubmixVoice: Submixing voice management interface. 912 * 913 **************************************************************************/ 914 915 interface IXAudio2SubmixVoice : IXAudio2Voice 916 { 917 // There are currently no methods specific to submix voices. 918 } 919 920 921 /************************************************************************** 922 * 923 * IXAudio2MasteringVoice: Mastering voice management interface. 924 * 925 **************************************************************************/ 926 927 interface IXAudio2MasteringVoice : IXAudio2Voice 928 { 929 version(XAUDIO_2_8) 930 HRESULT GetChannelMask(DWORD* pChannelmask); 931 } 932 933 934 /************************************************************************** 935 * 936 * IXAudio2EngineCallback: Client notification interface for engine events. 937 * 938 * REMARKS: Contains methods to notify the client when certain events happen 939 * in the XAudio2 engine. This interface should be implemented by 940 * the client. XAudio2 will call these methods via the interface 941 * pointer provided by the client when it calls XAudio2Create or 942 * IXAudio2::Initialize. 943 * 944 **************************************************************************/ 945 946 extern(C++) interface IXAudio2EngineCallback 947 { 948 extern(Windows): 949 // Called by XAudio2 just before an audio processing pass begins. 950 void OnProcessingPassStart (); 951 952 // Called just after an audio processing pass ends. 953 void OnProcessingPassEnd (); 954 955 // Called in the event of a critical system error which requires XAudio2 956 // to be closed down and restarted. The error code is given in Error. 957 void OnCriticalError (HRESULT Error); 958 } 959 960 961 /************************************************************************** 962 * 963 * IXAudio2VoiceCallback: Client notification interface for voice events. 964 * 965 * REMARKS: Contains methods to notify the client when certain events happen 966 * in an XAudio2 voice. This interface should be implemented by the 967 * client. XAudio2 will call these methods via an interface pointer 968 * provided by the client in the IXAudio2::CreateSourceVoice call. 969 * 970 **************************************************************************/ 971 972 extern(C++) interface IXAudio2VoiceCallback 973 { 974 // Called just before this voice's processing pass begins. 975 void OnVoiceProcessingPassStart (UINT32 BytesRequired); 976 977 // Called just after this voice's processing pass ends. 978 void OnVoiceProcessingPassEnd (); 979 980 // Called when this voice has just finished playing a buffer stream 981 // (as marked with the XAUDIO2_END_OF_STREAM flag on the last buffer). 982 void OnStreamEnd (); 983 984 // Called when this voice is about to start processing a new buffer. 985 void OnBufferStart (void* pBufferContext); 986 987 // Called when this voice has just finished processing a buffer. 988 // The buffer can now be reused or destroyed. 989 void OnBufferEnd (void* pBufferContext); 990 991 // Called when this voice has just reached the end position of a loop. 992 void OnLoopEnd (void* pBufferContext); 993 994 // Called in the event of a critical error during voice processing, 995 // such as a failing xAPO or an error from the hardware XMA decoder. 996 // The voice may have to be destroyed and re-created to recover from 997 // the error. The callback arguments report which buffer was being 998 // processed when the error occurred, and its HRESULT code. 999 void OnVoiceError (void* pBufferContext, HRESULT Error); 1000 } 1001 1002 version (XAUDIO2_HELPER_FUNCTIONS) 1003 { 1004 1005 // Calculate the argument to SetVolume from a decibel value 1006 float XAudio2DecibelsToAmplitudeRatio(float Decibels) 1007 { 1008 return pow(10.0f, Decibels / 20.0f); 1009 } 1010 1011 // Recover a volume in decibels from an amplitude factor 1012 float XAudio2AmplitudeRatioToDecibels(float Volume) 1013 { 1014 if (Volume == 0) 1015 { 1016 return -3.402823466e+38f; // Smallest float value (-FLT_MAX) 1017 } 1018 return 20.0f * log10(Volume); 1019 } 1020 1021 // Calculate the argument to SetFrequencyRatio from a semitone value 1022 float XAudio2SemitonesToFrequencyRatio(float Semitones) 1023 { 1024 // FrequencyRatio = 2 ^ Octaves 1025 // = 2 ^ (Semitones / 12) 1026 return pow(2.0f, Semitones / 12.0f); 1027 } 1028 1029 // Recover a pitch in semitones from a frequency ratio 1030 float XAudio2FrequencyRatioToSemitones(float FrequencyRatio) 1031 { 1032 // Semitones = 12 * log2(FrequencyRatio) 1033 // = 12 * log2(10) * log10(FrequencyRatio) 1034 return 39.86313713864835f * log10(FrequencyRatio); 1035 } 1036 1037 // Convert from filter cutoff frequencies expressed in Hertz to the radian 1038 // frequency values used in XAUDIO2_FILTER_PARAMETERS.Frequency. Note that 1039 // the highest CutoffFrequency supported is SampleRate/6. Higher values of 1040 // CutoffFrequency will return XAUDIO2_MAX_FILTER_FREQUENCY. 1041 float XAudio2CutoffFrequencyToRadians(float CutoffFrequency, UINT32 SampleRate) 1042 { 1043 if (cast(UINT32)(CutoffFrequency * 6.0f) >= SampleRate) 1044 { 1045 return XAUDIO2_MAX_FILTER_FREQUENCY; 1046 } 1047 return 2.0f * sin(cast(float)PI * CutoffFrequency / SampleRate); 1048 } 1049 1050 // Convert from radian frequencies back to absolute frequencies in Hertz 1051 float XAudio2RadiansToCutoffFrequency(float Radians, float SampleRate) 1052 { 1053 return SampleRate * asin(Radians / 2.0f) / cast(float)PI; 1054 } 1055 1056 } 1057 1058 /************************************************************************** 1059 * 1060 * XAudio2Create: Top-level function that creates an XAudio2 instance. 1061 * 1062 * On Windows this is just an inline function that calls CoCreateInstance 1063 * and Initialize. The arguments are described above, under Initialize, 1064 * except that the XAUDIO2_DEBUG_ENGINE flag can be used here to select 1065 * the debug version of XAudio2. 1066 * 1067 * On Xbox, this function is implemented in the XAudio2 library, and the 1068 * XAUDIO2_DEBUG_ENGINE flag has no effect; the client must explicitly 1069 * link with the debug version of the library to obtain debug behavior. 1070 * 1071 **************************************************************************/ 1072 1073 version(XBOX) 1074 { 1075 1076 STDAPI XAudio2Create(IXAudio2* ppXAudio2, UINT32 Flags = 0, 1077 XAUDIO2_PROCESSOR XAudio2Processor = XAUDIO2_DEFAULT_PROCESSOR); 1078 } 1079 else // Windows 1080 { 1081 extern(Windows): 1082 version(DXSDK_2010_6) 1083 HRESULT XAudio2Create(out IXAudio2 ppXAudio2, UINT32 Flags = 0, 1084 XAUDIO2_PROCESSOR XAudio2Processor = XAUDIO2_DEFAULT_PROCESSOR) 1085 { 1086 // Instantiate the appropriate XAudio2 engine 1087 IXAudio2 pXAudio2; 1088 1089 HRESULT hr = CoCreateInstance((Flags & XAUDIO2_DEBUG_ENGINE) ? &IID_XAudio2_Debug : &IID_XAudio2, 1090 1091 null, CLSCTX_INPROC_SERVER, &IID_IXAudio2, cast(void**)&pXAudio2); 1092 if (SUCCEEDED(hr)) 1093 { 1094 hr = pXAudio2.Initialize(Flags, XAudio2Processor); 1095 1096 if (SUCCEEDED(hr)) 1097 { 1098 ppXAudio2 = pXAudio2; 1099 } 1100 else 1101 { 1102 pXAudio2.Release(); 1103 } 1104 } 1105 1106 return hr; 1107 } 1108 else version(XAUDIO_2_8) 1109 { 1110 HRESULT XAudio2Create(out IXAudio2 ppXAudio2, UINT32 Flags = 0, 1111 XAUDIO2_PROCESSOR XAudio2Processor = XAUDIO2_DEFAULT_PROCESSOR); 1112 } 1113 1114 } 1115 }