Last active
December 31, 2015 09:09
-
-
Save SDraw/7964711 to your computer and use it in GitHub Desktop.
[MTA] FFT
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local handl = nil | |
local sx,_ = guiGetScreenSize() | |
local colors = { tocolor(255,0,0),tocolor(0,255,0) } | |
function clientRenderFunc() | |
if(handl) then | |
dxDrawRectangle(sx/2,0,1,256,tocolor(255,255,255,127)) | |
local bt = getSoundFFTData(handl,2048,257) | |
if(not bt) then return end | |
for i=1,256 do | |
bt[i] = math.sqrt(bt[i])*256 --scale it (sqrt to make low values more visible) | |
dxDrawRectangle(sx/2-bt[i]/2,i-1,bt[i],1) | |
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment