sound.Generate
sound.Generate( string indentifier, number samplerate, number length, function callbackOrData, number loopStart = nil )
Description
Creates a sound from a function.
Arguments
4 function or table callbackOrData
A function which will be called to generate every sample on the sound.
Function argument(s):
1 number sampleIndex - The current sample number.
Function return value(s):
1 number sampleValue - The return value must be between
Other values will wrap back to the -1 to 1 range and basically clip.
There are 65535 possible quantifiable values 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
.This argument can also be given a table of samples, where values must range from -1
to 1
.
This argument can also be a string of raw 16bit binary data, (each sample is unsigned short).
5 number loopStart = nil
Sample ID of the loop start. If given, the sound will be looping and will restart playing at given position after reaching its end.
This was recently added in version (2024.06.04). It might only be available on the Dev Branch right now.
Example
Plays a 2000 Hz sine wave at maximum volume.