Skip to content

Instantly share code, notes, and snippets.

@SDraw
Last active December 31, 2015 09:09
Show Gist options
  • Save SDraw/7964716 to your computer and use it in GitHub Desktop.
Save SDraw/7964716 to your computer and use it in GitHub Desktop.
[MTA] Waveform
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 = getSoundWaveData(handl,512)
if(not bt) then return end
for i=1,127 do
dxDrawLine(sx/2+64*bt[2*i-1],i*2-2,sx/2+64*bt[2*(i+1)-1],(i+1)*2-2,colors[2])
dxDrawLine(sx/2+64*bt[2*i],i*2-1,sx/2+64*bt[2*(i+1)],(i+1)*2-1,colors[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('btr.mp3')
addEventHandler("onClientRender",root,clientRenderFunc)
addEventHandler("onClientSoundStopped",root,clientSoundStopFunc)
end
end
function musicStopFunc()
if(handl) then
removeEventHandler("onClientRender",root,clientRenderFunc)
removeEventHandler("onClientSoundStopped",root,clientSoundStopFunc)
stopSound(handl)
handl = nil
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