Skip to content

Commit

Permalink
Merge pull request naudio#599 from tebjan/asio-driver-reset-event
Browse files Browse the repository at this point in the history
[ASIO] Added DriverResetRequest event
  • Loading branch information
markheath authored Feb 24, 2020
2 parents 2ded654 + 21f20b3 commit 1f2cbc7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
3 changes: 3 additions & 0 deletions NAudio/Wave/Asio/ASIODriverExt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public class AsioDriverExt
private int bufferSize;
private int outputChannelOffset;
private int inputChannelOffset;
public Action ResetRequestCallback;

/// <summary>
/// Initializes a new instance of the <see cref="AsioDriverExt"/> class based on an already
Expand Down Expand Up @@ -338,6 +339,7 @@ private int AsioMessageCallBack(AsioMessageSelector selector, int value, IntPtr
case AsioMessageSelector.kAsioEngineVersion:
return 1;
case AsioMessageSelector.kAsioResetRequest:
ResetRequestCallback?.Invoke();
return 0;
case AsioMessageSelector.kAsioBufferSizeChange:
return 0;
Expand All @@ -356,6 +358,7 @@ private int AsioMessageCallBack(AsioMessageSelector selector, int value, IntPtr
case AsioMessageSelector.kAsioEngineVersion:
return 2;
case AsioMessageSelector.kAsioResetRequest:
ResetRequestCallback?.Invoke();
return 1;
case AsioMessageSelector.kAsioBufferSizeChange:
return 0;
Expand Down
14 changes: 14 additions & 0 deletions NAudio/Wave/WaveOutputs/AsioOut.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ public class AsioOut : IWavePlayer
/// </summary>
public event EventHandler<AsioAudioAvailableEventArgs> AudioAvailable;

/// <summary>
/// Occurs when the driver settings are changed by the user, e.g. in the control panel.
/// </summary>
public event EventHandler DriverResetRequest;

/// <summary>
/// Initializes a new instance of the <see cref="AsioOut"/> class with the first
/// available ASIO Driver.
Expand Down Expand Up @@ -97,6 +102,7 @@ public void Dispose()
{
driver.Stop();
}
driver.ResetRequestCallback = null;
driver.ReleaseDriver();
driver = null;
}
Expand Down Expand Up @@ -147,9 +153,17 @@ private void InitFromName(string driverName)

// Instantiate the extended driver
driver = new AsioDriverExt(basicDriver);
driver.ResetRequestCallback = OnDriverResetRequest;
this.ChannelOffset = 0;
}



private void OnDriverResetRequest()
{
DriverResetRequest?.Invoke(this, EventArgs.Empty);
}

/// <summary>
/// Shows the control panel
/// </summary>
Expand Down

0 comments on commit 1f2cbc7

Please sign in to comment.