// %BANNER_BEGIN% // --------------------------------------------------------------------- // %COPYRIGHT_BEGIN% // Copyright (c) (2018-2022) Magic Leap, Inc. All Rights Reserved. // Use of this file is governed by the Software License Agreement, located here: https://www.magicleap.com/software-license-agreement-ml2 // Terms and conditions applicable to third-party materials accompanying this distribution may also be found in the top-level NOTICE file appearing herein. // %COPYRIGHT_END% // --------------------------------------------------------------------- // %BANNER_END% // Disable warnings about missing documentation for native interop. #pragma warning disable 1591 namespace UnityEngine.XR.MagicLeap { using System; using System.Runtime.InteropServices; /// /// Manages Audio. /// public sealed partial class MLAudioInput { /// /// See ml_audio.h for additional comments. /// private class NativeBindings : Native.MagicLeapNativeBindings { /// /// The callback that occurs when an input buffer is available. /// /// Handle used to identify the sound input. /// A pointer to the callback. public delegate void MLAudioOnBufferDelegate(ulong handle, IntPtr context); /// /// The callback that occurs when the mute state changes for the microphone. /// /// The mute state of the microphone. /// A pointer to the callback. public delegate void MLAudioMicMuteCallback([MarshalAs(UnmanagedType.I1)] bool muted, IntPtr callback); /// /// Sets the mute state of the microphone. /// /// The mute state of the microphone. /// /// MLResult.Result will be MLResult.Code.Ok if successful. /// MLResult.Result will be MLResult.Code.UnspecifiedFailure if failed due to internal error. /// MLResult.Result will be MLResult.Code.PermissionDenied if AudioCaptureMic permission is denied. /// MLResult.Result will be MLResult.Code.NotImplemented. /// [DllImport(AudioPlayerDLL, CallingConvention = CallingConvention.Cdecl)] public static extern MLResult.Code MLAudioSetMicMute([MarshalAs(UnmanagedType.I1)] bool muted); /// /// Gets the mute state of the microphone. /// /// The mute state of the microphone. /// /// MLResult.Result will be MLResult.Code.Ok if successful. /// MLResult.Result will be MLResult.Code.UnspecifiedFailure if failed due to internal error. /// MLResult.Result will be MLResult.Code.InvalidParam if input parameter is invalid. /// MLResult.Result will be MLResult.Code.PermissionDenied if AudioCaptureMic permission is denied. /// MLResult.Result will be MLResult.Code.AllocFailed if failed due to internal error. /// MLResult.Result will be MLResult.Code.NotImplemented. /// [DllImport(AudioPlayerDLL, CallingConvention = CallingConvention.Cdecl)] public static extern MLResult.Code MLAudioGetMicMute([MarshalAs(UnmanagedType.I1)] out bool isMuted); /// /// Register a callback for when the mute state changes for the microphone. /// /// A pointer to the callback. /// A generic data pointer passed back to the callback. /// /// MLResult.Result will be MLResult.Code.Ok if successful. /// MLResult.Result will be MLResult.Code.UnspecifiedFailure if failed due to internal error. /// MLResult.Result will be MLResult.Code.PermissionDenied if AudioCaptureMic permission is denied. /// MLResult.Result will be MLResult.Code.AllocFailed if failed due to internal error. /// MLResult.Result will be MLResult.Code.NotImplemented. /// [DllImport(AudioPlayerDLL, CallingConvention = CallingConvention.Cdecl)] public static extern MLResult.Code MLAudioSetMicMuteCallback(MLAudioMicMuteCallback callback, IntPtr data); /// /// Gets the result string for a MLResult.Code. /// /// The MLResult.Code to be requested. /// A pointer to the result string. [DllImport(AudioPlayerDLL, CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr MLAudioGetResultString(MLResult.Code result); /// /// Returns the preferred (i.e. best performing) settings for buffered input. /// /// Number of audio channels (e.g. 2 for stereo). /// Sample rate for the buffered input. /// Recommended Settings for MLAudioBufferFormat. /// Recommended size for the buffers. /// Minimum allowable size for the buffers. /// /// MLResult.Result will be MLResult.AllocFailed due to memory allocation failure. /// MLResult.Result will be MLResult.InvalidParam due to an invalid parameter. /// MLResult.Result will be MLResult.Ok Successfully created new sound input that provides a "mixed capture" stream. /// MLResult.Result will be MLResult.PermissionDenied due to lack of permission. /// MLResult.Result will be MLResult.UnspecifiedFailure due to an unknown error. /// MLResult.Result will be MLAudioResult.InternalConfigError due to an internal configuration error. /// MLResult.Result will be MLAudioResult.InvalidBitsPerSample due to an invalid bits per sample. /// MLResult.Result will be MLAudioResult.InvalidBufferSize due to an invalid buffer size. /// MLResult.Result will be MLAudioResult.InvalidChannelCount due to an invalid channel count. /// MLResult.Result will be MLAudioResult.InvalidSampleFormat due to an invalid sample format. /// MLResult.Result will be MLAudioResult.InvalidSampleRate due to an invalid sample rate. /// MLResult.Result will be MLAudioResult.InvalidValidBits due to an invalid valid bits per sample. /// MLResult.Result will be MLAudioResult.NotImplemented because feature has not been implemented yet. /// [DllImport(AudioPlayerDLL, CallingConvention = CallingConvention.Cdecl)] public static extern MLResult.Code MLAudioGetBufferedInputDefaults(uint channelCount, uint samplesPerSecond, out MLAudioOutput.NativeBindings.MLAudioBufferFormat format, out uint recommendedSizeInBytes, out uint minimumSizeInBytes); /// /// Creates a new sound input that provides audio from the mics on the wearable. /// /// Specifies the type of mic capture created. /// MLAudioBufferFormat specifying the audio format of the stream. /// Requested size in bytes for each of the two stream buffers. /// Function to use for callback. /// A generic data pointer passed back to the callback. /// Handle used in subsequent calls for this sound input. /// /// MLResult.Result will be MLResult.AllocFailed due to memory allocation failure. /// MLResult.Result will be MLResult.InvalidParam due to an invalid parameter. /// MLResult.Result will be MLResult.Ok Successfully created new sound input that provides a mic capture stream. /// MLResult.Result will be MLResult.PermissionDenied due to lack of permission. /// MLResult.Result will be MLResult.UnspecifiedFailure due to an unknown error. /// MLResult.Result will be MLAudioResult.InternalConfigError due to an internal configuration error. /// MLResult.Result will be MLAudioResult.InvalidBitsPerSample due to an invalid bits per sample. /// MLResult.Result will be MLAudioResult.InvalidBufferSize due to an invalid buffer size. /// MLResult.Result will be MLAudioResult.InvalidChannelCount due to an invalid channel count. /// MLResult.Result will be MLAudioResult.InvalidSampleFormat due to an invalid sample format. /// MLResult.Result will be MLAudioResult.InvalidSampleRate due to an invalid sample rate. /// MLResult.Result will be MLAudioResult.InvalidValidBits due to an invalid valid bits per sample. /// MLResult.Result will be MLAudioResult.NotImplemented because feature has not been implemented yet. /// [DllImport(AudioPlayerDLL, CallingConvention = CallingConvention.Cdecl)] public static extern MLResult.Code MLAudioCreateInputFromMicCapture(MicCaptureType captureType, in MLAudioOutput.NativeBindings.MLAudioBufferFormat format, uint bufferSizeInBytes, MLAudioOnBufferDelegate callback, IntPtr context, out ulong handle); /// /// Returns a full buffer containing captured audio data. /// /// Used to identify the sound input. /// Contains the buffer to read from. /// /// MLResult.Result will be MLResult.InvalidParam due to an invalid parameter. /// MLResult.Result will be MLResult.Ok Successfully returned full buffer containing captured audio data. /// MLResult.Result will be MLResult.UnspecifiedFailure due to an unknown error. /// MLResult.Result will be MLResult.AudioBufferNotReady because buffer was not ready. /// MLResult.Result will be MLResult.AudioHandleNotFound due to a missing handle. /// MLResult.Result will be MLResult.AudioInternalConfigError due to an internal configurations error. /// MLResult.Result will be MLResult.NotImplemented because feature has not been implemented yet. /// MLResult.Result will be MLResult.OperationUnavailable because operation is unavailable. /// [DllImport(AudioPlayerDLL, CallingConvention = CallingConvention.Cdecl)] public static extern MLResult.Code MLAudioGetInputBuffer(ulong handle, out MLAudioOutput.NativeBindings.MLAudioBuffer buffer); /// /// Releases a buffer once it has been read. /// /// Used to identify the sound input. /// /// MLResult.Result will be MLResult.Ok Successfully released buffer. /// MLResult.Result will be MLResult.UnspecifiedFailure due to an unknown error. /// MLResult.Result will be MLResult.AudioBufferNotReady because buffer was not ready. /// MLResult.Result will be MLResult.AudioHandleNotFound due to a missing handle. /// MLResult.Result will be MLResult.AudioInternalConfigError due to an internal configurations error. /// MLResult.Result will be MLResult.NotImplemented because feature has not been implemented yet. /// MLResult.Result will be MLResult.OperationUnavailable because operation is unavailable. /// [DllImport(AudioPlayerDLL, CallingConvention = CallingConvention.Cdecl)] public static extern MLResult.Code MLAudioReleaseInputBuffer(ulong handle); /// /// Starts capture for a sound input. /// /// Used to identify the sound input. /// /// MLResult.Result will be MLResult.Ok Successfully started capture for sound input. /// MLResult.Result will be MLResult.PermissionDenied due to lack of permission. /// MLResult.Result will be MLResult.UnspecifiedFailure due to an unknown error. /// MLResult.Result will be MLResult.AudioHandleNotFound due to a missing handle. /// MLResult.Result will be MLResult.NotImplemented because feature has not been implemented yet. /// [DllImport(AudioPlayerDLL, CallingConvention = CallingConvention.Cdecl)] public static extern MLResult.Code MLAudioStartInput(ulong handle); /// /// Stops capture for a sound input. /// /// Used to identify the sound input. /// /// MLResult.Result will be MLResult.Ok Successfully stopped capture for sound input. /// MLResult.Result will be MLResult.PermissionDenied due to lack of permission. /// MLResult.Result will be MLResult.UnspecifiedFailure due to an unknown error. /// MLResult.Result will be MLResult.AudioHandleNotFound due to a missing handle. /// MLResult.Result will be MLResult.NotImplemented because feature has not been implemented yet. /// [DllImport(AudioPlayerDLL, CallingConvention = CallingConvention.Cdecl)] public static extern MLResult.Code MLAudioStopInput(ulong handle); } } }