473,394 Members | 1,737 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,394 software developers and data experts.

.wav file

I am reading a .wav file and storing the data in an array,
then I am multiplying each element by a constant double say 0.35,
then I am dividing the elements of new array with corresponding elements of the previous array,
I expect a new array containing 0.35 as element but this is not the case,
I dont know why
can some one help
Sep 22 '06 #1
5 3843
I am not getting anything from the above. Could you paste the code so that we can debug your code.
Sep 22 '06 #2
I am not getting anything from the above. Could you paste the code so that we can debug your code.
#include <math.h>
#include <stdio.h>
#include <float.h>
#include <conio.h>
#include <string.h>
#include <stdlib.h>
#include <backward_kernel.h>

/* variables for reading and writing a wave file */
FILE* fp;
wav_info file_info;
int header_flag;
long num_data_read;
long num_data_write;

/* variables for Embedding Process */
long low_lim=0;
long up_lim=FRAME_SIZE;
int emb_index;
int in_size;
int index;
int i;

void main()
{
/* for reading from an audio file stored as .wav file */
fp=fopen("C:\\Documents and Settings\\Administrator\\Desktop\\c_ref\\L_fm_sig0 00.wav","rb");
header_flag=1;
in_size=0;
num_data_read=wavread(fp,&file_info,header_flag,da ta_L,data_R,0);
header_flag=0;
num_data_read=wavread(fp,&file_info,header_flag,da ta_L,data_R,file_info.data_size);
fclose(fp);


/* For generating echo signal corresponding to DELAY_ONE */
for(index=0;index<(LENGTH_AUDIO);index++)
echo_signal_one_L[index]=0.0;
for(index=0;index<(LENGTH_AUDIO-DELAY_ONE);index++)
{
echo_signal_one_L[index+DELAY_ONE]=((REL_AMP_ONE )*(data_L[index]));
}


now if DELAY_ONE=0 and if I am dividing elements of echo_signal_one with data_L , I must get REL_AMP_ONE as elements,
waveread is a function which read the data byte wise and store it as double,
hope its clear now











/*
for(index=0;index<LENGTH_AUDIO;index++)
{
wm_signal_one[index]=data_L[index]+echo_signal_one[index];

}
for(index=0;index<(LENGTH_AUDIO-DELAY_ZERO);index++)
{
echo_signal_zero[index+DELAY_ZERO]=((REL_AMP_ZERO)*(data_L[index]));
}

for(index=0;index<LENGTH_AUDIO;index++)
{
wm_signal_zero[index]=data_L[index]+echo_signal_zero[index];

}
Sep 22 '06 #3
Banfa
9,065 Expert Mod 8TB
You problem is that you are using ints.

Although I can't see it in the code you have said that you are performing the operation

result = (n * 0.35) / n

Which in normal mathamatics you would expect to give a value of 0.35 for result.

However you are not performing normal mathmatcatic you are performing integer arrithmatic. At the end (and sometimes in the middle) of the operation the result is stored in an integer, this means that the whole of the fraction part is lost, since (n * 0.35) < n this will give result a value of 0 in integer arithmatic for any n.

I suggest you should you float or double types that support floating point operations (but have there own limitations for instance 0.1 == 0.1 is not always true in floating point arithmatic).
Sep 22 '06 #4
You problem is that you are using ints.

Although I can't see it in the code you have said that you are performing the operation

result = (n * 0.35) / n

Which in normal mathamatics you would expect to give a value of 0.35 for result.

However you are not performing normal mathmatcatic you are performing integer arrithmatic. At the end (and sometimes in the middle) of the operation the result is stored in an integer, this means that the whole of the fraction part is lost, since (n * 0.35) < n this will give result a value of 0 in integer arithmatic for any n.

I suggest you should you float or double types that support floating point operations (but have there own limitations for instance 0.1 == 0.1 is not always true in floating point arithmatic).





Let me explain the problem I am facing:
Suppose I have a float array,say A[1323000],
which I create by reading a single channel audio clip(.wav) of 30 sec duration sampled at 44.1KHz,
Now I am creating one more float array say B[1323000],
by multiplying each element of A with a float constant say x,
Now if the value of x=1.0or 2.0 or 3.0 or 4.0 like that,
and if I divide each element of B with corresponding element of A,
then I am getting x,
but if the fractional part of x is not 0,say if I take x=0.35 or 1.2 or 1.3 like that,
and then dividing each elements of B with A I am not getting x for all cases,
this small difference or error get accumulated and final o/p is not what it must be,
the above thing I am doing just for debugging the code,
I am not performing any integer operations
Sep 23 '06 #5
Banfa
9,065 Expert Mod 8TB
If you think that the code you have already posted is the code that produces this behaviour then I am afarid you are wrong.

The posted code is not doing any floating point calculations. All the variables are integer types and there are not casts to floating point types therefore all the calculations are integer calculations.

I do note that some of the posted code uses variables that are not defined by the posted code. Perhaps you should post all the relevent code and then highlight the lines you think are going wrong.

Particularly Important is how you have defined REL_AMP_ZERO
Sep 23 '06 #6

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

Similar topics

2
by: matt | last post by:
I have compiled some code, some written by me, some compiled from various sources online, and basically i've got a very simple flat file photo gallery. An upload form, to upload the photos and give...
5
by: Dave Smithz | last post by:
Hi There, I have a PHP script that sends an email with attachment and works great when provided the path to the file to send. However this file needs to be on the same server as the script. ...
7
by: Joseph | last post by:
Hi, I'm having bit of questions on recursive pointer. I have following code that supports upto 8K files but when i do a file like 12K i get a segment fault. I Know it is in this line of code. ...
3
by: StGo | last post by:
How can i read/write file's custom attributs(like subject,author...) in C#??? Thanks :))
0
by: Lokkju | last post by:
I am pretty much lost here - I am trying to create a managed c++ wrapper for this dll, so that I can use it from c#/vb.net, however, it does not conform to any standard style of coding I have seen....
13
by: Sky Sigal | last post by:
I have created an IHttpHandler that waits for uploads as attachments for a webmail interface, and saves it to a directory that is defined in config.xml. My question is the following: assuming...
1
by: Roy | last post by:
Hi, I have a problem that I have been working with for a while. I need to be able from server side (asp.net) to detect that the file i'm streaming down to the client is saved...
3
by: Shapper | last post by:
Hello, I created a script to upload a file. To determine the file type I am using userPostedFile.ContentType. For example, for a png image I get "image/png". My questions are: 1. Where can...
0
by: troutbum | last post by:
I am experiencing problems when one user has a document open through a share pointing to the web site. I use the dsolefile to read the contents of a particular directory and then display them in a...
0
by: thjwong | last post by:
I'm using WinXP with Microsoft Visual C++ .NET 69462-006-3405781-18776, Microsoft Development Environment 2003 Version 7.1.3088, Microsoft .NET Framework 1.1 Version 1.1.4322 SP1 Most developers...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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
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...
0
tracyyun
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...

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.