Ezombort
Ezombort

Reputation: 1912

C# - Bogus data when loading a *.wav file to byte array

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.

Upvotes: 0

Views: 5479

Answers (1)

Guffa
Guffa

Reputation: 700182

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

You could try the simpler code:

byte[] bytes = File.ReadAllBytes(filedialog.FileName);

Upvotes: 2

Related Questions