如何以数字方式正确应用体积增益?
我有一个音频应用程序来记录非常低的野生动物声音,因此我需要使用(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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论