r/AskProgramming • • 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 Upvotes

22 comments sorted by

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.

0

u/max123246 4d ago

Humans are very sensitive to audio latency. Considering both games and daws, windows really should've considered doing better

3

u/cjc4096 4d 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/max123246 4d 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

u/A_modicum_of_cheese 4d ago

depends on the driver. Steinberg builtin works

1

u/oriolid 4d 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.

2

u/prjktphoto 3d 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 3d ago edited 3d 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/cjc4096 4d ago

Interesting that an API so integral to windows DAWs didn't originate with MS.

2

u/prjktphoto 3d 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/A_modicum_of_cheese 4d ago

pipewire too on linux now.

2

u/Xirdus 4d ago

Loopback audio is NOT what humans hear. You're not going to experience this latency. The actual speaker out latency is fairly small, and the video/audio lag is compensated with some hardware features.

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.

5

u/Mr_Engineering 4d ago

FFT is always taken over a window of time, right?

Correct, and a minimum window of time at that.

2

u/joonazan 4d 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 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 • Bravo

If you are playing mp3 you can get it almost for free because the music is already stored in the frequency domain.

1

u/Cultural-Desk-9045 4d ago

Music players use MPEG libraries as literal black boxes.

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.