【发布时间】: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 如果我的解释正确,但我希望这是一个简单的解决方法。
【问题讨论】:
-
Objective C 中的相同问题。用类似 C 的伪代码回答:stackoverflow.com/questions/11793310/…
-
如需尽快获得更好的帮助,请发帖SSCCE。