I have not tested your code and at this moment I have no time for this. But I can tell you a thing that is worth to know: the .wav file format is a quite complex format with many possible bitrates...