be.tarsos.dsp.pitch.PitchProcessor.PitchEstimationAlgorithm Java Examples

The following examples show how to use be.tarsos.dsp.pitch.PitchProcessor.PitchEstimationAlgorithm. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ListenerFragment.java    From cythara with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected Void doInBackground(Void... params) {
    PitchDetectionHandler pitchDetectionHandler = (pitchDetectionResult, audioEvent) -> {

        if (isCancelled()) {
            stopAudioDispatcher();
            return;
        }

        if (!IS_RECORDING) {
            IS_RECORDING = true;
            publishProgress();
        }

        float pitch = pitchDetectionResult.getPitch();

        if (pitch != -1) {
            PitchDifference pitchDifference = PitchComparator.retrieveNote(pitch);

            pitchDifferences.add(pitchDifference);

            if (pitchDifferences.size() >= MIN_ITEMS_COUNT) {
                PitchDifference average =
                        Sampler.calculateAverageDifference(pitchDifferences);

                publishProgress(average);

                pitchDifferences.clear();
            }
        }
    };

    PitchProcessor pitchProcessor = new PitchProcessor(PitchEstimationAlgorithm.FFT_YIN,
            SAMPLE_RATE,
            BUFFER_SIZE, pitchDetectionHandler);

    audioDispatcher = AudioDispatcherFactory.fromDefaultMicrophone(SAMPLE_RATE,
            BUFFER_SIZE, OVERLAP);

    audioDispatcher.addAudioProcessor(pitchProcessor);

    audioDispatcher.run();

    return null;
}
 
Example #2
Source File: RecordingMfccService.java    From android-speaker-audioanalysis with MIT License 2 votes vote down vote up
public void startPitchDetection()
{
       Log.d(TAG, "startPitchDetection");

	//algorithm, sampleRate, bufferSize, handler
	dispatcher.addAudioProcessor(new PitchProcessor(PitchEstimationAlgorithm.FFT_YIN, 16000, 1024, new PitchDetectionHandler() {
		
		@Override
		public void handlePitch(PitchDetectionResult pitchDetectionResult, AudioEvent audioEvent) {
			
			//-1 means no sound 
			final float pitchInHz = pitchDetectionResult.getPitch();
			//Log.i("Pitch", String.valueOf(pitchInHz));
			
			if(pitchInHz == -1)
	    		sendResult("Silent");
	    	else
	    		sendResult("Speaking");
			
			
			//call showPitchOnUI(pitchInHz) 
			/*runOnUiThread(new Runnable() {
			     @Override
			     public void run() {
			    	
			    	 
			    	 
			    	if(pitchInHz == -1)
			    		uiMessage = "Silent";
			    	else
			    		uiMessage = "Speaking";
			    }
			});
			
			*/
			
		}
	}));
	

	
}