GetSoundLevelData: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(More sensible example)
(Remove obsolete Requirements section)
 
(9 intermediate revisions by 8 users not shown)
Line 12: Line 12:


===Returns===
===Returns===
Returns a two ''integers'' in range from 0 to 32767.
Returns a two ''integers'' in range from 0 to 32768.


==Example==
==Example==
<section name="Client" class="client" show="true">
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
soundHandler = playSound ( "sound.wav" )
local soundHandler = playSound ( "sound.wav" )


function onSoundPlayRender ( )
function onSoundPlayRender ( )
Line 23: Line 22:
         local leftData, rightData = getSoundLevelData ( soundHandler )
         local leftData, rightData = getSoundLevelData ( soundHandler )
if ( leftData ) then
if ( leftData ) then
             dxDrawRectangle ( 0, 0, 64, leftData / 32767 * 256, tocolor ( 255, 0, 0 ) )
             dxDrawRectangle ( 0, 0, 64, leftData / 32768 * 256, tocolor ( 255, 0, 0 ) )
             dxDrawRectangle ( 64, 0, 64, rightData / 32767 * 256, tocolor ( 0, 0, 255 ) )
             dxDrawRectangle ( 64, 0, 64, rightData / 32768 * 256, tocolor ( 0, 0, 255 ) )
         end
         end
     end
     end
end
end
addEventHandler ( "onClientRender", getRootElement(), onSoundPlayRender )
addEventHandler ( "onClientRender", root, onSoundPlayRender )
</syntaxhighlight>
</syntaxhighlight>
</section>
==Requirements==
{{Requirements|n/a|1.3.0-9.04162|}}


==Changelog==
==Changelog==
Line 40: Line 35:


==See Also==
==See Also==
{{Client_audio_functions}}
{{Audio_functions|client}}


[[hu:getSoundLevelData]]
[[ar: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