1
我正在使用下面的代码来规范化PCM音频数据,这是正常化的正确方法吗?标准化后,我正在应用LPF。订单是否重要,首先要做LPF还是标准化,否则我的现有订单只有在重要时才更好。此外,我的targetMax设置为8000,我从这个论坛的帖子中使用。它的最佳价值是什么?我输入16位单声道PCM与44100正常化PCM数据
private static int findMaxAmplitude(short[] buffer) {
short max = Short.MIN_VALUE;
for (int i = 0; i < 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 < 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);
}