gpt4 book ai didi

java - 如何在Jython中减少声音?

转载 作者:行者123 更新时间:2023-12-03 02:15:47 24 4
gpt4 key购买 nike

我要线性降低声音中的采样值,从第一个采样[0]开始,它的最大值(32767),最后一个[sound length end]具有最小的值(-32767)。为此,我假设您可以使用y=mx+b格式。由于m = y2-y1/x2-x1我有:

def decreasing(sound):
length = getLength(sound)
max = 32767.0
min= -32767.0
for sample in getSamples(sound):
setSampleValue(sound, int((((min-max) / (length)) * (index)) + max))

我遇到的问题是 y=mx+b中的x,x是我认为的索引,因为它是找到样本值(y)时x平原上的值。但是,当我运行代码时,我得到:

The error was:index ... Name not found globally



由于我不确定如何定义它。所以基本上我要问的是我该如何编号:

在我的方程式中

最佳答案

假设getSamples()返回一个列表,您可能想要这样的东西:

for index, sample in enumerate(getSamples(sound)):
setSampleValue(sample, int((((min-max)/length) * index) + max))

关于java - 如何在Jython中减少声音?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20207054/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com