GetSoundLevelData: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
(Remove obsolete Requirements section)
 
(24 intermediate revisions by 15 users not shown)
Line 1: Line 1:
__NOTOC__  
__NOTOC__  
{{Client function}}
{{Client function}}
{{New feature/item|4.0140|1.3.0|4162|
This function gets the left/right level from a [[sound]] [[element]].
Get a sound level data from [[sound]] [[element]].
{{New feature/item|3.0132|1.3.2||
}}<br />
If the element is a player, this function will use the players voice.
<br />
}}
 
==Syntax==  
==Syntax==  
<syntaxhighlight lang="lua">int Left, int Right getSoundLevelData( element theSound )</syntaxhighlight>  
<syntaxhighlight lang="lua">int, int getSoundLevelData ( element theSound )</syntaxhighlight>  
 
{{OOP||[[sound]]:getLevelData}}
===Required Arguments===  
===Required Arguments===  
*'''theSound''' The [[sound]] [[element]] which level data you want to return.
*'''theSound:''' the [[sound]] [[element]] which level data you want to return.


===Returns===
===Returns===
Returns a 2 values with Left, Right level data from sound, ''false'' otherwise.
Returns a two ''integers'' in range from 0 to 32768.


==Requirements==
==Example==
{{Requirements|n/a|1.3.0-9.04162|}}
<syntaxhighlight lang="lua">
local soundHandler = playSound ( "sound.wav" )
 
function onSoundPlayRender ( )
    if ( soundHandler ) then
        local leftData, rightData = getSoundLevelData ( soundHandler )
if ( leftData ) then
            dxDrawRectangle ( 0, 0, 64, leftData / 32768 * 256, tocolor ( 255, 0, 0 ) )
            dxDrawRectangle ( 64, 0, 64, rightData / 32768 * 256, tocolor ( 0, 0, 255 ) )
        end
    end
end
addEventHandler ( "onClientRender", root, onSoundPlayRender )
</syntaxhighlight>
 
==Changelog==
{{ChangelogHeader}}
{{ChangelogItem|1.3.2|Added player element to use a players voice}}


==See Also==
==See Also==
{{Client_audio_functions}}
{{Audio_functions|client}}
 
[[hu:getSoundLevelData]]
[[ar:getSoundLevelData]]
[[ro:getSoundLevelData]]
[[pt-br:getSoundLevelData]]

Latest revision as of 17:07, 7 November 2024

This function gets the left/right level from a sound element. If the element is a player, this function will use the players voice.

Syntax

int, int getSoundLevelData ( element theSound )

OOP Syntax Help! I don't understand this!

Method: sound:getLevelData(...)


Required Arguments

  • theSound: the sound element which level data you want to return.

Returns

Returns a two integers in range from 0 to 32768.

Example

local soundHandler = playSound ( "sound.wav" )

function onSoundPlayRender ( )
    if ( soundHandler ) then
        local leftData, rightData = getSoundLevelData ( soundHandler )
	if ( leftData ) then
            dxDrawRectangle ( 0, 0, 64, leftData / 32768 * 256, tocolor ( 255, 0, 0 ) )
            dxDrawRectangle ( 64, 0, 64, rightData / 32768 * 256, tocolor ( 0, 0, 255 ) )
        end
    end
end
addEventHandler ( "onClientRender", root, onSoundPlayRender )

Changelog

Version Description
1.3.2 Added player element to use a players voice

See Also