为什么我的白噪音有敲击声/爆裂声/咩咩声?
我的 Android 应用程序正在尝试生成白噪声以在 Android 设备上播放。目前,我正在生成一个随机数数组,该数组是 AudioTrack.getMinBufferSize(...) Shorts long,并在计时器中循环。它看起来像这样:
INTERVAL_MILLISECONDS = (int)((double)(bufSize) / (double)(nativeSampleRate * 2) * 1000);
timer.scheduleAtFixedRate( new TimerTask() {
public void run() {
synchronized(this){
//System.out.println("playing. Sample rate is + " + nativeSampleRate + ", buffer is " + data.length + " shorts long, interval is " + INTERVAL_MILLISECONDS);
track.write(data, 0, bufSize);
track.play();
}
}
}, 0, INTERVAL_MILLISECONDS);
但是当我在 Android 模拟器上听它时,我会听到白噪音,带有非常快速的“跳动”或“咩咩”节奏,很难描述。我不是音响工程师,有人可以指出我正确的方向为什么会发生这种情况吗?
***********< em>*** 更新********* *** 我只是做了几个变体,其中一个是我确保样本大小为整数毫秒长,另一个是我将样本大小设为整秒长。
样本大小为 8820(5 毫秒长,仍然超过 8192 最小值),跳动没有变化。
然而,当样本量达到 44100(一整秒)时,这种现象就消失了。我使用的计时器是否有可能在较小的时间间隔内不准确?
My android app is trying to generate white noise to play on an android device. Currently, I'm generating an array of random numbers that is AudioTrack.getMinBufferSize(...) shorts long, and looping through in a timer. It looks like this:
INTERVAL_MILLISECONDS = (int)((double)(bufSize) / (double)(nativeSampleRate * 2) * 1000);
timer.scheduleAtFixedRate( new TimerTask() {
public void run() {
synchronized(this){
//System.out.println("playing. Sample rate is + " + nativeSampleRate + ", buffer is " + data.length + " shorts long, interval is " + INTERVAL_MILLISECONDS);
track.write(data, 0, bufSize);
track.play();
}
}
}, 0, INTERVAL_MILLISECONDS);
But when I listen to it on my android emulator, I get white noise with a very rapid "beating" or "bleating" rhythm that's hard to describe. I'm not a sound engineer, can someone point me in the right direction about why this is happening?
************** UPDATE ************
I just did a couple of variations, one where I made sure my sample size was a whole number of milliseconds long, and one where I made my sample size a whole second long.
With a sample size of 8820 (five milliseconds long, and still over the 8192 minimum), the beating is unchanged.
However, with a sample size of 44100 (a whole second), the beating went away. Is it possible the timer I'm using just isn't accurate at the small intervals?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题似乎出在产生白噪声的方式上。我不知道有关在 Android 上编程的第一件事,但如果我正确理解了这个问题,那么您将创建一个缓冲区的随机数据,然后一遍又一遍地循环它。
问题(正如您的更新指出的那样)是这个单个缓冲区每秒重复几次。这意味着它不再是“白”(即完全随机)噪声。已经变成周期性的了
您的大脑非常擅长识别周期性波形,因此您会听到这种跳动声。这是你的大脑告诉你除了白噪音之外还有其他事情发生。在这里,您引入了 5.38Hz 左右的强大分量,在调制音频的其余部分时,您将其解释为“跳动”效果。
当您增加缓冲区长度时,跳动就会消失(或降低到可感知以下),因为在 44100 个样本时,您的大脑不再有足够的数据来捕捉,因此无法识别该序列是周期性的。但低频信息仍然存在。
生成完美白噪声 并不像您想象的那么简单!。就您的情况而言,我认为最好使噪声缓冲区尽可能长 - 当然这取决于您正在构建的应用程序的上下文。
The problem seems to be the way you're generating white noise. I don't know the first thing about programming on the android, but if I understand the question correctly you're creating a single buffer's worth of random data then cycling through it over and over again.
The problem, (as your update points out) is that this single buffer is repeating several times a second. This means it's no longer 'white' (i.e. completely random) noise. It's become periodic.
Your brain is very good at picking out periodic waveforms, hence why you hear this beating. It's your brain telling you that there's something going on other than the white noise. Here you're introducing a strong component around 5.38Hz, which when modulating the rest of the audio you interpret as a "beating" effect.
The beating disappears (or decreases below perceptibility) when you increase the buffer length because at 44100 samples your brain no longer has enough to latch on to, and hence fails to recognise that the sequence is periodic. The low frequency information will still be there though.
Generating perfect white noise isn't as straightforward as you might think!. In your case I think it's best to make the noise buffer as long as possible - depending of course on the context of the application you're building.