424,984 Members | 1,025 Online
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
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

 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

 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