473,396 Members | 1,765 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Problems with reading wav files

I am trying to access the data with in a wav file. I am testing with very
small files in order to keep the code simple to start with.

Basically, im writing the entire wav file to a byte[] using a fileStream.

The problem is that when reading back the data word by word and printing the
results on a general form, once the data chunk header has been read, i.e,
"data" and "chunk size", all the rest of the bytes in the array have the
value "0". Is there some thing strange about wav files that no one is telling
me. The code that reads the file into a byt array looks like this:

NOTE THE FILE IS SMALLER THAN 1MB AND IS NOT SILENT!

private int myBufferSize = 1024;
private string myFilePath "C:\\File.wav";

private byte[] myChunk = new byte[myBufferSize];

FileStream fileStream = new FileStream(myFilePath, FileMode.Open,
FileAccess.Read, FileShare.Read, myBufferSize, true);

fileStream.Read(myChunk, 0, myBufferSize);

Any help would be REALLY apprciated.

Thanks.

Nov 17 '05 #1
4 12776
This page might help...

http://www.yoda.arachsys.com/csharp/readbinary.html

Nov 17 '05 #2
Erpman <Er****@discussions.microsoft.com> wrote:
I am trying to access the data with in a wav file. I am testing with very
small files in order to keep the code simple to start with.

Basically, im writing the entire wav file to a byte[] using a fileStream.

The problem is that when reading back the data word by word and printing the
results on a general form, once the data chunk header has been read, i.e,
"data" and "chunk size", all the rest of the bytes in the array have the
value "0". Is there some thing strange about wav files that no one is telling
me. The code that reads the file into a byt array looks like this:

NOTE THE FILE IS SMALLER THAN 1MB AND IS NOT SILENT!

private int myBufferSize = 1024;
private string myFilePath "C:\\File.wav";

private byte[] myChunk = new byte[myBufferSize];

FileStream fileStream = new FileStream(myFilePath, FileMode.Open,
FileAccess.Read, FileShare.Read, myBufferSize, true);

fileStream.Read(myChunk, 0, myBufferSize);

Any help would be REALLY apprciated.


Well, you're only reading 1024 *bytes* of data at most - and you're not
guaranteed to read that, either. (See the page referenced in the other
post.)

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Nov 17 '05 #3
"Erpman" <Er****@discussions.microsoft.com> wrote in message
news:CB**********************************@microsof t.com...
The problem is that when reading back the data word by word and printing the
results on a general form, once the data chunk header has been read, i.e,
"data" and "chunk size", all the rest of the bytes in the array have the
value "0". Is there some thing strange about wav files that no one is telling
me. The code that reads the file into a byt array looks like this:


Wave files can come in some bizarre flavors, but in general, most are not too bad.

You always have a "format" chunk and a "data" chunk.
You may have other chunks as well.
They are not guaranteed to be in any particular order, although it is usually
"format", "data", other.

Each chunk has a small "chunk header" including it's ID and ChunkLength.

So far all of this sounds like it should be familiar to you.

/******* What I think is wrong **********/
Wave files have TONS of data.
A common sampling rate is 44100 samples per second.
If it represents 2 channel/16 bit data that is 176,400 bytes of data for 1 second of sound.
Your byte[1024] buffer would capture ~1/172 sec (assuming 2channel/16bit).

Before chasing this problem any further I suggest that you read a bigger block of data.
Most wave files start off with a bunch of zeros (silence).

---------------
Try this

//------- Psuedocode ------//
FileInfo fileinfo = new FileInfo("C:\\File.wav")
samples = dataChunk.Size/formatChunk.WBlockAlign; // total number of samples
byte[] buf = ReadDataChunk(fileinfo, samples);

// This should read the entire data block into a byte[]
public byte[] ReadDataChunk(FileInfo fileinfo, int samples)
{
byte[] buf;
using(FileStream fs = fileinfo.Open(FileMode.Open, FileAccess.Read, FileShare.Read))
using(BinaryReader br = new BinaryReader(fs))
{
fs.Position = dataChunk.Offset;
buf = br.ReadBytes(samples*4);
}
return (buf);
}

Hope this helps
Bill
Nov 17 '05 #4
Hi,

You can get details of the wav file format and others at this site:

http://www.wotsit.org/

Hope this helps,
Phil

"Erpman" wrote:
I am trying to access the data with in a wav file. I am testing with very
small files in order to keep the code simple to start with.

Basically, im writing the entire wav file to a byte[] using a fileStream.

The problem is that when reading back the data word by word and printing the
results on a general form, once the data chunk header has been read, i.e,
"data" and "chunk size", all the rest of the bytes in the array have the
value "0". Is there some thing strange about wav files that no one is telling
me. The code that reads the file into a byt array looks like this:

NOTE THE FILE IS SMALLER THAN 1MB AND IS NOT SILENT!

private int myBufferSize = 1024;
private string myFilePath "C:\\File.wav";

private byte[] myChunk = new byte[myBufferSize];

FileStream fileStream = new FileStream(myFilePath, FileMode.Open,
FileAccess.Read, FileShare.Read, myBufferSize, true);

fileStream.Read(myChunk, 0, myBufferSize);

Any help would be REALLY apprciated.

Thanks.

Nov 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Keegan Alex | last post by:
Hi folks, I downloaded PHP-Nuke 6.7, and after reading the INSTALL file, it looks very simple... but either i'm reading them wrong or they're very flawed. First, it says: Untar the package...
5
by: Sergey Poberezovskiy | last post by:
Hi, I have an .xsd document (Inc_B.xsd) that "includes" two more from the same folder: <xs:include schemaLocation="Inc.xsd" /> <xs:include schemaLocation="Inc_A.xsd" /> They all have the same...
2
by: Mike | last post by:
Hi, I am new to C and having problems with the following program. Basically I am trying to read some files, loading data structures into memory for latter searching. I am trying to use structres...
3
by: akang2005 | last post by:
When I write 'double' data to the file, it seems working fine, but when I read it later, it returns a eof when it encounters a particular number even the file is not at the end yet. However, while...
9
by: Sheldon | last post by:
Good day Everyone, I am a still very new at learning C and I have thrown myself in the deep end. I started with a simple program and kept widening the scope. This has taught me many things about...
2
by: subsanta | last post by:
My computer has so many problems and ive looked around on the internet and ive managed to fix some of them. I know that i have a few viruses on my computer, but i cant get rid of them, in one case i...
2
by: patrickdepinguin | last post by:
Hi, I use zlib to write data structures to a compressed file, using the gzwrite function. Afterwards I read the data back with gzread. I notice that this works well when the data written is not...
12
by: xamdam | last post by:
Hi fellas, I am experiencing problems reading a 2GB zipfile consisting of multiple zipped files. I found a thread http://mail.python.org/pipermail/python-dev/2005-April/053027.html that mentions...
10
by: lancer6238 | last post by:
Hi all, I'm having programs reading from files. I have a text file "files.txt" that contains the names of the files to be opened, i.e. the contents of files.txt are Homo_sapiens.fa...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.