【问题标题】:Inappropriate argument value (of correct type). in JES (Python/Jython)不适当的参数值(正确类型)。在 JES (Python/Jython) 中
【发布时间】:2015-03-01 08:06:26
【问题描述】:

嘿,所以我正在使用 JES 为我的 Python 课程做一些编码作业。我们的任务是获取声音,在背景中添加一些白噪声并添加回声。还有一些更精确的,但我相信我对此很好。我们正在制作四个不同的函数:主函数、基于用户定义的时间长度和回声量的回声方程、白噪声生成函数和合并噪声的函数。

这是我目前所拥有的,还没有开始合并或主要。

#put the following line at the top of your file. This will let
#you access the random module functions
import random

#White noise Generation functiton, requires a sound to match sound length
def whiteNoiseGenerator(baseSound) :
 noise = makeEmptySound(getLength(baseSound))
 index = 0  
 for index in range(0, getLength(baseSound)) :
  sample = random.randint(-500, 500)
  setSampleValueAt(noise, index, sample)
 return noise


def multipleEchoesGenerator(sound, delay, number) :
  endSound = getLength(sound)
  newEndSound = endSound +(delay * number)

  len = 1 + int(newEndSound/getSamplingRate(sound))
  newSound = makeEmptySound(len)

  echoAmplitude = 1.0
  for echoCount in range (1, number) :
    echoAmplitude = echoAmplitude * 0.60
    for posns1 in range (0, endSound):
    posns2 = posns1 + (delay * echoCount)
    values1 = getSampleValueAt(sound, posns1) * echoAmplitude
    values2 = getSampleValueAt(newSound, posns2)
    setSampleValueAt (newSound, posns2, values1 + values2)
return newSound

每当我尝试加载它时都会收到此错误。

错误是:

Inappropriate argument value (of correct type).
An error occurred attempting to pass an argument to a function.
Please check line 38 of C:\Users\insanity180\Desktop\Work\Winter Sophomore\CS 140\homework3\homework_3.py

那行代码是:

setSampleValueAt (newSound, posns2, values1 + values2)

有人知道这里会发生什么吗?任何帮助都会很棒,因为我希望给自己足够的时间来完成这项任务的编码。我之前遇到过类似的错误,通常是语法错误,但是我在这里没有看到任何此类错误。

声音是在我运行这个程序之前发出的,我将延迟和数字分别定义为值 1 和 3。

【问题讨论】:

  • 对不起,我对你所说的 Antti 的意思感到困惑。我对 setSampleValueAt 的假设是它确实被声明了,并且更像是我链接的第一个生成白噪声的函数。它能够在没有定义的情况下运行(因为它正在改变声音中每个位置的样本值)。我对编码还是很陌生,但我不认为应该定义它。

标签: python computer-science jython jes


【解决方案1】:

检查setSampleValueAt的参数;您的样本值必须超出范围(应在 -32768 - 32767 范围内)。你需要为你的算法做一些输出钳制。

另一种可能性(根据进一步的输入,确实是错误)是您的回声将超出样本的范围 - 也就是说,如果您的样本长度为 5 秒,并且回声为 0.5 秒长;或posns1 + delay 超出样本长度;新声音的长度计算不正确。

【讨论】:

  • 我不确定你所说的输出钳位是什么意思,但我不认为这是错误。通过部分注释,我相信错误与代码的 posn2 部分有关,尽管我不确定为什么。当我定义它时,我给它 posn1 的值(应该是一个 int),然后添加延迟和 echoCount。它们只是数字,没有什么会导致错误。我什至尝试定义 echoCount 并将其值设为 1,但这没有任何好处。
  • 也刚刚注意到这也出现在我忘记发布的错误消息中。“您正在尝试访问索引处的示例:6,但最后一个有效索引位于 5”跨度>
  • 我认为这不是问题,因为当我定义 newEndSound 时,我定义了原始声音的长度,然后我将延迟时间乘以回声数。那应该是多久才没有?
猜你喜欢
  • 2013-11-11
  • 1970-01-01
  • 2013-09-26
  • 1970-01-01
  • 2011-02-28
  • 1970-01-01
  • 2015-12-17
  • 1970-01-01
相关资源
最近更新 更多