Skip to content

Features

Vurv edited this page May 8, 2022 · 5 revisions

Here you will find everything WebAudio can do.

Getting the current state of a stream:

local Stream = webAudio("<URL>")
print(Stream:getState() == _CHANNEL_PAUSED) # --> Will print 0 because streams start at (_CHANNEL_STOPPED aka 0)
# When this stream hits the duration of the link, it will automatically put itself in the _CHANNEL_STOPPED state.

Having streams be independent from props

You can just set the position of the stream anywhere. No props or parenting is needed.

local Stream = webAudio("<URL>")
Stream:setPos( randvec(-1000, 1000) )

Getting the current playback position of the stream

You can get the current playback position of the stream, using information provided by the client.

# Make sure to check if Stream:getLength() != -1 before doing this. If it is -1 we don't know the length yet.
local ElapsedPercentage = Stream:getTime() / Stream:getLength()

Getting a stream's FFT values

You can get the DFT (discrete Fourier transform) of a stream using xwa:getFFT().
It is an array containing _WA_FFT_SAMPLES samples of values from 0-255.
It updates every _WA_FFT_DELAY milliseconds.

local FFTs = Stream:getFFT()

Looping a stream

You can loop a stream using webaudio.
Here's an example to enable it.

local Stream = webAudio("<URL>")
Stream:setLooping(1)

Flat Audio

You can use 2d audio to hear it at the same volume directly to your player with set3DEnabled.

# Play the stream in 2D mode.
local Stream = webAudio("<URL>")
Stream:set3DEnabled(0)
Stream:play()

Ignoring players

You can ignore specific players from being sent WebAudio streams / playing audio. Here's an example on how to make a stream only for yourself

local Stream = webAudio("<URL>")
Stream:setIgnored(players(), 1)
Stream:setIgnored(owner(), 0)