Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
419 views
in Technique[技术] by (71.8m points)

c# - Convert Audio samples from bytes to complex numbers?

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...