public void CreateTokenByAddingParameterRecordingObserver() { TestRuntime.AssertXcodeVersion(7, 0); const ulong address = 0; const float newValue = 10f; bool recordingObserverInvoked = false; var completion = new ManualResetEvent(false); using (var parameter = CreateAUParameter()) { using (var tree = AUParameterTree.CreateTree(new AUParameterNode[] { parameter })) { Exception ex = null; var recordingObserver = tree.CreateTokenByAddingParameterRecordingObserver((nint numberOfEvents, ref AURecordedParameterEvent events) => { try { Assert.True(numberOfEvents == 1, $"Number of events was wrong. Expected {1} but was {numberOfEvents}"); Assert.True(events.Address == address, $"Address was wrong. Expected {address} but was {events.Address}"); Assert.True(events.Value == newValue, $"Value was wrong. Expected {newValue} but was {events.Value}"); recordingObserverInvoked = true; } catch (Exception e) { ex = e; } finally { completion.Set(); } }); Assert.True(recordingObserver.ObserverToken != IntPtr.Zero, "TokenByAddingParameterRecordingObserver return zero pointer for recording observer."); parameter.Value = newValue; completion.WaitOne(TimeSpan.FromSeconds(1)); Assert.IsNull(ex, "Exceptions"); Assert.True(recordingObserverInvoked, "Recording observer was not invoked when parameter value was changed."); } } }
public void CreateTokenByAddingParameterRecordingObserver() { if (!TestRuntime.CheckSystemAndSDKVersion(9, 0)) { Assert.Ignore("Ignoring AudioUnitv3 tests: Requires iOS9+"); } const ulong address = 0; const float newValue = 10f; bool recordingObserverInvoked = false; var completion = new ManualResetEvent(false); using (var parameter = CreateAUParameter()) { using (var tree = AUParameterTree.CreateTree(new AUParameterNode[] { parameter })) { var recordingObserver = tree.CreateTokenByAddingParameterRecordingObserver((nint numberOfEvents, ref AURecordedParameterEvent events) => { Assert.True(numberOfEvents == 1, $"Number of events was wrong. Expected {1} but was {numberOfEvents}"); Assert.True(events.Address == address, $"Address was wrong. Expected {address} but was {events.Address}"); Assert.True(events.Value == newValue, $"Value was wrong. Expected {newValue} but was {events.Value}"); recordingObserverInvoked = true; completion.Set(); }); Assert.True(recordingObserver.ObserverToken != IntPtr.Zero, "TokenByAddingParameterRecordingObserver return zero pointer for recording observer."); parameter.Value = newValue; completion.WaitOne(TimeSpan.FromSeconds(1)); Assert.True(recordingObserverInvoked, "Recording observer was not invoked when paramter value was changed."); } } }
public MyAudioUnit(AudioComponentDescription description, AudioComponentInstantiationOptions options, out NSError error) : base(description, options, out error) { // Create parameter objects. AUParameter param1 = AUParameterTree.CreateParameter( "param1", "Parameter 1", 0, 0, 100, AudioUnitParameterUnit.Percent, string.Empty, 0, null, null ); // Initialize the parameter values. param1.Value = .5f; // Create the parameter tree. parameterTree = AUParameterTree.CreateTree(new[] { param1 }); // Create the input and output busses. // Create the input and output bus arrays. // A function to provide string representations of parameter values. parameterTree.ImplementorStringFromValueCallback = (AUParameter param, ref float?value) => { switch (param.Address) { case 0: return((NSString)value?.ToString()); default: return(new NSString("?")); } }; MaximumFramesToRender = 512; }
static AUParameter CreateAUParameter() { return(AUParameterTree.CreateParameter("resonance", "Resonance", 0, -20, 20, AudioUnitParameterUnit.Decibels, null, (AudioUnitParameterOptions)0, null, null)); }