Class WaveFile
Represents a WAV audio file, exposing its channels, sample rate, bit depth, and duration, and providing methods to read normalized audio samples.
public sealed class WaveFile : IDisposable
- Inheritance
-
WaveFile
- Implements
- Inherited Members
Constructors
- WaveFile(byte[])
Initializes a new WaveFile by reading WAV data from the given in-memory buffer.
- WaveFile(Stream, bool)
Initializes a new WaveFile from the provided
stream.
- WaveFile(float[], uint)
Creates a new WaveFile instance from normalized mono float samples. The provided samples array is used directly without copying.
- WaveFile(string)
Initializes a new WaveFile by opening the WAV file at the specified
path, reading its audio header information and locating the data section.
Properties
- BitsPerSample
Gets the bit depth per sample in the WAV stream.
- Channels
Gets the number of audio channels in the WAV stream.
- Duration
Gets the total duration of the audio in the WAV stream.
- EnableLowPassFilter
Gets or sets whether to apply a Hamming-windowed sinc FIR low-pass filter before resampling to 16 kHz. Defaults to true (filter enabled). When enabled, reduces aliasing and smooths audio at the cost of extra CPU usage and processing time.
- SampleRate
Gets the sample rate, in hertz, of the WAV stream.
Methods
- CalculateRms(int, int, CancellationToken)
Calculates the Root Mean Square (RMS) energy for a specific sample range.
- CalculateRms(CancellationToken)
Calculates the Root Mean Square (RMS) energy of the entire audio.
- CalculateRms(TimeSpan, TimeSpan, CancellationToken)
Calculates the Root Mean Square (RMS) energy for a specific time range.
- GetChannel16kSamples(int, CancellationToken)
Returns normalized samples for a single channel, resampled to 16 kHz if necessary.
- GetMono16kSamples(CancellationToken)
Returns the per-frame average across all channels, normalized into [-1, 1], and resampled to 16 kHz if necessary.
- IsValidWaveFile(byte[])
Determines whether the specified in-memory buffer contains a valid WAV file.
- IsValidWaveFile(Stream)
Determines whether the WAV data in the specified stream is valid.
- IsValidWaveFile(string)
Determines whether the WAV file at the specified path is valid.
- LowPassFilter(float[], int, float, int)
Applies a Hamming-windowed sinc FIR low-pass filter to the input data. Uses SIMD vectorization and parallel processing for improved performance.
- SaveAsMono16k(Stream, CancellationToken)
Saves the current WAV as a 16 kHz, mono, 16-bit PCM WAV file to the given stream. The stream is left open after writing.
- SaveAsMono16k(string, CancellationToken)
Saves the current WAV as a 16 kHz, mono, 16-bit PCM WAV file to the given path.