GetSoundLevelData: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 11: Line 11:


===Returns===
===Returns===
Returns a 2 values with Left, Right level data from sound, ''false'' otherwise.
Returns a 2 values with Left, Right level data from sound (range is [0,32768]), ''false'' otherwise.


==Example==
==Example==
TODO
This code creates vertical lines of right and left level in center of screen from top to bottom. [http://imageshack.com/a/img716/8689/4ud1.png] Key '''9''' - start, key '''0''' - stop.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
--TODO
local handl = nil
local sx,_ = guiGetScreenSize()
local colors = { tocolor(255,0,0),tocolor(0,255,0) }
function clientRenderFunc()
    if(handl) then
        local ls,rs = getSoundLevelData(handl)
        dxDrawRectangle(sx/2-10,0,10,128*(ls/32768),colors[1])
        dxDrawRectangle(sx/2+10,0,10,128*(rs/32768),colors[2])
    end
end
function musicStartFunc()
    if(not handl) then
        handl = playSound('btr.mp3')
        addEventHandler("onClientRender",root,clientRenderFunc)
    end
end
function musicStopFunc()
    if(handl) then
        stopSound(handl)
        handl = nil
        removeEventHandler("onClientRender",root,clientRenderFunc)
    end
end
bindKey("9","down",musicStartFunc)
bindKey("0","down",musicStopFunc)
</syntaxhighlight>
</syntaxhighlight>


Line 28: Line 56:
==See Also==
==See Also==
{{Client_audio_functions}}
{{Client_audio_functions}}
[[Category:Needs Example]]
[[AR:getSoundLevelData]]
[[AR:getSoundLevelData]]

Revision as of 19:18, 14 December 2013

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 )

Required Arguments

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

Returns

Returns a 2 values with Left, Right level data from sound (range is [0,32768]), false otherwise.

Example

This code creates vertical lines of right and left level in center of screen from top to bottom. [1] Key 9 - start, key 0 - stop.

local handl = nil
local sx,_ = guiGetScreenSize()
local colors = { tocolor(255,0,0),tocolor(0,255,0) }
 
function clientRenderFunc()
    if(handl) then
        local ls,rs = getSoundLevelData(handl)
        dxDrawRectangle(sx/2-10,0,10,128*(ls/32768),colors[1])
        dxDrawRectangle(sx/2+10,0,10,128*(rs/32768),colors[2])
    end
end
 
function musicStartFunc()
    if(not handl) then
        handl = playSound('btr.mp3')
        addEventHandler("onClientRender",root,clientRenderFunc)
    end
end
 
function musicStopFunc()
    if(handl) then
        stopSound(handl)
        handl = nil
        removeEventHandler("onClientRender",root,clientRenderFunc)
    end
end
 
bindKey("9","down",musicStartFunc)
bindKey("0","down",musicStopFunc)

Requirements

Minimum server version n/a
Minimum client version 1.3.0-9.04162

Note: Using this feature requires the resource to have the above minimum version declared in the meta.xml <min_mta_version> section. e.g. <min_mta_version client="1.3.0-9.04162" />

Changelog

Version Description
1.3.2 Added player element to use a players voice

See Also