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,mod e);
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,"RI FF");
//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,"WA VE"))
{ //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_l ength, 4 ,1,fp);
fread(&format_t ag, 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_r ate, 4 , 1, fp); //like 44100, 22050, etc...
fread(&avg_byte s_sec, 4 , 1, fp); //probably won't need this
fread(&block_al ign, 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_buffe r = (char *) malloc (sizeof(char) * data_size))==NU LL); //set aside sound buffer space
cout<<"not enough memory";
fread(sound_buf fer, sizeof(sound_bu ffer), data_size, fp); //read in our whole sound data chunk
for(i=0;i<=data _size;i++)
cout<<sound_buf fer[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",file name);
file f(filename,"rb" );
getch();
}
can anybody tell whats the problem?
0 2023 Sign in to post your reply or Sign up for a free account.
Similar topics |
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
|
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:
http://www.codeproject.com/audio/waveedit.asp#xx489900xx
is it doable with DX 9?
can you show some code sample or doc or URL i can read more?
|
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
|
by: VenuGopal |
last post by:
hi,
i want to store the WAVE FILE CONTENTS in an XML.
How do i do it?
thanks
Venugopal
|
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 this? I am
assuming my card is full duplex, it is a built-in sound card on a new
dell 600m laptop, but I am not sure how to tell for sure. But I think
the problem is not so much my sound card, but that I am making some
fundamentally wrong...
| |
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?
Thanks in advance
|
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 server, WMP 10.0 .
If I type the full path in an IE address field it plays the file in WMP
When I test my Web page ( running the debugger in VS.)
The datagrid has a column called "MsgFile" with the full path to the wave
file e.g....
|
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 advance for any
help.
from Tkinter import *
root = Tk()
import tkSnack
tkSnack.initializeSnack(root)
|
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 usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 most users, this new feature is actually very convenient. If you want to control the update process,...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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 launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
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
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |