本文整理汇总了Java中be.tarsos.dsp.pitch.PitchDetectionResult.getPitch方法的典型用法代码示例。如果您正苦于以下问题:Java PitchDetectionResult.getPitch方法的具体用法?Java PitchDetectionResult.getPitch怎么用?Java PitchDetectionResult.getPitch使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类be.tarsos.dsp.pitch.PitchDetectionResult
的用法示例。
在下文中一共展示了PitchDetectionResult.getPitch方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handlePitch
import be.tarsos.dsp.pitch.PitchDetectionResult; //导入方法依赖的package包/类
public void handlePitch(PitchDetectionResult pitchDetectionResult, AudioEvent audioEvent) {
if (pitchDetectionResult.getPitch() != -1) {
double timeStamp = audioEvent.getTimeStamp();
float pitch = pitchDetectionResult.getPitch();
float probability = pitchDetectionResult.getProbability();
double rms = audioEvent.getRMS() * 100;
String message = String.format("Pitch detected at %.2fs: %.2fHz ( %.2f probability, RMS: %.5f )\n",
timeStamp, pitch, probability, rms);
System.out.println(message);
String addMe1;
if (probability < 0.5 && Pitch.pitches.getItemCount() > 2) {
addMe1 = Pitch.pitches.getItem(Pitch.pitches.getItemCount() - 1);
} else {
addMe1 = String.valueOf(pitch);
}
String addMe2 = String.valueOf(timeStamp);
Pitch.pitches.add(addMe1);
Pitch.time.add(addMe2);
}
}
示例2: checkMicrophone
import be.tarsos.dsp.pitch.PitchDetectionResult; //导入方法依赖的package包/类
private void checkMicrophone() {
AudioDispatcher dispatcher = AudioDispatcherFactory.fromDefaultMicrophone(22050, 1024, 0);
PitchDetectionHandler pdh = new PitchDetectionHandler() {
@Override
public void handlePitch(PitchDetectionResult result,AudioEvent e) {
final float pitchInHz = result.getPitch();
runOnUiThread(new Runnable() {
@Override
public void run() {
if (pitchInHz != -1) {
System.out.println(pitchInHz);
}
if (pitchInHz <= 18500 && pitchInHz >= 17500) {
System.err.println("Pitch Richtig");
}
}
});
}
};
AudioProcessor p = new PitchProcessor(PitchProcessor.PitchEstimationAlgorithm.FFT_YIN, 22050, 1024, pdh);
dispatcher.addAudioProcessor(p);
new Thread(dispatcher,"Audio Dispatcher").start();
}
示例3: computeFrequency
import be.tarsos.dsp.pitch.PitchDetectionResult; //导入方法依赖的package包/类
public double computeFrequency(PitchDetectionResult pitchDetectionResult) {
double frequency = pitchDetectionResult.getPitch();
if (frequency == -1) {
frequency = prevFrequency;
} else {
if (previousFrequencies.length != 0) {
// median filter
// store and adjust pointer
previousFrequencies[previousFrequencyIndex] = frequency;
previousFrequencyIndex++;
previousFrequencyIndex %= previousFrequencies.length;
// sort to get median frequency
double[] frequenciesCopy = previousFrequencies.clone();
Arrays.sort(frequenciesCopy);
// use the median as frequency
frequency = frequenciesCopy[frequenciesCopy.length / 2];
}
prevFrequency = frequency;
}
return frequency;
}
示例4: transform
import be.tarsos.dsp.pitch.PitchDetectionResult; //导入方法依赖的package包/类
@Override
public void transform(Stream[] stream_in, Stream stream_out) throws SSJFatalException
{
float[] data = stream_in[0].ptrF();
float[] out = stream_out.ptrF();
PitchDetectionResult result = _detector.getPitch(data);
float pitch = result.getPitch();
if (pitch > options.maxPitch.get() || pitch < options.minPitch.get())
{
pitch = -1;
}
int dim = 0;
if (options.computePitch.get())
{
out[dim++] = pitch;
}
if (options.computePitchEnvelope.get()) {
if (pitch < 0) {
out[dim++] = _lastPitch;
} else {
out[dim++] = pitch;
_lastPitch = pitch;
}
}
if (options.computeVoicedProb.get())
{
out[dim++] = result.getProbability();
}
if (options.computePitchedState.get())
{
out[dim++] = (result.isPitched() && pitch > 0) ? 1.0f : 0.0f;
}
}
示例5: doInBackground
import be.tarsos.dsp.pitch.PitchDetectionResult; //导入方法依赖的package包/类
@Override
protected Void doInBackground(Void... params) {
PitchDetectionHandler pitchDetectionHandler = new PitchDetectionHandler() {
@Override
public void handlePitch(PitchDetectionResult pitchDetectionResult,
AudioEvent 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(FFT_YIN, SAMPLE_RATE,
BUFFER_SIZE, pitchDetectionHandler);
audioDispatcher = fromDefaultMicrophone(SAMPLE_RATE,
BUFFER_SIZE, OVERLAP);
audioDispatcher.addAudioProcessor(pitchProcessor);
audioDispatcher.run();
return null;
}
示例6: handlePitch
import be.tarsos.dsp.pitch.PitchDetectionResult; //导入方法依赖的package包/类
@Override
public void handlePitch(PitchDetectionResult pitchDetectionResult,
AudioEvent audioEvent) {
double frequency = pitchDetectionResult.getPitch();
if(frequency==-1){
frequency=prevFrequency;
}else{
if(previousFrequencies.length!=0){
//median filter
//store and adjust pointer
previousFrequencies[previousFrequencyIndex] = frequency;
previousFrequencyIndex++;
previousFrequencyIndex %= previousFrequencies.length;
//sort to get median frequency
double[] frequenciesCopy = previousFrequencies.clone();
Arrays.sort(frequenciesCopy);
//use the median as frequency
frequency = frequenciesCopy[frequenciesCopy.length/2];
}
prevFrequency = frequency;
}
final double twoPiF = 2 * Math.PI * frequency;
float[] audioBuffer = audioEvent.getFloatBuffer();
float[] envelope = null;
if(followEnvelope){
envelope = audioBuffer.clone();
envelopeFollower.calculateEnvelope(envelope);
}
for (int sample = 0; sample < audioBuffer.length; sample++) {
double time = sample / samplerate;
double wave = Math.sin(twoPiF * time + phase);
if(!usePureSine){
wave += 0.05 * Math.sin(twoPiF * 4 * time + phaseFirst);
wave += 0.01 * Math.sin(twoPiF * 8 * time + phaseSecond);
}
audioBuffer[sample] = (float) wave;
if(followEnvelope){
audioBuffer[sample] = audioBuffer[sample] * envelope[sample];
}
}
double timefactor = twoPiF * audioBuffer.length / samplerate;
phase = timefactor + phase;
if(!usePureSine){
phaseFirst = 4 * timefactor + phaseFirst;
phaseSecond = 8 * timefactor + phaseSecond;
}
}