// -----------------------------------------
// SoundScribe (TM) and related software.
//
// Copyright (C) 2007-2011 Vannatech
// http://www.vannatech.com
// All rights reserved.
//
// This source code is subject to the MIT License.
// http://www.opensource.org/licenses/mit-license.php
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
// -----------------------------------------
using System;
using System.Runtime.InteropServices;
using Vannatech.CoreAudio.Externals;
using Vannatech.CoreAudio.Enumerations;
using Vannatech.CoreAudio.Constants;
namespace Vannatech.CoreAudio.Interfaces
{
///
/// Enables a client to create and initialize an audio stream between an audio application and the
/// audio engine (for a shared-mode stream) or the hardware buffer (for an exclusive-mode stream).
///
///
/// MSDN Reference: http://msdn.microsoft.com/en-us/library/dd370865.aspx
///
public partial interface IAudioClient
{
///
/// Initializes the audio stream.
///
/// The sharing mode for the connection.
/// One or more flags to control creation of the stream.
/// The buffer capacity as a time value.
///
/// In exclusive mode, this parameter specifies the requested scheduling period for successive
/// buffer accesses by the audio endpoint device. In shared mode, it should always be set to zero.
///
/// The format descriptor.
/// The ID of the audio session.
/// An HRESULT code indicating whether the operation succeeded of failed.
[PreserveSig]
int Initialize(
[In] [MarshalAs(UnmanagedType.I4)] AUDCLNT_SHAREMODE shareMode,
[In] [MarshalAs(UnmanagedType.U4)] UInt32 streamFlags,
[In] [MarshalAs(UnmanagedType.U8)] UInt64 bufferDuration,
[In] [MarshalAs(UnmanagedType.U8)] UInt64 devicePeriod,
[In] [MarshalAs(UnmanagedType.SysInt)] IntPtr format, // TODO: Explore options for WAVEFORMATEX definition here
[In, Optional] [MarshalAs(UnmanagedType.LPStruct)] Guid audioSessionId);
///
/// Retrieves the size (maximum capacity) of the audio buffer associated with the endpoint.
///
/// Receives the number of audio frames that the buffer can hold.
/// An HRESULT code indicating whether the operation succeeded of failed.
[PreserveSig]
int GetBufferSize(
[Out] [MarshalAs(UnmanagedType.U4)] out UInt32 size);
///
/// Retrieves the maximum latency for the current stream and can be called any time after the stream has been initialized.
///
/// Receives a time value representing the latency.
/// An HRESULT code indicating whether the operation succeeded of failed.
[PreserveSig]
int GetStreamLatency(
[Out] [MarshalAs(UnmanagedType.U8)] out UInt64 latency);
///
/// Retrieves the number of frames of padding in the endpoint buffer.
///
/// Receives the number of audio frames of padding in the buffer.
/// An HRESULT code indicating whether the operation succeeded of failed.
[PreserveSig]
int GetCurrentPadding(
[Out] [MarshalAs(UnmanagedType.U4)] out UInt32 frameCount);
///
/// Indicates whether the audio endpoint device supports a particular stream format.
///
/// The sharing mode for the stream format.
/// The specified stream format.
/// The supported format that is closest to the format specified in the format parameter.
/// An HRESULT code indicating whether the operation succeeded of failed.
[PreserveSig]
int IsFormatSupported(
[In] [MarshalAs(UnmanagedType.I4)] AUDCLNT_SHAREMODE shareMode,
[In] [MarshalAs(UnmanagedType.SysInt)] IntPtr format, // TODO: Explore options for WAVEFORMATEX definition here
[Out, Optional] out IntPtr closestMatch); // TODO: Sort out WAVEFORMATEX **match (returned)
///
/// Retrieves the stream format that the audio engine uses for its internal processing of shared-mode streams.
///
/// Receives the address of the mix format.
/// An HRESULT code indicating whether the operation succeeded of failed.
[PreserveSig]
int GetMixFormat(
[Out] [MarshalAs(UnmanagedType.SysInt)] out IntPtr format); // TODO: Explore options for WAVEFORMATEX definition here
///
/// Retrieves the length of the periodic interval separating successive processing passes by the audio engine on the data in the endpoint buffer.
///
/// Receives a time value specifying the default interval between processing passes by the audio engine.
/// Receives a time value specifying the minimum interval between processing passes by the audio endpoint device.
/// An HRESULT code indicating whether the operation succeeded of failed.
[PreserveSig]
int GetDevicePeriod(
[Out, Optional] [MarshalAs(UnmanagedType.U8)] out UInt64 processInterval,
[Out, Optional] [MarshalAs(UnmanagedType.U8)] out UInt64 minimumInterval);
///
/// Starts the audio stream.
///
/// An HRESULT code indicating whether the operation succeeded of failed.
[PreserveSig]
int Start();
///
/// Stops the audio stream.
///
/// An HRESULT code indicating whether the operation succeeded of failed.
[PreserveSig]
int Stop();
///
/// Resets the audio stream.
///
/// An HRESULT code indicating whether the operation succeeded of failed.
[PreserveSig]
int Reset();
///
/// Sets the event handle that the audio engine will signal each time a buffer becomes ready to be processed by the client.
///
/// The event handle.
/// An HRESULT code indicating whether the operation succeeded of failed.
[PreserveSig]
int SetEventHandle(
[In] [MarshalAs(UnmanagedType.SysInt)] IntPtr handle);
///
/// Accesses additional services from the audio client object.
///
/// The interface ID for the requested service.
/// Receives the address of an instance of the requested interface.
/// An HRESULT code indicating whether the operation succeeded of failed.
[PreserveSig]
int GetService(
[In] [MarshalAs(UnmanagedType.LPStruct)] Guid interfaceId,
[Out] [MarshalAs(UnmanagedType.IUnknown)] out object instancePtr);
}
}