IAudioClient.cs 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. // -----------------------------------------
  2. // SoundScribe (TM) and related software.
  3. //
  4. // Copyright (C) 2007-2011 Vannatech
  5. // http://www.vannatech.com
  6. // All rights reserved.
  7. //
  8. // This source code is subject to the MIT License.
  9. // http://www.opensource.org/licenses/mit-license.php
  10. //
  11. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  12. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  13. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  14. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  15. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  16. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  17. // THE SOFTWARE.
  18. // -----------------------------------------
  19. using System;
  20. using System.Runtime.InteropServices;
  21. using Vannatech.CoreAudio.Externals;
  22. using Vannatech.CoreAudio.Enumerations;
  23. using Vannatech.CoreAudio.Constants;
  24. namespace Vannatech.CoreAudio.Interfaces
  25. {
  26. /// <summary>
  27. /// Enables a client to create and initialize an audio stream between an audio application and the
  28. /// audio engine (for a shared-mode stream) or the hardware buffer (for an exclusive-mode stream).
  29. /// </summary>
  30. /// <remarks>
  31. /// MSDN Reference: http://msdn.microsoft.com/en-us/library/dd370865.aspx
  32. /// </remarks>
  33. public partial interface IAudioClient
  34. {
  35. /// <summary>
  36. /// Initializes the audio stream.
  37. /// </summary>
  38. /// <param name="shareMode">The sharing mode for the connection.</param>
  39. /// <param name="streamFlags">One or more <see cref="AUDCLNT_STREAMFLAGS_XXX"/> flags to control creation of the stream.</param>
  40. /// <param name="bufferDuration">The buffer capacity as a time value.</param>
  41. /// <param name="devicePeriod">
  42. /// In exclusive mode, this parameter specifies the requested scheduling period for successive
  43. /// buffer accesses by the audio endpoint device. In shared mode, it should always be set to zero.
  44. /// </param>
  45. /// <param name="format">The format descriptor.</param>
  46. /// <param name="audioSessionId">The ID of the audio session.</param>
  47. /// <returns>An HRESULT code indicating whether the operation succeeded of failed.</returns>
  48. [PreserveSig]
  49. int Initialize(
  50. [In] [MarshalAs(UnmanagedType.I4)] AUDCLNT_SHAREMODE shareMode,
  51. [In] [MarshalAs(UnmanagedType.U4)] UInt32 streamFlags,
  52. [In] [MarshalAs(UnmanagedType.U8)] UInt64 bufferDuration,
  53. [In] [MarshalAs(UnmanagedType.U8)] UInt64 devicePeriod,
  54. [In] [MarshalAs(UnmanagedType.SysInt)] IntPtr format, // TODO: Explore options for WAVEFORMATEX definition here
  55. [In, Optional] [MarshalAs(UnmanagedType.LPStruct)] Guid audioSessionId);
  56. /// <summary>
  57. /// Retrieves the size (maximum capacity) of the audio buffer associated with the endpoint.
  58. /// </summary>
  59. /// <param name="size">Receives the number of audio frames that the buffer can hold.</param>
  60. /// <returns>An HRESULT code indicating whether the operation succeeded of failed.</returns>
  61. [PreserveSig]
  62. int GetBufferSize(
  63. [Out] [MarshalAs(UnmanagedType.U4)] out UInt32 size);
  64. /// <summary>
  65. /// Retrieves the maximum latency for the current stream and can be called any time after the stream has been initialized.
  66. /// </summary>
  67. /// <param name="latency">Receives a time value representing the latency.</param>
  68. /// <returns>An HRESULT code indicating whether the operation succeeded of failed.</returns>
  69. [PreserveSig]
  70. int GetStreamLatency(
  71. [Out] [MarshalAs(UnmanagedType.U8)] out UInt64 latency);
  72. /// <summary>
  73. /// Retrieves the number of frames of padding in the endpoint buffer.
  74. /// </summary>
  75. /// <param name="frameCount">Receives the number of audio frames of padding in the buffer.</param>
  76. /// <returns>An HRESULT code indicating whether the operation succeeded of failed.</returns>
  77. [PreserveSig]
  78. int GetCurrentPadding(
  79. [Out] [MarshalAs(UnmanagedType.U4)] out UInt32 frameCount);
  80. /// <summary>
  81. /// Indicates whether the audio endpoint device supports a particular stream format.
  82. /// </summary>
  83. /// <param name="shareMode">The sharing mode for the stream format.</param>
  84. /// <param name="format">The specified stream format.</param>
  85. /// <param name="closestMatch">The supported format that is closest to the format specified in the format parameter.</param>
  86. /// <returns>An HRESULT code indicating whether the operation succeeded of failed.</returns>
  87. [PreserveSig]
  88. int IsFormatSupported(
  89. [In] [MarshalAs(UnmanagedType.I4)] AUDCLNT_SHAREMODE shareMode,
  90. [In] [MarshalAs(UnmanagedType.SysInt)] IntPtr format, // TODO: Explore options for WAVEFORMATEX definition here
  91. [Out, Optional] out IntPtr closestMatch); // TODO: Sort out WAVEFORMATEX **match (returned)
  92. /// <summary>
  93. /// Retrieves the stream format that the audio engine uses for its internal processing of shared-mode streams.
  94. /// </summary>
  95. /// <param name="format">Receives the address of the mix format.</param>
  96. /// <returns>An HRESULT code indicating whether the operation succeeded of failed.</returns>
  97. [PreserveSig]
  98. int GetMixFormat(
  99. [Out] [MarshalAs(UnmanagedType.SysInt)] out IntPtr format); // TODO: Explore options for WAVEFORMATEX definition here
  100. /// <summary>
  101. /// Retrieves the length of the periodic interval separating successive processing passes by the audio engine on the data in the endpoint buffer.
  102. /// </summary>
  103. /// <param name="processInterval">Receives a time value specifying the default interval between processing passes by the audio engine.</param>
  104. /// <param name="minimumInterval">Receives a time value specifying the minimum interval between processing passes by the audio endpoint device.</param>
  105. /// <returns>An HRESULT code indicating whether the operation succeeded of failed.</returns>
  106. [PreserveSig]
  107. int GetDevicePeriod(
  108. [Out, Optional] [MarshalAs(UnmanagedType.U8)] out UInt64 processInterval,
  109. [Out, Optional] [MarshalAs(UnmanagedType.U8)] out UInt64 minimumInterval);
  110. /// <summary>
  111. /// Starts the audio stream.
  112. /// </summary>
  113. /// <returns>An HRESULT code indicating whether the operation succeeded of failed.</returns>
  114. [PreserveSig]
  115. int Start();
  116. /// <summary>
  117. /// Stops the audio stream.
  118. /// </summary>
  119. /// <returns>An HRESULT code indicating whether the operation succeeded of failed.</returns>
  120. [PreserveSig]
  121. int Stop();
  122. /// <summary>
  123. /// Resets the audio stream.
  124. /// </summary>
  125. /// <returns>An HRESULT code indicating whether the operation succeeded of failed.</returns>
  126. [PreserveSig]
  127. int Reset();
  128. /// <summary>
  129. /// Sets the event handle that the audio engine will signal each time a buffer becomes ready to be processed by the client.
  130. /// </summary>
  131. /// <param name="handle">The event handle.</param>
  132. /// <returns>An HRESULT code indicating whether the operation succeeded of failed.</returns>
  133. [PreserveSig]
  134. int SetEventHandle(
  135. [In] [MarshalAs(UnmanagedType.SysInt)] IntPtr handle);
  136. /// <summary>
  137. /// Accesses additional services from the audio client object.
  138. /// </summary>
  139. /// <param name="interfaceId">The interface ID for the requested service.</param>
  140. /// <param name="instancePtr">Receives the address of an instance of the requested interface.</param>
  141. /// <returns>An HRESULT code indicating whether the operation succeeded of failed.</returns>
  142. [PreserveSig]
  143. int GetService(
  144. [In] [MarshalAs(UnmanagedType.LPStruct)] Guid interfaceId,
  145. [Out] [MarshalAs(UnmanagedType.IUnknown)] out object instancePtr);
  146. }
  147. }