java 处理 IDE 时由 for 循环引起的“意外令牌:无效”错误,无论位置如何?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5419607/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 11:02:00  来源:igfitidea点击:

"Unexpected token: Void" error in processing IDE caused by for loop regardless of position?

javaaudiodelayvoidprocessing-ide

提问by Joe Fitzpatrick

I'm currently trying to code a simple audio delay sketch in the processing IDE. I keep getting an "unexpected token: Void" error pointed at my Void Setup() function. If I comment out the contents of this for loop:

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

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

then this error does not appear. This error occurs regardless of which function i put this loop in, and I've tried coding it in alternate ways. No luck.

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

Here's the code for the tab that's giving me trouble:

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

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;
        }
    }

}

can anyone help?

有人可以帮忙吗?

回答by Peter Lawrey

Perhaps you forgot to close the bracket with a ')' ?

也许您忘记用 ')' 关闭括号?

I don't see the loop in the code you gave.

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

回答by Brian Roach

output[i] = (audioData[i]+audioData[i-44100]; 
            ^

See that (? It needs to go :)

看到了(吗?它需要去:)

回答by SLaks

You have an unclosed (.

你有一个未关闭的(.