wav: Correct RIFF and data size calculation and buffer write operations.