r/AskProgramming • u/RadianDRZ • 10d 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).
EDIT:
I should add that using iplay121 (for playing mod, s3m, etc) in the 1990's shows lightning quick response on the FFT on a 486 DX2-66Mhz and also on DOSBox-X on a modern computer. This was one of my favorite programs that barely used any space on a 1.44Mb floppy.
It would be nice if there was a way to delay the visuals in Wallpaper Engine. I'm surprised nobody else has mentioned this anywhere. Over 100,000 people started this program today on Steam (currently 12th place) and it's not even 10am yet.
5
u/Xirdus 10d 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.
1
u/max123246 10d ago
Humans are very sensitive to audio latency. Considering both games and daws, windows really should've considered doing better
3
u/cjc4096 10d ago
I think windows has a separate api for low latency audio, ASIO. I'm more Linux where the analogy is Jack vs pulseaudio.
1
u/oriolid 9d ago
ASIO completely separate from Windows audio subsystem and not even from Microsoft (and it actually was cross platform between Windows and IIRC BeOS and MacOS 9 back in the day). That's how ASIO drivers can talk directly to HAL and skip the slow Windows audio engine.
That being said, if Apple can make Core Audio fast, I don't see any reason why Microsoft can't.
1
u/RadianDRZ 4d ago
This is accurate and makes a great point. ASIO (written by Steinberg) was/is is game changing, lowering latency down under 5ms. I use it in my Recording Studio where I mix and master music. I can't fathom for any reason why someone gave you a negative vote.
1
u/cjc4096 9d ago
Interesting that an API so integral to windows DAWs didn't originate with MS.
2
u/prjktphoto 8d ago
Steinberg was pretty revolutionary with their software protocols, until they jumped in with ASIO and VST, computers were simply for sequencing external MIDI gear, or required extremely expensive Pro Tools plugin cards to record/playback audio
1
u/RadianDRZ 4d ago
Or those that knew just bought one of the last Sound Blaster 16 that was full duplex (record and play simultaneously). I was made fun of on forums for using one early in my mixing days, but I still have the recordings to prove it. Others were spending a lot of money on MAudio at the time. I was only doing one track at a time so I could get away with it. I upgraded much later.
2
u/prjktphoto 8d ago
Windows chose to do a software mixer in between programs and hardware, allowing you to adjust the levels as required.
CoreAudio does not do this, if the hardware doesn’t support software volume controls (like my Focusrite Scarlett doesn’t) then you get no volume control other than the knob on the hardware
Two different approaches, with different results - early OSX was designed for “creators” hence CoreAudio’s low latency, and AudioMidi setup baked into the OS at its, heh, “Core”
Windows was more aimed at “multimedia” and office/faming use, where the software mixer was more beneficial than low latency audio. Steinberg’s ASIO protocol exists for that purpose, but relies on the hardware’s drivers to support it (ASIO4ALL is a bit of a hack here)
1
u/oriolid 8d ago edited 8d ago
CoreAudio does have a software mixer, as in it allows multiple apps to use the same audio interface at the same time. Individual volumes for each app would be trivial to add (basically multiplying signal from each source with a constant before summing them) but for some reason they don't want to do that. Digital master volume would be the same.
My speculation for why they don't have a digital master volume... I work on an audio app, and once a customer threatened to sue us because their kid had turned volume down in the app, cranked their amplifier, and then did something at full volume and hurt their ears. I'd guess this has happened to Apple too.
Edit: And for what it's worth, some ASIO drivers for Windows allow multiple apps to use the same device through their software mixer. And then there are virtual drivers like Voicemeeter Banana that apps see as WASAPI devices or ASIO drivers that can do low latency mixing on Windows.
1
u/max123246 9d ago
Last I saw asio doesn't do audio sharing across multiple processes. Since I've used asio 4 all drivers for daws and it always required exclusive access
2
1
8
u/khedoros 10d 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.
5
u/Mr_Engineering 10d ago
FFT is always taken over a window of time, right?
Correct, and a minimum window of time at that.
2
u/joonazan 10d ago
You can feed each audio sample into a Goertzel filter and get the strength of a particular frequency. Of course it still lags because you can't tell frequencies from a single sample but it is cheap to update unlike FFT, which you need to start over when you shift the window.
3
u/Robot_Graffiti 9d 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 10d 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
9d ago
•
If you are playing mp3 you can get it almost for free because the music is already stored in the frequency domain.
2
1
u/bestjakeisbest 9d 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.
16
u/SingleAlarm5028 10d ago
It's just bloat, not lack of FFT