java – TarsosDSP Pitch Analysis for Dummies

java – TarsosDSP Pitch Analysis for Dummies

The basic flow of audio in the TarsosDSP framework is as follows: the incoming audio stream originating from an audio file or a microphone is read and chopped into frames of e.g. 1024 samples. Each frame travels through a pipeline that modifies or analyses (e.g. pitch analysis) it.

In TarsosDSP the AudioDispatcher is responsible to chop the audio in frames. Also it wraps an audio frame into an AudioEvent object. This AudioEvent object is send through a chain of AudioProcessors.

So in the code you quoted mBuffer is the audio frame, mBufferSize is the size of the buffer in samples. You can choose the buffer size yourself but for pitch detection 2048 samples is reasonable.

For pitch detection you could do something like this with the TarsosDSP library:

   PitchDetectionHandler handler = new PitchDetectionHandler() {
        @Override
        public void handlePitch(PitchDetectionResult pitchDetectionResult,
                AudioEvent audioEvent) {
            System.out.println(audioEvent.getTimeStamp() +   pitchDetectionResult.getPitch());
        }
    };
    AudioDispatcher adp = AudioDispatcherFactory.fromDefaultMicrophone(2048, 0);
    adp.addAudioProcessor(new PitchProcessor(PitchEstimationAlgorithm.YIN, 44100, 2048, handler));
    adp.run();

In this code first a handler is created which simply prints the detected pitch. The AudioDispatcher is attached to the default microphone and has a buffersize of 2048. An audio processor that detects pitch is added to the AudioDispatcher. The handler is used there as well.

The last line starts the process.

java – TarsosDSP Pitch Analysis for Dummies

Leave a Reply

Your email address will not be published.