Function toWAVFile

Converts audio data of supported types to WAV file format as a ubyte[] buffer.

ubyte[] toWAVFile(T) (
  const T[] audioData,
  uint sampleRate,
  ushort numChannels
)
if (is(T == ubyte) || is(T == byte) || is(T == short) || is(T == int) || is(T == float));

This function constructs a WAV file header and appends audio data to create a valid WAV file format byte array. It supports the following data types: - ubyte (8-bit unsigned) - byte (8-bit signed) -> mapped to unsigned 8 bit - short (16-bit signed) - int (32-bit signed) - float (32-bit float)

Parameters

NameDescription
T The type of audio data (e.g., ubyte, short, int, float).
audioData The raw audio data to be written to the WAV file.
sampleRate The sampling rate of the audio data.
numChannels The number of audio channels (1 for mono, 2 for stereo).

Returns

A ubyte[] containing the WAV file formatted data.