java - Normalize the PCM data -


i using following code normalize pcm audio data, correct way normalize? after normalization applying lpf. order matters whether lpf first , normalization on output or current order better if matters. targetmax set 8000 used on of forum's posting. optimal value it. input 16 bit mono pcm sample rate of 44100.

private static int findmaxamplitude(short[] buffer) {     short max = short.min_value;     (int = 0; < 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);     (int index = 0; index < 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); } 

your findmaxamplitude looks @ positive excursions. should use like

max = (short)math.max(max, math.abs(value)); 

your normalization seems quite involved. simpler version use:

return (short)math.round(value * targetmax / rawmax); 

whether targetmax of 8000 correct matter of taste. expect normalisation of 16-bit samples use maximum range of values. targetmax of 32767 seems more logical. normalization should done after lpf operation, gain of lpf may change maximum value of sequence.


Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

html - Unable to style the color of bullets in a list -

c# - must be a non-abstract type with a public parameterless constructor in redis -