r/AskProgramming • u/RadianDRZ • 4d ago
FFT (Fast Fourier Transform) in modern programs
I haven't seen a modern music player on modern day computers represent FFT as responsive as it could in the days of the 486Mhz with 16Mb of RAM (or less) (DAW's not included). I know DOS worked more directly with hardware, but we are over 20 years into the future and I want my Wallpaper Engine to keep up with the sound. Maybe there is an offset somewhere to delay the audio a few ms, but I haven't found it.
I was just reminiscing over some Future Crew demos from the 1990's in DosBox-X (when much was written in C and Assembly).
I was around during the time and owned a 486 DX2-66Mhz. These demos were big at this time (Panic, Unreal, 2nd Reality).
16
u/SingleAlarm5028 4d ago
It's just bloat, not lack of FFT
5
u/Xirdus 4d ago
In 2007, Windows audio subsystem went through a major rewrite. It did make everything heaps more stable and problem-free, but at the cost of big audio latency, especially through the loopback device that audio visualizers use to visualize audio. This isn't bloat, they just prioritized other things above real time audio processing. Which makes sense in a world were barely anybody does real time audio processing on PCs. There's specialized hardware for that.
8
u/khedoros 4d ago
FFT is always taken over a window of time, right? Maybe they're using a longer window than they used to. There's some latency from not having direct access to the video framebuffer, but it's not huge. Like, I have a waveform visualization in one of my emulators, written pretty straight-forwardly by drawing to an in-RAM framebuffer using SDL2, and it seems right on time with the audio that it's displaying.
I take that as evidence that it's possible to do, if someone cares.
3
u/Robot_Graffiti 4d ago
Those old demos weren't doing FFT on pre-existing audio, they were creating the audio and visuals at the same time. Starting to draw a thingy at the same moment you start to play a BOOP sound is easier than doing an FFT.
Some of the slower 486es couldn't do FFT in real time. A sub-100MHz processor would really struggle to play an MP3.
Fast forward a couple years though and late 90s WinAmp could synchronise visualisations in time with any music you want. It was doing FFT (but, like, in reverse) to turn the frequency samples of an MP3 into audio and then playing the audio, so it already had the frequency data to make visualisations from, before the audio was ready to be sent to the speakers.
Now your Wallpaper Engine doesn't have WinAmp's head start; it doesn't have a frequency analysis before the audio has been sent to the operating system. So it has to generate it after the fact, producing a slight delay which is always a little bit longer than the longest wavelength which can be detected by its FFT.
2
u/nixiebunny 4d ago
Layers of abstraction have been added to display functions and hardware. Are modern audio analysis programs written by programmers with attention to display latency?
2
u/gwenbeth 4d ago •
If you are playing mp3 you can get it almost for free because the music is already stored in the frequency domain.
1
u/bestjakeisbest 4d ago
The issue is the transfer of data from one program to another. Im not sure how wallpaper engine does it, but if it is just sampling a virtual line or a loop back then it can only sample after the sound has been made, then there is the issue of how many samples should it capture? 1024 samples will give you a pretty detailed plot, but at 44khz is a pretty sizable amount of samples to get, maybe you wait for 128, 256 or 512 samples, but even the fft is nlog(n) and the fft wont start until it recieves its samples for that frame and computation is not instant.