Java/Android - 实时使用 FFT 失真音频
此问题与具有使用 JTransform 经验的用户最相关快速傅立叶变换包。我试图最终创建一个均衡器作为更大的实时音频项目的一部分。现在我只是尝试应用傅里叶变换,然后使用逆方法取回原始数据,然后输出该音频。我得到的是高度失真的音频。我想知道是否有人有做过此类事情的经验?
对音频输入进行采样后,我在回调方法中应用转换。
public void onMarkerReached(AudioRecord recorder)
double[] input = new double[buffers[ix].length];
for(int i=0;i<input.length;i++)
{
input[i] = (double)buffers[ix][i];
}
DoubleFFT_1D ft = new DoubleFFT_1D(input.length);
ft.realForward(input);
//some filtering here
ft.realInverse(input, false);
for(int i=0;i<input.length;i++)
{
buffers[ix][i] = (short)input[i];
}
player.write(buffers[ix], 0,
buffers[ix].length);
}
}
由于只保留变换的实部,我是否会丢失部分信号?由于它只是音频数据,因此输入应该是纯实数,对吧?不确定我在这里做错了什么,任何意见将不胜感激!
this question is most relevant for users with experience using the JTransform package for Fast Fourier Transforms. I'm attempting to eventually create an equalizer as part of a larger realtime audio project. Right now I was simply attempting to apply the Fourier transform, then use the inverse method to get back the original data, then output that audio. What I'm getting is highly distorted audio. I wonder if anyone has any experience doing this sort of thing?
I apply the transform in a callback method after sampling the audio input.
public void onMarkerReached(AudioRecord recorder)
double[] input = new double[buffers[ix].length];
for(int i=0;i<input.length;i++)
{
input[i] = (double)buffers[ix][i];
}
DoubleFFT_1D ft = new DoubleFFT_1D(input.length);
ft.realForward(input);
//some filtering here
ft.realInverse(input, false);
for(int i=0;i<input.length;i++)
{
buffers[ix][i] = (short)input[i];
}
player.write(buffers[ix], 0,
buffers[ix].length);
}
}
Am I losing part of the signal as a result of only keeping the real part of the transform? Since it's only audio data the input should be real-only, right? Not sure what I'm doing wrong here, any input would be greatly appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我使用 ft.realInverse(input, true); 测试了您的代码片段加上适当的样本大小,为我解决了失真问题。
I tested your snippet, using ft.realInverse(input, true); along with proper sample size fixed the distortion for me.