Skip to content

Commit

Permalink
add missing XML docs for NAudio.Extras
Browse files Browse the repository at this point in the history
  • Loading branch information
markheath committed Feb 13, 2024
1 parent fb1c044 commit a106da4
Show file tree
Hide file tree
Showing 8 changed files with 113 additions and 3 deletions.
3 changes: 3 additions & 0 deletions NAudio.Asio/ASIODriverExt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ public class AsioDriverExt
private int bufferSize;
private int outputChannelOffset;
private int inputChannelOffset;
/// <summary>
/// Reset Request Callback
/// </summary>
public Action ResetRequestCallback;

/// <summary>
Expand Down
12 changes: 12 additions & 0 deletions NAudio.Extras/AudioPlaybackEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ public class AudioPlaybackEngine : IDisposable
private readonly IWavePlayer outputDevice;
private readonly MixingSampleProvider mixer;

/// <summary>
/// Audio Playback Engine
/// </summary>
public AudioPlaybackEngine(int sampleRate = 44100, int channelCount = 2)
{
outputDevice = new WaveOutEvent();
Expand All @@ -21,6 +24,9 @@ public AudioPlaybackEngine(int sampleRate = 44100, int channelCount = 2)
outputDevice.Play();
}

/// <summary>
/// Fire and forget playback of sound
/// </summary>
public void PlaySound(string fileName)
{
var input = new AudioFileReader(fileName);
Expand All @@ -40,6 +46,9 @@ private ISampleProvider ConvertToRightChannelCount(ISampleProvider input)
throw new NotImplementedException("Not yet implemented this channel count conversion");
}

/// <summary>
/// Fire and forget playback of a cached sound
/// </summary>
public void PlaySound(CachedSound sound)
{
AddMixerInput(new CachedSoundSampleProvider(sound));
Expand All @@ -50,6 +59,9 @@ private void AddMixerInput(ISampleProvider input)
mixer.AddMixerInput(ConvertToRightChannelCount(input));
}

