如何以数字方式正确应用体积增益?

发布于 2025-02-05 14:18:43 字数 962 浏览 3 评论 0原文

我有一个音频应用程序来记录非常低的野生动物声音,因此我需要使用(float)增益因素以数字方式提高播放量。这些文件是16位Wave Mono,44100。

我现在要做的是:

AudioTrack mplayer = new AudioTrack(....);
FileInputStream is = new FileInputStream(songfile);
...
while (isPlaying() && (i = is.read(music)) != -1) {
    for (int j = 0; j < i / 2; j++) {
        shortv = ((music[j * 2] & 0xff) | (music[j * 2 + 1] << 8));
        musics[j] = (short) Math.max(Math.min(gain * shortv, Short.MAX_VALUE), Short.MIN_VALUE);
    }

    if (isPlaying()) mplayer.write(musics, 0, j);
}
...

如您所见,我只是从两个字节中提取的简短,带有gain,从0到100(最大/分钟将限制在范围内)。

我的问题是,当增益太高时,我会听到失真。当然,这是可以预期的。但是,当增益很高时,上述代码给出了“像素化”(对不起,摄影师在这里!)。也就是说,musics []的值是0、100、200、300 ...我想知道有多少失真来自微小的扬声器,以及来自“像素化”的多少

...有一种天然/知名/常用/标准方法来处理这种“像素化”?当然,我可以“模糊”(对不起...)带有过滤器的信号,但我想知道有更有效的东西。

或者,也许我太挑剔了,因为信号已经有16位?

I have an audio app to record very low wildlife sounds, and I thus need to raise the playback volume digitally with a (float) gain factor. The files are 16 bit WAVE mono, 44100.

What I do now is the following:

AudioTrack mplayer = new AudioTrack(....);
FileInputStream is = new FileInputStream(songfile);
...
while (isPlaying() && (i = is.read(music)) != -1) {
    for (int j = 0; j < i / 2; j++) {
        shortv = ((music[j * 2] & 0xff) | (music[j * 2 + 1] << 8));
        musics[j] = (short) Math.max(Math.min(gain * shortv, Short.MAX_VALUE), Short.MIN_VALUE);
    }

    if (isPlaying()) mplayer.write(musics, 0, j);
}
...

As you can see, I just multiply the short extracted from the two bytes, with the gain, which goes from 0 to 100 (the max/min is to limit in the short range).

My problem is that when gain is too high, I hear distortions. This is expected, of course. Yet, when gain is high the above code gives "pixelation" (sorry, a photographer here!). Namely, the values of musics[] is 0, 100, 200, 300... I wonder how much of the distortion comes from the tiny speakers and how much from the "pixelation"...

Is there a natural/well-known/frequently-used/standard method to deal with this "pixelation"? Of course I could just "blur" (sorry...) the signal with a filter, but I wonder is there is something more effective.

Or maybe I am being too picky since the signal is already in 16 bits?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文