[audiotoolbox] Add nullability to (generated and manual) bindings (#14232)

* Enabling nullability

* Throwing better null exceptions

* use is null and is not null

* Undo spacing differences for consistency

* Use GetHandle ()

Co-authored-by: TJ Lambert <tjlambert@microsoft.com>
This commit is contained in:
TJ Lambert 2022-02-28 09:27:01 -06:00 коммит произвёл GitHub
Родитель f1899bc25d
Коммит a812ce4242
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
16 изменённых файлов: 329 добавлений и 308 удалений

Просмотреть файл

@ -26,6 +26,8 @@
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// //
#nullable enable
using System; using System;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using CoreFoundation; using CoreFoundation;
@ -60,8 +62,8 @@ namespace AudioToolbox {
// The documentation is wrong too // The documentation is wrong too
public unsafe static uint? HardwareCodecCapabilities (AudioClassDescription[] descriptions) public unsafe static uint? HardwareCodecCapabilities (AudioClassDescription[] descriptions)
{ {
if (descriptions == null) if (descriptions is null)
throw new ArgumentNullException ("descriptions"); ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (descriptions));
fixed (AudioClassDescription* item = &descriptions[0]) { fixed (AudioClassDescription* item = &descriptions[0]) {
uint successfulCodecs; uint successfulCodecs;

Просмотреть файл

@ -223,7 +223,7 @@ namespace AudioToolbox
set { set {
if (value is null) if (value is null)
throw new ArgumentNullException (nameof (value)); ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (value));
var res = AudioConverterSetProperty (Handle, AudioConverterPropertyID.CompressionMagicCookie, value.Length, value); var res = AudioConverterSetProperty (Handle, AudioConverterPropertyID.CompressionMagicCookie, value.Length, value);
if (res != AudioConverterError.None) if (res != AudioConverterError.None)
@ -246,7 +246,7 @@ namespace AudioToolbox
} }
set { set {
if (value is null) if (value is null)
throw new ArgumentNullException (nameof (value)); ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (value));
var res = AudioConverterSetProperty (Handle, AudioConverterPropertyID.DecompressionMagicCookie, value.Length, value); var res = AudioConverterSetProperty (Handle, AudioConverterPropertyID.DecompressionMagicCookie, value.Length, value);
if (res != AudioConverterError.None) if (res != AudioConverterError.None)
@ -412,7 +412,7 @@ namespace AudioToolbox
public static AudioConverter? Create (AudioStreamBasicDescription sourceFormat, AudioStreamBasicDescription destinationFormat, AudioClassDescription[] descriptions) public static AudioConverter? Create (AudioStreamBasicDescription sourceFormat, AudioStreamBasicDescription destinationFormat, AudioClassDescription[] descriptions)
{ {
if (descriptions is null) if (descriptions is null)
throw new ArgumentNullException (nameof (descriptions)); ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (descriptions));
IntPtr ptr = new IntPtr (); IntPtr ptr = new IntPtr ();
var res = AudioConverterNewSpecific (ref sourceFormat, ref destinationFormat, descriptions.Length, ref descriptions, ref ptr); var res = AudioConverterNewSpecific (ref sourceFormat, ref destinationFormat, descriptions.Length, ref descriptions, ref ptr);
@ -450,9 +450,9 @@ namespace AudioToolbox
public AudioConverterError ConvertBuffer (byte[] input, byte[] output) public AudioConverterError ConvertBuffer (byte[] input, byte[] output)
{ {
if (input is null) if (input is null)
throw new ArgumentNullException (nameof (input)); ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (input));
if (output is null) if (output is null)
throw new ArgumentNullException (nameof (output)); ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (output));
int outSize = output.Length; int outSize = output.Length;
return AudioConverterConvertBuffer (Handle, input.Length, input, ref outSize, output); return AudioConverterConvertBuffer (Handle, input.Length, input, ref outSize, output);
@ -461,9 +461,9 @@ namespace AudioToolbox
public AudioConverterError ConvertComplexBuffer (int numberPCMFrames, AudioBuffers inputData, AudioBuffers outputData) public AudioConverterError ConvertComplexBuffer (int numberPCMFrames, AudioBuffers inputData, AudioBuffers outputData)
{ {
if (inputData is null) if (inputData is null)
throw new ArgumentNullException (nameof (inputData)); ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (inputData));
if (outputData is null) if (outputData is null)
throw new ArgumentNullException (nameof (outputData)); ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (outputData));
return AudioConverterConvertComplexBuffer (Handle, numberPCMFrames, (IntPtr) inputData, (IntPtr) outputData); return AudioConverterConvertComplexBuffer (Handle, numberPCMFrames, (IntPtr) inputData, (IntPtr) outputData);
} }
@ -472,10 +472,10 @@ namespace AudioToolbox
AudioBuffers outputData, AudioStreamPacketDescription[] packetDescription, AudioConverterComplexInputData newInputDataHandler) AudioBuffers outputData, AudioStreamPacketDescription[] packetDescription, AudioConverterComplexInputData newInputDataHandler)
{ {
if (outputData is null) if (outputData is null)
throw new ArgumentNullException (nameof (outputData)); ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (outputData));
if (newInputDataHandler is null) if (newInputDataHandler is null)
throw new ArgumentNullException (nameof (newInputDataHandler)); ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (newInputDataHandler));
return FillComplexBuffer (ref outputDataPacketSize, outputData, packetDescription, new Tuple<AudioConverter, AudioConverterComplexInputData?> (this, newInputDataHandler)); return FillComplexBuffer (ref outputDataPacketSize, outputData, packetDescription, new Tuple<AudioConverter, AudioConverterComplexInputData?> (this, newInputDataHandler));
} }
@ -484,7 +484,7 @@ namespace AudioToolbox
AudioBuffers outputData, AudioStreamPacketDescription[] packetDescription) AudioBuffers outputData, AudioStreamPacketDescription[] packetDescription)
{ {
if (outputData is null) if (outputData is null)
throw new ArgumentNullException (nameof (outputData)); ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (outputData));
return FillComplexBuffer (ref outputDataPacketSize, outputData, packetDescription, new Tuple<AudioConverter, AudioConverterComplexInputData?> (this, null)); return FillComplexBuffer (ref outputDataPacketSize, outputData, packetDescription, new Tuple<AudioConverter, AudioConverterComplexInputData?> (this, null));
} }
@ -521,7 +521,7 @@ namespace AudioToolbox
var instanceData = handler.Target as Tuple<AudioConverter, AudioConverterComplexInputData?>; var instanceData = handler.Target as Tuple<AudioConverter, AudioConverterComplexInputData?>;
if (instanceData is null) if (instanceData is null)
throw new ArgumentNullException (nameof (instanceData)); ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (instanceData));
var inst = instanceData.Item1; var inst = instanceData.Item1;
var callback = instanceData.Item2; var callback = instanceData.Item2;
@ -529,7 +529,7 @@ namespace AudioToolbox
// Invoke event handler with an argument // Invoke event handler with an argument
// since callback is not provided, must come from the old FillComplexBuffer call // since callback is not provided, must come from the old FillComplexBuffer call
if (callback is null && inst.InputData is null) if (callback is null && inst.InputData is null)
throw new ArgumentNullException ("InputData"); ObjCRuntime.ThrowHelper.ThrowArgumentNullException ("InputData");
// Check if subscribed to event and provided a callback, error out if true // Check if subscribed to event and provided a callback, error out if true
else if (callback is not null && inst.InputData is not null) else if (callback is not null && inst.InputData is not null)
throw new InvalidOperationException ("Please either only subscribe to InputData event or provide newInputDataHandler in FillComplexBuffer, using both is unsuported."); throw new InvalidOperationException ("Please either only subscribe to InputData event or provide newInputDataHandler in FillComplexBuffer, using both is unsuported.");

Просмотреть файл

