• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java PitchDetectionResult类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中be.tarsos.dsp.pitch.PitchDetectionResult的典型用法代码示例。如果您正苦于以下问题:Java PitchDetectionResult类的具体用法?Java PitchDetectionResult怎么用?Java PitchDetectionResult使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



PitchDetectionResult类属于be.tarsos.dsp.pitch包,在下文中一共展示了PitchDetectionResult类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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);

	}
}
 
开发者ID:Scoutdrago3,项目名称:MusicToGraph,代码行数:23,代码来源:MyPitchDetector.java


示例2: startDispatch

import be.tarsos.dsp.pitch.PitchDetectionResult; //导入依赖的package包/类
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();
}
 
开发者ID:skydoves,项目名称:MagicLight-Controller,代码行数:27,代码来源:MainActivity.java


示例3: 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();
}
 
开发者ID:AndroidMusicSync,项目名称:AndroidMusicSync,代码行数:25,代码来源:ServantActivity.java


示例4: newPitchDetectionHandler

import be.tarsos.dsp.pitch.PitchDetectionResult; //导入依赖的package包/类
/**
 * A pitch detection storing {@link SoundEvent}
 */
protected VoiceDetection newPitchDetectionHandler() {
    VoiceDetection prs = new VoiceDetection(settings.format.getSampleRate(), settings) {
        @Override
        public void handlePitch(PitchDetectionResult pitchDetectionResult, AudioEvent audioEvent) {
            // Process
            float frequency = (float) computeFrequency(pitchDetectionResult);
            float amplitude = computeAmplitude(audioEvent);
            double timestamp = audioEvent.getTimeStamp();

            // pitch
            SoundEvent pitch = SoundEvent.pitch((float) timestamp, frequency);
            pitch.confidence = pitchDetectionResult.getProbability();
            pitchEvents.add(pitch);

            // amplitude
            ampliEvents.add(SoundEvent.amplitude((float) timestamp, amplitude));
        }
    };
    return prs;
}
 
开发者ID:vocobox,项目名称:vocobox,代码行数:24,代码来源:VoiceFileRead.java


示例5: 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;
}
 
开发者ID:vocobox,项目名称:vocobox,代码行数:24,代码来源:VoiceDetection.java


示例6: 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;
    }
}
 
开发者ID:hcmlab,项目名称:ssj,代码行数:41,代码来源:Pitch.java


示例7: applyDetectionToSelfOscillo

import be.tarsos.dsp.pitch.PitchDetectionResult; //导入依赖的package包/类
protected void applyDetectionToSelfOscillo(PitchDetectionResult pitchDetectionResult, AudioEvent audioEvent) {
    double frequency = computeFrequency(pitchDetectionResult);
    final float[] audioBuffer = audioEvent.getFloatBuffer();
    final double twoPiF = 2 * Math.PI * frequency;
    double timefactor = twoPiF * audioBuffer.length / sampleRate;
    computeEnvelopeAndApplyToBuffer(audioBuffer, twoPiF);
    computePhase(timefactor);
}
 
开发者ID:vocobox,项目名称:vocobox,代码行数:9,代码来源:VoiceDetection.java


示例8: handlePitch

import be.tarsos.dsp.pitch.PitchDetectionResult; //导入依赖的package包/类
@Override
public void handlePitch(PitchDetectionResult pitchDetectionResult, AudioEvent audioEvent) {
    if (synth != null) {
        applyDetectionToSynth(pitchDetectionResult, audioEvent);
    } else {
        applyDetectionToSelfOscillo(pitchDetectionResult, audioEvent);
    }
}
 
开发者ID:vocobox,项目名称:vocobox,代码行数:9,代码来源:VoiceDetectionSynthController.java


示例9: applyDetectionToSynth

import be.tarsos.dsp.pitch.PitchDetectionResult; //导入依赖的package包/类
public void applyDetectionToSynth(PitchDetectionResult pitchDetectionResult, AudioEvent audioEvent) {
    // Process
    float frequency = (float)computeFrequency(pitchDetectionResult);
    float amplitude = computeAmplitude(audioEvent);

    // Apply
    synth.sendFrequency(frequency);
    synth.sendAmplitude(amplitude);
    synth.sendConfidence(pitchDetectionResult.getProbability());
}
 
开发者ID:vocobox,项目名称:vocobox,代码行数:11,代码来源:VoiceDetectionSynthController.java


示例10: 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;
}
 
开发者ID:gstraube,项目名称:cythara,代码行数:50,代码来源:ListenerFragment.java


示例11: 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;
	}
}
 
开发者ID:gstraube,项目名称:cythara,代码行数:55,代码来源:PitchResyntheziser.java


示例12: startPitchDetection

import be.tarsos.dsp.pitch.PitchDetectionResult; //导入依赖的package包/类
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";
			    }
			});
			
			*/
			
		}
	}));
	

	
}
 
开发者ID:wahibhaq,项目名称:android-speaker-audioanalysis,代码行数:43,代码来源:RecordingMfccService.java



注:本文中的be.tarsos.dsp.pitch.PitchDetectionResult类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java MountdBase类代码示例发布时间:2022-05-22
下一篇:
Java LogicalValues类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap