将音频样本从字节转换为复数? [英] Convert Audio samples from bytes to complex numbers?

查看:34
本文介绍了将音频样本从字节转换为复数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我目前正在用 C# 后端在 Silverlight 中开发用于乐器/声音的半音调音器.我正处于开始阶段,在获取音频数据时遇到问题.当实时捕获开始时,我正在使用 AudioSink 类将音频写入内存流.我遇到的问题是将流中的这些字节转换为复数,以便将其输入 FFT 算法.我已经尝试了这篇文章中讨论的各种方法将字节数组转换为双精度的问题 但不确定应该使用哪种方法.

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.

干杯和感谢!

乔希

推荐答案

这个项目 on CodeProject 可能对您有用,因为它在 C# 中并通过 Cooley-Turkey FFT 算法.

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]);
}

我对声音处理知之甚少,所以不知道除以 32768 是此解决方案独有的还是一般情况下正确的.

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.

此外,虽然这将是 100% 准确的,但我不知道它的表现如何.如果这成为一个问题,您可能需要重构.

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.

这篇关于将音频样本从字节转换为复数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