I want to use FastFourierTransformer to convert AudioRecord ByteArray from time domain to frequency domain. Ultimately, I want to use the frequencies to draw on the Canvas. However, FastFourierTransformer returns complex numbers, is there a way I can use these complex numbers to draw on the Canvas?
Asked
Active
Viewed 26 times
0
-
Two suggestions. Read: [Why does FFT produce complex numbers instead of real numbers?](https://stackoverflow.com/q/10304532/295004), and have you seen: https://developer.android.com/reference/android/media/audiofx/Visualizer – Morrison Chang Feb 12 '23 at 08:08
-
@MorrisonChang Thanks for the links. I now understand I only need the magnitudes, which are the amplitudes. I calculated it by: `val doubles = byteArray.map { it.toDouble() }.toDoubleArray() val amplitudes = FastFourierTransformer(DftNormalization.STANDARD).transform(doubles, TransformType.FORWARD).map { (it).multiply(it.conjugate()).sqrt().real }.joinToString()}` `byteArray` is the result of polling `AudioRecord`. I tried using the Visualizer class earlier it doesn't work for `AudioRecord. Setting the Aaudio session to `0` doesn't work either. – X09 Feb 12 '23 at 17:32
-
To get the magnitude of each complext number, I multiplied it with its conjugate and got the square root of the multiplication. – X09 Feb 12 '23 at 17:34
-
The magnitudes I am getting are pretty large, though, even when the recording should be silent or nearly silent. – X09 Feb 12 '23 at 17:52