0

I am having problems with detecting clapping sounds using TarsosDSP. PitchDetectioHandler somehow works but when it comes to using PercussionOnsetDetector, it does not detect anything.

Am I doing anything wrong here?

 @Override
   protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        //Checks Permission
        checkPermission(Manifest.permission.RECORD_AUDIO,REQUEST_RECORD_AUDIO_PERMISSION);

        pitchText = (TextView) findViewById(R.id.pitch);
        noteText = (TextView) findViewById(R.id.note);

        /*PitchDetectionHandler pdh = new PitchDetectionHandler() {
            @Override
            public void handlePitch(PitchDetectionResult res, AudioEvent e){
                final float pitchInHz = res.getPitch();
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        processPitch(pitchInHz);
                    }
                });
            }
        };
        AudioProcessor pitchProcessor = new PitchProcessor(PitchProcessor.PitchEstimationAlgorithm.FFT_YIN, 22050, 1024, pdh);
        dispatcher.addAudioProcessor(pitchProcessor);

        Thread audioThread = new Thread(dispatcher, "Audio Thread");
        audioThread.start(); */

        AudioDispatcher dispatcher = AudioDispatcherFactory.fromDefaultMicrophone(22050,1024,0);

        double threshold = 8;
        double sensitivity = 20;

        PercussionOnsetDetector mPercussionDetector = new PercussionOnsetDetector(22050, 1024,
                new OnsetHandler() {

                    @Override
                    public void handleOnset(double time, double salience) {
                        runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                System.out.println("YAAAYYY");
                            }
                        });
                    }
                }, sensitivity, threshold);

        dispatcher.addAudioProcessor(mPercussionDetector);
        new Thread(dispatcher,"Audio Dispatcher").start();

    }
prosoitos
  • 6,679
  • 5
  • 27
  • 41

1 Answers1

0

The following code detects the clap with Tarsos DSP:

 final AudioDispatcher fromDefaultMicrophone = AudioDispatcherFactory.fromDefaultMicrophone(22050, 1024, 0);
        double threshold = 6; // lower it a bit
        double sensitivity = 20;

        PercussionOnsetDetector mPercussionDetector = new PercussionOnsetDetector(22050, 1024,
                new OnsetHandler() {

                    @Override
                    public void handleOnset(double time, double salience) {
                        Log.d(TAG, "Clap detected!");
                        startAlarm();
                    }
                }, sensitivity, threshold);

        fromDefaultMicrophone.addAudioProcessor(mPercussionDetector);
        new Thread(fromDefaultMicrophone,"Audio Dispatcher").start();
mahamrauf
  • 21
  • 4