The main audio stream in the TarsosDSP structure is as follows: the incoming audio stream coming from an audio file or microphone is read and interrupted in the form of frames, for example. 1024 samples. Each frame moves through a pipeline that modifies or analyzes (for example, pitch analysis).
At TarsosDSP, AudioDispatcher is responsible for chopping audio into frames. It also wraps the audio frame in an AudioEvent object. This AudioEvent object AudioEvent dispatched through the AudioProcessors chain.
So, in the code you specified, mBuffer is the audio frame, mBufferSize is the size of the buffer in the samples. You can choose the size of the buffer yourself, but to determine the pitch of 2048 samples is reasonable.
To determine the pitch, you can do something similar 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, a handler is first created that simply prints the detected step. AudioDispatcher connects to the microphone by default and has AudioDispatcher buffering. The sound processor that determines the pitch is added to AudioDispatcher . A handler is also used there.
The last line starts the process.
source share