如何在奈奎斯特中找到声音的平均值
我正在尝试为 Audacity 编写一个简单的测量插件,它就像用石头砸我的头骨一样有趣。我想做的就是获取一块音频并找到所有样本的平均值(该块的 DC 偏移),以便我可以将其作为数字呈现给用户,并且可以从样本中减去直流偏移以进行进一步处理。我知道并理解我想要做的数学,但我不明白如何在 Lisp/XLisp/Nyquist/其他语言中做它。
信息
此帖子中的背景 我知道,没有函数可以做到这一点。由于某种原因,snd-avg function
实际上并不像您所期望的那样计算声音的平均值。它
首先计算绝对值,然后计算平均值计算平均值,然后计算绝对值。即使有一个单独的 snd-abs 函数可以做到这一点。 >:(
所以我想我必须自己编写?这意味着将声音转换为数组,然后计算其平均值?
(snd-fetch-array sound len 步骤)
阅读 样本的连续数组 声音,返回数组 FLONUMs 或 NIL 当声音 终止。
(snd-samples声音限制)
转换 将样本放入 Lisp 数组中。
甚至没有一个平均函数,所以我也得自己算一笔账?但数学函数只适用于列表?那么我需要将数组转换为列表吗?
对于较长的波形(每个样本 18 个字节),这也会占用大量内存,因此最好以块的形式处理它并执行 累计平均值。但我什至不知道如何做未优化的版本。
不,(hp s 0.1)
不起作用,因为:
- 我只想删除 DC,并保持任意低频。 0.01 Hz 应保持不变地通过,应去除 DC。
- 高通滤波器是因果的,无论您使用什么拐点频率,波形的第一个样本都保持不变,这使得它对于测量峰值样本等毫无用处。
I'm trying to write a simple measurement plug-in for Audacity and it's about as much fun as pounding rocks against my skull. All I want to do is take a chunk of audio and find the average of all the samples (the chunk's DC offset) so that I can present it as a number to the user, and so that I can subtract the DC offset from the samples for further processing. I know and understand the math I want to do, but I don't understand how to do it in Lisp/XLisp/Nyquist/whatever.
Background information in this thread
As far as I know, there is no function to do this. For some reason, the snd-avg
function does not actually compute the average of the sound, as you might expect. It does the absolute value first, and then computes the average computes the average and then does the absolute value. Even though there's a separate snd-abs
function that could do it. >:(
So I guess I have to write my own? This means converting a sound into an array and then computing the average of that?
(snd-fetch-array sound len step)
Reads
sequential arrays of samples from
sound, returning either an array of
FLONUMs or NIL when the sound
terminates.
(snd-samples sound limit)
Converts the
samples into a lisp array.
And there's not even an average function, so I'll have to do a sum myself, too? But the math functions only work on lists? So I need to convert the array into a list?
And this will also use up a huge amount of memory for longer waveforms (18 bytes per sample), so it would be best to process it in chunks and do a cumulative average. But I don't even know how to do the unoptimized version.
No, (hp s 0.1)
won't work, since:
- I want to remove DC only, and keep arbitrarily low frequencies. 0.01 Hz should pass through unchanged, DC should be removed.
- The high-pass filter is causal and the first samples of the waveform remain unchanged, no matter what knee frequency you use, making it useless for measuring peak samples, etc.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
别介意
snd-maxsamp
正在计算绝对值,而不是snd-avg
。snd-avg
工作得很好。以下是如何从中挤出一个数字(“FLONUM”):这会为负样本生成一个负数,为正样本生成一个正数,正如它应该的那样。
这个问题应该删除还是留给其他人作为例子?
NEVERMIND
snd-maxsamp
is computing the absolute value, notsnd-avg
.snd-avg
works just fine. Here's how to squeeze a number ("FLONUM") out of it:This produces a negative number for negative samples and a positive number for positive samples, as it should.
Should this question be deleted or left as an example to others?