GetSoundProperties: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(Created page with "__NOTOC__ {{Client function}} {{New feature/item|4.0140|1.3.0|4097| This function gets the properties of a specific sound. }} ==Syntax== <syntaxhighlight lang="lua">float, float, float, ...")
 
m (Reverted edits by Ameir (talk) to last revision by Alvesvin)
Tag: Rollback
 
(14 intermediate revisions by 10 users not shown)
Line 1: Line 1:
__NOTOC__  
__NOTOC__  
{{Client function}}
{{Client function}}
{{New feature/item|4.0140|1.3.0|4097|
{{New feature/item|3.0130|1.3.0|4097|
This function gets the properties of a specific [[sound]].
This function gets the properties of a specific [[sound]].
}}
}}


==Syntax==  
==Syntax==  
<syntaxhighlight lang="lua">float, float, float, bool getSoundProperties(element sound)</syntaxhighlight>  
<syntaxhighlight lang="lua">float, float, float, bool getSoundProperties( element sound )</syntaxhighlight>  
 
{{OOP||[[sound]]:getProperties||setSoundProperties}}
===Required Arguments===  
===Required Arguments===  
*'''sound:''' A sound element that is created using [[playSound]] or [[playSound3D]]
*'''sound:''' a [[sound]] [[element]] that is created using [[playSound]] or [[playSound3D]]


===Returns===
===Returns===
This function returns 3 floats and a boolean value:
This function returns 3 [[float|floats]] and a [[boolean]] value:


The first float is the sound's [http://en.wikipedia.org/wiki/Sampling_rate sample rate], the second one the sound's [http://en.wikipedia.org/wiki/Tempo tempo], and the third one the [http://en.wikipedia.org/wiki/Pitch_%28music%29 pitch] of the sound. The boolean representing whether the sound is reversed or not.
The first float is the sound's [http://en.wikipedia.org/wiki/Sampling_rate sample rate], the second one the sound's [http://en.wikipedia.org/wiki/Tempo tempo], and the third one the [http://en.wikipedia.org/wiki/Pitch_%28music%29 pitch] of the sound. The boolean representing whether the sound is reversed or not.


==Example==  
==Example==  
<section name="Client" class="client" show="true">
'''Example 1:''' This example would return three float values representing the sample rate, tempo, pitch and a boolean value representing whether the sound is reversed or not, every 5 seconds.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
-- not done yet
local sound
local timer
 
addCommandHandler("playsound",
function ()
    sound = playSound("wasted.mp3")
    timer = setTimer(function() soundProperties(sound) end, 5000, 0)
end
)
 
function soundProperties(sound)
    local sampleRate, tempo, pitch, isReversed = getSoundProperties(sound) --gets the sample rate, tempo, pitch and a boolean value representing whether the sound is reversed or not.
    outputChatBox(sampleRate.." "..tempo.." "..pitch.." "..tostring(isReversed))
end
</syntaxhighlight>
</syntaxhighlight>
</section>


==See Also==
==See Also==
{{Client_audio_functions}}
{{Client_audio_functions}}
[[hu:getSoundProperties]]
[[ar:getSoundProperties]]
[[pt-br:getSoundProperties]]

Latest revision as of 16:36, 26 September 2021

This function gets the properties of a specific sound.

Syntax

float, float, float, bool getSoundProperties( element sound )

OOP Syntax Help! I don't understand this!

Method: sound:getProperties(...)
Counterpart: setSoundProperties


Required Arguments

Returns

This function returns 3 floats and a boolean value:

The first float is the sound's sample rate, the second one the sound's tempo, and the third one the pitch of the sound. The boolean representing whether the sound is reversed or not.

Example

Example 1: This example would return three float values representing the sample rate, tempo, pitch and a boolean value representing whether the sound is reversed or not, every 5 seconds.

local sound 
local timer

addCommandHandler("playsound",
function () 
    sound = playSound("wasted.mp3")
    timer = setTimer(function() soundProperties(sound) end, 5000, 0)
end
)

function soundProperties(sound)
    local sampleRate, tempo, pitch, isReversed = getSoundProperties(sound) --gets the sample rate, tempo, pitch and a boolean value representing whether the sound is reversed or not.
    outputChatBox(sampleRate.." "..tempo.." "..pitch.." "..tostring(isReversed))
end

See Also