Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[AudioToolbox] Update bindings to Xcode 9 beta2. #2294

Merged
merged 9 commits into from
Aug 11, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/AudioToolbox/AudioFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ public enum AudioFileType { // UInt32 AudioFileTypeID
AIFF = 0x41494646, // AIFF
AIFC = 0x41494643, // AIFC
WAVE = 0x57415645, // WAVE
[NoWatch, iOS (11,0), Mac(10,13), TV (11,0)]
RF64 = 0x52463634, // RF64
SoundDesigner2 = 0x53643266, // Sd2f
Next = 0x4e655854, // NeXT
MP3 = 0x4d504733, // MPG3
Expand All @@ -60,6 +62,8 @@ public enum AudioFileType { // UInt32 AudioFileTypeID
ThreeGP = 0x33677070, // 3gpp
ThreeGP2 = 0x33677032, // 3gp2
AMR = 0x616d7266, // amrf
[NoWatch, iOS (11,0), Mac(10,13), TV (11,0)]
FLAC = 0x666c6163, // flac
}

public enum AudioFileError {// Implictly cast to OSType in AudioFile.h
Expand Down
223 changes: 222 additions & 1 deletion src/AudioUnit/AudioComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,177 @@

namespace XamCore.AudioUnit
{

#if !COREBUILD
// keys are not constants and had to be found in AudioToolbox.framework/Headers/AudioComponent.h
[NoWatch, NoTV, Mac (10,13), iOS (11,0)]
public partial class ResourceUsageInfo : DictionaryContainer {
static NSString userClientK = new NSString ("iokit.user-client");
static NSString globalNameK = new NSString ("mach-lookup.global-name");
static NSString networkClientK = new NSString ("network.client");
static NSString exceptionK = new NSString ("temporary-exception.files.all.read-write");

public ResourceUsageInfo () : base () {}

public ResourceUsageInfo (NSDictionary dic) : base (dic) {}

public string[] IOKitUserClient {
get {
var array = GetNativeValue<NSArray> (userClientK);
if (array == null )
return null;
return NSArray.StringArrayFromHandle (array.Handle);
}
set {
if (value == null)
RemoveValue (userClientK);
else
SetArrayValue (userClientK, value);
}
}

public string[] MachLookUpGlobalName {
get {
var array = GetNativeValue<NSArray> (globalNameK);
if (array == null)
return null;
return NSArray.StringArrayFromHandle (array.Handle);
}
set {
if (value == null)
RemoveValue (globalNameK);
else
SetArrayValue (globalNameK, value);
}
}

public bool? NetworkClient {
get {
return GetBoolValue (networkClientK);
}
set {
SetBooleanValue (networkClientK, value);
}
}

public bool? TemporaryExceptionReadWrite {
get {
return GetBoolValue (exceptionK);
}
set {
SetBooleanValue (exceptionK, value);
}
}
}

// keys are not constants and had to be found in AudioToolbox.framework/Headers/AudioComponent.h
[NoWatch, NoTV, Mac (10,13), iOS (11,0)]
public partial class AudioComponentInfo : DictionaryContainer {
static NSString typeK = new NSString ("type");
static NSString subtypeK = new NSString ("subtype");
static NSString manufacturerK = new NSString ("manufacturer");
static NSString nameK = new NSString ("name");
static NSString versionK = new NSString ("version");
static NSString factoryFunctionK = new NSString ("factoryFunction");
static NSString sandboxSafeK = new NSString ("sandboxSafe");
static NSString resourceUsageK = new NSString ("resourceUsage");
static NSString tagsK = new NSString ("tags");

public AudioComponentInfo () : base () {}

public AudioComponentInfo (NSDictionary dic) : base (dic) {}

public string Type {
get {
return GetStringValue (typeK);
}
set {
SetStringValue (typeK, value);
}
}

public string Subtype {
get {
return GetStringValue (subtypeK);
}
set {
SetStringValue (subtypeK, value);
}
}

public string Manufacturer {
get {
return GetStringValue (manufacturerK);
}
set {
SetStringValue (manufacturerK, value);
}
}

public string Name {
get {
return GetStringValue (nameK);
}
set {
SetStringValue (nameK, value);
}
}

public nuint? Version {
get {
return GetNUIntValue (versionK);
}
set {
SetNumberValue (versionK, value);
}
}

public string FactoryFunction {
get {
return GetStringValue (factoryFunctionK);
}
set {
SetStringValue (factoryFunctionK, value);
}
}

public bool? SandboxSafe {
get {
return GetBoolValue (sandboxSafeK);
}
set {
SetBooleanValue (sandboxSafeK, value);
}
}

public ResourceUsageInfo ResourceUsage {
get {
return GetStrongDictionary<ResourceUsageInfo> (resourceUsageK);
}
set {
SetNativeValue (resourceUsageK, value?.Dictionary, true);
}
}

public string[] Tags {
get {
var array = GetNativeValue<NSArray> (tagsK);
if (array == null)
return null;
return NSArray.StringArrayFromHandle (array.Handle);
}
set {
if (value == null)
RemoveValue (tagsK);
else
SetArrayValue (tagsK, value);
}
}
}

#endif


public class AudioComponent : INativeObject {
#if !COREBUILD
internal IntPtr handle;
Expand Down Expand Up @@ -224,6 +395,56 @@ public XamCore.AppKit.NSImage GetIcon ()
return new XamCore.AppKit.NSImage (AudioComponentGetIcon (handle));
}
#endif
[NoWatch, NoTV, Mac (10,13), iOS (11,0)]
[DllImport (Constants.AudioUnitLibrary)]
static extern int /* OSStatus */ AudioUnitExtensionSetComponentList (IntPtr /* CFString */ extensionIdentifier, /* CFArrayRef */ IntPtr audioComponentInfo);

[NoWatch, NoTV, Mac (10,13), iOS (11,0)]
[DllImport (Constants.AudioUnitLibrary)]
static extern /* CFArrayRef */ IntPtr AudioUnitExtensionCopyComponentList (IntPtr /* CFString */ extensionIdentifier);

[NoWatch, NoTV, Mac (10,13), iOS (11,0)]
public AudioComponentInfo[] ComponentList {
get {
using (var cfString = new CFString (Name)) {
var cHandle = AudioUnitExtensionCopyComponentList (cfString.Handle);
if (cHandle == IntPtr.Zero)
return null;
using (var nsArray = Runtime.GetNSObject<NSArray> (cHandle, owns: true)) {
if (nsArray == null)
return null;
// make things easier for developers since we do not know how to have an implicit conversion from NSObject to AudioComponentInfo
var dics = NSArray.FromArray <NSDictionary> (nsArray);
var result = new AudioComponentInfo [dics.Length];
for (var i = 0; i < result.Length; i++) {
result [i] = new AudioComponentInfo (dics[i]);
}
return result;
}
}
}
set {
if (value == null)
throw new ArgumentNullException (nameof (value));
using (var cfString = new CFString (Name)) {
var dics = new NSDictionary [value.Length];
for (var i = 0; i < value.Length; i++) {
dics [i] = value [i].Dictionary;
}
using (var array = NSArray.FromNSObjects (dics)) {
var result = (AudioConverterError) AudioUnitExtensionSetComponentList (cfString.Handle, array.Handle);
switch (result) {
case AudioConverterError.None:
return;
default:
throw new InvalidOperationException ($"ComponentList could not be set, error {result.ToString ()}");

}
}
}
}
}

#endif // !COREBUILD
}

Expand All @@ -241,4 +462,4 @@ public static class AudioComponentConfigurationInfo {
public static NSString ValidationResult = new NSString ("ValidationResult");
}
#endif
}
}
59 changes: 58 additions & 1 deletion src/AudioUnit/AudioUnit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ public enum AudioUnitStatus { // Implictly cast to OSType
Initialized = -10849,
InvalidOfflineRender = -10848,
Unauthorized = -10847,
[iOS (11,0), Mac (10,13, onlyOn64: true), TV (11,0), NoWatch]
MidiOutputBufferFull = -66753,
[iOS (11,0), Mac (10,13, onlyOn64: true), TV (11,0), NoWatch]
ExtensionNotFound = -66744,
}

