The real test of a writer is that a reader gets back exactly what you put in. Today you write samples to a file and read them back, proving the whole read/write path is lossless.
Write samples to WAV bytes, read them back, and confirm the samples and format match.
A writer you cannot verify is a writer you cannot trust, and the cleanest
verification is a round trip: take samples, write them to bytes, read those
bytes back, and assert you got the identical samples and format. WriteSamples ties
the chapter together - interleave the channels, encode them to 16-bit bytes, wrap
them in a file - and ReadSamples from lesson 13 unwinds all of it. If the two are
true inverses, the loop is lossless.
Test it on values that stress the extremes and the channel logic at once: the
[0, 32767, -32768, -1] mono case covers both signed edges, and a stereo case
proves interleave and de-interleave undo each other while the format survives the
trip. This is the payoff of the writing chapter - not a single new algorithm but the
proof that everything built so far composes into a correct, symmetric codec. From
here on you stop moving bytes and start changing the audio itself.
// WriteSamples: interleave -> encode16 -> buildFilefunc WriteSamples(f Format, channels [][]int) []byte {flat := interleave(channels)data := encode16(flat)return buildFile(f, data)}// round-trip: ReadSamples(WriteSamples(f, chans)) == (f, chans)