javaandroidaudiotarsosdsp

Cannot resolve symbol using TarsosDSP for an android application


This problem really stumbled me. I am trying to implement the percussionDetector class from the TarsosDSP audio library but something is not right...

this is my code:

public class PercussionDetectionForTimer extends Timer {
int SAMPLING_RATE=22050;
int BUFFER_SIZE=1024;
int BUFFER_OVERLAP=0;

AudioDispatcher dispatcher = AudioDispatcherFactory.fromDefaultMicrophone(SAMPLING_RATE,BUFFER_SIZE,BUFFER_OVERLAP);

OnsetHandler handler = new OnsetHandler() {
    @Override
    public void handleOnset(double time, double salience) {
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                //do stuff with result and audioevent
            }
        });
    }
};

double sens = 0.8;
double threshold = 10;

PercussionOnsetDetector percussionDetector = new PercussionOnsetDetector(SAMPLING_RATE,BUFFER_SIZE,handler,sens,threshold);
dispatcher.addAudioDispatcher(percussionDetector);
dispatcher.start();
}

I get the following error message from Android Studio: ' Cannot resolve symbol 'addAudioDispatcher()' '

But when i try to call the method at the same line I declared the variable 'dispatcher' there is no such error... What might be wrong?

It's like Android studio won't recognise the variable dispatcher, it only recognises the class AudioDispatcher, which is weird.

All help is appreciated!


Solution

  • If someone else has this problem, which I find very unlikely since I feel really dumb posting this answer, I will answer my own question:

    I forgot to declare a method for the entire thing so I wrote all the code outside all other methods. No wonder it didn't work!