开发者

C# Silverlight get frequency of sound

开发者 https://www.devze.com 2023-04-02 07:57 出处:网络
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)

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号