be.tarsos.dsp.io.android.AudioDispatcherFactory Java Examples

The following examples show how to use be.tarsos.dsp.io.android.AudioDispatcherFactory. 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: MainActivity.java    From MagicLight-Controller with Apache License 2.0 6 votes vote down vote up
private void startDispatch() {
    dispatcher = AudioDispatcherFactory.fromDefaultMicrophone(22050, 1024, 0);
    uiThread = new Handler();
    PitchDetectionHandler pdh = (PitchDetectionResult result, AudioEvent audioEven) -> uiThread.post(() -> {
        final float pitchInHz = result.getPitch();
        int pitch =  pitchInHz > 0 ? (int) pitchInHz : 1;

        if(pitch > 1 && mConnected) {
            if((pitch - lastPitch) >= sensitive * 10) {
                Random random = new Random();
                byte[] rgb = getLedBytes(random.nextInt(600000000) + 50000);
                controlLed(rgb);
            }

            if(minPitch > pitch)
                minPitch = pitch;
        }

        lastPitch = pitch;
    });

    processor = new PitchProcessor(PitchProcessor.PitchEstimationAlgorithm.FFT_YIN, 22050, 1024, pdh);
    dispatcher.addAudioProcessor(processor);
    listeningThread = new Thread(dispatcher);
    listeningThread.start();
}
 
Example #2
Source File: RecordingMfccService.java    From android-speaker-audioanalysis with MIT License 5 votes vote down vote up
/**
   * methods for handling TarsosDSP
   */
  
  public void initDispatcher()
  {
      Log.d(TAG, "initDispatcher done");
mfccList = new ArrayList<float[]>();

  	//sampleRate, audioBufferSize, int bufferOverlap 
//Florian suggested to use 16kHz as sample rate 
dispatcher = AudioDispatcherFactory.fromDefaultMicrophone(16000, 1024 ,0); //(22050,1024,0);

  }
 
Example #3
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;
}