Vixen
02b45cc4
csharp
public sealed class WaveDecoder

Reads a RIFF/WAVE file.

No guide page documents this yet — the page shows what the code says about itself.

Remarks

Written here rather than taken from a package, which is the opposite of the choice made for images. A PNG decoder is a compression implementation and writing one would be foolish; a WAV file is a chunk header and then the samples, and the entire specification that matters fits on this page. A dependency for it would be a licence, a supply-chain entry and a version to track, in exchange for about a hundred lines.

The chunks are walked, not assumed. The naive reader — seek 44 bytes, read the rest — works on the files a tool writes and fails on the ones a DAW writes, because those carry LIST, fact, bext and cue chunks between the header and the samples. It fails by reading metadata as audio, which sounds like a burst of noise at the start of the clip and is diagnosed by ear rather than by a stack trace.

Every uncompressed layout the format has, and nothing else. 8-bit unsigned, 16-, 24- and 32-bit signed, and 32- and 64-bit float, in plain PCM and in WAVE_FORMAT_EXTENSIBLE — which is what anything above two channels or above 16 bits is written as. ADPCM and the rest are compressed formats hiding inside a WAV, and are refused by name.

Fields and properties (1)

  • public IReadOnlyList<string> Extensions

    Which extensions it reads, lowercase and with their leading dots.

Methods (2)

  • public AudioClip Decode(Stream stream, string extension)

    Decodes a file.

  • public static AudioClip Decode(ReadOnlySpan<byte> bytes)

    Decodes a file already in memory.

Used by (2)

  • AudioDecodersVixen.Editor.Assets
  • WaveDecoderTestsVixen.Editor.Assets.Tests