src/audio/xaudio2/SDL_xaudio2.h
author Ryan C. Gordon
Tue, 24 Jan 2017 16:18:25 -0500
changeset 10850 c9dc0068b0e7
parent 10737 3406a0f8b041
child 11382 2c50e79b19e0
permissions -rw-r--r--
configure: report libsamplerate support status.
     1 /*
     2   Simple DirectMedia Layer
     3   Copyright (C) 1997-2017 Sam Lantinga <slouken@libsdl.org>
     4 
     5   This software is provided 'as-is', without any express or implied
     6   warranty.  In no event will the authors be held liable for any damages
     7   arising from the use of this software.
     8 
     9   Permission is granted to anyone to use this software for any purpose,
    10   including commercial applications, and to alter it and redistribute it
    11   freely, subject to the following restrictions:
    12 
    13   1. The origin of this software must not be misrepresented; you must not
    14      claim that you wrote the original software. If you use this software
    15      in a product, an acknowledgment in the product documentation would be
    16      appreciated but is not required.
    17   2. Altered source versions must be plainly marked as such, and must not be
    18      misrepresented as being the original software.
    19   3. This notice may not be removed or altered from any source distribution.
    20 */
    21 
    22 #ifndef _SDL_XAUDIO2_H
    23 #define _SDL_XAUDIO2_H
    24 
    25 #include <windows.h>
    26 #include <mmreg.h>
    27 #include <objbase.h>
    28 
    29 /* XAudio2 packs its structure members together as tightly as possible.
    30    This pragma is needed to ensure compatibility with XAudio2 on 64-bit
    31    platforms.
    32 */
    33 #pragma pack(push, 1)
    34 
    35 typedef interface IXAudio2 IXAudio2;
    36 typedef interface IXAudio2SourceVoice IXAudio2SourceVoice;
    37 typedef interface IXAudio2MasteringVoice IXAudio2MasteringVoice;
    38 typedef interface IXAudio2EngineCallback IXAudio2EngineCallback;
    39 typedef interface IXAudio2VoiceCallback IXAudio2VoiceCallback;
    40 typedef interface IXAudio2Voice IXAudio2Voice;
    41 typedef interface IXAudio2SubmixVoice IXAudio2SubmixVoice;
    42 
    43 typedef enum _AUDIO_STREAM_CATEGORY {
    44     AudioCategory_Other = 0,
    45     AudioCategory_ForegroundOnlyMedia,
    46     AudioCategory_BackgroundCapableMedia,
    47     AudioCategory_Communications,
    48     AudioCategory_Alerts,
    49     AudioCategory_SoundEffects,
    50     AudioCategory_GameEffects,
    51     AudioCategory_GameMedia,
    52     AudioCategory_GameChat,
    53     AudioCategory_Movie,
    54     AudioCategory_Media
    55 } AUDIO_STREAM_CATEGORY;
    56 
    57 typedef struct XAUDIO2_BUFFER {
    58     UINT32     Flags;
    59     UINT32     AudioBytes;
    60     const BYTE *pAudioData;
    61     UINT32     PlayBegin;
    62     UINT32     PlayLength;
    63     UINT32     LoopBegin;
    64     UINT32     LoopLength;
    65     UINT32     LoopCount;
    66     void       *pContext;
    67 } XAUDIO2_BUFFER;
    68 
    69 typedef struct XAUDIO2_BUFFER_WMA {
    70     const UINT32 *pDecodedPacketCumulativeBytes;
    71     UINT32       PacketCount;
    72 } XAUDIO2_BUFFER_WMA;
    73 
    74 typedef struct XAUDIO2_SEND_DESCRIPTOR {
    75     UINT32        Flags;
    76     IXAudio2Voice *pOutputVoice;
    77 } XAUDIO2_SEND_DESCRIPTOR;
    78 
    79 typedef struct XAUDIO2_VOICE_SENDS {
    80     UINT32                  SendCount;
    81     XAUDIO2_SEND_DESCRIPTOR *pSends;
    82 } XAUDIO2_VOICE_SENDS;
    83 
    84 typedef struct XAUDIO2_EFFECT_DESCRIPTOR {
    85     IUnknown *pEffect;
    86     BOOL     InitialState;
    87     UINT32   OutputChannels;
    88 } XAUDIO2_EFFECT_DESCRIPTOR;
    89 
    90 typedef struct XAUDIO2_EFFECT_CHAIN {
    91     UINT32                    EffectCount;
    92     XAUDIO2_EFFECT_DESCRIPTOR *pEffectDescriptors;
    93 } XAUDIO2_EFFECT_CHAIN;
    94 
    95 typedef struct XAUDIO2_PERFORMANCE_DATA {
    96     UINT64 AudioCyclesSinceLastQuery;
    97     UINT64 TotalCyclesSinceLastQuery;
    98     UINT32 MinimumCyclesPerQuantum;
    99     UINT32 MaximumCyclesPerQuantum;
   100     UINT32 MemoryUsageInBytes;
   101     UINT32 CurrentLatencyInSamples;
   102     UINT32 GlitchesSinceEngineStarted;
   103     UINT32 ActiveSourceVoiceCount;
   104     UINT32 TotalSourceVoiceCount;
   105     UINT32 ActiveSubmixVoiceCount;
   106     UINT32 ActiveResamplerCount;
   107     UINT32 ActiveMatrixMixCount;
   108     UINT32 ActiveXmaSourceVoices;
   109     UINT32 ActiveXmaStreams;
   110 } XAUDIO2_PERFORMANCE_DATA;
   111 
   112 typedef struct XAUDIO2_DEBUG_CONFIGURATION {
   113     UINT32 TraceMask;
   114     UINT32 BreakMask;
   115     BOOL   LogThreadID;
   116     BOOL   LogFileline;
   117     BOOL   LogFunctionName;
   118     BOOL   LogTiming;
   119 } XAUDIO2_DEBUG_CONFIGURATION;
   120 
   121 typedef struct XAUDIO2_VOICE_DETAILS {
   122     UINT32 CreationFlags;
   123     UINT32 ActiveFlags;
   124     UINT32 InputChannels;
   125     UINT32 InputSampleRate;
   126 } XAUDIO2_VOICE_DETAILS;
   127 
   128 typedef enum XAUDIO2_FILTER_TYPE {
   129     LowPassFilter = 0,
   130     BandPassFilter = 1,
   131     HighPassFilter = 2,
   132     NotchFilter = 3,
   133     LowPassOnePoleFilter = 4,
   134     HighPassOnePoleFilter = 5
   135 } XAUDIO2_FILTER_TYPE;
   136 
   137 typedef struct XAUDIO2_FILTER_PARAMETERS {
   138     XAUDIO2_FILTER_TYPE Type;
   139     float               Frequency;
   140     float               OneOverQ;
   141 } XAUDIO2_FILTER_PARAMETERS;
   142 
   143 typedef struct XAUDIO2_VOICE_STATE {
   144     void   *pCurrentBufferContext;
   145     UINT32 BuffersQueued;
   146     UINT64 SamplesPlayed;
   147 } XAUDIO2_VOICE_STATE;
   148 
   149 
   150 typedef UINT32 XAUDIO2_PROCESSOR;
   151 #define Processor1 0x00000001
   152 #define XAUDIO2_DEFAULT_PROCESSOR Processor1
   153 
   154 #define XAUDIO2_E_DEVICE_INVALIDATED 0x88960004
   155 #define XAUDIO2_COMMIT_NOW 0
   156 #define XAUDIO2_VOICE_NOSAMPLESPLAYED 0x0100
   157 #define XAUDIO2_DEFAULT_CHANNELS 0
   158 
   159 extern HRESULT __stdcall XAudio2Create(
   160     _Out_ IXAudio2          **ppXAudio2,
   161     _In_  UINT32            Flags,
   162     _In_  XAUDIO2_PROCESSOR XAudio2Processor
   163     );
   164 
   165 #undef INTERFACE
   166 #define INTERFACE IXAudio2
   167 typedef interface IXAudio2 {
   168     const struct IXAudio2Vtbl FAR* lpVtbl;
   169 } IXAudio2;
   170 typedef const struct IXAudio2Vtbl IXAudio2Vtbl;
   171 const struct IXAudio2Vtbl
   172 {
   173     /* IUnknown */
   174     STDMETHOD(QueryInterface)(THIS_ REFIID iid, LPVOID *ppv) PURE;
   175     STDMETHOD_(ULONG, AddRef)(THIS) PURE;
   176     STDMETHOD_(ULONG, Release)(THIS) PURE;
   177 
   178     /* IXAudio2 */
   179     STDMETHOD_(HRESULT, RegisterForCallbacks)(THIS, IXAudio2EngineCallback *pCallback) PURE;
   180     STDMETHOD_(VOID, UnregisterForCallbacks)(THIS, IXAudio2EngineCallback *pCallback) PURE;
   181     STDMETHOD_(HRESULT, CreateSourceVoice)(THIS, IXAudio2SourceVoice **ppSourceVoice,
   182                                            const WAVEFORMATEX *pSourceFormat,
   183                                            UINT32 Flags,
   184                                            float MaxFrequencyRatio,
   185                                            IXAudio2VoiceCallback *pCallback,
   186                                            const XAUDIO2_VOICE_SENDS *pSendList,
   187                                            const XAUDIO2_EFFECT_CHAIN *pEffectChain) PURE;
   188     STDMETHOD_(HRESULT, CreateSubmixVoice)(THIS, IXAudio2SubmixVoice **ppSubmixVoice,
   189                                            UINT32 InputChannels,
   190                                            UINT32 InputSampleRate,
   191                                            UINT32 Flags,
   192                                            UINT32 ProcessingStage,
   193                                            const XAUDIO2_VOICE_SENDS *pSendList,
   194                                            const XAUDIO2_EFFECT_CHAIN *pEffectChain) PURE;
   195     STDMETHOD_(HRESULT, CreateMasteringVoice)(THIS, IXAudio2MasteringVoice **ppMasteringVoice,
   196                                               UINT32 InputChannels,
   197                                               UINT32 InputSampleRate,
   198                                               UINT32 Flags,
   199                                               LPCWSTR szDeviceId,
   200                                               const XAUDIO2_EFFECT_CHAIN *pEffectChain,
   201                                               AUDIO_STREAM_CATEGORY StreamCategory) PURE;
   202     STDMETHOD_(HRESULT, StartEngine)(THIS) PURE;
   203     STDMETHOD_(VOID, StopEngine)(THIS) PURE;
   204     STDMETHOD_(HRESULT, CommitChanges)(THIS, UINT32 OperationSet) PURE;
   205     STDMETHOD_(HRESULT, GetPerformanceData)(THIS, XAUDIO2_PERFORMANCE_DATA *pPerfData) PURE;
   206     STDMETHOD_(HRESULT, SetDebugConfiguration)(THIS, XAUDIO2_DEBUG_CONFIGURATION *pDebugConfiguration,
   207                                                VOID *pReserved) PURE;
   208 };
   209 
   210 #define IXAudio2_Release(A) ((A)->lpVtbl->Release(A))
   211 #define IXAudio2_CreateSourceVoice(A,B,C,D,E,F,G,H) ((A)->lpVtbl->CreateSourceVoice(A,B,C,D,E,F,G,H))
   212 #define IXAudio2_CreateMasteringVoice(A,B,C,D,E,F,G,H) ((A)->lpVtbl->CreateMasteringVoice(A,B,C,D,E,F,G,H))
   213 #define IXAudio2_StartEngine(A) ((A)->lpVtbl->StartEngine(A))
   214 #define IXAudio2_StopEngine(A) ((A)->lpVtbl->StopEngine(A))
   215 
   216 
   217 #undef INTERFACE
   218 #define INTERFACE IXAudio2SourceVoice
   219 typedef interface IXAudio2SourceVoice {
   220     const struct IXAudio2SourceVoiceVtbl FAR* lpVtbl;
   221 } IXAudio2SourceVoice;
   222 typedef const struct IXAudio2SourceVoiceVtbl IXAudio2SourceVoiceVtbl;
   223 const struct IXAudio2SourceVoiceVtbl
   224 {
   225     /* MSDN says that IXAudio2Voice inherits from IXAudio2, but MSVC's debugger
   226      * says otherwise, and that IXAudio2Voice doesn't inherit from any other
   227      * interface!
   228      */
   229 
   230     /* IXAudio2Voice */
   231     STDMETHOD_(VOID, GetVoiceDetails)(THIS, XAUDIO2_VOICE_DETAILS *pVoiceDetails) PURE;
   232     STDMETHOD_(HRESULT, SetOutputVoices)(THIS, const XAUDIO2_VOICE_SENDS *pSendList) PURE;
   233     STDMETHOD_(HRESULT, SetEffectChain)(THIS, const XAUDIO2_EFFECT_CHAIN *pEffectChain) PURE;
   234     STDMETHOD_(HRESULT, EnableEffect)(THIS, UINT32 EffectIndex, UINT32 OperationSet) PURE;
   235     STDMETHOD_(HRESULT, DisableEffect)(THIS, UINT32 EffectIndex, UINT32 OperationSet) PURE;
   236     STDMETHOD_(VOID, GetEffectState)(THIS, UINT32 EffectIndex, BOOL *pEnabled) PURE;
   237     STDMETHOD_(HRESULT, SetEffectParameters)(THIS, UINT32 EffectIndex,
   238                                              const void *pParameters,
   239                                              UINT32 ParametersByteSize,
   240                                              UINT32 OperationSet) PURE;
   241     STDMETHOD_(VOID, GetEffectParameters)(THIS, UINT32 EffectIndex,
   242                                           void *pParameters,
   243                                           UINT32 ParametersByteSize) PURE;
   244     STDMETHOD_(HRESULT, SetFilterParameters)(THIS, const XAUDIO2_FILTER_PARAMETERS *pParameters,
   245                                              UINT32 OperationSet) PURE;
   246     STDMETHOD_(VOID, GetFilterParameters)(THIS, XAUDIO2_FILTER_PARAMETERS *pParameters) PURE;
   247     STDMETHOD_(HRESULT, SetOutputFilterParameters)(THIS, IXAudio2Voice *pDestinationVoice,
   248                                                    XAUDIO2_FILTER_PARAMETERS *pParameters,
   249                                                    UINT32 OperationSet) PURE;
   250     STDMETHOD_(VOID, GetOutputFilterParameters)(THIS, IXAudio2Voice *pDestinationVoice,
   251                                                 XAUDIO2_FILTER_PARAMETERS *pParameters) PURE;
   252     STDMETHOD_(HRESULT, SetVolume)(THIS, float Volume,
   253                                    UINT32 OperationSet) PURE;
   254     STDMETHOD_(VOID, GetVolume)(THIS, float *pVolume) PURE;
   255     STDMETHOD_(HRESULT, SetChannelVolumes)(THIS, UINT32 Channels,
   256                                            const float *pVolumes,
   257                                            UINT32 OperationSet) PURE;
   258     STDMETHOD_(VOID, GetChannelVolumes)(THIS, UINT32 Channels,
   259                                         float *pVolumes) PURE;
   260     STDMETHOD_(HRESULT, SetOutputMatrix)(THIS, IXAudio2Voice *pDestinationVoice,
   261                                          UINT32 SourceChannels,
   262                                          UINT32 DestinationChannels,
   263                                          const float *pLevelMatrix,
   264                                          UINT32 OperationSet) PURE;
   265     STDMETHOD_(VOID, GetOutputMatrix)(THIS, IXAudio2Voice *pDestinationVoice,
   266                                       UINT32 SourceChannels,
   267                                       UINT32 DestinationChannels,
   268                                       float *pLevelMatrix) PURE;
   269     STDMETHOD_(VOID, DestroyVoice)(THIS) PURE;
   270 
   271     /* IXAudio2SourceVoice */
   272     STDMETHOD_(HRESULT, Start)(THIS, UINT32 Flags,
   273                                UINT32 OperationSet) PURE;
   274     STDMETHOD_(HRESULT, Stop)(THIS, UINT32 Flags,
   275                               UINT32 OperationSet) PURE;
   276     STDMETHOD_(HRESULT, SubmitSourceBuffer)(THIS, const XAUDIO2_BUFFER *pBuffer,
   277                                             const XAUDIO2_BUFFER_WMA *pBufferWMA) PURE;
   278     STDMETHOD_(HRESULT, FlushSourceBuffers)(THIS) PURE;
   279     STDMETHOD_(HRESULT, Discontinuity)(THIS) PURE;
   280     STDMETHOD_(HRESULT, ExitLoop)(THIS, UINT32 OperationSet) PURE;
   281     STDMETHOD_(VOID, GetState)(THIS, XAUDIO2_VOICE_STATE *pVoiceState,
   282                                UINT32 Flags) PURE;
   283     STDMETHOD_(HRESULT, SetFrequencyRatio)(THIS, float Ratio,
   284                                            UINT32 OperationSet) PURE;
   285     STDMETHOD_(VOID, GetFrequencyRatio)(THIS, float *pRatio) PURE;
   286     STDMETHOD_(HRESULT, SetSourceSampleRate)(THIS, UINT32 NewSourceSampleRate) PURE;
   287 };
   288 
   289 #define IXAudio2SourceVoice_DestroyVoice(A) ((A)->lpVtbl->DestroyVoice(A))
   290 #define IXAudio2SourceVoice_Start(A,B,C) ((A)->lpVtbl->Start(A,B,C))
   291 #define IXAudio2SourceVoice_Stop(A,B,C) ((A)->lpVtbl->Stop(A,B,C))
   292 #define IXAudio2SourceVoice_SubmitSourceBuffer(A,B,C) ((A)->lpVtbl->SubmitSourceBuffer(A,B,C))
   293 #define IXAudio2SourceVoice_FlushSourceBuffers(A) ((A)->lpVtbl->FlushSourceBuffers(A))
   294 #define IXAudio2SourceVoice_Discontinuity(A) ((A)->lpVtbl->Discontinuity(A))
   295 #define IXAudio2SourceVoice_GetState(A,B,C) ((A)->lpVtbl->GetState(A,B,C))
   296 
   297 
   298 #undef INTERFACE
   299 #define INTERFACE IXAudio2MasteringVoice
   300 typedef interface IXAudio2MasteringVoice {
   301     const struct IXAudio2MasteringVoiceVtbl FAR* lpVtbl;
   302 } IXAudio2MasteringVoice;
   303 typedef const struct IXAudio2MasteringVoiceVtbl IXAudio2MasteringVoiceVtbl;
   304 const struct IXAudio2MasteringVoiceVtbl
   305 {
   306     /* MSDN says that IXAudio2Voice inherits from IXAudio2, but MSVC's debugger
   307      * says otherwise, and that IXAudio2Voice doesn't inherit from any other
   308      * interface!
   309      */
   310 
   311     /* IXAudio2Voice */
   312     STDMETHOD_(VOID, GetVoiceDetails)(THIS, XAUDIO2_VOICE_DETAILS *pVoiceDetails) PURE;
   313     STDMETHOD_(HRESULT, SetOutputVoices)(THIS, const XAUDIO2_VOICE_SENDS *pSendList) PURE;
   314     STDMETHOD_(HRESULT, SetEffectChain)(THIS, const XAUDIO2_EFFECT_CHAIN *pEffectChain) PURE;
   315     STDMETHOD_(HRESULT, EnableEffect)(THIS, UINT32 EffectIndex, UINT32 OperationSet) PURE;
   316     STDMETHOD_(HRESULT, DisableEffect)(THIS, UINT32 EffectIndex, UINT32 OperationSet) PURE;
   317     STDMETHOD_(VOID, GetEffectState)(THIS, UINT32 EffectIndex, BOOL *pEnabled) PURE;
   318     STDMETHOD_(HRESULT, SetEffectParameters)(THIS, UINT32 EffectIndex,
   319                                              const void *pParameters,
   320                                              UINT32 ParametersByteSize,
   321                                              UINT32 OperationSet) PURE;
   322     STDMETHOD_(VOID, GetEffectParameters)(THIS, UINT32 EffectIndex,
   323                                           void *pParameters,
   324                                           UINT32 ParametersByteSize) PURE;
   325     STDMETHOD_(HRESULT, SetFilterParameters)(THIS, const XAUDIO2_FILTER_PARAMETERS *pParameters,
   326                                              UINT32 OperationSet) PURE;
   327     STDMETHOD_(VOID, GetFilterParameters)(THIS, XAUDIO2_FILTER_PARAMETERS *pParameters) PURE;
   328     STDMETHOD_(HRESULT, SetOutputFilterParameters)(THIS, IXAudio2Voice *pDestinationVoice,
   329                                                    XAUDIO2_FILTER_PARAMETERS *pParameters,
   330                                                    UINT32 OperationSet) PURE;
   331     STDMETHOD_(VOID, GetOutputFilterParameters)(THIS, IXAudio2Voice *pDestinationVoice,
   332                                                 XAUDIO2_FILTER_PARAMETERS *pParameters) PURE;
   333     STDMETHOD_(HRESULT, SetVolume)(THIS, float Volume,
   334                                    UINT32 OperationSet) PURE;
   335     STDMETHOD_(VOID, GetVolume)(THIS, float *pVolume) PURE;
   336     STDMETHOD_(HRESULT, SetChannelVolumes)(THIS, UINT32 Channels,
   337                                            const float *pVolumes,
   338                                            UINT32 OperationSet) PURE;
   339     STDMETHOD_(VOID, GetChannelVolumes)(THIS, UINT32 Channels,
   340                                         float *pVolumes) PURE;
   341     STDMETHOD_(HRESULT, SetOutputMatrix)(THIS, IXAudio2Voice *pDestinationVoice,
   342                                          UINT32 SourceChannels,
   343                                          UINT32 DestinationChannels,
   344                                          const float *pLevelMatrix,
   345                                          UINT32 OperationSet) PURE;
   346     STDMETHOD_(VOID, GetOutputMatrix)(THIS, IXAudio2Voice *pDestinationVoice,
   347                                       UINT32 SourceChannels,
   348                                       UINT32 DestinationChannels,
   349                                       float *pLevelMatrix) PURE;
   350     STDMETHOD_(VOID, DestroyVoice)(THIS) PURE;
   351 
   352     /* IXAudio2SourceVoice */
   353     STDMETHOD_(VOID, GetChannelMask)(THIS, DWORD *pChannelMask) PURE;
   354 };
   355 
   356 #define IXAudio2MasteringVoice_DestroyVoice(A) ((A)->lpVtbl->DestroyVoice(A))
   357 
   358 
   359 #undef INTERFACE
   360 #define INTERFACE IXAudio2VoiceCallback
   361 typedef interface IXAudio2VoiceCallback {
   362     const struct IXAudio2VoiceCallbackVtbl FAR* lpVtbl;
   363 } IXAudio2VoiceCallback;
   364 typedef const struct IXAudio2VoiceCallbackVtbl IXAudio2VoiceCallbackVtbl;
   365 const struct IXAudio2VoiceCallbackVtbl
   366 {
   367     /* MSDN says that IXAudio2VoiceCallback inherits from IXAudio2, but SDL's
   368      * own code says otherwise, and that IXAudio2VoiceCallback doesn't inherit
   369      * from any other interface!
   370      */
   371 
   372     /* IXAudio2VoiceCallback */
   373     STDMETHOD_(VOID, OnVoiceProcessingPassStart)(THIS, UINT32 BytesRequired) PURE;
   374     STDMETHOD_(VOID, OnVoiceProcessingPassEnd)(THIS) PURE;
   375     STDMETHOD_(VOID, OnStreamEnd)(THIS) PURE;
   376     STDMETHOD_(VOID, OnBufferStart)(THIS, void *pBufferContext) PURE;
   377     STDMETHOD_(VOID, OnBufferEnd)(THIS, void *pBufferContext) PURE;
   378     STDMETHOD_(VOID, OnLoopEnd)(THIS, void *pBufferContext) PURE;
   379     STDMETHOD_(VOID, OnVoiceError)(THIS, void *pBufferContext, HRESULT Error) PURE;
   380 };
   381 
   382 #pragma pack(pop)   /* Undo pragma push */
   383 
   384 #endif  /* _SDL_XAUDIO2_H */
   385 
   386 /* vi: set ts=4 sw=4 expandtab: */