简体   繁体   English

参数值不正确(类型正确)。 在JES(Python / Jython)中

[英]Inappropriate argument value (of correct type). in JES (Python/Jython)

Hey so I am just working on some coding homework for my Python class using JES. 嘿,所以我正在使用JES为我的Python类编写一些编码作业。 Our assignment is to take a sound, add some white noise to the background and to add an echo as well. 我们的任务是获取声音,在背景中添加一些白噪声,并添加回声。 There is a bit more exacts but I believe I am fine with that. 有更多的确切信息,但我相信我可以接受。 There are four different functions that we are making: a main, an echo equation based on a user defined length of time and amount of echos, a white noise generation function, and a function to merge the noises. 我们正在制作四个不同的函数:一个主函数,一个基于用户定义的时间长度和回声量的回声方程式,一个白噪声生成函数以及一个合并噪声的函数。

Here is what I have so far, haven't started the merging or the main yet. 到目前为止,这是我尚未开始的合并或主要操作。

#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

I receive this error whenever I try to load it in. 每当我尝试加载它时,我都会收到此错误。

The error was: 错误是:

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

That line of code is: 该行代码是:

setSampleValueAt (newSound, posns2, values1 + values2)

Anyone have an idea what might be happening here? 有人知道这里可能会发生什么吗? Any assistance would be great since I am hoping to give myself plenty of time to finish coding this assignment. 任何帮助都会很棒,因为我希望给自己很多时间来完成此作业的编码。 I have gotten a similar error before and it was usually a syntax error however I don't see any such errors here. 我之前也遇到过类似的错误,通常是语法错误,但是我在这里看不到任何此类错误。

The sound is made before I run this program and I defined delay and number as values 1 and 3 respectively. 声音是在运行该程序之前发出的,我将延迟和数字分别定义为值1和3。

Check the arguments to setSampleValueAt ; 检查setSampleValueAt的参数; your sample value must be out of bounds (should be within -32768 - 32767 ). 您的样本值必须是出界(应在-32768 - 32767 )。 You need to do some kind of output clamping for your algorithm. 您需要对算法进行某种输出钳位。

Another possibility (which indeed was the error , according to further input) is that your echo will be out of the range of the sample - that is, if your sample was 5 seconds long, and echo was 0.5 seconds long; 另一种可能性(根据进一步的输入,这确实是错误 )是您的回声将超出样本的范围-也就是说,如果您的样本长度为5秒,而回声长度则为0.5秒; or the posns1 + delay is beyond the length of the sample; posns1 + delay超出了样本的长度; the length of the new sound is not calculated correctly. 新声音的长度计算不正确。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM