sound/Generate

From Garry's Mod
(Difference between revisions)
Jump to: navigation, search
m (Bug)
(Bug)
 
Line 3: Line 3:
  
 
{{Bug|Issue=3360|This function cannot generate sounds that have a duration of less than 1 second.}}
 
{{Bug|Issue=3360|This function cannot generate sounds that have a duration of less than 1 second.}}
 +
{{Bug|Issue=4082|Sounds persist between disconnects.}}
 
|Realm=Client
 
|Realm=Client
 
|IsClass=No
 
|IsClass=No
Line 9: Line 10:
 
|type=string
 
|type=string
 
|name=indentifier
 
|name=indentifier
|desc=An unique identified for the sound. You cannot override already existing ones.
+
|desc=An unique identified for the sound.
 +
 
 +
{{Warning|You cannot override already existing ones.}}
 
}}
 
}}
 
{{Arg
 
{{Arg

Latest revision as of 04:10, 3 December 2019

 sound.Generate( )

Contents

Description

Creates a sound from a function.

BUG

This function cannot generate sounds that have a duration of less than 1 second.

Issue Tracker: #3360

BUG

Sounds persist between disconnects.

Issue Tracker: #4082

Arguments

string indentifier

An unique identified for the sound.

WARNING

You cannot override already existing ones.

Arguments

number samplerate

The sample rate of the sound. Must be 11025, 22050 or 44100.

Arguments

number length

The length in seconds of the sound to generate.

Arguments

function callback

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.

Examples

Example

Plays a 2000 Hz sine wave at maximum volume

local frequency = 2000 -- Hz
local samplerate = 44100

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)


Personal tools
Navigation