Changing Sound TimePos Causes Static

Im doing some experiments with roblox sounds and I noticed that when changing timepos it causes a lot of static noises below is a example script


local audioPlayer = Instance.new("AudioPlayer")
audioPlayer.AssetId = "rbxassetid://9040512197"
audioPlayer.Looping = true
audioPlayer.Volume = 1
audioPlayer.Parent = Workspace

local deviceOutput = Instance.new("AudioDeviceOutput")
deviceOutput.Parent = Workspace

local wire = Instance.new("Wire")
wire.SourceInstance = audioPlayer
wire.TargetInstance = deviceOutput
wire.Parent = Workspace

while not audioPlayer.IsReady do
    task.wait()
end

audioPlayer:Play()

task.spawn(function()
    while true do
        if audioPlayer.IsReady then
            local newTime = math.random() * audioPlayer.TimeLength
            audioPlayer.TimePosition = newTime
        end
        task.wait(0.1)
    end
end)
3 Likes

Hey @figre – changing .TimePosition causes the AudioPlayer to seek to a new position within the file – doing this while the file is playing causes discontinuities

I would only recommend jumping around within the file while it’s either silent or not playing, to minimize audible artifacts; perhaps you could tween the volume down to 0, jump to a new location, and then tween back up to full-volume?

Still just minimizing though its not a perfect solution, Couldn’t you add a patch to this?

1 Like

Hi, I tested this and didn’t observe anything unexpected. When the script changes the TimePosition to a random position, it’s not likely to line up with the previous TimePosition in any way, so there are clicking sounds from that.

If you’re hearing something more severe than that, let us know - otherwise, this seems intended and we most likely wouldn’t be fixing it.