2

I've taken over maintaining an android application that records an audio source using AudioRecord in 44100, 16-bit mono. I need to downsample it to 8000. The current app has a downsample algorithm in it that I'm not sure is working correctly. When another app (which is a black box) receives it, the audio plays but with a loud buzzing sound in the background and slower than expected audio. Other audio in the proper format piped into the receiving app is received fine with no issues.

The algorithm that I have is listed here (I suspect it was originally decompiled code from somewhere based on the variable names).

private void downSample() {
    int v5 = 0;
    int v4 = 0;
    int v2;
    for (v2 = 0; v2 < 0xA0; ++v2) {
        v5 += 0xD755;
        int v6 = v5 / 0x2710;
        v5 -= v6 * 0x2710;
        double v0 = 0;
        int v3 = v4;
        v4 += v6;
        while (v3 < v4) {
            v0 += ((double) ((((float) this.readBuffer[v3])) * this.volume));
            ++v3;
        }

        v0 /= ((double) v6);
        if (32767 < v0) {
            v0 = 32767;
        }
        else if (-32768 > v0) {
            v0 = -32768;
        }

        this.downSampledBuffer[v2] = ((short) (((int) v0)));
    }
}

readBuffer is a short[] that is populated by the recording source. downSampledBuffer is also a short[]. Any thoughts on what is going wrong?

4

1 回答 1

1

“嗡嗡声”和“比预期的音频慢”是在此算法之外产生的。

该算法正好处理 882 个输入样本并产生 160 个输出样本。因此,在每次调用 downSample() 之前,您必须用恰好 882 个新的短值填充 this.readBuffer,并且在从 downSample() 返回后,您必须将生成的 160 个短值连接到已处理的样本。

集成的低通“滤波器”只是对 5 或 6 个输入样本进行简单平均,因此您无法摆脱所有混叠,但另一方面,它并不是下采样问题的最慢解决方案。

于 2013-10-31T08:03:35.380 回答