/// <summary>
/// Disposes this instance
/// </summary>
public void Dispose()
{
outputDevice.Dispose();
Expand Down
10 changes: 10 additions & 0 deletions NAudio.Extras/AutoDisposeFileReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,19 @@ public class AutoDisposeFileReader : ISampleProvider
{
private readonly ISampleProvider reader;
private bool isDisposed;

/// <summary>
/// Creates a new file reader that disposes the source reader when it finishes
/// </summary>
public AutoDisposeFileReader(ISampleProvider reader)
{
this.reader = reader;
WaveFormat = reader.WaveFormat;
}

/// <summary>
/// Reads samples from this file reader
/// </summary>
public int Read(float[] buffer, int offset, int count)
{
if (isDisposed)
Expand All @@ -33,6 +40,9 @@ public int Read(float[] buffer, int offset, int count)
return read;
}

/// <summary>
/// The WaveFormat of this file reader
/// </summary>
public WaveFormat WaveFormat { get; }
}
}
11 changes: 11 additions & 0 deletions NAudio.Extras/CachedSound.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,19 @@ namespace NAudio.Extras
/// </summary>
public class CachedSound
{
/// <summary>
/// Audio data
/// </summary>
public float[] AudioData { get; }

/// <summary>
/// Format of the audio
/// </summary>
public WaveFormat WaveFormat { get; }

/// <summary>
/// Creates a new CachedSound from a file
/// </summary>
public CachedSound(string audioFileName)
{
using (var audioFileReader = new AudioFileReader(audioFileName))
Expand Down
12 changes: 12 additions & 0 deletions NAudio.Extras/Equalizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ public class Equalizer : ISampleProvider
private readonly int bandCount;
private bool updated;

/// <summary>
/// Creates a new Equalizer
/// </summary>
public Equalizer(ISampleProvider sourceProvider, EqualizerBand[] bands)
{
this.sourceProvider = sourceProvider;
Expand All @@ -43,14 +46,23 @@ private void CreateFilters()
}
}

/// <summary>
/// Update the equalizer settings
/// </summary>
public void Update()
{
updated = true;
CreateFilters();
}

/// <summary>
/// Gets the WaveFormat of this Sample Provider
/// </summary>
public WaveFormat WaveFormat => sourceProvider.WaveFormat;

/// <summary>
/// Reads samples from this Sample Provider
/// </summary>
public int Read(float[] buffer, int offset, int count)
{
int samplesRead = sourceProvider.Read(buffer, offset, count);
Expand Down
12 changes: 12 additions & 0 deletions NAudio.Extras/EqualizerBand.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
namespace NAudio.Extras
{
/// <summary>
/// Equalizer Band
/// </summary>
public class EqualizerBand
{
/// <summary>
/// Frequency
/// </summary>
public float Frequency { get; set; }
/// <summary>
/// Gain
/// </summary>
public float Gain { get; set; }
/// <summary>
/// Bandwidth
/// </summary>
public float Bandwidth { get; set; }
}
}
52 changes: 49 additions & 3 deletions NAudio.Extras/SampleAggregator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,28 @@ namespace NAudio.Extras
/// </summary>
public class SampleAggregator : ISampleProvider
{
// volume
/// <summary>
/// Raised to indicate the maximum volume level in this period
/// </summary>
public event EventHandler<MaxSampleEventArgs> MaximumCalculated;
private float maxValue;
private float minValue;
/// <summary>
/// Notification count, number of samples between MaximumCalculated events
/// </summary>
public int NotificationCount { get; set; }
int count;

// FFT
/// <summary>
/// Raised to indicate that a block of samples has had an FFT performed on it
/// </summary>
public event EventHandler<FftEventArgs> FftCalculated;

/// <summary>
/// If true, performs an FFT on each block of samples
/// </summary>
public bool PerformFFT { get; set; }

private readonly Complex[] fftBuffer;
private readonly FftEventArgs fftArgs;
private int fftPos;
Expand All @@ -29,6 +41,11 @@ public class SampleAggregator : ISampleProvider

private readonly int channels;

/// <summary>
/// Creates a new SampleAggregator
/// </summary>
/// <param name="source">source sample provider</param>
/// <param name="fftLength">FFT length, must be a power of 2</param>
public SampleAggregator(ISampleProvider source, int fftLength = 1024)
{
channels = source.WaveFormat.Channels;
Expand All @@ -48,7 +65,9 @@ static bool IsPowerOfTwo(int x)
return (x & (x - 1)) == 0;
}


/// <summary>
/// Reset the volume calculation
/// </summary>
public void Reset()
{
count = 0;
Expand Down Expand Up @@ -81,8 +100,14 @@ private void Add(float value)
}
}

/// <summary>
/// Gets the WaveFormat of this Sample Provider
/// </summary>
public WaveFormat WaveFormat => source.WaveFormat;

/// <summary>
/// Reads samples from this sample provider
/// </summary>
public int Read(float[] buffer, int offset, int count)
{
var samplesRead = source.Read(buffer, offset, count);
Expand All @@ -95,25 +120,46 @@ public int Read(float[] buffer, int offset, int count)
}
}

/// <summary>
/// Max sample event args
/// </summary>
public class MaxSampleEventArgs : EventArgs
{
/// <summary>
/// Creates a new MaxSampleEventArgs
/// </summary>
[DebuggerStepThrough]
public MaxSampleEventArgs(float minValue, float maxValue)
{
MaxSample = maxValue;
MinSample = minValue;
}
/// <summary>
/// Maximum sample value in this period
/// </summary>
public float MaxSample { get; private set; }
/// <summary>
/// Minimum sample value in this period
/// </summary>
public float MinSample { get; private set; }
}

/// <summary>
/// FFT Event Args
/// </summary>
public class FftEventArgs : EventArgs
{
/// <summary>
/// Creates a new FFTEventArgs
/// </summary>
[DebuggerStepThrough]
public FftEventArgs(Complex[] result)
{
Result = result;
}
/// <summary>
/// Result of FFT
/// </summary>
public Complex[] Result { get; private set; }
}
}
4 changes: 4 additions & 0 deletions NAudio.Wasapi/CoreAudioApi/AudioClientStreamFlags.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ public enum AudioClientStreamFlags : uint

}

/* not currently used
/// <summary>
/// AUDIOCLIENT_ACTIVATION_PARAMS
/// https://docs.microsoft.com/en-us/windows/win32/api/audioclientactivationparams/ns-audioclientactivationparams-audioclient_activation_params
Expand All @@ -79,6 +81,8 @@ struct AudioClientProcessLoopbackParams
public ProcessLoopbackMode ProcessLoopbackMode;
}
*/

/// <summary>
/// PROCESS_LOOPBACK_MODE
/// https://docs.microsoft.com/en-us/windows/win32/api/audioclientactivationparams/ne-audioclientactivationparams-process_loopback_mode
Expand Down

0 comments on commit a106da4

Please sign in to comment.