public enum AudioComponentStatus { // Implictly cast to OSType
Expand Down Expand Up @@ -352,6 +356,50 @@ public enum AudioUnitClumpID // UInt32 in AudioUnitParameterInfo
System = 0
}

public enum AUParameterEventType : uint
{
Immediate = 1,
Ramped = 2,
}

[StructLayout (LayoutKind.Sequential)]
public struct AudioUnitParameterEvent
{
public uint Scope;
public uint Element;
public uint Parameter;
public AUParameterEventType EventType;

[StructLayout (LayoutKind.Explicit)]
public struct EventValuesStruct
{
[StructLayout (LayoutKind.Sequential)]
public struct RampStruct
{
public int StartBufferOffset;
public uint DurationInFrames;
public float StartValue;
public float EndValue;
}


[FieldOffset (0)]
public RampStruct Ramp;

[StructLayout (LayoutKind.Sequential)]
public struct ImmediateStruct
{
public uint BufferOffset;
public float Value;
}

[FieldOffset (0)]
public ImmediateStruct Immediate;
}

public EventValuesStruct EventValues;
}

public class AudioUnit : IDisposable, XamCore.ObjCRuntime.INativeObject
{
internal IntPtr handle;
Expand Down Expand Up @@ -873,6 +921,11 @@ public AudioUnitStatus SetParameter (AudioUnitParameterType type, float value, A
return AudioUnitSetParameter (handle, type, scope, audioUnitElement, value, 0);
}

public AudioUnitStatus ScheduleParameter (AudioUnitParameterEvent inParameterEvent, uint inNumParamEvents)
{
return AudioUnitScheduleParameters (handle, inParameterEvent, inNumParamEvents);
}

public void Dispose()
{
Dispose (true);
Expand Down Expand Up @@ -1032,6 +1085,9 @@ static extern AudioUnitStatus AudioUnitGetPropertyInfo (IntPtr inUnit, AudioUnit
static extern AudioUnitStatus AudioUnitSetParameter (IntPtr inUnit, AudioUnitParameterType inID, AudioUnitScopeType inScope,
uint inElement, float inValue, uint inBufferOffsetInFrames);

[DllImport (Constants.AudioUnitLibrary)]
static extern AudioUnitStatus AudioUnitScheduleParameters (IntPtr inUnit, AudioUnitParameterEvent inParameterEvent, uint inNumParamEvents);

#if MONOMAC
[DllImport (Constants.AudioUnitLibrary)]
static extern int AudioObjectGetPropertyData (
Expand Down Expand Up @@ -1954,7 +2010,8 @@ public enum AUSpatializationAlgorithm : uint
Hrtf = 2,
SoundField = 3,
VectorBasedPanning = 4,
StereoPassThrough = 5
StereoPassThrough = 5,
HrtfHQ = 6,
}

public enum AU3DMixerAttenuationCurve : uint
Expand Down
Loading