Oakrey.Audio 2.0.4

dotnet add package Oakrey.Audio --version 2.0.4
                    
NuGet\Install-Package Oakrey.Audio -Version 2.0.4
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Oakrey.Audio" Version="2.0.4" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Oakrey.Audio" Version="2.0.4" />
                    
Directory.Packages.props
<PackageReference Include="Oakrey.Audio" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Oakrey.Audio --version 2.0.4
                    
#r "nuget: Oakrey.Audio, 2.0.4"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Oakrey.Audio@2.0.4
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Oakrey.Audio&version=2.0.4
                    
Install as a Cake Addin
#tool nuget:?package=Oakrey.Audio&version=2.0.4
                    
Install as a Cake Tool

Oakrey.Audio

A Windows .NET library built on NAudio for audio recording, playback, synthesis, mixing, and signal analysis. The central type is FFTAudioSample, which wraps any ISampleProvider and adds an online STFT/FFT pipeline, reactive state tracking via IObservable<State>, and spectrum accumulation into SpectraList.

Main features

  • FFT / STFT pipeline - FFTAudioSample feeds every read through SampleAggregator and accumulates frequency spectra in SpectraList. ShortTimeFourierTransformation provides a standalone STFT entry point.
  • Playback - Player loads any audio file or ISampleProvider, supports configurable start/length offsets, volume control, output device selection, and SaveToFile.
  • Synthesis - Synthesizers generates sine, square, sawtooth, pink noise, and sweep waveforms at configurable frequency and gain, ready to play or compare.
  • Mixing - Mixer (playable) and SampleCreators.Mixer (analysis-only) wrap NAudio's MixingSampleProvider with automatic format conversion on AddAudioStream.
  • Recording - FileRecorder streams microphone input directly to a WAV file. ObservableRecorder publishes a completed FFTAudioSample via IObservable<FFTAudioSample> on StopRecording.
  • Audio comparators - ComparatorSNRSeg computes segmented SNR with Hann windowing and configurable overlap. ComparatorFwSNRSeg computes frequency-weighted segmented SNR. ComparatorLogLikelihoodRatio computes LLR using a Levinson-Durbin AR model.
  • Device enumeration - AudioDevicesEnumerator lists all WaveIn / WaveOut devices by name and resolves device indices for recording and playback.
  • File I/O - WaveAudioFileAccess loads a region of a WAV file into an FFTAudioSample and saves an FFTAudioSample back to a WAV file.

Architecture

classDiagram
    class FFTAudioSample {
        +SpectraList ListOfFrequencySpectra
        +IObservable~State~ Status
        +bool GetSpectra
        +Play() Pause() Stop() Resume() Record()
    }
    class AudioBasePlayable {
        +byte Volume
        +Play(deviceName)
        +SaveToFile(filename)
    }
    class RecorderBase {
        +TimeSpan RecordTime
        +bool SpectrumComputing
        +StartRecording()
        +StopRecording()
    }

    FFTAudioSample <|-- AudioBasePlayable
    FFTAudioSample <|-- RecorderBase
    AudioBasePlayable <|-- Player
    AudioBasePlayable <|-- Players_Mixer
    AudioBasePlayable <|-- Synthesizers
    RecorderBase <|-- FileRecorder
    RecorderBase <|-- ObservableRecorder

    class ComparatorBase
    ComparatorBase <|-- ComparatorSNRSeg
    ComparatorBase <|-- ComparatorFwSNRSeg
    ComparatorBase <|-- ComparatorLogLikelihoodRatio

Project structure

Path Purpose
FFTAudioSample.cs Core type: ISampleProvider + online FFT + reactive State
ISpectra.cs Interface for FFT data and frequency index resolution
State.cs Playing / Paused / Stopped / Recording enum
Players/Player.cs File and ISampleProvider playback with offset support
Players/Synthesizers.cs Playable signal generators (sine, square, sawtooth, sweep, pink noise)
Players/Mixer.cs Playable multi-input mixer
Players/FileRecorder.cs Microphone to WAV file recorder
Players/ObservableRecorder.cs Microphone recorder that publishes FFTAudioSample on stop
Players/AudioBasePlayable.cs Base for all playable types (WaveOut management, volume, device)
Players/RecorderBase.cs Base for all recorder types (WaveIn management, spectrum toggle)
SampleCreators/ Mixer (analysis), Synthesizers (analysis), WaveAudioFileAccess
AudioComparators/ ComparatorSNRSeg, ComparatorFwSNRSeg, ComparatorLogLikelihoodRatio
AudioLib/ SampleAggregator, ShortTimeFourierTransformation
Mathematic/ Vector, Matrix, NumericArrayExtensions, NumericExtensions
AudioDevicesEnumerator.cs WaveIn / WaveOut device discovery
SpectraList.cs, SampleList.cs Spectrum and sample collection types

