2013-07-21 50 views
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); 
} 

回答

1

采样率你findMaxAmplitude只着眼于正偏移。它应该使用类似于

max = (short)Math.Max(max, Math.Abs(value)); 

您的标准化似乎相当复杂。一个更简单的版本可以使用:

return (short)Math.Round(value * targetMax/rawMax); 

8000的targetMax是否正确是一个问题。通常我会期望16位采样的归一化使用最大值范围。所以32767的最大目标似乎更符合逻辑。 归一化应该可能在LPF操作后完成,因为LPF的增益可能会改变序列的最大值。