【问题标题】:Creating Java echo sound effect创建 Java 回声音效
【发布时间】:2013-03-18 15:18:25
【问题描述】:

所以我试图通过将声音文件分解为样本并将这些样本存储在数组中来操作 java 中的声音文件。然后我循环遍历更改每个样本的数组。我意识到java中已经有一个回声过滤器,但我需要通过在整个声音片段中以不同的间隔重复声音来设计自己的回声过滤器,并减少音量。我目前有一种控制音量的方法,但在让声音在当前声音文件的特定延迟处开始重复时,我感到很困惑。这是我目前所拥有的:

public void echoEffect(int delay){
   SoundSample[] sampleArray = this.getSamples(); // get array

   SoundSample sample = null;                     // current sample obj
   int value = 0;                                 // value at sample

 // loop through SoundSample objects
 for(int i = 0, index = 0; index < sampleArray.length; i++,index++)
 {
  sample = sampleArray[index];    // get current obj
  value = sample.getValue();      // get the value
  sample.setValue(value*2);       // set the value
 }
}

我认为我需要做的是将方法从 void 更改为 Sound 并返回延迟的声音文件。可能返回类似 value + value[i+delay]*(一些分数以减少声音)

新更新而不是发布:

无论如何,这就是我目前所拥有的,我似乎无法让代码正常工作,我知道我已经接近了,但我需要在声音文件上输出回声效果的方法。这是我目前所拥有的:

public void echo(int delay){
   SoundSample[] sampleArray = this.getSamples();   // get array
   //Sound target = new Sound(sampleArray.length);

   SoundSample sampleDelay = null;
   SoundSample sample = null;                       // current sample obj

   int value = 0;                                   // value at sample
   int index = 0;
   double value2 = 0;
// loop through SoundSample objects
while (index < sampleArray.length)
 {
  sample = sampleArray[index]; // get current obj
  value = sample.getValue();     // get the value      
  sampleDelay = (sampleArray[delay-index]);
  value2 = (sampleDelay.getValue()*.6);
  sample.setValue(value + (int) value2);       // set the value
  index++;                                  // increment index
 }
}

让我知道你们认为这一切似乎是出于某种原因改变幅度...... 发布 SSCCE 的问题在于,我相信这是在使用一些不经常在 java 中使用的类,因此我只是在寻找帮助逻辑的人。我正在尝试遍历声音文件的样本,然后将延迟点的值设置为声音的开头,但音量较弱。 IDK 如果我的解释正确,但我希望这是一个简单的解决方法。

【问题讨论】:

标签: java audio javasound


【解决方案1】:

而不是

sampleDelay = (sampleArray[delay-index]);

你想要的

sampleDelay = (sampleArray[index-delay]);

【讨论】:

  • 当我改变这个时,我得到一个 ArrayIndexOutOfBoundsException: -3000 ,其中数字等于延迟值。并感谢您的帮助。
  • @adrv1400 好吧,那就不要访问0以下的数组! :)
  • 是的,你不能回显不存在的东西 :) 你会想在某个大于你要返回的量的地方开始回显..
【解决方案2】:

你确定不是下面这个?

sampleDelay = (sampleArray[index*delay]);

【讨论】:

  • 随着指数的上升,这会带来更多的延迟。延迟应该是常数。我认为 Patashu 的答案是正确的。
猜你喜欢
  • 1970-01-01
  • 2011-11-25
  • 2012-06-21
  • 2011-04-07
  • 2016-03-30
  • 2023-03-27
  • 2013-11-12
  • 1970-01-01
  • 2019-08-09
相关资源
最近更新 更多