2

我正在使用以下代码来规范化 PCM 音频数据,这是规范化的正确方法吗?标准化后,我正在应用 LPF。订单是否重要,是否首先进行 LPF 和规范化其输出或我当前的订单只有在重要的情况下才会更好。我的 targetMax 也设置为 8000,这是我在这个论坛的帖子中使用的。它的最佳值是多少。我的输入是 16 位 MONO PCM,采样率为 44100。

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);
}
4

1 回答 1

1

您的 findMaxAmplitude 仅查看正偏移。它应该使用类似的东西

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

你的规范化似乎很复杂。更简单的版本将使用:

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

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

于 2013-07-21T15:31:15.427 回答