BUG: io/wavfile: safer writing directly from buffer

Fixes gh-2928
Merge pull request #2933 from pv/wavfile-buf

BUG: io/wavfile: safer writing directly from buffer