Fixed bug in wav file write function