java - "Unexpected token: Void"for循环导致IDE处理错误,无论位置如何?

标签 java audio delay void processing-ide

我目前正在尝试在处理 IDE 中编写一个简单的音频延迟草图。我不断收到指向我的 Void Setup() 函数的“意外标记:Void”错误。如果我注释掉这个 for 循环的内容:

for (int i = 0; i < output.length; i++)  
{  
    output[i] = (audioData[i]+audioData[i-44100];  
}

那么就不会出现这个错误了。无论我将此循环放入哪个函数,都会发生此错误,并且我尝试以其他方式对其进行编码。运气不好。

这是给我带来麻烦的选项卡的代码:

AudioThread audioThread;
// we'll use this to store the audio data we read from the audio file
float[] audioData;
float[] delayData;
// we'll use this to remember our position in the audio data array
float readHead;
float readHeadDelay;

void setup() {
    size(500, 400, P2D);
    // the audio file we want to play, which should be in the data dir
    String audioFilename = "myk_hats_dub1.wav";

    // read the audio data into a float array using the AudioFileIn class
    audioData = new AudioFileIn(audioFilename, this).getSampleData();
    delayData = new AudioFileIn(audioFilename, this).getSampleData();

    // print how many samples we read
    println("Read " + audioData.length + " samples");
    // set the read head to zero, the first sample
    readHead = 0;
    readHeadDelay = 44100;
    // start up the audio thread
    audioThread = new AudioThread();
    audioThread.start();
}

void draw() {
    background(255);
    fill(0);
}

// this function gets called when you press the escape key in the sketch
void stop() {
    // tell the audio to stop
    audioThread.quit();
    // call the version of stop defined in our parent class, in case it does
    // anything vital
    super.stop();
}

// this gets called by the audio thread when it wants some audio
// we should fill the sent buffer with the audio we want to send to the
// audio output
void generateAudioOut(float[] buffer) {

    for (int i = 0; i < buffer.length; i++) {

        // copy data from the audio we read from the file (audioData)
        // into the buffer that gets sent to the sound card
        buffer[i] = audioData[(int) readHead];

        // add a sample from the other array
        buffer[i] += delayData[(int) readHeadDelay];
        // scale it so it does not go over 1.0
        buffer[i] *= 0.5;

        // move the read head along one, resetting to zero
        // if it goes to the end of the audioData array
        readHead++;
        readHeadDelay++;
        if (readHead >= audioData.length) {
            readHead = 0;
        }
        if (readHeadDelay >= delayData.length) {
            readHeadDelay = 0;
        }
    }

}

有人可以帮忙吗?

最佳答案

也许您忘记用“)”结束括号?

我在您提供的代码中没有看到循环。

关于java - "Unexpected token: Void"for循环导致IDE处理错误,无论位置如何?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5419607/

相关文章:

ios - 使用他的路径获取音频文件的信息 - Objective-c iOS

objective-c - AVAudioPlayer - 你必须创建一个属性才能让它工作吗? (X代码)

java - 如何延迟程序以便在文本之间有停顿?

java - Android应用程序一启动就崩溃

java - 完成我的第一个 Spring MVC 应用程序 - 老板想看我的单元测试 - 我从哪里开始?

javascript - 如何在浏览页面时保持音频播放?

Java,如何让程序等待视频结束然后继续,wait()使程序停止

r - slider 输入延迟

java - 如何修复 Apache Flink 中卡住的检查点

java - 为什么从方法内部调用时方法回溯不起作用