开发者

Java/Android - Distorted Audio using FFT in realtime

开发者 https://www.devze.com 2023-02-22 08:24 出处:网络
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

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.le开发者_运维知识库ngth;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!


I tested your snippet, using ft.realInverse(input, true); along with proper sample size fixed the distortion for me.

0

精彩评论

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