Revision Difference
sound.Generate#529032
<function name="Generate" parent="sound" type="libraryfunc">
<description>
Creates a sound from a function.
<bug issue="3360">This function cannot generate sounds that have a duration of less than 1 second.</bug>
<bug issue="4082">Sounds persist between disconnects.</bug>
</description>
<realm>Client</realm>
<args>
<arg name="indentifier" type="string">An unique identified for the sound.
⤶
<warning>You cannot override already existing ones.</warning></arg>⤶
<arg name="samplerate" type="number">The sample rate of the sound. Must be 11025, 22050 or 44100.</arg>
⤶
<warning>You cannot override already existing ones.</warning>⤶
</arg>
<arg name="samplerate" type="number">The sample rate of the sound. Must be `11025`, `22050` or `44100`.</arg>⤶
<arg name="length" type="number">The length in seconds of the sound to generate.</arg>
<arg name="callback" type="function">A function which will be called to generate every sample on the sound. This function gets the current sample number passed as the first argument. The return value must be between -1.0 and 1.0. Other values will wrap back to the -1 to 1 range and basically clip. There are 65535 possible quantifiable values between -1 and 1.</arg>
<arg name="callback" type="function">A function which will be called to generate every sample on the sound. This function gets the current sample number passed as the first argument. The return value must be between `-1.0` and `1.0`. Other values will wrap back to the -1 to 1 range and basically clip. There are **65535** possible quantifiable values between -1 and 1.</arg>
</args>
</function>
<example>
<description>Plays a 2000 Hz sine wave at maximum volume</description>⤶
<description>Plays a 2000 Hz sine wave at maximum volume.</description>⤶
<code>
local frequency = 2000 -- Hz
local samplerate = 44100
local function data(t)
local function data( t )
return math.sin( t * math.pi * 2 / samplerate * frequency )
end
test_sound_id = test_sound_id and test_sound_id + 1 or 10
sound.Generate ("testgen" .. test_sound_id, samplerate, 2, data)
surface.PlaySound("testgen" .. test_sound_id)
sound.Generate( "testgen" .. test_sound_id, samplerate, 2, data )
surface.PlaySound( "testgen" .. test_sound_id )
</code>
⤶
</example></example>