Skip to content

Commit

Permalink
[AudioToolbox] Updated bindings to Xcode 9 beta 3.
Browse files Browse the repository at this point in the history
  • Loading branch information
mandel-macaque committed Jul 16, 2017
1 parent 1065cdb commit 24454ec
Show file tree
Hide file tree
Showing 6 changed files with 380 additions and 6 deletions.
2 changes: 2 additions & 0 deletions src/AudioToolbox/AudioFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public enum AudioFileType { // UInt32 AudioFileTypeID
AIFF = 0x41494646, // AIFF
AIFC = 0x41494643, // AIFC
WAVE = 0x57415645, // WAVE
RF64 = 0x52463634, // RF64
SoundDesigner2 = 0x53643266, // Sd2f
Next = 0x4e655854, // NeXT
MP3 = 0x4d504733, // MPG3
Expand All @@ -60,6 +61,7 @@ public enum AudioFileType { // UInt32 AudioFileTypeID
ThreeGP = 0x33677070, // 3gpp
ThreeGP2 = 0x33677032, // 3gp2
AMR = 0x616d7266, // amrf
FLAC = 0x666c6163, // flac
}

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

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 NSString[] IOKitUserClient {
get {
return GetArray<NSString> (userClientK);
}
set {
SetArrayValue <NSString> (userClientK, value);
}
}

public NSString[] MachLookUpGlobalName {
get {
return GetArray<NSString> (globalNameK);
}
set {
SetArrayValue <NSString> (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 NSString[] Tags {
get {
return GetArray<NSString> (tagsK);
}
set {
SetArrayValue <NSString> (tagsK, value);
}
}
}

#endif


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

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

[NoWatch, NoTV, Mac (10,13), iOS (11,0)]
public AudioComponentInfo[] ComponentList {
get {
using (var cfString = new CFString (Name)) {
var cHandle = CopyComponentList (cfString.Handle);
if (cHandle == IntPtr.Zero)
return null;
using (var nsArray = Runtime.GetNSObject<NSArray> (cHandle)) {
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 {
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) SetComponentList (cfString.Handle, array.Handle);
switch (result) {
case AudioConverterError.HardwareInUse:
throw new InvalidOperationException ("ComponentList could not be set: 'Hardware is in use.'");
case AudioConverterError.NoHardwarePermission:
throw new InvalidOperationException ("ComponentList could not be set: 'No Hardware permission.'");
case AudioConverterError.None:
return;
default:
throw new InvalidOperationException ("ComponentList could not be set.");

}
}
}
}
}

#endif // !COREBUILD
}

Expand All @@ -241,4 +446,4 @@ public static class AudioComponentConfigurationInfo {
public static NSString ValidationResult = new NSString ("ValidationResult");
}
#endif
}
}
60 changes: 59 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 EventValues
{
[StructLayout (LayoutKind.Sequential)]
public struct Ramp
{
public int startBufferOffset;
public uint durationInFrames;
public float startValue;
public float endValue;
}


[FieldOffset (0)]
public Ramp ramp;

[StructLayout (LayoutKind.Sequential)]
public struct Immediate
{
public uint bufferOffset;
public float value;
}

[FieldOffset (0)]
public Immediate immediate;
}

public EventValues 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,10 @@ static extern AudioUnitStatus AudioUnitGetPropertyInfo (IntPtr inUnit, AudioUnit
static extern AudioUnitStatus AudioUnitSetParameter (IntPtr inUnit, AudioUnitParameterType inID, AudioUnitScopeType inScope,
uint inElement, float inValue, uint inBufferOffsetInFrames);

[iOS (2,0)]
[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 +2011,8 @@ public enum AUSpatializationAlgorithm : uint
Hrtf = 2,
SoundField = 3,
VectorBasedPanning = 4,
StereoPassThrough = 5
StereoPassThrough = 5,
HRTFHQ = 6,
}

public enum AU3DMixerAttenuationCurve : uint
Expand Down
Loading

0 comments on commit 24454ec

Please sign in to comment.