allows you to make sounds of robot heads and horns
you can also run loop effects that will simulate engine sounds
with betterAPI, you can load ANY SOUND AT ALL!
the maximum number of audio effects is 32
the maximum number of loop effects is 32
number of simultaneously loaded samples: 32
component name - synthesizer
wave types (works only with betterAPI):
- sine - 0
- square - 1
- sawtooth - 2
- triangle - 3
new sound api:
- synthesizer.stop() - stops all currently playing sounds (does not stop loop effects and samples)
- synthesizer.hornBeep(pitch:number (0 - 1), duration:number|nil):id - makes a horn sound
- synthesizer.ballBeep(velocity:number (0 - 50), duration:number|nil):id - generates the sound of the challengeball_rolling
- synthesizer.toteBeep(device:number (1 - 9), note:number (0 - 24), duration:number|nil):id - it can emit both the sound of a horn (instrument 0) and the sound of robot heads. but it's designed for robot heads (since it accepts a note)
- synthesizer.sampleBeep(sample (1 - 32), volume, speed, pitch, rate, startpos, endpos):id - creates a new instance of the already loaded sample and reproduces it immediately with the specified parameters
you can specify the start and end time to reproduce a specific sample fragment
please note that audio started in this way cannot be stopped via synthesizer.stopSample
since it is called a beep and not a sample, although it is fork from the sample. to stop it, use synthesizer.stop or synthesizer.stopBeep
- synthesizer.alarmBeep(index (1 - 4)):id - play the alarm sound from the chapter two with the specified index
- synthesizer.waveBeep(wave:number (0 - 3), volume, freq, duration:number|nil):id - play a wave with a certain frequency. if the duration parameter is not specified, the sound will be played until you stop it using synthesizer.stopBeep or synthesizer.stop
- synthesizer.stopBeep(id:number) - accepts the index of the beep, which is returned by the function that makes the sound. stops this sound instantly
sound api (it is outdated, it is better not to use it):
- synthesizer.stop() - stops all currently playing sounds (does not stop loop effects and samples)
- synthesizer.clear() - clears the sound buffer
- synthesizer.delBeep(index:number) - cancels addBeep with the passed index
- synthesizer.addBeep(device:number|nil, pitch:number|nil, volume:number|nil (in fact, it starts the same sound several times, from 1 to 10 it is not recommended to set this parameter to more than 0.3), duration:number|nil):index - adds sound to the buffer
- synthesizer.flush() - sends the audio buffer to clients, but does not clear it. do not forget to clear the buffer yourself so as not to overflow it
- synthesizer.flushWithStop() - it works the same way as flush, but stops playback of all previously started sounds that were not updated in this call
- synthesizer.flushWithBind() - it works the same way as flush, but it doesn't restart sounds with similar instruments that are already playing, instead it updates them with the remaining time
loop api:
- synthesizer.getMaxLoopsCount():number - returns the constant 32
- synthesizer.getLoopsWhilelist():table - returns a table with all loops effects that can be triggered
- synthesizer.stopLoops() - stops all loop effects
- synthesizer.startLoop(slot:number, loopname:string, params:table|string) - triggers a loop effect in the specified slot (from 1 to 32) with the specified name and specified parameters
- synthesizer.stopLoop(slot:number) - stops the loop effect in a certain slot
- synthesizer.setLoopParams(slot:number, params:table) - sets the parameters for the running loop effect in the specified slot
sample api (works only with betterAPI):
- synthesizer.getMaxSamplesCount():number - returns the constant 32
- synthesizer.getDefaultSamplesList():table - return a list of samples that are available by default via synthesizer.loadSampleFromSComputers
- synthesizer.stopSamples() - stops all samples, but it doesn't unload them (does not stop samples that were started via synthesizer.sampleBeep)
- synthesizer.loadSampleFromTTS(slot:number (1-32), text:string) - loads a sample from TTS
- synthesizer.loadSampleFromURL(slot:number (1-32), url:string) - loads a sample from URL
- synthesizer.loadSampleFromSComputers(slot:number (1-32), name:string) - loads a standard sample from SComputers
- synthesizer.loadSampleFromBlueprint(slot:number (1-32), uuid:string, steamid:string|nil, filename:string) - loads a sample from a file at the blueprint.
the audio file should be added to the folder with the creation in the same way as you would add it for reading via a rom disk.
please note that you need to specify the steamID of your creation, this is necessary so that the file can be found from the subscribers.
this means that you need to first upload your creation to steam, then copy the steamID and enter it into the code, then upload the update and only then make your creation public.
please note that when you overwrite your creation with the changed code, enter the name manually!
if you insert it, despite the rewrite window, a new instance with the same name may be created (this is a bug in the game) which will lead to confusion and probably inoperable audio for subscribers (since the file will remain in the previous version and you will post a new one)
before publishing your building on steam, you can specify the steamID as nil
please note that in order for a person to hear the sound, they need to be subscribed to the creation!
- synthesizer.startSample(slot:number (1-32)) - start the sample
- synthesizer.stopSample(slot:number (1-32)) - stop the sample
- synthesizer.pauseSample(slot:number (1-32)) - pause the sample
- synthesizer.loopSample(slot:number (1-32), state:boolean) - enables or disables sample looping
- synthesizer.setSampleVolume(slot:number (1-32), volume (0 - 3)) - set the sample volume
- synthesizer.setSampleRate(slot:number (1-32), rate:number) - set the sample rate (default: 1) changes the speed without changing the pitch
- synthesizer.setSamplePitch(slot:number (1-32), pitch:number) - set the sample pitch [-60...0...60] (default: 0)
- synthesizer.setSampleSpeed(slot:number (1-32), speed:number) - set the sample speed (default: 1) changes the speed and tone
standard samples embedded in the mod (for load via synthesizer.loadSampleFromSComputers):
- mc_noteblock_0
- mc_noteblock_1
- mc_noteblock_2
- mc_noteblock_3
- mc_noteblock_4
- mc_noteblock_5
- mc_noteblock_6
- mc_noteblock_7
- mc_noteblock_8
- mc_noteblock_9
- mc_noteblock_10
- mc_noteblock_12
- mc_noteblock_13
- mc_noteblock_14
- mc_noteblock_15
- wave_sine - it is better not to use these samples separately, launch these sounds using synthesizer.waveBeep
- wave_square
- wave_sawtooth
- wave_triangle
methods for unrestricted speaker from the power toys addon:
- synthesizer.setSampleDistance(number) - sets the distance at which all samples will be heard. It can be set as math.huge so that the sound is broadcast to the heads of all players in the world (default: 25)
- synthesizer.getSampleDistance():number
- synthesizer.setSpatialEnabled(boolean) - enables or disables spatial sound (default: true)
- synthesizer.getSpatialEnabled():boolean
- synthesizer.setLocalSound(boolean) - sets the position of ordinary sounds (not samples) to the player's position, thus it is an analog of synthesizer.setSampleDistance(math.huge) for sounds that are not samples (default: false)
- synthesizer.getLocalSound():boolean
--the sample api requires a betterAPI to work!
--https://steamcommunity.com/sharedfiles/filedetails/?id=3177944610
local synthesizer = getComponent("synthesizer")
synthesizer.loadSampleFromURL(1, "https://raw.githubusercontent.com/igorkll/trashfolder/refs/heads/main/sound/1.mp3")
synthesizer.loopSample(1, true)
synthesizer.setSampleVolume(1, 0.5)
synthesizer.startSample(1)
function callback_loop()
if _endtick then
synthesizer.loopSample(1, false)
synthesizer.stopSample(1)
return
end
end
--the sample api requires a betterAPI to work!
--https://steamcommunity.com/sharedfiles/filedetails/?id=3177944610
local timerhost = require("timer").createHost()
local synthesizer = getComponent("synthesizer")
synthesizer.loadSampleFromTTS(1, "hello world")
synthesizer.loadSampleFromTTS(2, "danger")
synthesizer.loadSampleFromTTS(3, "evacuation")
local timer = timerhost:createTimer(40, false, function ()
synthesizer.startSample(1)
local timer = timerhost:createTimer(80, false, function ()
synthesizer.startSample(2)
local timer = timerhost:createTimer(40, true, function ()
synthesizer.startSample(3)
end)
timer:reset()
timer:setEnabled(true)
end)
timer:reset()
timer:setEnabled(true)
end)
timer:reset()
timer:setEnabled(true)
function callback_loop()
if _endtick then
synthesizer.stopSample(1)
synthesizer.stopSample(2)
synthesizer.stopSample(3)
return
end
timerhost:tick()
end
local utils = require("utils")
local synthesizer = getComponent("synthesizer")
function onTick(dt)
local sin = math.sin(math.rad(getTick() * 4))
synthesizer.ballBeep(utils.map(sin, -1, 1, 25, 40), 5)
end
function onStop()
synthesizer.stop()
end
_enableCallbacks = true
synthesizers = getComponents("synthesizer")
function calls(...)
local args = {...}
for i, cmp in ipairs(synthesizers) do
cmp[args[1] ] (unpack(args, 2))
end
end
calls("stop")
tick = 1
function callback_loop()
if _endtick then
calls("stop")
else
currentBeep = tick % 40 > 20
if currentBeep ~= oldBeep then
calls("stop")
calls("clear")
if currentBeep then
calls("addBeep", 3, 0.5, 1, 40)
else
calls("addBeep", 3, 1, 1, 40)
end
calls("flush")
end
oldBeep = currentBeep
end
tick = tick + 1
end
--the sample api requires a betterAPI to work!
--https://steamcommunity.com/sharedfiles/filedetails/?id=3177944610
--https://igorkll.github.io/synthesizer.html
local timerhost = require("timer").createHost()
local synthesizer = getComponent("synthesizer")
synthesizer.loadSampleFromTTS(1, "hello world")
synthesizer.loadSampleFromTTS(2, "danger")
synthesizer.loadSampleFromTTS(3, "evacuation")
local timer = timerhost:createTimer(40, false, function ()
synthesizer.startSample(1)
local timer = timerhost:createTimer(80, false, function ()
synthesizer.startSample(2)
local timer = timerhost:createTimer(40, true, function ()
synthesizer.startSample(3)
end)
timer:reset()
timer:setEnabled(true)
end)
timer:reset()
timer:setEnabled(true)
end)
timer:reset()
timer:setEnabled(true)
function callback_loop()
timerhost:tick()
end