473,566 Members | 3,004 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.w av";

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

FileStream fileStream = new FileStream(myFi lePath, 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 12792
This page might help...

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

Nov 17 '05 #2
Erpman <Er****@discuss ions.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.w av";

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

FileStream fileStream = new FileStream(myFi lePath, 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.co m>
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****@discuss ions.microsoft. com> wrote in message
news:CB******** *************** ***********@mic rosoft.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:\\F ile.wav")
samples = dataChunk.Size/formatChunk.WBl ockAlign; // total number of samples
byte[] buf = ReadDataChunk(f ileinfo, samples);

// This should read the entire data block into a byte[]
public byte[] ReadDataChunk(F ileInfo fileinfo, int samples)
{
byte[] buf;
using(FileStrea m fs = fileinfo.Open(F ileMode.Open, FileAccess.Read , FileShare.Read) )
using(BinaryRea der br = new BinaryReader(fs ))
{
fs.Position = dataChunk.Offse t;
buf = br.ReadBytes(sa mples*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.w av";

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

FileStream fileStream = new FileStream(myFi lePath, 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
3292
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 into the directory you want to use on you web server, if you're unsure where that is, ask you system administrator.
5
1456
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 targetNamespace="http://tempuri.org/Inc.xsd" xmlns:ir="http://tempuri.org/Inc.xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema"
2
3258
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 and arrays of pointers to them. I have gotten the program to compile with gcc on WinXP. If the file i read doesnt have alot of records, it runs...
3
2920
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 I write a different set of data, there is no problem to read it. Attached is the file: try change the #define RANGE 1000 into 10000, the code...
9
2187
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 C and some, I must admit, have not really sunk in yet. Still, I push on. Now I am taken a library of C programs that were designed to read HDF...
2
2846
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 think i have one on my ipod "boot.exe" and i cant get rid of it. All of the antivirus programs ive tried either dont pick it up or cant scan my ipod....
2
2950
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 that much, but when there is more data to write, after a while I get data errors when reading back the data. Error in main: couldn't read stat...
12
4649
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 a problem on the writing side, does such a problem exist on a reading side? I am using 2.4.1, perhaps there is a fix in a later version?
10
3162
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 Rattus_norvegicus.fa (They are FA files that can be opened in any text editor.)
0
7673
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8109
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7645
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6263
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5485
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5213
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3643
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2085
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1202
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.