C# Silverlight get frequency of sound
I've been trying to use some code like the following to read current sound from the mic
_Capture is a CaptureSource
and _Encoder is a SimpleAudioEncoder
(Custom class)
_Capture = new CaptureSource();
_Encoder = new SimpleAudioEncoder(this);
_Encoder.CaptureSource = _Capture;
if (_Capture != null)
{
_Capture.AudioCaptureDevice = CaptureDeviceConfiguration.GetDefaultAudioCaptureDevice();
CaptureDeviceConfiguration.GetDefaultAudioCaptureDevice();
if (CaptureDeviceConfiguration.AllowedDeviceAccess || CaptureDeviceConfiguration.RequestDeviceAccess())
{
MessageBox.Show("_Capture.Start()");
_Capture.Start();
}
}
Definition of SimpleAudioEncoder
public class SimpleAudioEncoder : AudioSink
{
public SimpleAudioEncoder() {
}
protected override void OnCaptureStarted()
{
}
protected override void OnCaptureStopped()
{
}
protected override void OnFormatChange(
开发者_如何学运维 AudioFormat audioFormat) {
}
protected override void OnSamples(
long sampleTimeInHundredNanoseconds,
long sampleDurationInHundredNanoseconds,
byte[] sampleData)
{
}
}
Im guessing that the sampleData
byte[]
array has the data I'm looking for but how can I use it to find the frequency of the sound?
It would be great if I could find a function like
public double GetFreq(byte[] data)
To use like
double hertz = GetFreq(sampleData)
Establishing the frequency of the sound requires converting the signal from the time domain to the frequency domain. It will involve Fourier transforms and subsequent analysis of the output. It's really not a job for anyone without a pretty thorough understanding of DSP techniques. If you have to ask, then you're a long way from being able to implement this yourself. I'd recommend a third party library.
This page gives a fairly good view from somebody new to frequency detection.
精彩评论