WAV support, improve PCM writing code