By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,984 Members | 1,025 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,984 IT Pros & Developers. It's quick & easy.

.wav file

P: 13
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
Share this Question
Share on Google+
5 Replies


P: 61
I am not getting anything from the above. Could you paste the code so that we can debug your code.
Sep 22 '06 #2

P: 13
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
Expert Mod 5K+
P: 8,916
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

P: 13
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
Expert Mod 5K+
P: 8,916
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

Post your reply

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