.wav file

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • shinelakshmanan
    New Member
    • Aug 2006
    • 13

    .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
  • pukur123
    New Member
    • Sep 2006
    • 61

    #2
    I am not getting anything from the above. Could you paste the code so that we can debug your code.

    Comment

    • shinelakshmanan
      New Member
      • Aug 2006
      • 13

      #3
      Originally posted by pukur123
      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_kerne l.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_SI ZE;
      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:\\D ocuments and Settings\\Admin istrator\\Deskt op\\c_ref\\L_fm _sig000.wav","r b");
      header_flag=1;
      in_size=0;
      num_data_read=w avread(fp,&file _info,header_fl ag,data_L,data_ R,0);
      header_flag=0;
      num_data_read=w avread(fp,&file _info,header_fl ag,data_L,data_ R,file_info.dat a_size);
      fclose(fp);


      /* For generating echo signal corresponding to DELAY_ONE */
      for(index=0;ind ex<(LENGTH_AUDI O);index++)
      echo_signal_one _L[index]=0.0;
      for(index=0;ind ex<(LENGTH_AUDI O-DELAY_ONE);inde x++)
      {
      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;ind ex<LENGTH_AUDIO ;index++)
      {
      wm_signal_one[index]=data_L[index]+echo_signal_on e[index];

      }
      for(index=0;ind ex<(LENGTH_AUDI O-DELAY_ZERO);ind ex++)
      {
      echo_signal_zer o[index+DELAY_ZER O]=((REL_AMP_ZERO )*(data_L[index]));
      }

      for(index=0;ind ex<LENGTH_AUDIO ;index++)
      {
      wm_signal_zero[index]=data_L[index]+echo_signal_ze ro[index];

      }

      Comment

      • Banfa
        Recognized Expert Expert
        • Feb 2006
        • 9067

        #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).

        Comment

        • shinelakshmanan
          New Member
          • Aug 2006
          • 13

          #5
          Originally posted by Banfa
          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

          Comment

          • Banfa
            Recognized Expert Expert
            • Feb 2006
            • 9067

            #6
            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

            Comment

            Working...