@ -616,7 +616,7 @@ namespace AudioToolbox {
public static AudioFile? Create (string url, AudioFileType fileType, AudioStreamBasicDescription format, AudioFileFlags inFlags) public static AudioFile? Create (string url, AudioFileType fileType, AudioStreamBasicDescription format, AudioFileFlags inFlags)
{ {
if (url is null) if (url is null)
throw new ArgumentNullException (nameof (url)); ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (url));
using (var cfurl = CFUrl.FromUrlString (url, null)!) using (var cfurl = CFUrl.FromUrlString (url, null)!)
return Create (cfurl, fileType, format, inFlags); return Create (cfurl, fileType, format, inFlags);
@ -625,7 +625,7 @@ namespace AudioToolbox {
public static AudioFile? Create (CFUrl url, AudioFileType fileType, AudioStreamBasicDescription format, AudioFileFlags inFlags) public static AudioFile? Create (CFUrl url, AudioFileType fileType, AudioStreamBasicDescription format, AudioFileFlags inFlags)
{ {
if (url is null) if (url is null)
throw new ArgumentNullException (nameof (url)); ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (url));
IntPtr h; IntPtr h;
@ -637,7 +637,7 @@ namespace AudioToolbox {
public static AudioFile? Create (NSUrl url, AudioFileType fileType, AudioStreamBasicDescription format, AudioFileFlags inFlags) public static AudioFile? Create (NSUrl url, AudioFileType fileType, AudioStreamBasicDescription format, AudioFileFlags inFlags)
{ {
if (url is null) if (url is null)
throw new ArgumentNullException (nameof (url)); ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (url));
IntPtr h; IntPtr h;
@ -689,7 +689,7 @@ namespace AudioToolbox {
public static AudioFile? Open (string url, AudioFilePermission permissions, out AudioFileError error, AudioFileType fileTypeHint = 0) public static AudioFile? Open (string url, AudioFilePermission permissions, out AudioFileError error, AudioFileType fileTypeHint = 0)
{ {
if (url is null) if (url is null)
throw new ArgumentNullException (nameof (url)); ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (url));
using (var cfurl = CFUrl.FromUrlString (url, null)!) using (var cfurl = CFUrl.FromUrlString (url, null)!)
return Open (cfurl, permissions, out error, fileTypeHint); return Open (cfurl, permissions, out error, fileTypeHint);
@ -704,7 +704,7 @@ namespace AudioToolbox {
public static AudioFile? Open (CFUrl url, AudioFilePermission permissions, out AudioFileError error, AudioFileType fileTypeHint = 0) public static AudioFile? Open (CFUrl url, AudioFilePermission permissions, out AudioFileError error, AudioFileType fileTypeHint = 0)
{ {
if (url is null) if (url is null)
throw new ArgumentNullException (nameof (url)); ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (url));
return Open (url.Handle, permissions, fileTypeHint, out error); return Open (url.Handle, permissions, fileTypeHint, out error);
} }
@ -718,7 +718,7 @@ namespace AudioToolbox {
public static AudioFile? Open (NSUrl url, AudioFilePermission permissions, out AudioFileError error, AudioFileType fileTypeHint = 0) public static AudioFile? Open (NSUrl url, AudioFilePermission permissions, out AudioFileError error, AudioFileType fileTypeHint = 0)
{ {
if (url is null) if (url is null)
throw new ArgumentNullException (nameof (url)); ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (url));
return Open (url.Handle, permissions, fileTypeHint, out error); return Open (url.Handle, permissions, fileTypeHint, out error);
} }
@ -829,7 +829,7 @@ namespace AudioToolbox {
public AudioStreamPacketDescription []? ReadPacketData (long inStartingPacket, int nPackets, byte [] buffer, out AudioFileError error) public AudioStreamPacketDescription []? ReadPacketData (long inStartingPacket, int nPackets, byte [] buffer, out AudioFileError error)
{ {
if (buffer is null) if (buffer is null)
throw new ArgumentNullException (nameof (buffer)); ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (buffer));
int count = buffer.Length; int count = buffer.Length;
return RealReadPacketData (false, inStartingPacket, ref nPackets, buffer, 0, ref count, out error); return RealReadPacketData (false, inStartingPacket, ref nPackets, buffer, 0, ref count, out error);
} }
@ -870,7 +870,7 @@ namespace AudioToolbox {
public AudioStreamPacketDescription []? ReadPacketData (bool useCache, long inStartingPacket, ref int nPackets, byte [] buffer, int offset, ref int count, out AudioFileError error) public AudioStreamPacketDescription []? ReadPacketData (bool useCache, long inStartingPacket, ref int nPackets, byte [] buffer, int offset, ref int count, out AudioFileError error)
{ {
if (buffer is null) if (buffer is null)
throw new ArgumentNullException (nameof (buffer)); ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (buffer));
if (offset < 0) if (offset < 0)
throw new ArgumentException (nameof (offset), "<0"); throw new ArgumentException (nameof (offset), "<0");
if (count < 0) if (count < 0)
@ -899,11 +899,11 @@ namespace AudioToolbox {
public unsafe AudioStreamPacketDescription []? ReadPacketData (bool useCache, long inStartingPacket, ref int nPackets, IntPtr buffer, ref int count, out AudioFileError error, AudioStreamPacketDescription[] descriptions) public unsafe AudioStreamPacketDescription []? ReadPacketData (bool useCache, long inStartingPacket, ref int nPackets, IntPtr buffer, ref int count, out AudioFileError error, AudioStreamPacketDescription[] descriptions)
{ {
if (buffer == IntPtr.Zero) if (buffer == IntPtr.Zero)
throw new ArgumentNullException (nameof (buffer)); ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (buffer));
if (count < 0) if (count < 0)
throw new ArgumentException (nameof (count), "<0"); throw new ArgumentException (nameof (count), "<0");
if (descriptions is null) if (descriptions is null)
throw new ArgumentNullException (nameof (descriptions)); ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (descriptions));
fixed (AudioStreamPacketDescription *p = descriptions) { fixed (AudioStreamPacketDescription *p = descriptions) {
return RealReadPacketData (useCache, inStartingPacket, ref nPackets, buffer, ref count, out error, descriptions); return RealReadPacketData (useCache, inStartingPacket, ref nPackets, buffer, ref count, out error, descriptions);
@ -953,7 +953,7 @@ namespace AudioToolbox {
public AudioStreamPacketDescription []? ReadFixedPackets (long inStartingPacket, int nPackets, byte [] buffer, out AudioFileError error) public AudioStreamPacketDescription []? ReadFixedPackets (long inStartingPacket, int nPackets, byte [] buffer, out AudioFileError error)
{ {
if (buffer is null) if (buffer is null)
throw new ArgumentNullException (nameof (buffer)); ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (buffer));
return RealReadFixedPackets (false, inStartingPacket, nPackets, buffer, 0, buffer.Length, out error); return RealReadFixedPackets (false, inStartingPacket, nPackets, buffer, 0, buffer.Length, out error);
} }
@ -966,7 +966,7 @@ namespace AudioToolbox {
public AudioStreamPacketDescription []? ReadFixedPackets (bool useCache, long inStartingPacket, int nPackets, byte [] buffer, int offset, int count, out AudioFileError error) public AudioStreamPacketDescription []? ReadFixedPackets (bool useCache, long inStartingPacket, int nPackets, byte [] buffer, int offset, int count, out AudioFileError error)
{ {
if (buffer is null) if (buffer is null)
throw new ArgumentNullException (nameof (buffer)); ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (buffer));
if (offset < 0) if (offset < 0)
throw new ArgumentException (nameof (offset), "<0"); throw new ArgumentException (nameof (offset), "<0");
if (count < 0) if (count < 0)
@ -1007,7 +1007,7 @@ namespace AudioToolbox {
public int WritePackets (bool useCache, long startingPacket, int numPackets, IntPtr buffer, int byteCount) public int WritePackets (bool useCache, long startingPacket, int numPackets, IntPtr buffer, int byteCount)
{ {
if (buffer == IntPtr.Zero) if (buffer == IntPtr.Zero)
throw new ArgumentNullException (nameof (buffer)); ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (buffer));
if (AudioFileWritePackets (Handle, useCache, byteCount, null, startingPacket, ref numPackets, buffer) == 0) if (AudioFileWritePackets (Handle, useCache, byteCount, null, startingPacket, ref numPackets, buffer) == 0)
return numPackets; return numPackets;
@ -1018,9 +1018,9 @@ namespace AudioToolbox {
public int WritePackets (bool useCache, long startingPacket, AudioStreamPacketDescription [] packetDescriptions, IntPtr buffer, int byteCount) public int WritePackets (bool useCache, long startingPacket, AudioStreamPacketDescription [] packetDescriptions, IntPtr buffer, int byteCount)
{ {
if (packetDescriptions is null) if (packetDescriptions is null)
throw new ArgumentNullException (nameof (packetDescriptions)); ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (packetDescriptions));
if (buffer == IntPtr.Zero) if (buffer == IntPtr.Zero)
throw new ArgumentNullException (nameof (buffer)); ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (buffer));
int nPackets = packetDescriptions.Length; int nPackets = packetDescriptions.Length;
if (AudioFileWritePackets (Handle, useCache, byteCount, packetDescriptions, startingPacket, ref nPackets, buffer) == 0) if (AudioFileWritePackets (Handle, useCache, byteCount, packetDescriptions, startingPacket, ref nPackets, buffer) == 0)
return nPackets; return nPackets;
@ -1030,9 +1030,9 @@ namespace AudioToolbox {
unsafe public int WritePackets (bool useCache, long startingPacket, AudioStreamPacketDescription [] packetDescriptions, byte [] buffer, int offset, int byteCount) unsafe public int WritePackets (bool useCache, long startingPacket, AudioStreamPacketDescription [] packetDescriptions, byte [] buffer, int offset, int byteCount)
{ {
if (packetDescriptions is null) if (packetDescriptions is null)
throw new ArgumentNullException (nameof (packetDescriptions)); ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (packetDescriptions));
if (buffer is null) if (buffer is null)
throw new ArgumentNullException (nameof (buffer)); ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (buffer));
if (offset < 0) if (offset < 0)
throw new ArgumentOutOfRangeException (nameof (offset), "< 0"); throw new ArgumentOutOfRangeException (nameof (offset), "< 0");
if (byteCount < 0) if (byteCount < 0)
@ -1051,7 +1051,7 @@ namespace AudioToolbox {
public int WritePackets (bool useCache, long startingPacket, AudioStreamPacketDescription [] packetDescriptions, IntPtr buffer, int byteCount, out int errorCode) public int WritePackets (bool useCache, long startingPacket, AudioStreamPacketDescription [] packetDescriptions, IntPtr buffer, int byteCount, out int errorCode)
{ {
if (packetDescriptions is null) if (packetDescriptions is null)
throw new ArgumentNullException (nameof (packetDescriptions)); ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (packetDescriptions));
if (buffer == IntPtr.Zero) if (buffer == IntPtr.Zero)
throw new ArgumentException (nameof (buffer)); throw new ArgumentException (nameof (buffer));
int nPackets = packetDescriptions.Length; int nPackets = packetDescriptions.Length;
@ -1065,9 +1065,9 @@ namespace AudioToolbox {
unsafe public int WritePackets (bool useCache, long startingPacket, AudioStreamPacketDescription [] packetDescriptions, byte [] buffer, int offset, int byteCount, out int errorCode) unsafe public int WritePackets (bool useCache, long startingPacket, AudioStreamPacketDescription [] packetDescriptions, byte [] buffer, int offset, int byteCount, out int errorCode)
{ {
if (packetDescriptions is null) if (packetDescriptions is null)
throw new ArgumentNullException (nameof (packetDescriptions)); ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (packetDescriptions));
if (buffer is null) if (buffer is null)
throw new ArgumentNullException (nameof (buffer)); ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (buffer));
if (offset < 0) if (offset < 0)
throw new ArgumentOutOfRangeException (nameof (offset), "< 0"); throw new ArgumentOutOfRangeException (nameof (offset), "< 0");
if (byteCount < 0) if (byteCount < 0)
@ -1128,7 +1128,7 @@ namespace AudioToolbox {
public int SetUserData (int userDataId, int index, int userDataSize, IntPtr userData) public int SetUserData (int userDataId, int index, int userDataSize, IntPtr userData)
{ {
if (userData == IntPtr.Zero) if (userData == IntPtr.Zero)
throw new ArgumentNullException (nameof (userData)); ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (userData));
return AudioFileSetUserData (Handle, userDataId, index, userDataSize, userData); return AudioFileSetUserData (Handle, userDataId, index, userDataSize, userData);
} }
@ -1265,7 +1265,7 @@ namespace AudioToolbox {
public bool SetProperty (AudioFileProperty property, int dataSize, IntPtr propertyData) public bool SetProperty (AudioFileProperty property, int dataSize, IntPtr propertyData)
{ {
if (propertyData == IntPtr.Zero) if (propertyData == IntPtr.Zero)
throw new ArgumentNullException (nameof (propertyData)); ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (propertyData));
return AudioFileSetProperty (Handle, property, dataSize, propertyData) == 0; return AudioFileSetProperty (Handle, property, dataSize, propertyData) == 0;
} }
@ -1345,7 +1345,7 @@ namespace AudioToolbox {
set { set {
if (value is null) if (value is null)
throw new ArgumentNullException (nameof (value)); ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (value));
unsafe { unsafe {
fixed (byte *bp = &value [0]){ fixed (byte *bp = &value [0]){
@ -1470,7 +1470,7 @@ namespace AudioToolbox {
} }
set { set {
if (value is null) if (value is null)
throw new ArgumentNullException (nameof (value)); ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (value));
AudioFilePacketTableInfo afpti = value.Value; AudioFilePacketTableInfo afpti = value.Value;
var res = AudioFileSetProperty (Handle, AudioFileProperty.PacketTableInfo, sizeof (AudioFilePacketTableInfo), ref afpti); var res = AudioFileSetProperty (Handle, AudioFileProperty.PacketTableInfo, sizeof (AudioFilePacketTableInfo), ref afpti);

Просмотреть файл

@ -26,6 +26,8 @@
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// //
#nullable enable
using System; using System;
using System.IO; using System.IO;
using System.Collections.Generic; using System.Collections.Generic;
@ -39,7 +41,7 @@ namespace AudioToolbox {
public unsafe static class AudioFileGlobalInfo public unsafe static class AudioFileGlobalInfo
{ {
public static AudioFileType[] ReadableTypes { public static AudioFileType[]? ReadableTypes {
get { get {
uint size; uint size;
if (AudioFileGetGlobalInfoSize (AudioFileGlobalProperty.ReadableTypes, 0, IntPtr.Zero, out size) != 0) if (AudioFileGetGlobalInfoSize (AudioFileGlobalProperty.ReadableTypes, 0, IntPtr.Zero, out size) != 0)
@ -56,7 +58,7 @@ namespace AudioToolbox {
} }
} }
public static AudioFileType[] WritableTypes { public static AudioFileType[]? WritableTypes {
get { get {
uint size; uint size;
if (AudioFileGetGlobalInfoSize (AudioFileGlobalProperty.WritableTypes, 0, IntPtr.Zero, out size) != 0) if (AudioFileGetGlobalInfoSize (AudioFileGlobalProperty.WritableTypes, 0, IntPtr.Zero, out size) != 0)
@ -73,7 +75,7 @@ namespace AudioToolbox {
} }
} }
public static string GetFileTypeName (AudioFileType fileType) public static string? GetFileTypeName (AudioFileType fileType)
{ {
IntPtr ptr; IntPtr ptr;
var size = (uint) sizeof (IntPtr); var size = (uint) sizeof (IntPtr);
@ -83,7 +85,7 @@ namespace AudioToolbox {
return CFString.FromHandle (ptr); return CFString.FromHandle (ptr);
} }
public static AudioFormatType[] GetAvailableFormats (AudioFileType fileType) public static AudioFormatType[]? GetAvailableFormats (AudioFileType fileType)
{ {
uint size; uint size;
if (AudioFileGetGlobalInfoSize (AudioFileGlobalProperty.AvailableFormatIDs, sizeof (AudioFileType), ref fileType, out size) != 0) if (AudioFileGetGlobalInfoSize (AudioFileGlobalProperty.AvailableFormatIDs, sizeof (AudioFileType), ref fileType, out size) != 0)
@ -99,7 +101,7 @@ namespace AudioToolbox {
} }
} }
public static AudioStreamBasicDescription[] GetAvailableStreamDescriptions (AudioFileType fileType, AudioFormatType formatType) public static AudioStreamBasicDescription[]? GetAvailableStreamDescriptions (AudioFileType fileType, AudioFormatType formatType)
{ {
AudioFileTypeAndFormatID input; AudioFileTypeAndFormatID input;
input.FileType = fileType; input.FileType = fileType;
@ -119,7 +121,7 @@ namespace AudioToolbox {
} }
} }
public static string[] AllExtensions { public static string?[]? AllExtensions {
get { get {
IntPtr ptr; IntPtr ptr;
var size = (uint) sizeof (IntPtr); var size = (uint) sizeof (IntPtr);
@ -130,7 +132,7 @@ namespace AudioToolbox {
} }
} }
public static string[] AllUTIs { public static string?[]? AllUTIs {
get { get {
IntPtr ptr; IntPtr ptr;
var size = (uint) sizeof (IntPtr); var size = (uint) sizeof (IntPtr);
@ -141,7 +143,7 @@ namespace AudioToolbox {
} }
} }
public static string[] AllMIMETypes { public static string?[]? AllMIMETypes {
get { get {
IntPtr ptr; IntPtr ptr;
var size = (uint) sizeof (IntPtr); var size = (uint) sizeof (IntPtr);
@ -172,7 +174,7 @@ namespace AudioToolbox {
} }
*/ */
public static string[] GetExtensions (AudioFileType fileType) public static string?[]? GetExtensions (AudioFileType fileType)
{ {
IntPtr ptr; IntPtr ptr;
var size = (uint) sizeof (IntPtr); var size = (uint) sizeof (IntPtr);
@ -182,7 +184,7 @@ namespace AudioToolbox {
return NSArray.ArrayFromHandleFunc (ptr, l => CFString.FromHandle (l)); return NSArray.ArrayFromHandleFunc (ptr, l => CFString.FromHandle (l));
} }
public static string[] GetUTIs (AudioFileType fileType) public static string?[]? GetUTIs (AudioFileType fileType)
{ {
IntPtr ptr; IntPtr ptr;
var size = (uint) sizeof (IntPtr); var size = (uint) sizeof (IntPtr);
@ -192,7 +194,7 @@ namespace AudioToolbox {
return NSArray.ArrayFromHandleFunc (ptr, l => CFString.FromHandle (l)); return NSArray.ArrayFromHandleFunc (ptr, l => CFString.FromHandle (l));
} }
public static string[] GetMIMETypes (AudioFileType fileType) public static string?[]? GetMIMETypes (AudioFileType fileType)
{ {
IntPtr ptr; IntPtr ptr;
var size = (uint) sizeof (IntPtr); var size = (uint) sizeof (IntPtr);

Просмотреть файл

@ -27,6 +27,8 @@
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// //
#nullable enable
using System; using System;
using System.IO; using System.IO;
using System.Collections.Generic; using System.Collections.Generic;
@ -102,7 +104,7 @@ namespace AudioToolbox {
} }
public class PacketReceivedEventArgs : EventArgs { public class PacketReceivedEventArgs : EventArgs {
public PacketReceivedEventArgs (int numberOfBytes, IntPtr inputData, AudioStreamPacketDescription [] packetDescriptions) public PacketReceivedEventArgs (int numberOfBytes, IntPtr inputData, AudioStreamPacketDescription []? packetDescriptions)
{ {
this.Bytes = numberOfBytes; this.Bytes = numberOfBytes;
this.InputData = inputData; this.InputData = inputData;
@ -110,11 +112,11 @@ namespace AudioToolbox {
} }
public int Bytes { get; private set; } public int Bytes { get; private set; }
public IntPtr InputData { get; private set; } public IntPtr InputData { get; private set; }
public AudioStreamPacketDescription [] PacketDescriptions { get; private set;} public AudioStreamPacketDescription []? PacketDescriptions { get; private set;}
public override string ToString () public override string ToString ()
{ {
return String.Format ("Packet (Bytes={0} InputData={1} PacketDescriptions={2}", Bytes, InputData, PacketDescriptions.Length); return String.Format ("Packet (Bytes={0} InputData={1} PacketDescriptions={2}", Bytes, InputData, PacketDescriptions?.Length ?? -1);
} }
} }
@ -179,22 +181,22 @@ namespace AudioToolbox {
var afs = handle.Target as AudioFileStream; var afs = handle.Target as AudioFileStream;
var desc = AudioFile.PacketDescriptionFrom (numberPackets, packetDescriptions); var desc = AudioFile.PacketDescriptionFrom (numberPackets, packetDescriptions);
afs.OnPacketDecoded (numberBytes, inputData, desc); afs!.OnPacketDecoded (numberBytes, inputData, desc);
} }
public EventHandler<PacketReceivedEventArgs> PacketDecoded; public EventHandler<PacketReceivedEventArgs>? PacketDecoded;
protected virtual void OnPacketDecoded (int numberOfBytes, IntPtr inputData, AudioStreamPacketDescription [] packetDescriptions) protected virtual void OnPacketDecoded (int numberOfBytes, IntPtr inputData, AudioStreamPacketDescription []? packetDescriptions)
{ {
var p = PacketDecoded; var p = PacketDecoded;
if (p != null) if (p is not null)
p (this, new PacketReceivedEventArgs (numberOfBytes, inputData, packetDescriptions)); p (this, new PacketReceivedEventArgs (numberOfBytes, inputData, packetDescriptions));
} }
public EventHandler<PropertyFoundEventArgs> PropertyFound; public EventHandler<PropertyFoundEventArgs>? PropertyFound;
protected virtual void OnPropertyFound (AudioFileStreamProperty propertyID, ref AudioFileStreamPropertyFlag ioFlags) protected virtual void OnPropertyFound (AudioFileStreamProperty propertyID, ref AudioFileStreamPropertyFlag ioFlags)
{ {
var p = PropertyFound; var p = PropertyFound;
if (p != null){ if (p is not null){
var pf = new PropertyFoundEventArgs (propertyID, ioFlags); var pf = new PropertyFoundEventArgs (propertyID, ioFlags);
p (this, pf); p (this, pf);
ioFlags = pf.Flags; ioFlags = pf.Flags;
@ -207,7 +209,7 @@ namespace AudioToolbox {
GCHandle handle = GCHandle.FromIntPtr (clientData); GCHandle handle = GCHandle.FromIntPtr (clientData);
var afs = handle.Target as AudioFileStream; var afs = handle.Target as AudioFileStream;
afs.OnPropertyFound (propertyID, ref ioFlags); afs!.OnPropertyFound (propertyID, ref ioFlags);
} }
public AudioFileStream (AudioFileType fileTypeHint) public AudioFileStream (AudioFileType fileTypeHint)
@ -232,14 +234,14 @@ namespace AudioToolbox {
public AudioFileStreamStatus ParseBytes (int size, IntPtr data, bool discontinuity) public AudioFileStreamStatus ParseBytes (int size, IntPtr data, bool discontinuity)
{ {
if (data == IntPtr.Zero) if (data == IntPtr.Zero)
throw new ArgumentNullException ("data"); ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (data));
return LastError = AudioFileStreamParseBytes (handle, size, data, discontinuity ? (uint) 1 : (uint) 0); return LastError = AudioFileStreamParseBytes (handle, size, data, discontinuity ? (uint) 1 : (uint) 0);
} }
public AudioFileStreamStatus ParseBytes (byte [] bytes, bool discontinuity) public AudioFileStreamStatus ParseBytes (byte [] bytes, bool discontinuity)
{ {
if (bytes == null) if (bytes is null)
throw new ArgumentNullException ("bytes"); ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (bytes));
unsafe { unsafe {
fixed (byte *bp = &bytes[0]){ fixed (byte *bp = &bytes[0]){
return LastError = AudioFileStreamParseBytes (handle, bytes.Length, (IntPtr) bp, discontinuity ? (uint) 1 : (uint) 0); return LastError = AudioFileStreamParseBytes (handle, bytes.Length, (IntPtr) bp, discontinuity ? (uint) 1 : (uint) 0);
@ -249,8 +251,8 @@ namespace AudioToolbox {
public AudioFileStreamStatus ParseBytes (byte [] bytes, int offset, int count, bool discontinuity) public AudioFileStreamStatus ParseBytes (byte [] bytes, int offset, int count, bool discontinuity)
{ {
if (bytes == null) if (bytes is null)
throw new ArgumentNullException ("bytes"); ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (bytes));
if (offset < 0) if (offset < 0)
throw new ArgumentException ("offset"); throw new ArgumentException ("offset");
if (count < 0) if (count < 0)
@ -301,7 +303,7 @@ namespace AudioToolbox {
public bool GetProperty (AudioFileStreamProperty property, ref int dataSize, IntPtr outPropertyData) public bool GetProperty (AudioFileStreamProperty property, ref int dataSize, IntPtr outPropertyData)
{ {
if (outPropertyData == IntPtr.Zero) if (outPropertyData == IntPtr.Zero)
throw new ArgumentNullException ("outPropertyData"); ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (outPropertyData));
return AudioFileStreamGetProperty (handle, property, ref dataSize, outPropertyData) == 0; return AudioFileStreamGetProperty (handle, property, ref dataSize, outPropertyData) == 0;
} }
@ -374,7 +376,7 @@ namespace AudioToolbox {
try { try {
LastError = AudioFileStreamGetProperty (handle, property, ref size, buffer); LastError = AudioFileStreamGetProperty (handle, property, ref size, buffer);
if (LastError == 0){ if (LastError == 0){
return (T) Marshal.PtrToStructure (buffer, typeof (T)); return (T) Marshal.PtrToStructure (buffer, typeof (T))!;
} }
return null; return null;
@ -393,7 +395,7 @@ namespace AudioToolbox {
public bool SetProperty (AudioFileStreamProperty property, int dataSize, IntPtr propertyData) public bool SetProperty (AudioFileStreamProperty property, int dataSize, IntPtr propertyData)
{ {
if (propertyData == IntPtr.Zero) if (propertyData == IntPtr.Zero)
throw new ArgumentNullException ("propertyData"); ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (propertyData));
LastError = AudioFileStreamSetProperty (handle, property, dataSize, propertyData); LastError = AudioFileStreamSetProperty (handle, property, dataSize, propertyData);
return LastError == 0; return LastError == 0;
} }
@ -426,7 +428,7 @@ namespace AudioToolbox {
} }
} }
public unsafe AudioFormat [] FormatList { public unsafe AudioFormat []? FormatList {
get { get {
int size; int size;
var r = GetProperty (AudioFileStreamProperty.FormatList, out size); var r = GetProperty (AudioFileStreamProperty.FormatList, out size);
@ -491,7 +493,7 @@ namespace AudioToolbox {
} }
} }
public AudioChannelLayout ChannelLayout { public AudioChannelLayout? ChannelLayout {
get { get {
int size; int size;
var h = GetProperty (AudioFileStreamProperty.ChannelLayout, out size); var h = GetProperty (AudioFileStreamProperty.ChannelLayout, out size);

Просмотреть файл

@ -26,6 +26,9 @@
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// //
#nullable enable
using System; using System;
using System.IO; using System.IO;
using System.Collections.Generic; using System.Collections.Generic;
@ -53,10 +56,10 @@ namespace AudioToolbox {
#if !WATCH #if !WATCH
public unsafe static AudioFormat? GetFirstPlayableFormat (AudioFormat[] formatList) public unsafe static AudioFormat? GetFirstPlayableFormat (AudioFormat[] formatList)
{ {
if (formatList == null) if (formatList is null)
throw new ArgumentNullException ("formatList"); ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (formatList));
if (formatList.Length < 2) if (formatList.Length < 2)
throw new ArgumentException ("formatList"); ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (formatList));
fixed (AudioFormat* item = &formatList[0]) { fixed (AudioFormat* item = &formatList[0]) {
uint index; uint index;
@ -118,8 +121,8 @@ namespace AudioToolbox {
public AudioBalanceFade (AudioChannelLayout channelLayout) public AudioBalanceFade (AudioChannelLayout channelLayout)
{ {
if (channelLayout == null) if (channelLayout is null)
throw new ArgumentNullException ("channelLayout"); ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (channelLayout));
this.ChannelLayout = channelLayout; this.ChannelLayout = channelLayout;
} }
@ -129,7 +132,7 @@ namespace AudioToolbox {
public AudioBalanceFadeType Type { get; set; } public AudioBalanceFadeType Type { get; set; }
public AudioChannelLayout ChannelLayout { get; private set; } public AudioChannelLayout ChannelLayout { get; private set; }
public unsafe float[] GetBalanceFade () public unsafe float[]? GetBalanceFade ()
{ {
var type_size = sizeof (Layout); var type_size = sizeof (Layout);
@ -162,7 +165,7 @@ namespace AudioToolbox {
Type = Type, Type = Type,
}; };
if (ChannelLayout != null) { if (ChannelLayout is not null) {
int temp; int temp;
l.ChannelLayoutWeak = ChannelLayout.ToBlock (out temp); l.ChannelLayoutWeak = ChannelLayout.ToBlock (out temp);
} }
@ -193,19 +196,19 @@ namespace AudioToolbox {
public AudioPanningInfo (AudioChannelLayout outputChannelMap) public AudioPanningInfo (AudioChannelLayout outputChannelMap)
{ {
if (outputChannelMap == null) if (outputChannelMap is null)
throw new ArgumentNullException ("outputChannelMap"); ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (outputChannelMap));
this.OutputChannelMap = outputChannelMap; this.OutputChannelMap = outputChannelMap;
} }
public PanningMode PanningMode { get; set; } public PanningMode PanningMode { get; set; }
public AudioChannelFlags CoordinateFlags { get; set; } public AudioChannelFlags CoordinateFlags { get; set; }
public float[] Coordinates { get; private set; } public float[] Coordinates { get; private set; } = Array.Empty<float> ();
public float GainScale { get; set; } public float GainScale { get; set; }
public AudioChannelLayout OutputChannelMap { get; private set; } public AudioChannelLayout OutputChannelMap { get; private set; }
public unsafe float[] GetPanningMatrix () public unsafe float[]? GetPanningMatrix ()
{ {
var type_size = sizeof (Layout); var type_size = sizeof (Layout);
@ -241,7 +244,7 @@ namespace AudioToolbox {
GainScale = GainScale GainScale = GainScale
}; };
if (OutputChannelMap != null) { if (OutputChannelMap is not null) {
int temp; int temp;
l.OutputChannelMapWeak = OutputChannelMap.ToBlock (out temp); l.OutputChannelMapWeak = OutputChannelMap.ToBlock (out temp);
} }

Просмотреть файл

@ -26,6 +26,8 @@
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// //
#nullable enable
using System; using System;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
@ -37,27 +39,27 @@ namespace AudioToolbox {
public static class AudioFormatAvailability public static class AudioFormatAvailability
{ {
public static AudioValueRange[] GetAvailableEncodeBitRates (AudioFormatType format) public static AudioValueRange[]? GetAvailableEncodeBitRates (AudioFormatType format)
{ {
return GetAvailable<AudioValueRange> (AudioFormatProperty.AvailableEncodeBitRates, format); return GetAvailable<AudioValueRange> (AudioFormatProperty.AvailableEncodeBitRates, format);
} }
public static AudioValueRange[] GetAvailableEncodeSampleRates (AudioFormatType format) public static AudioValueRange[]? GetAvailableEncodeSampleRates (AudioFormatType format)
{ {
return GetAvailable<AudioValueRange> (AudioFormatProperty.AvailableEncodeSampleRates, format); return GetAvailable<AudioValueRange> (AudioFormatProperty.AvailableEncodeSampleRates, format);
} }
public static AudioClassDescription[] GetDecoders (AudioFormatType format) public static AudioClassDescription[]? GetDecoders (AudioFormatType format)
{ {
return GetAvailable<AudioClassDescription> (AudioFormatProperty.Decoders, format); return GetAvailable<AudioClassDescription> (AudioFormatProperty.Decoders, format);
} }
public static AudioClassDescription[] GetEncoders (AudioFormatType format) public static AudioClassDescription[]? GetEncoders (AudioFormatType format)
{ {
return GetAvailable<AudioClassDescription> (AudioFormatProperty.Encoders, format); return GetAvailable<AudioClassDescription> (AudioFormatProperty.Encoders, format);
} }
unsafe static T[] GetAvailable<T> (AudioFormatProperty prop, AudioFormatType format) unsafe static T[]? GetAvailable<T> (AudioFormatProperty prop, AudioFormatType format)
{ {
uint size; uint size;
if (AudioFormatPropertyNative.AudioFormatGetPropertyInfo (prop, sizeof (AudioFormatType), ref format, out size) != 0) if (AudioFormatPropertyNative.AudioFormatGetPropertyInfo (prop, sizeof (AudioFormatType), ref format, out size) != 0)

Просмотреть файл

@ -28,6 +28,8 @@
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// //
#nullable enable
using System; using System;
using System.IO; using System.IO;
using System.Collections; using System.Collections;
@ -252,7 +254,7 @@ namespace AudioToolbox {
public IntPtr IntPtrPacketDescriptions; public IntPtr IntPtrPacketDescriptions;
public int PacketDescriptionCount; public int PacketDescriptionCount;
public AudioStreamPacketDescription [] PacketDescriptions { public AudioStreamPacketDescription []? PacketDescriptions {
get { get {
return AudioFile.PacketDescriptionFrom (PacketDescriptionCount, IntPtrPacketDescriptions); return AudioFile.PacketDescriptionFrom (PacketDescriptionCount, IntPtrPacketDescriptions);
} }
@ -327,7 +329,7 @@ namespace AudioToolbox {
} }
public class InputCompletedEventArgs : EventArgs { public class InputCompletedEventArgs : EventArgs {
public unsafe InputCompletedEventArgs (IntPtr audioQueueBuffer, AudioTimeStamp timeStamp, AudioStreamPacketDescription [] pdec) public unsafe InputCompletedEventArgs (IntPtr audioQueueBuffer, AudioTimeStamp timeStamp, AudioStreamPacketDescription []? pdec)
{ {
IntPtrBuffer = audioQueueBuffer; IntPtrBuffer = audioQueueBuffer;
TimeStamp = timeStamp; TimeStamp = timeStamp;
@ -343,7 +345,7 @@ namespace AudioToolbox {
get { return *(AudioQueueBuffer *) IntPtrBuffer; } get { return *(AudioQueueBuffer *) IntPtrBuffer; }
} }
public AudioTimeStamp TimeStamp { get; private set; } public AudioTimeStamp TimeStamp { get; private set; }
public AudioStreamPacketDescription [] PacketDescriptions { get; private set; } public AudioStreamPacketDescription []? PacketDescriptions { get; private set; }
} }
public abstract class AudioQueue : IDisposable { public abstract class AudioQueue : IDisposable {
@ -384,7 +386,7 @@ namespace AudioToolbox {
{ {
if (handle != IntPtr.Zero){ if (handle != IntPtr.Zero){
if (disposing){ if (disposing){
if (listeners != null){ if (listeners is not null){
foreach (AudioQueueProperty prop in listeners.Keys){ foreach (AudioQueueProperty prop in listeners.Keys){
AudioQueueRemovePropertyListener (handle, prop, property_changed, GCHandle.ToIntPtr (gch)); AudioQueueRemovePropertyListener (handle, prop, property_changed, GCHandle.ToIntPtr (gch));
} }
@ -478,7 +480,7 @@ namespace AudioToolbox {
public void FreeBuffer (IntPtr audioQueueBuffer) public void FreeBuffer (IntPtr audioQueueBuffer)
{ {
if (audioQueueBuffer == IntPtr.Zero) if (audioQueueBuffer == IntPtr.Zero)
throw new ArgumentNullException ("audioQueueBuffer"); ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (audioQueueBuffer));
AudioQueueFreeBuffer (handle, audioQueueBuffer); AudioQueueFreeBuffer (handle, audioQueueBuffer);
} }
@ -491,12 +493,12 @@ namespace AudioToolbox {
} }
[DllImport (Constants.AudioToolboxLibrary)] [DllImport (Constants.AudioToolboxLibrary)]
internal extern unsafe static AudioQueueStatus AudioQueueEnqueueBuffer (IntPtr AQ, AudioQueueBuffer* audioQueueBuffer, int nPackets, AudioStreamPacketDescription [] desc); internal extern unsafe static AudioQueueStatus AudioQueueEnqueueBuffer (IntPtr AQ, AudioQueueBuffer* audioQueueBuffer, int nPackets, AudioStreamPacketDescription []? desc);
public AudioQueueStatus EnqueueBuffer (IntPtr audioQueueBuffer, int bytes, AudioStreamPacketDescription [] desc) public AudioQueueStatus EnqueueBuffer (IntPtr audioQueueBuffer, int bytes, AudioStreamPacketDescription [] desc)
{ {
if (audioQueueBuffer == IntPtr.Zero) if (audioQueueBuffer == IntPtr.Zero)
throw new ArgumentNullException ("audioQueueBuffer"); ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (audioQueueBuffer));
unsafe { unsafe {
AudioQueueBuffer *buffer = (AudioQueueBuffer *) audioQueueBuffer; AudioQueueBuffer *buffer = (AudioQueueBuffer *) audioQueueBuffer;
@ -507,18 +509,18 @@ namespace AudioToolbox {
public unsafe AudioQueueStatus EnqueueBuffer (AudioQueueBuffer* audioQueueBuffer, AudioStreamPacketDescription [] desc) public unsafe AudioQueueStatus EnqueueBuffer (AudioQueueBuffer* audioQueueBuffer, AudioStreamPacketDescription [] desc)
{ {
if (audioQueueBuffer == null) if (audioQueueBuffer is null)
throw new ArgumentNullException ("audioQueueBuffer"); ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (audioQueueBuffer));
return AudioQueueEnqueueBuffer (handle, audioQueueBuffer, desc == null ? 0 : desc.Length, desc); return AudioQueueEnqueueBuffer (handle, audioQueueBuffer, desc?.Length ?? 0, desc);
} }
public unsafe AudioQueueStatus EnqueueBuffer (IntPtr audioQueueBuffer, AudioStreamPacketDescription [] desc) public unsafe AudioQueueStatus EnqueueBuffer (IntPtr audioQueueBuffer, AudioStreamPacketDescription [] desc)
{ {
if (audioQueueBuffer == IntPtr.Zero) if (audioQueueBuffer == IntPtr.Zero)
throw new ArgumentNullException ("audioQueueBuffer"); ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (audioQueueBuffer));
return AudioQueueEnqueueBuffer (handle, (AudioQueueBuffer *) audioQueueBuffer, desc == null ? 0 : desc.Length, desc); return AudioQueueEnqueueBuffer (handle, (AudioQueueBuffer *) audioQueueBuffer, desc?.Length ?? 0, desc);
} }
[DllImport (Constants.AudioToolboxLibrary)] [DllImport (Constants.AudioToolboxLibrary)]
@ -526,11 +528,11 @@ namespace AudioToolbox {
IntPtr AQ, IntPtr AQ,
AudioQueueBuffer *audioQueueBuffer, AudioQueueBuffer *audioQueueBuffer,
int nPackets, int nPackets,
AudioStreamPacketDescription [] desc, AudioStreamPacketDescription []? desc,
int trimFramesAtStart, int trimFramesAtStart,
int trimFramesAtEnd, int trimFramesAtEnd,
int nParam, int nParam,
AudioQueueParameterEvent [] parameterEvents, AudioQueueParameterEvent []? parameterEvents,
ref AudioTimeStamp startTime, ref AudioTimeStamp startTime,
out AudioTimeStamp actualStartTime); out AudioTimeStamp actualStartTime);
@ -539,11 +541,11 @@ namespace AudioToolbox {
IntPtr AQ, IntPtr AQ,
AudioQueueBuffer *audioQueueBuffer, AudioQueueBuffer *audioQueueBuffer,
int nPackets, int nPackets,
AudioStreamPacketDescription [] desc, AudioStreamPacketDescription []? desc,
int trimFramesAtStart, int trimFramesAtStart,
int trimFramesAtEnd, int trimFramesAtEnd,
int nParam, int nParam,
AudioQueueParameterEvent [] parameterEvents, AudioQueueParameterEvent []? parameterEvents,
AudioTimeStamp *startTime, AudioTimeStamp *startTime,
out AudioTimeStamp actualStartTime); out AudioTimeStamp actualStartTime);
@ -552,15 +554,15 @@ namespace AudioToolbox {
ref AudioTimeStamp startTime, out AudioTimeStamp actualStartTime) ref AudioTimeStamp startTime, out AudioTimeStamp actualStartTime)
{ {
if (audioQueueBuffer == IntPtr.Zero) if (audioQueueBuffer == IntPtr.Zero)
throw new ArgumentNullException ("audioQueueBuffer"); ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (audioQueueBuffer));
unsafe { unsafe {
AudioQueueBuffer *buffer = (AudioQueueBuffer *) audioQueueBuffer; AudioQueueBuffer *buffer = (AudioQueueBuffer *) audioQueueBuffer;
buffer->AudioDataByteSize = (uint) bytes; buffer->AudioDataByteSize = (uint) bytes;
return AudioQueueEnqueueBufferWithParameters ( return AudioQueueEnqueueBufferWithParameters (
handle, buffer, desc == null ? 0 : desc.Length, desc, handle, buffer, desc?.Length ?? 0, desc,
trimFramesAtStart, trimFramesAtEnd, parameterEvents == null ? 0 : parameterEvents.Length, trimFramesAtStart, trimFramesAtEnd, parameterEvents?.Length ?? 0,
parameterEvents, parameterEvents,
ref startTime, ref startTime,
out actualStartTime); out actualStartTime);
@ -571,15 +573,15 @@ namespace AudioToolbox {
out AudioTimeStamp actualStartTime) out AudioTimeStamp actualStartTime)
{ {
if (audioQueueBuffer == IntPtr.Zero) if (audioQueueBuffer == IntPtr.Zero)
throw new ArgumentNullException ("audioQueueBuffer"); ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (audioQueueBuffer));
unsafe { unsafe {
AudioQueueBuffer *buffer = (AudioQueueBuffer *) audioQueueBuffer; AudioQueueBuffer *buffer = (AudioQueueBuffer *) audioQueueBuffer;
buffer->AudioDataByteSize = (uint) bytes; buffer->AudioDataByteSize = (uint) bytes;
return AudioQueueEnqueueBufferWithParameters ( return AudioQueueEnqueueBufferWithParameters (
handle, buffer, desc == null ? 0 : desc.Length, desc, handle, buffer, desc?.Length ?? 0, desc,
trimFramesAtStart, trimFramesAtEnd, parameterEvents == null ? 0 : parameterEvents.Length, trimFramesAtStart, trimFramesAtEnd, parameterEvents?.Length ?? 0,
parameterEvents, parameterEvents,
null, null,
out actualStartTime); out actualStartTime);
@ -590,12 +592,12 @@ namespace AudioToolbox {
int trimFramesAtStart, int trimFramesAtEnd, AudioQueueParameterEvent [] parameterEvents, int trimFramesAtStart, int trimFramesAtEnd, AudioQueueParameterEvent [] parameterEvents,
ref AudioTimeStamp startTime, out AudioTimeStamp actualStartTime) ref AudioTimeStamp startTime, out AudioTimeStamp actualStartTime)
{ {
if (audioQueueBuffer == null) if (audioQueueBuffer is null)
throw new ArgumentNullException ("audioQueueBuffer"); ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (audioQueueBuffer));
return AudioQueueEnqueueBufferWithParameters ( return AudioQueueEnqueueBufferWithParameters (
handle, audioQueueBuffer, desc == null ? 0 : desc.Length, desc, handle, audioQueueBuffer, desc?.Length ?? 0, desc,
trimFramesAtStart, trimFramesAtEnd, parameterEvents == null ? 0 : parameterEvents.Length, trimFramesAtStart, trimFramesAtEnd,parameterEvents?.Length ?? 0,
parameterEvents, parameterEvents,
ref startTime, ref startTime,
out actualStartTime); out actualStartTime);
@ -605,12 +607,12 @@ namespace AudioToolbox {
int trimFramesAtStart, int trimFramesAtEnd, AudioQueueParameterEvent [] parameterEvents, int trimFramesAtStart, int trimFramesAtEnd, AudioQueueParameterEvent [] parameterEvents,
out AudioTimeStamp actualStartTime) out AudioTimeStamp actualStartTime)
{ {
if (audioQueueBuffer == null) if (audioQueueBuffer is null)
throw new ArgumentNullException ("audioQueueBuffer"); ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (audioQueueBuffer));
return AudioQueueEnqueueBufferWithParameters ( return AudioQueueEnqueueBufferWithParameters (
handle, audioQueueBuffer, desc == null ? 0 : desc.Length, desc, handle, audioQueueBuffer, desc?.Length ?? 0, desc,
trimFramesAtStart, trimFramesAtEnd, parameterEvents == null ? 0 : parameterEvents.Length, trimFramesAtStart, trimFramesAtEnd, parameterEvents?.Length ?? 0,
parameterEvents, parameterEvents,
null, null,
out actualStartTime); out actualStartTime);
@ -619,7 +621,7 @@ namespace AudioToolbox {
[DllImport (Constants.AudioToolboxLibrary)] [DllImport (Constants.AudioToolboxLibrary)]
extern static AudioQueueStatus AudioQueueCreateTimeline (IntPtr AQ, out IntPtr timeline); extern static AudioQueueStatus AudioQueueCreateTimeline (IntPtr AQ, out IntPtr timeline);
public AudioQueueTimeline CreateTimeline () public AudioQueueTimeline? CreateTimeline ()
{ {
IntPtr thandle; IntPtr thandle;
@ -634,7 +636,7 @@ namespace AudioToolbox {
public AudioQueueStatus GetCurrentTime (AudioQueueTimeline timeline, ref AudioTimeStamp time, ref bool timelineDiscontinuty) public AudioQueueStatus GetCurrentTime (AudioQueueTimeline timeline, ref AudioTimeStamp time, ref bool timelineDiscontinuty)
{ {
IntPtr arg; IntPtr arg;
if (timeline == null) if (timeline is null)
arg = IntPtr.Zero; arg = IntPtr.Zero;
else { else {
arg = timeline.timelineHandle; arg = timeline.timelineHandle;
@ -744,16 +746,16 @@ namespace AudioToolbox {
delegate void AudioQueuePropertyListenerProc (IntPtr userData, IntPtr AQ, AudioQueueProperty id); delegate void AudioQueuePropertyListenerProc (IntPtr userData, IntPtr AQ, AudioQueueProperty id);
Hashtable listeners; Hashtable? listeners;
[MonoPInvokeCallback (typeof(AudioQueuePropertyListenerProc))] [MonoPInvokeCallback (typeof(AudioQueuePropertyListenerProc))]
static void property_changed (IntPtr userData, IntPtr AQ, AudioQueueProperty id) static void property_changed (IntPtr userData, IntPtr AQ, AudioQueueProperty id)
{ {
GCHandle gch = GCHandle.FromIntPtr (userData); GCHandle gch = GCHandle.FromIntPtr (userData);
var aq = gch.Target as AudioQueue; var aq = gch.Target as AudioQueue;
lock (aq.listeners){ lock (aq!.listeners!){
ArrayList a = (ArrayList)aq.listeners [id]; ArrayList a = (ArrayList)aq.listeners [id]!;
if (a == null) if (a is null)
return; return;
foreach (AudioQueuePropertyChanged cback in a){ foreach (AudioQueuePropertyChanged cback in a){
cback (id); cback (id);
@ -765,15 +767,15 @@ namespace AudioToolbox {
public AudioQueueStatus AddListener (AudioQueueProperty property, AudioQueuePropertyChanged callback) public AudioQueueStatus AddListener (AudioQueueProperty property, AudioQueuePropertyChanged callback)
{ {
if (callback == null) if (callback is null)
throw new ArgumentNullException ("callback"); ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (callback));
if (listeners == null) if (listeners is null)
listeners = new Hashtable (); listeners = new Hashtable ();
AudioQueueStatus res = AudioQueueStatus.Ok; AudioQueueStatus res = AudioQueueStatus.Ok;
lock (listeners){ lock (listeners){
var a = (ArrayList) listeners [property]; var a = (ArrayList) listeners [property]!;
if (a == null){ if (a is null){
res = AudioQueueAddPropertyListener (handle, property, property_changed, GCHandle.ToIntPtr (gch)); res = AudioQueueAddPropertyListener (handle, property, property_changed, GCHandle.ToIntPtr (gch));
if (res != AudioQueueStatus.Ok) if (res != AudioQueueStatus.Ok)
return res; return res;
@ -788,13 +790,13 @@ namespace AudioToolbox {
public void RemoveListener (AudioQueueProperty property, AudioQueuePropertyChanged callback) public void RemoveListener (AudioQueueProperty property, AudioQueuePropertyChanged callback)
{ {
if (callback == null) if (callback is null)
throw new ArgumentNullException ("callback"); ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (callback));
if (listeners == null) if (listeners is null)
return; return;
lock (listeners){ lock (listeners){
var a = (ArrayList) listeners [property]; var a = (ArrayList) listeners [property]!;
if (a == null) if (a is null)
return; return;
a.Remove (callback); a.Remove (callback);
if (a.Count == 0){ if (a.Count == 0){
@ -823,7 +825,7 @@ namespace AudioToolbox {
public bool GetProperty (AudioQueueProperty property, ref int dataSize, IntPtr outdata) public bool GetProperty (AudioQueueProperty property, ref int dataSize, IntPtr outdata)
{ {
if (outdata == IntPtr.Zero) if (outdata == IntPtr.Zero)
throw new ArgumentNullException ("outdata"); ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (outdata));
return AudioQueueGetProperty (handle, (uint) property, outdata, ref dataSize) == 0; return AudioQueueGetProperty (handle, (uint) property, outdata, ref dataSize) == 0;
} }
@ -831,7 +833,7 @@ namespace AudioToolbox {
public bool SetProperty (AudioQueueProperty property, int dataSize, IntPtr propertyData) public bool SetProperty (AudioQueueProperty property, int dataSize, IntPtr propertyData)
{ {
if (propertyData == IntPtr.Zero) if (propertyData == IntPtr.Zero)
throw new ArgumentNullException ("propertyData"); ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (propertyData));
return AudioQueueSetProperty (handle, property, propertyData, dataSize) == 0; return AudioQueueSetProperty (handle, property, propertyData, dataSize) == 0;
} }
@ -868,7 +870,7 @@ namespace AudioToolbox {
try { try {
r = AudioQueueGetProperty (handle, (uint) property, buffer, ref size); r = AudioQueueGetProperty (handle, (uint) property, buffer, ref size);
if (r == 0){ if (r == 0){
T result = (T) Marshal.PtrToStructure (buffer, typeof (T)); T result = (T) Marshal.PtrToStructure (buffer, typeof (T))!;
return result; return result;
} }
@ -892,7 +894,7 @@ namespace AudioToolbox {
try { try {
r = AudioQueueGetProperty (handle, (uint) property, buffer, ref size); r = AudioQueueGetProperty (handle, (uint) property, buffer, ref size);
if (r == 0){ if (r == 0){
T result = (T) Marshal.PtrToStructure (buffer, typeof (T)); T result = (T) Marshal.PtrToStructure (buffer, typeof (T))!;
return result; return result;
} }
@ -956,7 +958,7 @@ namespace AudioToolbox {
} }
} }
public string CurrentDevice { public string? CurrentDevice {
get { get {
return CFString.FromHandle ((IntPtr) GetInt (AudioQueueProperty.CurrentDevice)); return CFString.FromHandle ((IntPtr) GetInt (AudioQueueProperty.CurrentDevice));
} }
@ -984,8 +986,8 @@ namespace AudioToolbox {
} }
set { set {
if (value == null) if (value is null)
throw new ArgumentNullException ("value"); ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (value));
if (value.Length == 0) if (value.Length == 0)
return; return;
@ -998,7 +1000,7 @@ namespace AudioToolbox {
} }
} }
public AudioChannelLayout ChannelLayout { public AudioChannelLayout? ChannelLayout {
get { get {
int size; int size;
var h = GetProperty (AudioQueueProperty.ChannelLayout, out size); var h = GetProperty (AudioQueueProperty.ChannelLayout, out size);
@ -1012,8 +1014,8 @@ namespace AudioToolbox {
} }
set { set {
if (value == null) if (value is null)
throw new ArgumentNullException ("value"); // TODO: enable ? ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (value)); // TODO: enable ?
int size; int size;
var h = value.ToBlock (out size); var h = value.ToBlock (out size);
@ -1116,8 +1118,8 @@ namespace AudioToolbox {
public AudioQueueStatus SetChannelAssignments (params AudioQueueChannelAssignment[] channelAssignments) public AudioQueueStatus SetChannelAssignments (params AudioQueueChannelAssignment[] channelAssignments)
{ {
if (channelAssignments == null) if (channelAssignments is null)
throw new ArgumentNullException ("channelAssignments"); ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (channelAssignments));
int length; int length;
var ptr = MarshalArray (ref channelAssignments, out length); var ptr = MarshalArray (ref channelAssignments, out length);
@ -1146,7 +1148,7 @@ namespace AudioToolbox {
IntPtr inClientData, AudioQueueProcessingTapFlags inFlags, out uint outMaxFrames, IntPtr inClientData, AudioQueueProcessingTapFlags inFlags, out uint outMaxFrames,
out AudioStreamBasicDescription outProcessingFormat, out IntPtr outAQTap); out AudioStreamBasicDescription outProcessingFormat, out IntPtr outAQTap);
public AudioQueueProcessingTap CreateProcessingTap (AudioQueueProcessingTapDelegate processingCallback, AudioQueueProcessingTapFlags flags, public AudioQueueProcessingTap? CreateProcessingTap (AudioQueueProcessingTapDelegate processingCallback, AudioQueueProcessingTapFlags flags,
out AudioQueueStatus status) out AudioQueueStatus status)
{ {
var aqpt = new AudioQueueProcessingTap (processingCallback); var aqpt = new AudioQueueProcessingTap (processingCallback);
@ -1181,7 +1183,7 @@ namespace AudioToolbox {
{ {
internal static readonly AudioQueueProcessingTapCallbackShared CreateTapCallback = TapCallback; internal static readonly AudioQueueProcessingTapCallbackShared CreateTapCallback = TapCallback;
AudioQueueProcessingTapDelegate callback; AudioQueueProcessingTapDelegate? callback;
readonly GCHandle gc_handle; readonly GCHandle gc_handle;
internal AudioQueueProcessingTap (AudioQueueProcessingTapDelegate callback) internal AudioQueueProcessingTap (AudioQueueProcessingTapDelegate callback)
@ -1234,8 +1236,8 @@ namespace AudioToolbox {
public AudioQueueStatus GetSourceAudio (uint numberOfFrames, ref AudioTimeStamp timeStamp, public AudioQueueStatus GetSourceAudio (uint numberOfFrames, ref AudioTimeStamp timeStamp,
out AudioQueueProcessingTapFlags flags, out uint parentNumberOfFrames, AudioBuffers data) out AudioQueueProcessingTapFlags flags, out uint parentNumberOfFrames, AudioBuffers data)
{ {
if (data == null) if (data is null)
throw new ArgumentNullException ("data"); ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (data));
return AudioQueueProcessingTapGetSourceAudio (TapHandle, numberOfFrames, ref timeStamp, return AudioQueueProcessingTapGetSourceAudio (TapHandle, numberOfFrames, ref timeStamp,
out flags, out parentNumberOfFrames, (IntPtr) data); out flags, out parentNumberOfFrames, (IntPtr) data);
@ -1254,10 +1256,10 @@ namespace AudioToolbox {
out uint outNumberFrames, IntPtr data) out uint outNumberFrames, IntPtr data)
{ {
GCHandle gch = GCHandle.FromIntPtr (clientData); GCHandle gch = GCHandle.FromIntPtr (clientData);
var aqpt = (AudioQueueProcessingTap) gch.Target; var aqpt = (AudioQueueProcessingTap) gch.Target!;
using (var buffers = new AudioBuffers (data)) { using (var buffers = new AudioBuffers (data)) {
outNumberFrames = aqpt.callback (aqpt, numberFrames, ref timeStamp, ref flags, buffers); outNumberFrames = aqpt.callback !(aqpt, numberFrames, ref timeStamp, ref flags, buffers);
} }
} }
} }
@ -1275,35 +1277,35 @@ namespace AudioToolbox {
{ {
GCHandle gch = GCHandle.FromIntPtr (userData); GCHandle gch = GCHandle.FromIntPtr (userData);
var aq = gch.Target as OutputAudioQueue; var aq = gch.Target as OutputAudioQueue;
aq.OnBufferCompleted (audioQueueBuffer); aq!.OnBufferCompleted (audioQueueBuffer);
} }
public event EventHandler<BufferCompletedEventArgs> BufferCompleted; public event EventHandler<BufferCompletedEventArgs>? BufferCompleted;
protected virtual void OnBufferCompleted (IntPtr audioQueueBuffer) protected virtual void OnBufferCompleted (IntPtr audioQueueBuffer)
{ {
var h = BufferCompleted; var h = BufferCompleted;
if (h != null) if (h is not null)
h (this, new BufferCompletedEventArgs (audioQueueBuffer)); h (this, new BufferCompletedEventArgs (audioQueueBuffer));
} }
public OutputAudioQueue (AudioStreamBasicDescription desc) : this (desc, null, (CFString) null) public OutputAudioQueue (AudioStreamBasicDescription desc) : this (desc, null, (CFString) null!)
{ {
} }
public OutputAudioQueue (AudioStreamBasicDescription desc, CFRunLoop runLoop, string runMode) public OutputAudioQueue (AudioStreamBasicDescription desc, CFRunLoop runLoop, string runMode)
: this (desc, runLoop, runMode == null ? null : new CFString (runMode)) : this (desc, runLoop, runMode is null ? null : new CFString (runMode))
{ {
} }
public OutputAudioQueue (AudioStreamBasicDescription desc, CFRunLoop runLoop, CFString runMode) public OutputAudioQueue (AudioStreamBasicDescription desc, CFRunLoop? runLoop, CFString? runMode)
{ {
IntPtr h; IntPtr h;
GCHandle gch = GCHandle.Alloc (this); GCHandle gch = GCHandle.Alloc (this);
var code = AudioQueueNewOutput (ref desc, dOutputCallback, GCHandle.ToIntPtr (gch), var code = AudioQueueNewOutput (ref desc, dOutputCallback, GCHandle.ToIntPtr (gch),
runLoop == null ? IntPtr.Zero : runLoop.Handle, runLoop.GetHandle (),
runMode == null ? IntPtr.Zero : runMode.Handle, 0, out h); runMode.GetHandle (), 0, out h);
if (code != 0) { if (code != 0) {
gch.Free (); gch.Free ();
@ -1323,7 +1325,7 @@ namespace AudioToolbox {
public AudioQueueStatus SetOfflineRenderFormat (AudioStreamBasicDescription desc, AudioChannelLayout layout) public AudioQueueStatus SetOfflineRenderFormat (AudioStreamBasicDescription desc, AudioChannelLayout layout)
{ {
int size; int size;
var h = layout == null ? IntPtr.Zero : layout.ToBlock (out size); var h = layout is null ? IntPtr.Zero : layout.ToBlock (out size);
try { try {
return AudioQueueSetOfflineRenderFormat (handle, ref desc, h); return AudioQueueSetOfflineRenderFormat (handle, ref desc, h);
} finally { } finally {
@ -1341,8 +1343,8 @@ namespace AudioToolbox {
public unsafe AudioQueueStatus RenderOffline (double timeStamp, AudioQueueBuffer* audioQueueBuffer, int frameCount) public unsafe AudioQueueStatus RenderOffline (double timeStamp, AudioQueueBuffer* audioQueueBuffer, int frameCount)
{ {
if (audioQueueBuffer == null) if (audioQueueBuffer is null)
throw new ArgumentNullException ("audioQueueBuffer"); ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (audioQueueBuffer));
var stamp = new AudioTimeStamp () { var stamp = new AudioTimeStamp () {
SampleTime = timeStamp, SampleTime = timeStamp,
@ -1362,14 +1364,14 @@ namespace AudioToolbox {
GCHandle gch = GCHandle.FromIntPtr (userData); GCHandle gch = GCHandle.FromIntPtr (userData);
var aq = gch.Target as InputAudioQueue; var aq = gch.Target as InputAudioQueue;
aq.OnInputCompleted (audioQueueBuffer, *startTime, AudioFile.PacketDescriptionFrom (descriptors, inPacketDesc)); aq!.OnInputCompleted (audioQueueBuffer, *startTime, AudioFile.PacketDescriptionFrom (descriptors, inPacketDesc));
} }
public event EventHandler<InputCompletedEventArgs> InputCompleted; public event EventHandler<InputCompletedEventArgs>? InputCompleted;
protected virtual void OnInputCompleted (IntPtr audioQueueBuffer, AudioTimeStamp timeStamp, AudioStreamPacketDescription [] packetDescriptions) protected virtual void OnInputCompleted (IntPtr audioQueueBuffer, AudioTimeStamp timeStamp, AudioStreamPacketDescription []? packetDescriptions)
{ {
var h = InputCompleted; var h = InputCompleted;
if (h != null) if (h is not null)
h (this, new InputCompletedEventArgs (audioQueueBuffer, timeStamp, packetDescriptions)); h (this, new InputCompletedEventArgs (audioQueueBuffer, timeStamp, packetDescriptions));
} }
@ -1388,16 +1390,16 @@ namespace AudioToolbox {
{ {
} }
public InputAudioQueue (AudioStreamBasicDescription desc, CFRunLoop runLoop, string runMode) public InputAudioQueue (AudioStreamBasicDescription desc, CFRunLoop? runLoop, string? runMode)
{ {
IntPtr h; IntPtr h;
GCHandle mygch = GCHandle.Alloc (this); GCHandle mygch = GCHandle.Alloc (this);
CFString s = runMode == null ? null : new CFString (runMode); CFString? s = runMode is null ? null : new CFString (runMode);
var code = AudioQueueNewInput (ref desc, dInputCallback, GCHandle.ToIntPtr (mygch), var code = AudioQueueNewInput (ref desc, dInputCallback, GCHandle.ToIntPtr (mygch),
runLoop == null ? IntPtr.Zero : runLoop.Handle, runLoop.GetHandle (),
s == null ? IntPtr.Zero : s.Handle, 0, out h); s.GetHandle (), 0, out h);
if (s != null) if (s is not null)
s.Dispose (); s.Dispose ();
if (code == 0){ if (code == 0){

Просмотреть файл

@ -26,6 +26,8 @@
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// //
#nullable enable
using System; using System;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;

Просмотреть файл

@ -28,6 +28,8 @@
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// //
#nullable enable
using System; using System;
using System.IO; using System.IO;
using System.Collections; using System.Collections;
@ -92,20 +94,20 @@ namespace AudioToolbox {
public class AccessoryInfo public class AccessoryInfo
{ {
internal AccessoryInfo (int id, string description) internal AccessoryInfo (int id, string? description)
{ {
ID = id; ID = id;
Description = description; Description = description;
} }
public int ID { get; private set; } public int ID { get; private set; }
public string Description { get; private set; } public string? Description { get; private set; }
} }
public class InputSourceInfo public class InputSourceInfo
{ {
public int ID { get; private set; } public int ID { get; private set; }
public string Description { get; private set; } public string? Description { get; private set; }
} }
public class AudioSessionPropertyEventArgs :EventArgs { public class AudioSessionPropertyEventArgs :EventArgs {
@ -154,7 +156,7 @@ namespace AudioToolbox {
} }
} }
NSArray Extract (IntPtr key, NSString secondKey) NSArray? Extract (IntPtr key, NSString secondKey)
{ {
var dictH = Dictionary.LowlevelObjectForKey (key); var dictH = Dictionary.LowlevelObjectForKey (key);
if (dictH == IntPtr.Zero) if (dictH == IntPtr.Zero)
@ -181,7 +183,7 @@ namespace AudioToolbox {
#endif #endif
public AudioSessionInputRouteKind PreviousInputRoute { public AudioSessionInputRouteKind PreviousInputRoute {
get { get {
using (var array = Extract (previous_route_key, AudioSession.AudioRouteKey_Inputs)) using (var array = Extract (previous_route_key, AudioSession.AudioRouteKey_Inputs!))
return AudioSession.GetInputRoute (array); return AudioSession.GetInputRoute (array);
} }
} }
@ -194,9 +196,9 @@ namespace AudioToolbox {
#else #else
[Deprecated (PlatformName.iOS, 7, 0)] [Deprecated (PlatformName.iOS, 7, 0)]
#endif #endif
public AudioSessionOutputRouteKind [] PreviousOutputRoutes { public AudioSessionOutputRouteKind []? PreviousOutputRoutes {
get { get {
using (var array = Extract (previous_route_key, AudioSession.AudioRouteKey_Outputs)) using (var array = Extract (previous_route_key, AudioSession.AudioRouteKey_Outputs!))
return AudioSession.GetOutputRoutes (array); return AudioSession.GetOutputRoutes (array);
} }
} }
@ -211,7 +213,7 @@ namespace AudioToolbox {
#endif #endif
public AudioSessionInputRouteKind CurrentInputRoute { public AudioSessionInputRouteKind CurrentInputRoute {
get { get {
using (var array = Extract (current_route_key, AudioSession.AudioRouteKey_Inputs)) using (var array = Extract (current_route_key, AudioSession.AudioRouteKey_Inputs!))
return AudioSession.GetInputRoute (array); return AudioSession.GetInputRoute (array);
} }
} }
@ -224,9 +226,9 @@ namespace AudioToolbox {
#else #else
[Deprecated (PlatformName.iOS, 7, 0)] [Deprecated (PlatformName.iOS, 7, 0)]
#endif #endif
public AudioSessionOutputRouteKind [] CurrentOutputRoutes { public AudioSessionOutputRouteKind []? CurrentOutputRoutes {
get { get {
using (var array = Extract (current_route_key, AudioSession.AudioRouteKey_Outputs)) using (var array = Extract (current_route_key, AudioSession.AudioRouteKey_Outputs!))
return AudioSession.GetOutputRoutes (array); return AudioSession.GetOutputRoutes (array);
} }
} }
@ -242,32 +244,32 @@ namespace AudioToolbox {
#endif #endif
public static class AudioSession { public static class AudioSession {
static bool initialized; static bool initialized;
public static event EventHandler Interrupted; public static event EventHandler? Interrupted;
public static event EventHandler Resumed; public static event EventHandler? Resumed;
internal static NSString AudioRouteKey_Type; internal static NSString? AudioRouteKey_Type;
internal static NSString AudioRouteKey_Inputs; internal static NSString? AudioRouteKey_Inputs;
internal static NSString AudioRouteKey_Outputs; internal static NSString? AudioRouteKey_Outputs;
static NSString InputRoute_LineIn; static NSString? InputRoute_LineIn;
static NSString InputRoute_BuiltInMic; static NSString? InputRoute_BuiltInMic;
static NSString InputRoute_HeadsetMic; static NSString? InputRoute_HeadsetMic;
static NSString InputRoute_BluetoothHFP; static NSString? InputRoute_BluetoothHFP;
static NSString InputRoute_USBAudio; static NSString? InputRoute_USBAudio;
static NSString OutputRoute_LineOut; static NSString? OutputRoute_LineOut;
static NSString OutputRoute_Headphones; static NSString? OutputRoute_Headphones;
static NSString OutputRoute_BluetoothHFP; static NSString? OutputRoute_BluetoothHFP;
static NSString OutputRoute_BluetoothA2DP; static NSString? OutputRoute_BluetoothA2DP;
static NSString OutputRoute_BuiltInReceiver; static NSString? OutputRoute_BuiltInReceiver;
static NSString OutputRoute_BuiltInSpeaker; static NSString? OutputRoute_BuiltInSpeaker;
static NSString OutputRoute_USBAudio; static NSString? OutputRoute_USBAudio;
static NSString OutputRoute_HDMI; static NSString? OutputRoute_HDMI;
static NSString OutputRoute_AirPlay; static NSString? OutputRoute_AirPlay;
static NSString InputSourceKey_ID; static NSString? InputSourceKey_ID;
static NSString InputSourceKey_Description; static NSString? InputSourceKey_Description;
static NSString OutputDestinationKey_ID; static NSString? OutputDestinationKey_ID;
static NSString OutputDestinationKey_Description; static NSString? OutputDestinationKey_Description;
[DllImport (Constants.AudioToolboxLibrary)] [DllImport (Constants.AudioToolboxLibrary)]
#if NET #if NET
@ -281,16 +283,16 @@ namespace AudioToolbox {
Initialize (null, null); Initialize (null, null);
} }
public static void Initialize (CFRunLoop runLoop, string runMode) public static void Initialize (CFRunLoop? runLoop, string? runMode)
{ {
CFString s = runMode == null ? null : new CFString (runMode); CFString? s = runMode is null ? null : new CFString (runMode);
#if NET #if NET
int k; int k;
unsafe { unsafe {
k = AudioSessionInitialize (runLoop.GetHandle (), s.GetHandle (), &Interruption, IntPtr.Zero); k = AudioSessionInitialize (runLoop.GetHandle (), s.GetHandle (), &Interruption, IntPtr.Zero);
} }
#else #else
int k = AudioSessionInitialize (runLoop == null ? IntPtr.Zero : runLoop.Handle, s == null ? IntPtr.Zero : s.Handle, Interruption, IntPtr.Zero); int k = AudioSessionInitialize (runLoop.GetHandle (), s.GetHandle (), Interruption, IntPtr.Zero);
#endif #endif
if (k != 0 && k != (int)AudioSessionErrors.AlreadyInitialized) if (k != 0 && k != (int)AudioSessionErrors.AlreadyInitialized)
throw new AudioSessionException (k); throw new AudioSessionException (k);
@ -342,8 +344,8 @@ namespace AudioToolbox {
{ {
EventHandler h; EventHandler h;
h = (state == 1) ? Interrupted : Resumed; h = (state == 1) ? Interrupted! : Resumed!;
if (h != null) if (h is not null)
h (null, EventArgs.Empty); h (null, EventArgs.Empty);
} }
@ -494,7 +496,7 @@ namespace AudioToolbox {
#else #else
[Deprecated (PlatformName.iOS, 5, 0, message : "Use 'InputRoute' or 'OutputRoute' instead.")] [Deprecated (PlatformName.iOS, 5, 0, message : "Use 'InputRoute' or 'OutputRoute' instead.")]
#endif #endif
static public string AudioRoute { static public string? AudioRoute {
get { get {
return CFString.FromHandle (GetIntPtr (AudioSessionProperty.AudioRoute)); return CFString.FromHandle (GetIntPtr (AudioSessionProperty.AudioRoute));
} }
@ -502,13 +504,13 @@ namespace AudioToolbox {
static public AccessoryInfo[] InputSources { static public AccessoryInfo[] InputSources {
get { get {
return ExtractAccessoryInfo (GetIntPtr (AudioSessionProperty.InputSources), InputSourceKey_ID, InputSourceKey_Description); return ExtractAccessoryInfo (GetIntPtr (AudioSessionProperty.InputSources), InputSourceKey_ID!, InputSourceKey_Description!);
} }
} }
static public AccessoryInfo[] OutputDestinations { static public AccessoryInfo[] OutputDestinations {
get { get {
return ExtractAccessoryInfo (GetIntPtr (AudioSessionProperty.OutputDestinations), OutputDestinationKey_ID, OutputDestinationKey_Description); return ExtractAccessoryInfo (GetIntPtr (AudioSessionProperty.OutputDestinations), OutputDestinationKey_ID!, OutputDestinationKey_Description!);
} }
} }
@ -550,19 +552,19 @@ namespace AudioToolbox {
*/ */
static internal AudioSessionInputRouteKind GetInputRoute (NSArray arr) static internal AudioSessionInputRouteKind GetInputRoute (NSArray? arr)
{ {
if (arr == null || arr.Count == 0) if (arr is null || arr.Count == 0)
return AudioSessionInputRouteKind.None; return AudioSessionInputRouteKind.None;
var dict = new NSDictionary (arr.ValueAt (0)); var dict = new NSDictionary (arr.ValueAt (0));
if (dict == null || dict.Count == 0) if (dict is null || dict.Count == 0)
return AudioSessionInputRouteKind.None; return AudioSessionInputRouteKind.None;
var val = (NSString) dict [AudioRouteKey_Type]; var val = (NSString) dict [AudioRouteKey_Type];
if (val == null) if (val is null)
return AudioSessionInputRouteKind.None; return AudioSessionInputRouteKind.None;
if (val == InputRoute_LineIn) { if (val == InputRoute_LineIn) {
@ -580,9 +582,9 @@ namespace AudioToolbox {
} }
} }
static internal AudioSessionOutputRouteKind [] GetOutputRoutes (NSArray arr) static internal AudioSessionOutputRouteKind []? GetOutputRoutes (NSArray? arr)
{ {
if (arr == null || arr.Count == 0) if (arr is null || arr.Count == 0)
return null; return null;
var result = new AudioSessionOutputRouteKind [arr.Count]; var result = new AudioSessionOutputRouteKind [arr.Count];
@ -591,12 +593,12 @@ namespace AudioToolbox {
result [i] = AudioSessionOutputRouteKind.None; result [i] = AudioSessionOutputRouteKind.None;
if (dict == null || dict.Count == 0) if (dict is null || dict.Count == 0)
continue; continue;
var val = (NSString) dict [AudioRouteKey_Type]; var val = (NSString) dict [AudioRouteKey_Type];
if (val == null) if (val is null)
continue; continue;
if (val == OutputRoute_LineOut) { if (val == OutputRoute_LineOut) {
@ -629,7 +631,7 @@ namespace AudioToolbox {
} }
} }
static public AudioSessionOutputRouteKind [] OutputRoutes { static public AudioSessionOutputRouteKind []? OutputRoutes {
get { get {
return GetOutputRoutes ((NSArray) AudioRouteDescription [AudioRouteKey_Outputs]); return GetOutputRoutes ((NSArray) AudioRouteDescription [AudioRouteKey_Outputs]);
} }
@ -775,8 +777,8 @@ namespace AudioToolbox {
#endif #endif
static void Listener (IntPtr userData, AudioSessionProperty prop, int size, IntPtr data) static void Listener (IntPtr userData, AudioSessionProperty prop, int size, IntPtr data)
{ {
ArrayList a = (ArrayList) listeners [prop]; ArrayList a = (ArrayList) listeners ![prop];
if (a == null){ if (a is null){
// Should never happen // Should never happen
return; return;
} }
@ -793,18 +795,18 @@ namespace AudioToolbox {
extern static AudioSessionErrors AudioSessionAddPropertyListener(AudioSessionProperty id, _PropertyListener inProc, IntPtr userData); extern static AudioSessionErrors AudioSessionAddPropertyListener(AudioSessionProperty id, _PropertyListener inProc, IntPtr userData);
#endif #endif
static Hashtable listeners; static Hashtable? listeners;
public static AudioSessionErrors AddListener (AudioSessionProperty property, PropertyListener listener) public static AudioSessionErrors AddListener (AudioSessionProperty property, PropertyListener listener)
{ {
if (listener == null) if (listener is null)
throw new ArgumentNullException ("listener"); ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (listener));
if (listeners == null) if (listeners is null)
listeners = new Hashtable (); listeners = new Hashtable ();
ArrayList a = (ArrayList) listeners [property]; ArrayList a = (ArrayList) listeners [property];
if (a == null) if (a is null)
listeners [property] = a = new ArrayList (); listeners [property] = a = new ArrayList ();
a.Add (listener); a.Add (listener);
@ -824,22 +826,22 @@ namespace AudioToolbox {
public static void RemoveListener (AudioSessionProperty property, PropertyListener listener) public static void RemoveListener (AudioSessionProperty property, PropertyListener listener)
{ {
if (listener == null) if (listener is null)
throw new ArgumentNullException ("listener"); ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (listener));
ArrayList a = (ArrayList) listeners [property]; ArrayList a = (ArrayList) listeners ![property];
if (a == null) if (a is null)
return; return;
a.Remove (listener); a.Remove (listener);
if (a.Count == 0) if (a.Count == 0)
listeners [property] = null; listeners [property] = null;
} }
static Hashtable strongListenerHash; static Hashtable? strongListenerHash;
static void AddListenerEvent (AudioSessionProperty property, object handler, PropertyListener listener) static void AddListenerEvent (AudioSessionProperty property, object handler, PropertyListener listener)
{ {
if (strongListenerHash == null) if (strongListenerHash is null)
Interlocked.CompareExchange (ref strongListenerHash, new Hashtable (), null); Interlocked.CompareExchange (ref strongListenerHash, new Hashtable (), null);
lock (strongListenerHash) { lock (strongListenerHash) {
@ -851,13 +853,13 @@ namespace AudioToolbox {
static void RemoveListenerEvent (AudioSessionProperty property, object handler) static void RemoveListenerEvent (AudioSessionProperty property, object handler)
{ {
if (strongListenerHash == null) if (strongListenerHash is null)
return; return;
PropertyListener listener; PropertyListener listener;
lock (strongListenerHash) { lock (strongListenerHash) {
listener = (PropertyListener) strongListenerHash [handler]; listener = (PropertyListener) strongListenerHash [handler];
if (listener == null) if (listener is null)
return; return;
strongListenerHash.Remove (handler); strongListenerHash.Remove (handler);
@ -929,7 +931,7 @@ namespace AudioToolbox {
public static event Action<AccessoryInfo[]> InputSourcesChanged { public static event Action<AccessoryInfo[]> InputSourcesChanged {
add { add {
AddListenerEvent (AudioSessionProperty.InputSources, value, AddListenerEvent (AudioSessionProperty.InputSources, value,
(prop, size, data) => value (ExtractAccessoryInfo (data, InputSourceKey_ID, InputSourceKey_Description))); (prop, size, data) => value (ExtractAccessoryInfo (data, InputSourceKey_ID!, InputSourceKey_Description!)));
} }
remove { remove {
RemoveListenerEvent (AudioSessionProperty.InputSources, value); RemoveListenerEvent (AudioSessionProperty.InputSources, value);
@ -939,7 +941,7 @@ namespace AudioToolbox {
public static event Action<AccessoryInfo[]> OutputDestinationsChanged { public static event Action<AccessoryInfo[]> OutputDestinationsChanged {
add { add {
AddListenerEvent (AudioSessionProperty.OutputDestinations, value, AddListenerEvent (AudioSessionProperty.OutputDestinations, value,
(prop, size, data) => value (ExtractAccessoryInfo (data, OutputDestinationKey_ID, OutputDestinationKey_Description))); (prop, size, data) => value (ExtractAccessoryInfo (data, OutputDestinationKey_ID!, OutputDestinationKey_Description!)));
} }
remove { remove {
RemoveListenerEvent (AudioSessionProperty.OutputDestinations, value); RemoveListenerEvent (AudioSessionProperty.OutputDestinations, value);

Просмотреть файл

@ -4,6 +4,8 @@
// Copyright 2013-2014 Xamarin Inc. // Copyright 2013-2014 Xamarin Inc.
// //
#nullable enable
using System; using System;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Runtime.Versioning; using System.Runtime.Versioning;
@ -34,15 +36,15 @@ namespace AudioToolbox {
} }
public int MSB { public int MSB {
get { return (Dictionary [MSBKey] as NSNumber).Int32Value; } get { return (Dictionary [MSBKey] as NSNumber)!.Int32Value; }
} }
public int LSB { public int LSB {
get { return (Dictionary [LSBKey] as NSNumber).Int32Value; } get { return (Dictionary [LSBKey] as NSNumber)!.Int32Value; }
} }
public int Program { public int Program {
get { return (Dictionary [ProgramKey] as NSNumber).Int32Value; } get { return (Dictionary [ProgramKey] as NSNumber)!.Int32Value; }
} }
// some API likely wants the [CF|NS]Dictionary // some API likely wants the [CF|NS]Dictionary
@ -64,12 +66,12 @@ namespace AudioToolbox {
#else #else
[iOS (7,0)] // 10.5 [iOS (7,0)] // 10.5
#endif #endif
public static string GetName (NSUrl url) public static string? GetName (NSUrl url)
{ {
if (url == null) if (url is null)
throw new ArgumentNullException ("url"); ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (url));
string result = null; string? result = null;
IntPtr name = IntPtr.Zero; IntPtr name = IntPtr.Zero;
var error = CopyNameFromSoundBank (url.Handle, ref name); var error = CopyNameFromSoundBank (url.Handle, ref name);
if (name != IntPtr.Zero) { if (name != IntPtr.Zero) {
@ -96,12 +98,12 @@ namespace AudioToolbox {
[iOS (7,0)] [iOS (7,0)]
[Mac (10,9)] [Mac (10,9)]
#endif #endif
public static InstrumentInfo [] GetInstrumentInfo (NSUrl url) public static InstrumentInfo []? GetInstrumentInfo (NSUrl url)
{ {
if (url == null) if (url is null)
throw new ArgumentNullException ("url"); ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (url));
InstrumentInfo [] result = null; InstrumentInfo []? result = null;
IntPtr array = IntPtr.Zero; IntPtr array = IntPtr.Zero;
var error = CopyInstrumentInfoFromSoundBank (url.Handle, ref array); var error = CopyInstrumentInfoFromSoundBank (url.Handle, ref array);
if (array != IntPtr.Zero) { if (array != IntPtr.Zero) {

Просмотреть файл

@ -30,6 +30,8 @@
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// //
#nullable enable
using System; using System;
using System.Text; using System.Text;
using System.Collections.Generic; using System.Collections.Generic;
@ -199,7 +201,7 @@ namespace AudioToolbox {
} }
#if !WATCH #if !WATCH
public unsafe static AudioChannelLayoutTag[] GetAvailableEncodeChannelLayoutTags (AudioStreamBasicDescription format) public unsafe static AudioChannelLayoutTag[]? GetAvailableEncodeChannelLayoutTags (AudioStreamBasicDescription format)
{ {
var type_size = sizeof (AudioStreamBasicDescription); var type_size = sizeof (AudioStreamBasicDescription);
uint size; uint size;
@ -216,7 +218,7 @@ namespace AudioToolbox {
} }
} }
public unsafe static int[] GetAvailableEncodeNumberChannels (AudioStreamBasicDescription format) public unsafe static int[]? GetAvailableEncodeNumberChannels (AudioStreamBasicDescription format)
{ {
uint size; uint size;
if (AudioFormatPropertyNative.AudioFormatGetPropertyInfo (AudioFormatProperty.AvailableEncodeNumberChannels, sizeof (AudioStreamBasicDescription), ref format, out size) != 0) if (AudioFormatPropertyNative.AudioFormatGetPropertyInfo (AudioFormatProperty.AvailableEncodeNumberChannels, sizeof (AudioStreamBasicDescription), ref format, out size) != 0)
@ -232,7 +234,7 @@ namespace AudioToolbox {
} }
} }
public unsafe AudioFormat[] GetOutputFormatList (byte[] magicCookie = null) public unsafe AudioFormat[]? GetOutputFormatList (byte[]? magicCookie = null)
{ {
var afi = new AudioFormatInfo (); var afi = new AudioFormatInfo ();
afi.AudioStreamBasicDescription = this; afi.AudioStreamBasicDescription = this;
@ -255,10 +257,10 @@ namespace AudioToolbox {
} }
} }
public unsafe AudioFormat[] GetFormatList (byte[] magicCookie) public unsafe AudioFormat[]? GetFormatList (byte[] magicCookie)
{ {
if (magicCookie == null) if (magicCookie is null)
throw new ArgumentNullException ("magicCookie"); ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (magicCookie));
var afi = new AudioFormatInfo (); var afi = new AudioFormatInfo ();
afi.AudioStreamBasicDescription = this; afi.AudioStreamBasicDescription = this;
@ -295,7 +297,7 @@ namespace AudioToolbox {
} }
} }
public unsafe string FormatName { public unsafe string? FormatName {
get { get {
IntPtr ptr; IntPtr ptr;
var size = sizeof (IntPtr); var size = sizeof (IntPtr);
@ -562,7 +564,7 @@ namespace AudioToolbox {
} }
#if !WATCH #if !WATCH
public unsafe string Name { public unsafe string? Name {
get { get {
IntPtr sptr; IntPtr sptr;
int size = sizeof (IntPtr); int size = sizeof (IntPtr);
@ -578,7 +580,7 @@ namespace AudioToolbox {
} }
} }
public unsafe string ShortName { public unsafe string? ShortName {
get { get {
IntPtr sptr; IntPtr sptr;
int size = sizeof (IntPtr); int size = sizeof (IntPtr);
@ -886,10 +888,10 @@ namespace AudioToolbox {
public AudioChannelLayoutTag AudioTag; public AudioChannelLayoutTag AudioTag;
public AudioChannelBit ChannelUsage; public AudioChannelBit ChannelUsage;
public AudioChannelDescription[] Channels; public AudioChannelDescription[]? Channels;
#if !WATCH #if !WATCH
public unsafe string Name { public unsafe string? Name {
get { get {
IntPtr sptr; IntPtr sptr;
int size = sizeof (IntPtr); int size = sizeof (IntPtr);
@ -905,7 +907,7 @@ namespace AudioToolbox {
} }
} }
public unsafe string SimpleName { public unsafe string? SimpleName {
get { get {
IntPtr sptr; IntPtr sptr;
int size = sizeof (IntPtr); int size = sizeof (IntPtr);
@ -921,22 +923,22 @@ namespace AudioToolbox {
} }
} }
public static AudioChannelLayout FromAudioChannelBitmap (AudioChannelBit channelBitmap) public static AudioChannelLayout? FromAudioChannelBitmap (AudioChannelBit channelBitmap)
{ {
return GetChannelLayout (AudioFormatProperty.ChannelLayoutForBitmap, (int) channelBitmap); return GetChannelLayout (AudioFormatProperty.ChannelLayoutForBitmap, (int) channelBitmap);
} }
public static AudioChannelLayout FromAudioChannelLayoutTag (AudioChannelLayoutTag channelLayoutTag) public static AudioChannelLayout? FromAudioChannelLayoutTag (AudioChannelLayoutTag channelLayoutTag)
{ {
return GetChannelLayout (AudioFormatProperty.ChannelLayoutForTag, (int) channelLayoutTag); return GetChannelLayout (AudioFormatProperty.ChannelLayoutForTag, (int) channelLayoutTag);
} }
static AudioChannelLayout GetChannelLayout (AudioFormatProperty property, int value) static AudioChannelLayout? GetChannelLayout (AudioFormatProperty property, int value)
{ {
int size; int size;
AudioFormatPropertyNative.AudioFormatGetPropertyInfo (property, sizeof (AudioFormatProperty), ref value, out size); AudioFormatPropertyNative.AudioFormatGetPropertyInfo (property, sizeof (AudioFormatProperty), ref value, out size);
AudioChannelLayout layout; AudioChannelLayout? layout;
IntPtr ptr = Marshal.AllocHGlobal (size); IntPtr ptr = Marshal.AllocHGlobal (size);
if (AudioFormatPropertyNative.AudioFormatGetProperty (property, sizeof (AudioFormatProperty), ref value, ref size, ptr) == 0) if (AudioFormatPropertyNative.AudioFormatGetProperty (property, sizeof (AudioFormatProperty), ref value, ref size, ptr) == 0)
layout = new AudioChannelLayout (ptr); layout = new AudioChannelLayout (ptr);
@ -948,7 +950,7 @@ namespace AudioToolbox {
} }
#endif // !WATCH #endif // !WATCH
internal static AudioChannelLayout FromHandle (IntPtr handle) internal static AudioChannelLayout? FromHandle (IntPtr handle)
{ {
if (handle == IntPtr.Zero) if (handle == IntPtr.Zero)
return null; return null;
@ -958,14 +960,14 @@ namespace AudioToolbox {
public override string ToString () public override string ToString ()
{ {
return String.Format ("AudioChannelLayout: Tag={0} Bitmap={1} Channels={2}", AudioTag, ChannelUsage, Channels.Length); return String.Format ("AudioChannelLayout: Tag={0} Bitmap={1} Channels={2}", AudioTag, ChannelUsage, Channels!.Length);
} }
// The returned block must be released with FreeHGlobal // The returned block must be released with FreeHGlobal
internal unsafe IntPtr ToBlock (out int size) internal unsafe IntPtr ToBlock (out int size)
{ {
if (Channels == null) if (Channels is null)
throw new ArgumentNullException ("Channels"); ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (Channels));
var desc_size = sizeof (AudioChannelDescription); var desc_size = sizeof (AudioChannelDescription);
@ -987,8 +989,8 @@ namespace AudioToolbox {
#if !WATCH #if !WATCH
public static AudioFormatError Validate (AudioChannelLayout layout) public static AudioFormatError Validate (AudioChannelLayout layout)
{ {
if (layout == null) if (layout is null)
throw new ArgumentNullException ("layout"); ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (layout));
int ptr_size; int ptr_size;
var ptr = layout.ToBlock (out ptr_size); var ptr = layout.ToBlock (out ptr_size);
@ -998,15 +1000,15 @@ namespace AudioToolbox {
return res; return res;
} }
public unsafe static int[] GetChannelMap (AudioChannelLayout inputLayout, AudioChannelLayout outputLayout) public unsafe static int[]? GetChannelMap (AudioChannelLayout inputLayout, AudioChannelLayout outputLayout)
{ {
if (inputLayout == null) if (inputLayout is null)
throw new ArgumentNullException ("inputLayout"); ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (inputLayout));
if (outputLayout == null) if (outputLayout is null)
throw new ArgumentNullException ("outputLayout"); ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (outputLayout));
var channels_count = GetNumberOfChannels (outputLayout); var channels_count = GetNumberOfChannels (outputLayout);
if (channels_count == null) if (channels_count is null)
throw new ArgumentException ("outputLayout"); throw new ArgumentException ("outputLayout");
int ptr_size; int ptr_size;
@ -1032,19 +1034,19 @@ namespace AudioToolbox {
return res == 0 ? value : null; return res == 0 ? value : null;
} }
public unsafe static float[,] GetMatrixMixMap (AudioChannelLayout inputLayout, AudioChannelLayout outputLayout) public unsafe static float[,]? GetMatrixMixMap (AudioChannelLayout inputLayout, AudioChannelLayout outputLayout)
{ {
if (inputLayout == null) if (inputLayout is null)
throw new ArgumentNullException ("inputLayout"); ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (inputLayout));
if (outputLayout == null) if (outputLayout is null)
throw new ArgumentNullException ("outputLayout"); ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (outputLayout));
var channels_count_output = GetNumberOfChannels (outputLayout); var channels_count_output = GetNumberOfChannels (outputLayout);
if (channels_count_output == null) if (channels_count_output is null)
throw new ArgumentException ("outputLayout"); throw new ArgumentException ("outputLayout");
var channels_count_input = GetNumberOfChannels (inputLayout); var channels_count_input = GetNumberOfChannels (inputLayout);
if (channels_count_input == null) if (channels_count_input is null)
throw new ArgumentException ("inputLayout"); throw new ArgumentException ("inputLayout");
int ptr_size; int ptr_size;
@ -1072,8 +1074,8 @@ namespace AudioToolbox {
public static int? GetNumberOfChannels (AudioChannelLayout layout) public static int? GetNumberOfChannels (AudioChannelLayout layout)
{ {
if (layout == null) if (layout is null)
throw new ArgumentNullException ("layout"); ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (layout));
int ptr_size; int ptr_size;
var ptr = layout.ToBlock (out ptr_size); var ptr = layout.ToBlock (out ptr_size);
@ -1087,8 +1089,8 @@ namespace AudioToolbox {
public static AudioChannelLayoutTag? GetTagForChannelLayout (AudioChannelLayout layout) public static AudioChannelLayoutTag? GetTagForChannelLayout (AudioChannelLayout layout)
{ {
if (layout == null) if (layout is null)
throw new ArgumentNullException ("layout"); ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (layout));
int ptr_size; int ptr_size;
var ptr = layout.ToBlock (out ptr_size); var ptr = layout.ToBlock (out ptr_size);
@ -1100,7 +1102,7 @@ namespace AudioToolbox {
return res != 0 ? null : (AudioChannelLayoutTag?) value; return res != 0 ? null : (AudioChannelLayoutTag?) value;
} }
public unsafe static AudioChannelLayoutTag[] GetTagsForNumberOfChannels (int count) public unsafe static AudioChannelLayoutTag[]? GetTagsForNumberOfChannels (int count)
{ {
const int type_size = sizeof (uint); const int type_size = sizeof (uint);
int size; int size;

Просмотреть файл

@ -89,7 +89,7 @@ namespace AudioToolbox {
{ {
} }
protected virtual void Dispose (bool disposing) new protected virtual void Dispose (bool disposing)
{ {
currentSequence = null; currentSequence = null;
if (Owns && Handle != IntPtr.Zero) if (Owns && Handle != IntPtr.Zero)

Просмотреть файл

@ -124,7 +124,7 @@ namespace AudioToolbox {
} }
set { set {
if (value is null) if (value is null)
throw new ArgumentNullException (nameof (value)); ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (value));
MusicSequenceSetAUGraph (Handle, value.Handle); MusicSequenceSetAUGraph (Handle, value.Handle);
} }
@ -209,7 +209,7 @@ namespace AudioToolbox {
public MusicPlayerStatus GetTrackIndex (MusicTrack track, out int index) public MusicPlayerStatus GetTrackIndex (MusicTrack track, out int index)
{ {
if (track is null) if (track is null)
throw new ArgumentNullException (nameof (track)); ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (track));
return MusicSequenceGetTrackIndex (Handle, track.Handle, out index); return MusicSequenceGetTrackIndex (Handle, track.Handle, out index);
} }
@ -232,7 +232,7 @@ namespace AudioToolbox {
public MusicPlayerStatus SetMidiEndpoint (MidiEndpoint endpoint) public MusicPlayerStatus SetMidiEndpoint (MidiEndpoint endpoint)
{ {
if (endpoint is null) if (endpoint is null)
throw new ArgumentNullException (nameof (endpoint)); ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (endpoint));
return MusicSequenceSetMIDIEndpoint (Handle, endpoint.handle); return MusicSequenceSetMIDIEndpoint (Handle, endpoint.handle);
} }
#endif // IOS #endif // IOS
@ -315,7 +315,7 @@ namespace AudioToolbox {
public MusicPlayerStatus LoadFile (NSUrl url, MusicSequenceFileTypeID fileTypeId, MusicSequenceLoadFlags loadFlags = 0) public MusicPlayerStatus LoadFile (NSUrl url, MusicSequenceFileTypeID fileTypeId, MusicSequenceLoadFlags loadFlags = 0)
{ {
if (url is null) if (url is null)
throw new ArgumentNullException (nameof (url)); ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (url));
return MusicSequenceFileLoad (Handle, url.Handle, fileTypeId, loadFlags); return MusicSequenceFileLoad (Handle, url.Handle, fileTypeId, loadFlags);
} }
@ -326,7 +326,7 @@ namespace AudioToolbox {
public MusicPlayerStatus LoadData (NSData data, MusicSequenceFileTypeID fileTypeId, MusicSequenceLoadFlags loadFlags = 0) public MusicPlayerStatus LoadData (NSData data, MusicSequenceFileTypeID fileTypeId, MusicSequenceLoadFlags loadFlags = 0)
{ {
if (data is null) if (data is null)
throw new ArgumentNullException (nameof (data)); ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (data));
return MusicSequenceFileLoadData (Handle, data.Handle, fileTypeId, loadFlags); return MusicSequenceFileLoadData (Handle, data.Handle, fileTypeId, loadFlags);
} }
@ -339,7 +339,7 @@ namespace AudioToolbox {
public MusicPlayerStatus CreateFile (NSUrl url, MusicSequenceFileTypeID fileType, MusicSequenceFileFlags flags = 0, ushort resolution = 0) public MusicPlayerStatus CreateFile (NSUrl url, MusicSequenceFileTypeID fileType, MusicSequenceFileFlags flags = 0, ushort resolution = 0)
{ {
if (url is null) if (url is null)
throw new ArgumentNullException (nameof (url)); ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (url));
return MusicSequenceFileCreate (Handle, url.Handle, fileType, flags, resolution); return MusicSequenceFileCreate (Handle, url.Handle, fileType, flags, resolution);
} }

Просмотреть файл

@ -143,7 +143,7 @@ namespace AudioToolbox {
internal MusicEventUserData (IntPtr handle) internal MusicEventUserData (IntPtr handle)
{ {
if (handle == IntPtr.Zero) if (handle == IntPtr.Zero)
throw new ArgumentNullException (nameof (handle)); ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (handle));
int length = Marshal.ReadInt32 (handle); int length = Marshal.ReadInt32 (handle);
@ -231,7 +231,7 @@ namespace AudioToolbox {
public static MusicTrack? FromSequence (MusicSequence sequence) public static MusicTrack? FromSequence (MusicSequence sequence)
{ {
if (sequence is null) if (sequence is null)
throw new ArgumentNullException (nameof (sequence)); ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (sequence));
return sequence.CreateTrack (); return sequence.CreateTrack ();
} }
@ -363,7 +363,7 @@ namespace AudioToolbox {
public MusicPlayerStatus AddMidiRawDataEvent (double timestamp, MidiRawData rawData) public MusicPlayerStatus AddMidiRawDataEvent (double timestamp, MidiRawData rawData)
{ {
if (rawData is null) if (rawData is null)
throw new ArgumentNullException (nameof (rawData)); ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (rawData));
var native = rawData.ToUnmanaged (); var native = rawData.ToUnmanaged ();
var r = MusicTrackNewMIDIRawDataEvent (Handle, timestamp, native); var r = MusicTrackNewMIDIRawDataEvent (Handle, timestamp, native);
@ -395,7 +395,7 @@ namespace AudioToolbox {
public MusicPlayerStatus AddMetaEvent (double timestamp, MidiMetaEvent metaEvent) public MusicPlayerStatus AddMetaEvent (double timestamp, MidiMetaEvent metaEvent)
{ {
if (metaEvent is null) if (metaEvent is null)
throw new ArgumentNullException (nameof (metaEvent)); ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (metaEvent));
var ptr = metaEvent.ToUnmanaged (); var ptr = metaEvent.ToUnmanaged ();
var ret = MusicTrackNewMetaEvent (Handle, timestamp, ptr); var ret = MusicTrackNewMetaEvent (Handle, timestamp, ptr);
@ -409,7 +409,7 @@ namespace AudioToolbox {
public MusicPlayerStatus AddUserEvent (double timestamp, MusicEventUserData userData) public MusicPlayerStatus AddUserEvent (double timestamp, MusicEventUserData userData)
{ {
if (userData is null) if (userData is null)
throw new ArgumentNullException (nameof (userData)); ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (userData));
var ptr = userData.ToUnmanaged (); var ptr = userData.ToUnmanaged ();
var ret = MusicTrackNewUserEvent (Handle, timestamp, ptr); var ret = MusicTrackNewUserEvent (Handle, timestamp, ptr);
Marshal.FreeHGlobal (ptr); Marshal.FreeHGlobal (ptr);
@ -446,7 +446,7 @@ namespace AudioToolbox {
public MusicPlayerStatus CopyInsert (double sourceStartTime, double sourceEndTime, MusicTrack targetTrack, double targetInsertTime) public MusicPlayerStatus CopyInsert (double sourceStartTime, double sourceEndTime, MusicTrack targetTrack, double targetInsertTime)
{ {
if (targetTrack is null) if (targetTrack is null)
throw new ArgumentNullException (nameof (targetTrack)); ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (targetTrack));
return MusicTrackCopyInsert (Handle, sourceStartTime, sourceEndTime, targetTrack.Handle, targetInsertTime); return MusicTrackCopyInsert (Handle, sourceStartTime, sourceEndTime, targetTrack.Handle, targetInsertTime);
} }
@ -456,7 +456,7 @@ namespace AudioToolbox {
public MusicPlayerStatus Merge (double sourceStartTime, double sourceEndTime, MusicTrack targetTrack, double targetInsertTime) public MusicPlayerStatus Merge (double sourceStartTime, double sourceEndTime, MusicTrack targetTrack, double targetInsertTime)
{ {
if (targetTrack is null) if (targetTrack is null)
throw new ArgumentNullException (nameof (targetTrack)); ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (targetTrack));
return MusicTrackMerge (Handle, sourceStartTime, sourceEndTime, targetTrack.Handle, targetInsertTime); return MusicTrackMerge (Handle, sourceStartTime, sourceEndTime, targetTrack.Handle, targetInsertTime);
} }
#endif // !COREBUILD #endif // !COREBUILD

Просмотреть файл

@ -222,7 +222,7 @@ namespace AudioToolbox {
public void PlayAlertSound (Action onCompletion) public void PlayAlertSound (Action onCompletion)
{ {
if (onCompletion is null) if (onCompletion is null)
throw new ArgumentNullException (nameof (onCompletion)); ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (onCompletion));
AssertNotDisposed (); AssertNotDisposed ();
@ -262,7 +262,7 @@ namespace AudioToolbox {
public void PlaySystemSound (Action onCompletion) public void PlaySystemSound (Action onCompletion)
{ {
if (onCompletion is null) if (onCompletion is null)
throw new ArgumentNullException (nameof (onCompletion)); ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (onCompletion));
AssertNotDisposed (); AssertNotDisposed ();
@ -317,7 +317,7 @@ namespace AudioToolbox {
static uint Create (NSUrl fileUrl) static uint Create (NSUrl fileUrl)
{ {
if (fileUrl is null) if (fileUrl is null)
throw new ArgumentNullException (nameof (fileUrl)); ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (fileUrl));
var error = AudioServicesCreateSystemSoundID (fileUrl.Handle, out var soundId); var error = AudioServicesCreateSystemSoundID (fileUrl.Handle, out var soundId);
if (error != AudioServicesError.None) if (error != AudioServicesError.None)
@ -334,7 +334,7 @@ namespace AudioToolbox {
public static SystemSound? FromFile (NSUrl fileUrl) public static SystemSound? FromFile (NSUrl fileUrl)
{ {
if (fileUrl is null) if (fileUrl is null)
throw new ArgumentNullException (nameof (fileUrl)); ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (fileUrl));
var error = AudioServicesCreateSystemSoundID (fileUrl.Handle, out var soundId); var error = AudioServicesCreateSystemSoundID (fileUrl.Handle, out var soundId);
if (error != AudioServicesError.None) if (error != AudioServicesError.None)
@ -345,7 +345,7 @@ namespace AudioToolbox {
public static SystemSound? FromFile (string filename) public static SystemSound? FromFile (string filename)
{ {
if (filename is null) if (filename is null)
throw new ArgumentNullException (nameof (filename)); ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (filename));
using (var url = new NSUrl (filename)){ using (var url = new NSUrl (filename)){
var error = AudioServicesCreateSystemSoundID (url.Handle, out var soundId); var error = AudioServicesCreateSystemSoundID (url.Handle, out var soundId);
@ -391,7 +391,7 @@ namespace AudioToolbox {
unsafe { unsafe {
return AudioServicesAddSystemSoundCompletion (soundId, return AudioServicesAddSystemSoundCompletion (soundId,
runLoop.GetHandle (), runLoop.GetHandle (),
IntPtr.Zero, // runLoopMode should be enum runLoopMode == null ? IntPtr.Zero : runLoopMode.Handle, IntPtr.Zero, // runLoopMode should be enum runLoopMode.GetHandle (),
#if NET #if NET
&SoundCompletionShared, &SoundCompletionShared,
#else #else