BUG: io/wavfile: safer writing directly from buffer

Fixes gh-2928