Convert Audio samples from bytes to complex numbers?

我怕爱的太早我们不能终老 提交于 2019-12-18 07:15:31

问题


Greetings everyone,

I am currently developing a chromatic tuner for instruments/voice in Silverlight with a C# back-end. I am in the beginning stages and am having issues in grabbing the audio data. I am using an AudioSink class to write the audio to a memory stream when the live capture starts. The problem I am having is converting those bytes in the stream to complex numbers so that it can be fed into a FFT algorithm. I have tried the various way discussed in this post Problem to convert byte array to double but am not sure which method should be used.

Any suggestions on going from a byte array to an array of complex numbers? Accuracy and speed is a must ( more accuracy than speed ) because the later stages of my project will do this process real time in order to diplay the pitch being played as the sound is coming in.

Cheers and thanks!

Josh


回答1:


This project on CodeProject might be of use to you as it's in C# and deals with audio processing via the Cooley-Turkey FFT algorithm.

If you don't want to sift through it here is the byte to complex number bit:

byte[] data = yourByteArray;
double[] x = new double[data.Length];
for (int i = 0; i < x.Length; i++)
{
    x[i] = data[i] / 32768.0;
}
ComplexNumber[] data = new ComplexNumber[length];
for (int i = 0; i < x.Length; i++)
{
    data[j] = new ComplexNumber(x[i]);
}

I don't know much about sound processing so don't know whether the dividing by 32768 is unique to this solution or true in general.

Also, although this will be 100% accurate, I don't know how well it performs. If that becomes an issue you might need to refactor.



来源:https://stackoverflow.com/questions/5012307/convert-audio-samples-from-bytes-to-complex-numbers

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!