473,511 Members | 14,052 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to read data from a wave file

1 New Member
hello friends
can anybody tell me how to read data from a wave file..
i have writen code as ...
class file
{
private:
FILE *fp;
char id[4];
char *sound_buffer; //four bytes to hold 'RIFF'
long int size; //32 bit value to hold file size
short int format_tag, channels, block_align, bits_per_sample; //our 16 values
long int format_length, sample_rate, avg_bytes_sec, data_size, i; //our 32 bit values
int a;

public:
file(const char *fname,const char *mode)
{
fp = fopen(fname,mode);
if (fp==NULL)
printf("cant open");
else
{
fread(id, sizeof(id), 1, fp); //read in first four bytes
cout<<"\n"<<"id is "<<id;
a=strcmp(id,"RIFF");
//if (!strcmp(id, "RIFF"))
if(a==0)
{ //we had 'RIFF' let's continue
fread(size, 4 , 1, fp); //read in 32bit size value
cout<<"\n size is "<< size;
fread(id, sizeof(id), 1, fp); //read in 4 byte string now
cout<<"\n wave id is "<<id;
if (!strcmp(id,"WAVE"))
{ //this is probably a wave file since it contained "WAVE"
fread(id, sizeof(id), 1, fp); //read in 4 bytes "fmt ";
cout<<"\n Format id is "<<id;
fread(&format_length, 4 ,1,fp);
fread(&format_tag, 2 , 1, fp); //check mmreg.h (i think?) for other
// possible format tags like ADPCM
fread(&channels, 2 ,1,fp); //1 mono, 2 stereo
fread(&sample_rate, 4 , 1, fp); //like 44100, 22050, etc...
fread(&avg_bytes_sec, 4 , 1, fp); //probably won't need this
fread(&block_align, 2 , 1, fp); //probably won't need this
fread(&bits_per_sample, 2 , 1, fp); //8 bit or 16 bit file?
fread(id, 4 , 1, fp); //read in 'data'
cout<<"\n id for data is "<<id;

upto here it is giving otput...
but after output it gives error as
loating point error:domain
abnormal program termination
null pointer assignment.



fread(data_size, 4 , 1, fp); //how many bytes of sound data we have
if((sound_buffer = (char *) malloc (sizeof(char) * data_size))==NULL); //set aside sound buffer space
cout<<"not enough memory";
fread(sound_buffer, sizeof(sound_buffer), data_size, fp); //read in our whole sound data chunk
for(i=0;i<=data_size;i++)
cout<<sound_buffer[i];
}
else
printf(" \nError: RIFF file but not a wave file\n");
}
else
printf("Error: not a RIFF file\n");
}
fclose(fp);
}
};
void main()
{
char filename[50],ch;
clrscr();
printf("enter file name ");
scanf("%s",filename);
file f(filename,"rb");
getch();
}

can anybody tell whats the problem?
Jun 10 '07 #1
0 2003

Sign in to post your reply or Sign up for a free account.

Similar topics

1
2800
by: webstar | last post by:
hi, could you please tell me how to play a small wave file if a button is pressed. or if there is another format that is easer then use that instead of wave. thanks matt
0
4964
by: Ada | last post by:
i'm using C# and have been reading DX doc but cannot find the info i'm looking for. i want to load WAVE file and display the waveform. something similar to this: ...
2
8081
by: Sagaert Johan | last post by:
Hi I can play a wave file through a p/invoke to winmm , but how can i play a wave file to a specific audio device if i have more then one audio device in my pc ? Johan
3
2141
by: VenuGopal | last post by:
hi, i want to store the WAVE FILE CONTENTS in an XML. How do i do it? thanks Venugopal
1
2522
by: Tito | last post by:
For an internet telephone application, I need to be able to read and write data to and from /dev/dsp simultaneously. I wrote some code and its not working. Anyone have any working code to do...
1
1636
by: Hitchkas | last post by:
I want to access a wave file's sound data buffer, manipulate the sound and attach the processed buffer back into the wave file using C#. Are there any C# sample codes showing how this can be done?...
9
5588
by: Morris Neuman | last post by:
Im working with VS 2005 and trying to use a Hyperlink field in a datagrid to play a wave file that is not located in the website folders but is in a plain folder on the same machine, windows 2003...
0
2212
by: Karthik | last post by:
Hi, I want to record a sound wave from a mic and at the same time invert it and play the inverted wave.My code goes as follows, however nothing is written into the E:\inverted.wav file.Thanks in...
0
7245
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
7356
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
7427
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
5671
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,...
0
4741
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...
0
3227
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...
0
3214
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
785
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
449
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.