Table of Contents

Class WavReader

Namespace
Sigil.Sound.Wav
Assembly
Sigil.Sound.dll

Decodes RIFF/WAVE data into an in-memory Sigil.Sound.AudioBuffer. Reads 8, 16, 24 and 32-bit integer PCM and 32-bit IEEE float, mono or stereo (mono is copied to both channels). The file's own sample rate is kept; playback converts it to the render rate. Stream-based, so it works without a file system.

public static class WavReader

Inheritance

Inherited Members

Methods

Read(Stream)

Decodes a WAV file from a stream. The stream is read to its end, so it does not need to be seekable.

public static AudioBuffer Read(Stream stream)

Parameters

stream Stream

A readable stream positioned at the first byte of the WAV file.

Returns

AudioBuffer

The decoded audio at the file's own sample rate.

Examples

using Sigil.Sound;

using var stream = File.OpenRead("pad.wav");
var pad = AudioBuffer.FromWav(stream);

Exceptions

InvalidDataException

The data is not a supported WAV file.

Read(ReadOnlySpan<byte>)

Decodes a WAV file that is already in memory. Use it for embedded resources or bytes received over a network.

public static AudioBuffer Read(ReadOnlySpan<byte> bytes)

Parameters

bytes ReadOnlySpan<byte>

The complete contents of a .wav file.

Returns

AudioBuffer

The decoded audio at the file's own sample rate. Samples that are not finite numbers become silence.

Examples

using Sigil.Sound;

var kick = AudioBuffer.FromWav(File.ReadAllBytes("kick.wav"));

Exceptions

InvalidDataException

The data is not a supported WAV file: only mono or stereo, and 8, 16, 24 or 32-bit PCM or 32-bit float.

ReadInfo(ReadOnlySpan<byte>)

Reads only what a WAV file says about itself: channels, sample rate, bit depth and length. It checks that the file is one Sigil.Sound.Wav.WavReader.Read(System.ReadOnlySpan{System.Byte}) can decode but does not decode it, so it is quick even for a long recording. Use it to accept or refuse a file, or to show its length, before paying for the full decode.

public static WavInfo ReadInfo(ReadOnlySpan<byte> bytes)

Parameters

bytes ReadOnlySpan<byte>

The complete contents of a .wav file.

Returns

WavInfo

The file's format and length.

Examples

using Sigil.Sound;
using Sigil.Sound.Wav;

// Check the file before paying for the full decode.
var info = WavReader.ReadInfo(File.ReadAllBytes("kick.wav"));
Console.WriteLine(info.Duration);   // the length in seconds

Exceptions

InvalidDataException

The data is not a supported WAV file: only mono or stereo, and 8, 16, 24 or 32-bit PCM or 32-bit float.