Recently, I was trying to make a radio with some advanced stuff.
I am stuck because I can’t calculate the maximum loudness a song/music will give before it plays.
I was wondering if there is a constant number, do I have to assume it? or is there a tool?
I tried to use CompressorSoundEffect and control the threshold but it didn’t get the max loudness number of a song/music.
strong note
" reflects the amplitude of the Sound ’s playback in the instance of time it is read"
so it will only give you the loudness at the given time loudness is read so if you want to cancel out loud songs u are probably going to use a loop to monitor the loudness and then you can adjust the volume and even better you could cache it into a table along with its loudness so if its played again u can adjust the volume straight away before it gets loud
local run = game:GetService("RunService")
local function getHighestPlaybackLoudness(sound)
local highestPlaybackLoudness = 0
sound:Play()
local connection do
connection = run.RenderStepped:Connect(function()
if not sound.IsPlaying then
connection:Disconnect()
end
if sound.PlaybackLoudness > highestPlaybackLoudness then
highestPlaybackLoudness = sound.PlaybackLoudness
end
end)
end
sound.Ended:Wait()
return highestPlaybackLoudness
end
local sound = script:WaitForChild("Sound") --Sample sound.
local highestPlaybackLoudness = getHighestPlaybackLoudness(sound)
print(highestPlaybackLoudness) --244, sample result.
As suggested, you’d check the sound’s PlaybackLoudness property every frame (as frequently as possible), if its current value exceeds the highest recorded value then you set the highest recorded value to that value and continue until the sound finishes.