Tags: Visualizer Mod
Music Stream Visualizer for Garrys Mod
Garrys Mod is one of the most extensible games around; it exposes a healthy Lua framework (with ample documentation allowing a modder to write in a dialect of Lua (GLua, short for GMod Lua) to script everything from vehicles to radios.
I've taken advantage of Garry's Mod recently to plan a party this coming May. The university imageboard of N.C. State will be shut down on 5/9 and, in keeping with our history of wild ragers and parties that go on way too late, I am planning to have one last bash. Unfortunately because of circumstances we're not at liberty to host one here in my apartment as usual (see: the University has sent everyone home and all classes are online until at least the end of the semester) so I've decided to host one online.
Originally I wanted to use VRChat however Bakesta pointed out that Garry's Mod would likely have the most extensibility and user-created content for what I was after. And as much as I would love to DJ in VRChat, I do not own any monitors or feedback devices to do so.
I am extremely happy to say that I've decided on Garry's Mod for this purpose because, in the past few days, it's proven again and again to be the most scriptable game for networking tens of hundreds of people.
What I'm Writing
I've written a visualizer exclusively for Internet radio which runs inside Garry's Mod; essentially it acts as a speaker and audio-visualization tool for a remote stream, an example is below:
The farther you get from the speaker, the dimmer the audio becomes; additionally (given that you're wearing headphones), the sound will appear to be coming from either the right or left monitor (or both) depending on where you are in the virtual world. You also may place as many visualizers as you want around a map, the requisite computational power to run one is nearly the same as to run one hundred of these music players.
Dirty Hacks for Speed and Profit
If you don't really care about the dirty details of the project then feel free to skip this part.
In the (client-side) Lua this visualizer connects to the remote URL (either
passed via chat by an admin or skimmed from a
cvar) using a
call to GMod's
sound.PlayURL function; this sound is virtualized using the
3D parameter to create the above "3D-sound" effects.
Once this "sound" is created it is passed to every other visualizer which is in the map; that's how it "appears" to be emitted from every visualizer at once. Every tick, the FFT of the sound is calculated and the resultant dataset is put in the "master" visualizer (defined as the first visualizer spawned); supporting / supplementary (i.e. not "master") visualizers then read from the master's FFT dataset and draw the waveform on their surface. Waveforms are adjusted for relative visualizer height and amplitude.
Additionally I found it helpful to (1) normalize these waveforms logarithmically and (2) scale them relative the maximum amplitude seen at the current sampling time. These two adjustments keep the visualizer lively / visually stimulating because the datapoints are given more room to bounce around.
Lastly, the data is "smoothed" using a linear interpolation involving a number of previous samples to remove any "jitter" which manifests between drawings of samples.
Now that the visualizer is completed, I've been training myself to use the Hammer editor included with GMod to rig a really neo- map. For the set I've decided to broadcast via Internet radio and play some looped video of my Twitch overlay (you can see more about my esthetic for DJ sets on DJR3.org) with the music.
Hammer is also very interesting to play around with: I've never given much thought to how (for example) lights are flashed or models placed or how maps are written.
Anyway, hope to see you (May 9th) at the party! And if you're reading this from the future an archived video of the party is sure to be up on my other site.
Related / Browse
- Favorite Songs from All DDR Ever
June 9, 2018
December 11, 2017
- Idle Thoughts on Doujinshi
April 24, 2018
May 16, 2016
December 8, 2018
November 5, 2017
- Music Stream Visualizer for Garrys Mod
March 31, 2020