GetSoundLevelData: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
|||
Line 22: | Line 22: | ||
function clientRenderFunc() | function clientRenderFunc() | ||
if(handl) then | if(handl) then | ||
local ls,rs = getSoundLevelData(handl) | |||
if(ls ~= false) then | |||
dxDrawRectangle(sx/2-10,0,10,128*(ls/32768),colors[1]) | |||
dxDrawRectangle(sx/2+10,0,10,128*(rs/32768),colors[2]) | |||
end | |||
end | |||
end | |||
function clientSoundStopFunc(_) | |||
if(source == handl) then | |||
removeEventHandler("onClientRender",root,clientRenderFunc) | |||
removeEventHandler("onClientSoundStopped",root,clientSoundStopFunc) | |||
handl = nil | |||
end | end | ||
end | end | ||
Line 30: | Line 40: | ||
function musicStartFunc() | function musicStartFunc() | ||
if(not handl) then | if(not handl) then | ||
handl = playSound(' | handl = playSound('nya.mp3') | ||
addEventHandler("onClientRender",root,clientRenderFunc) | addEventHandler("onClientRender",root,clientRenderFunc) | ||
addEventHandler("onClientSoundStopped",root,clientSoundStopFunc) | |||
end | end | ||
end | end | ||
Line 40: | Line 51: | ||
handl = nil | handl = nil | ||
removeEventHandler("onClientRender",root,clientRenderFunc) | removeEventHandler("onClientRender",root,clientRenderFunc) | ||
removeEventHandler("onClientSoundStopped",root,clientSoundStopFunc) | |||
end | end | ||
end | end |
Revision as of 21:13, 16 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
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) if(ls ~= false) then dxDrawRectangle(sx/2-10,0,10,128*(ls/32768),colors[1]) dxDrawRectangle(sx/2+10,0,10,128*(rs/32768),colors[2]) end end end function clientSoundStopFunc(_) if(source == handl) then removeEventHandler("onClientRender",root,clientRenderFunc) removeEventHandler("onClientSoundStopped",root,clientSoundStopFunc) handl = nil end end function musicStartFunc() if(not handl) then handl = playSound('nya.mp3') addEventHandler("onClientRender",root,clientRenderFunc) addEventHandler("onClientSoundStopped",root,clientSoundStopFunc) end end function musicStopFunc() if(handl) then stopSound(handl) handl = nil removeEventHandler("onClientRender",root,clientRenderFunc) removeEventHandler("onClientSoundStopped",root,clientSoundStopFunc) end end bindKey("9","down",musicStartFunc) bindKey("0","down",musicStopFunc)
Requirements
This template will be deleted.
Changelog
Version | Description |
---|
1.3.2 | Added player element to use a players voice |
See Also
- getRadioChannel
- getRadioChannelName
- getSFXStatus
- getSoundBPM
- getSoundBufferLength
- getSoundEffectParameters
- getSoundEffects
- getSoundFFTData
- getSoundLength
- getSoundLevelData
- getSoundMaxDistance
- getSoundMetaTags
- getSoundMinDistance
- getSoundPan
- getSoundPosition
- getSoundProperties
- getSoundSpeed
- getSoundVolume
- getSoundWaveData
- isSoundLooped
- isSoundPanningEnabled
- isSoundPaused
- playSFX3D
- playSFX
- playSound3D
- playSound
- setRadioChannel
- setSoundEffectEnabled
- setSoundEffectParameter
- setSoundLooped
- setSoundMaxDistance
- setSoundMinDistance
- setSoundPan
- setSoundPanningEnabled
- setSoundPaused
- setSoundPosition
- setSoundProperties
- setSoundSpeed
- setSoundVolume
- stopSound
- Shared
- playSoundFrontEnd