If I can change the volume of a soun on the fly, I would be able to use it in a game which will have computers that could run random/custom sounds made by players (or made by the script that players made)
The sounds will be moderated
You could try something similar to the FABRIK algorithm used in inverse kinematics. It makes multiple passes forth and back until a desired result is reached, or it goes through too many cycles.
Basically, if you had 10 points, you would first start from the point 2 and iterate through all of them but the last, checking if they are within limits and pulling them back to the max difference between points. Then you would do the same, but backwards and you repeat that multiple times.
What I’m saying is that you can apply it to your use as a way to smooth out what would cause artifacts in sounds, since you can’t run them at higher frequency.
Yes… But if I can do that at higher frequencies, I won’t really need that… I don’t think…
So… How can we make a high frequency loop? (with stable frequency)
local cycles = 5
local maxdiff = 1
local function SmoothArray(arr)
for i=1,cycles do
local p0 = arr[1]
for i=2,#arr-1 do
local p1 = arr[i]
if math.abs(p1-p0)>maxdiff then
p1 = p0 + maxdiff*math.sign(p1-p0)
arr[i] = p1
end
p0 = p1
end
local done = true
local p0 = arr[#arr]
for i=#arr-1,2,-1 do
local p1 = arr[i]
if math.abs(p1-p0)>maxdiff then
p1 = p0 + maxdiff*math.sign(p1-p0)
arr[i] = p1
done = false
end
p0 = p1
end
if done then
return
end
end
end
local TT=tick()
local FT=tick()
RS.RenderStepped:Connect(function()
FT=tick()
while tick()-FT<1/60 do
while tick()-TT<1/480 do end
TT=tick()
--Code
end
end)
This can work… But with waits too much between two frames…
It waits 130ms then ~20.8ms several times… Over and over…
This will lag to much. Just try running while true do end. It’ll crash your studio.
Roblox can’t run loops without yields, and what you’re doing will lower the framerate to something around 20.
Define lag, if you mean lag by the huge latency between the client and the server, that is not linked with this case. If you by lag you mean frame drops then you are partially correct. game:GetService(“RunService”).RenderStepped fires every frame so if a client is running ROBLOX at like 40 FPS, the event will get fired 40 times a second.
game:GetService(“RunService”).Heartbeat is fired on every frame in the RunService. It is still not guaranteed that it will fire 60 times a second, also it can only be used from the server.
Heartbeat can be used on both client and server. It’s an event used for physical simulations as it fires after each frame, giving a wide time window for complex operations.
RenderStepped it fires before each frame is rendered. Since the server doesn’t have a display, this event only exists on clients.
It’s the event every Luanoid and other Lua based physics simulations use. The default character probably also uses it in a way, but it probably doesn’t require a connection since it’s done in C++.
I’m saying it more as a “It will lower the frame rate to around 20 if you try adding any more functions that run per frame”. It eats up frame time, and it will cause low frames if all functions need more than 0.013 milliseconds to complete.
You could try making a hacky solution to this with coroutines by resuming them in a loop inside a heartbeat if the difference is less than 0.013, but I can’t immediately tell how to achieve this and it will not be consistent at all.
I’m trying to do a consistant wait of around milliseconds… If I can do that, it can run things way faster…
The solution I found can work…
I’ve a minimum wait equal to what was wanted but for the first Loop, it goes nut, around 3~30 ms more