Ejemplo n.º 1
0
 @Override
 public void handlePitch(PitchDetectionResult pitchDetectionResult, AudioEvent audioEvent) {
   if (pitchDetectionResult.isPitched()) {
     pitch = pitchDetectionResult.getPitch();
   } else {
     pitch = -1;
   }
 }
  // STEP 3: Handle pitch event
  @Override
  public void handlePitch(PitchDetectionResult pitchDetectionResult, AudioEvent audioEvent) {
    String newText;

    // have we detected a pitch?
    if (pitchDetectionResult.isPitched()) {
      float result = pitchDetectionResult.getPitch();
      newText = String.valueOf(result) + " Hz";
    } else {
      newText = "No pitch detected";
    }

    final String pitchText = newText;

    // handlePitch will be run from a background thread
    // so we need to run it on the UI thread
    runOnUiThread(
        new Runnable() {
          @Override
          public void run() {
            mPitchText.setText(pitchText);
          }
        });
  }