title: Normalize the PCM data
body: <p>I am using following code to normalize PCM audio data, Is this the correct way to normalize? After Normalization I am applying LPF. Does the order matters whether to do LPF first and Normalization on its output or my current order is better only if that matters. Also my targetMax is set to 8000 which I used from on of this forum's posting. What is the optimal value for it. My input is 16 bit MONO PCM with sample rate of 44100.</p>
  
  <pre><code>private static int findMaxAmplitude(short[] buffer) {
      short max = Short.MIN_VALUE;
      for (int i = 0; i &lt; buffer.length; ++i) {
          short value = buffer[i];
          max = (short) Math.max(max, value);
      }
      return max;
  }
  
  short[] process(short[] buffer) {
      short[] output = new short[buffer.length];
      int maxAmplitude = findMaxAmplitude(buffer);
      for (int index = 0; index &lt; buffer.length; index++) {
          output[index] = normalization(buffer[index], maxAmplitude);
      }
      return output;
  }
  
  private short normalization(short value, int rawMax) {
      short targetMax = 8000;
      double maxReduce = 1 - targetMax / (double) rawMax;
      int abs = Math.abs(value);
      double factor = (maxReduce * abs / (double) rawMax);
  
      return (short) Math.round((1 - factor) * value);
  }
  </code></pre>