Exemplo n.º 1
0
  void processVoiceRecord() {
    voiceDispatcher = AudioDispatcherFactory.fromDefaultMicrophone(sampleRate, bufferSize, overlap);
    score = 0;
    counter = 0;
    PitchDetectionHandler pdh =
        new PitchDetectionHandler() {
          @Override
          public void handlePitch(PitchDetectionResult result, AudioEvent e) {
            float voicePitch = result.getPitch();

            if (counter >= listSourcePitch.size()) return;
            if ((Math.abs(voicePitch - Math.round(listSourcePitch.get(counter))) < 20
                || Math.abs(Math.round(listSourcePitch.get(counter)) - voicePitch) < 20)) {
              score = score + 1;
              Log.d("-----", counter + "_" + voicePitch + "_" + listSourcePitch.get(counter));
              runOnUiThread(
                  new Runnable() {
                    @Override
                    public void run() {}
                  });
            }
            counter++;
          }
        };
    AudioProcessor p =
        new PitchProcessor(PitchEstimationAlgorithm.FFT_YIN, sampleRate, bufferSize, pdh);
    voiceDispatcher.addAudioProcessor(p);
    new Thread(voiceDispatcher, "Voice Audio Dispatcher").start();
  }
Exemplo n.º 2
0
  void processSourceRecord() {

    new AndroidFFMPEGLocator(this);
    sourceDispatcher =
        AudioDispatcherFactory.fromPipe(
            "http://media.karaokecuatui.vn/audio/AnhVanYeuEmNhuNgayDauTien_CaoThaiSon.mp3",
            (int) sampleRate,
            bufferSize,
            overlap);

    sourceDispatcher.addAudioProcessor(
        new PitchProcessor(PitchEstimationAlgorithm.FFT_YIN, sampleRate, bufferSize, this));
    sourceDispatcher.addAudioProcessor(
        new AudioProcessor() {
          FFT fft = new FFT(bufferSize);
          float[] amplitudes = new float[bufferSize / 2];

          @Override
          public void processingFinished() {
            // TODO Auto-generated method stub
          }

          @Override
          public boolean process(AudioEvent audioEvent) {
            try {
              float[] audioFloatBuffer = audioEvent.getFloatBuffer();
              float[] transformbuffer = new float[bufferSize * 2];
              System.arraycopy(audioFloatBuffer, 0, transformbuffer, 0, audioFloatBuffer.length);
              fft.forwardTransform(transformbuffer);
              fft.modulus(transformbuffer, amplitudes);

              return true;
            } catch (Exception exp) {
              return false;
            }
          }
        });

    new Thread(sourceDispatcher, "Audio dispatching").start();
  }