Requirements

  • .NET 10 or higher
  • Windows only (net10.0-windows, uses WaveInEvent / WaveOutEvent)
  • NAudio 2.2.1

Installation

dotnet add package Oakrey.Audio

Or via the Visual Studio NuGet Package Manager: search for Oakrey.Audio.

Example usage

Play a WAV file on a specific output device

using Oakrey.Audio.Players;

using Player player = Player.Create("speech.wav");
player.PlaybackStart = TimeSpan.FromSeconds(2);
player.PlaybackLength = TimeSpan.FromSeconds(5);
player.Volume = 80;
player.Play("Speakers (Realtek High Definition Audio)");

Record microphone input to a file

using Oakrey.Audio.Players;

using FileRecorder recorder = FileRecorder.Create("capture.wav", "Microphone Array");
recorder.RecordTime = TimeSpan.FromSeconds(10);
recorder.StartRecording();
// ... wait ...
recorder.StopRecording();

Reactive recording with FFT spectrum

using Oakrey.Audio;
using Oakrey.Audio.Players;

using ObservableRecorder recorder = ObservableRecorder.Create("Microphone Array");
recorder.SpectrumComputing = true;

using IDisposable sub = recorder.SampleRecorded.Subscribe(sample =>
{
    SpectraList spectra = sample.ListOfFrequencySpectra;
    Console.WriteLine($"Captured {spectra.Count} spectra frames");
});

recorder.StartRecording();
await Task.Delay(TimeSpan.FromSeconds(3));
recorder.StopRecording();

Compare two audio samples with segmented SNR

using Oakrey.Audio;
using Oakrey.Audio.AudioComparators;
using Oakrey.Audio.SampleCreators;

FFTAudioSample reference = WaveAudioFileAccess.LoadFromFile("ref.wav", TimeSpan.Zero, TimeSpan.FromSeconds(5));
FFTAudioSample distorted = WaveAudioFileAccess.LoadFromFile("dist.wav", TimeSpan.Zero, TimeSpan.FromSeconds(5));

ComparatorSNRSeg comparator = new(reference, distorted);
float snr = comparator.Analyze(CancellationToken.None);
Console.WriteLine($"SNR: {snr:F2} dB");

Synthesize and play a sine wave

using Oakrey.Audio.Players;

using Synthesizers synth = Synthesizers.CreateSine(TimeSpan.FromSeconds(3), frequency: 440.0);
synth.Volume = 60;
synth.Play();

Development notes

  • FFTAudioSample inherits from DisposableBase (Oakrey.Disposables). Always dispose instances created with new or factory methods.
  • The FFT window length is fixed at 2048 samples. Spectrum frames are accumulated in SpectraList only while GetSpectra = true.
  • RecorderBase.RecordTime = TimeSpan.Zero means unlimited recording duration.
  • AudioDevicesEnumerator includes device index -1 (the Windows default device mapper) in its enumeration; index -1 is valid for WaveIn/WaveOut.
  • ComparatorLogLikelihoodRatio uses a Levinson-Durbin AR model internally; AR order defaults apply and the computation supports CancellationToken.
  • The library targets net10.0-windows exclusively; it cannot be used in cross-platform or server-side (Linux/macOS) builds.

License

MIT - Copyright (c) Oakrey 2016-present. Repository: https://dev.azure.com/oakrey/OpenPackages/_git/Drivers

Product Compatible and additional computed target framework versions.
.NET net10.0-windows7.0 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.0.4 97 5/22/2026
2.0.3 94 5/15/2026
2.0.2 91 5/14/2026
2.0.1 127 2/2/2026
2.0.0 287 11/14/2025
1.1.0 268 6/18/2025
1.0.0 313 4/17/2025