0

I am writing a program for school that reduces noise in a sound file. So far i have written this code which I think takes n number of samples before a set one and n after and then averages the two. My problem is that everytime my second for loop runs i get a sampleoutofboundexception. I am guessing this means that it cant find the sample that i am asking it to look for, but i dont understand why.

for (int s = 0; s<= aSound.getNumSamples(); s++){    

  for ( int i=0; i<=level ; i++ ) {
    nSamp = aSound.getSample(i);
    sSize = nSamp.getValue();
    total=total + sSize;
  }

  for (int j = 0; j >= -level; j--){
    sSize2 = aSound.getSample(j).getValue();
    total1 = total1 + sSize2;
  }
  avg = (total1 + total) / level*2;

  for (int i = 0; i <= level*2+1; i++){
    result.getSample(i).setValue(avg);
  }
 }
 return aSound;
  }

I get the error every single time this line is run and I can't understand why. any help? thank you

sSize2 = aSound.getSample(j).getValue();
4

2 回答 2

2

的价值是level多少?我假设它是积极的,在这种情况下

for (int j = 0; j >= -level; j--)

在 的负值上循环j,负索引通常是无效的。这就是为什么你得到一个索引越界异常。

如果这不能解决您的问题,您应该发布更多详细信息,例如对象aSound的类型。

于 2010-11-13T03:11:46.327 回答
0

aSound 是一个包含 55125 个样本的 wav 文件的对象

aSound 就是收藏。它没有我评论中写的负指数

我认为 aSound 是一个集合,数组或集合没有负索引

于 2010-11-13T03:39:15.983 回答