views:

951

answers:

1

I am trying to load a *.wav file to a byte array using C# 3.0 and .NET 3.5 like this:

  var fs = File.Open(filedialog.FileName, FileMode.Open,FileAccess.Read);
  long numBytes = new FileInfo(filedialog.FileName).Length;
  BinaryReader br = new BinaryReader(fs);
  byte[] bytes = br.ReadBytes((int)numBytes);

From byte[58] and to the end (~50k bytes) all values are 127 or 128 (I guess the first ~58 bytes are header stuff?).

The wave file is playing fine in Windows media player and other players, and I am sure it is nothing wrong with it (it's recorded with the sound recorder in WinXP).

Wave file info:

BitRate: 176kbps
Audio sample size: 8bit
Audio sample rate: 22kHz
Audio format: PCM

When I try to play the byte stream using the .NET SoundPlayer it sounds terrible :-) Any idèas?

[SOLVED]
This was not the problem after all, so I'll have to continue my search for the real bug.

+1  A: 

The code looks all right, as far as I can see.

You could try the simpler code:

byte[] bytes = File.ReadAllBytes(filedialog.FileName);
Guffa
I have tried that too, no luck.
Ezombort
Would it be possible for you to post the file somewhere so that we can look at it and test it?
Guffa
Not really since it's work related, but the file looks fine in the hex editor and plays fine in all sound players I have tried.
Ezombort
Try it with a standard windows sound? That would help narrow down that it's your code and not the file for whatever reason.
chsh
It was neither, I was fooled by another strange issue. Thanks for your help though :)
Ezombort