Неожиданный токен: ошибка Void при обработке IDE, вызванная циклом for, независимо от позиции?

В настоящее время я пытаюсь закодировать простой эскиз задержки звука в IDE обработки. Я продолжаю получать ошибку «неожиданный токен: Void», указывающую на мою функцию Void Setup(). Если я прокомментирую содержимое этого цикла 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;
        }
    }

}

кто-нибудь может помочь?


person Joe Fitzpatrick    schedule 24.03.2011    source источник


Ответы (3)


Возможно, вы забыли закрыть скобку знаком ')'?

Я не вижу цикла в коде, который вы дали.

person Peter Lawrey    schedule 24.03.2011

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

Видишь этого (? Ехать надо :)

person Brian Roach    schedule 24.03.2011

У вас есть незакрытый (.

person SLaks    schedule 24.03.2011