SHOW:
|
|
- or go back to the newest paste.
| 1 | if html and html:IsValid() then html:Remove() end | |
| 2 | ||
| 3 | local html = vgui.Create("DHTML") _G.html = html
| |
| 4 | ||
| 5 | html:AddFunction("gmod", "print", print)
| |
| 6 | html:AddFunction("gmod", "data", function(data)
| |
| 7 | pcall(function() | |
| 8 | local data = CompileString(data, "data")() | |
| 9 | hook.Call("Spectrum", nil, data)
| |
| 10 | end) | |
| 11 | end) | |
| 12 | ||
| 13 | local player = setmetatable( | |
| 14 | {
| |
| 15 | }, | |
| 16 | {
| |
| 17 | __index = function(self, func_name) | |
| 18 | return function(...) | |
| 19 | local tbl = {...}
| |
| 20 | ||
| 21 | for key, val in pairs(tbl) do | |
| 22 | - | local str = ("%s(%q);"):format(func_name, table.concat(tbl, ", "))
|
| 22 | + | |
| 23 | ||
| 24 | if tbl[key] == "nil" or tbl[key] == "NULL" then | |
| 25 | tbl[key] = "null" | |
| 26 | end | |
| 27 | end | |
| 28 | ||
| 29 | local str = ("%s(%q)"):format(func_name, table.concat(tbl, ", "))
| |
| 30 | html:QueueJavascript(str) | |
| 31 | --print(str) | |
| 32 | end | |
| 33 | - | var obj = null; |
| 33 | + | |
| 34 | - | function player() |
| 34 | + | |
| 35 | ) | |
| 36 | - | if (!obj) |
| 36 | + | |
| 37 | - | obj = new Audio(); |
| 37 | + | |
| 38 | html:OpenURL("http://dl.dropbox.com/u/244444/gmod_audio.html")
| |
| 39 | - | return obj; |
| 39 | + | |
| 40 | var AudioContext = window.AudioContext || window.webkitAudioContext; | |
| 41 | ||
| 42 | - | function play(str) |
| 42 | + | window.onerror = function(desc, file, line) |
| 43 | {
| |
| 44 | - | try |
| 44 | + | gmod.print(desc) |
| 45 | gmod.print(file) | |
| 46 | - | player().src = str; |
| 46 | + | gmod.print(line) |
| 47 | - | player().play(); |
| 47 | + | |
| 48 | ||
| 49 | - | gmod.print("playing " + player().src);
|
| 49 | + | var audio = new AudioContext |
| 50 | var analyser = audio.createAnalyser() | |
| 51 | - | catch(err) |
| 51 | + | analyser.connect(audio.destination) |
| 52 | ||
| 53 | - | gmod.print(err); |
| 53 | + | setInterval( |
| 54 | function() | |
| 55 | {
| |
| 56 | var spectrum = new Uint8Array(analyser.frequencyBinCount); | |
| 57 | analyser.getByteFrequencyData(spectrum); | |
| 58 | - | player.play("http://dl.dropbox.com/u/244444/2-02%20New%20Map.mp3") |
| 58 | + | |
| 59 | var lol = new Array(spectrum.length); | |
| 60 | ||
| 61 | for(var i = 0; i < spectrum.length; ++i) | |
| 62 | lol[i] = spectrum[i] / 255; | |
| 63 | ||
| 64 | gmod.data("return {" + lol.join(",") + "}");
| |
| 65 | }, | |
| 66 | 0 | |
| 67 | ); | |
| 68 | ||
| 69 | function download(url, callback) | |
| 70 | {
| |
| 71 | var request = new XMLHttpRequest | |
| 72 | ||
| 73 | request.open("GET", url, true)
| |
| 74 | request.responseType = "arraybuffer" | |
| 75 | request.send(null) | |
| 76 | ||
| 77 | request.onload = function() | |
| 78 | {
| |
| 79 | gmod.print("loaded \"" + url + "\"")
| |
| 80 | gmod.print("status " + request.status)
| |
| 81 | callback(request.response) | |
| 82 | } | |
| 83 | ||
| 84 | request.onprogress = function(event) | |
| 85 | {
| |
| 86 | gmod.print(Math.round(event.loaded / event.total * 100) + "%") | |
| 87 | } | |
| 88 | } | |
| 89 | ||
| 90 | function play(url) | |
| 91 | {
| |
| 92 | download(url, function(data) | |
| 93 | {
| |
| 94 | gmod.print("decoding " + data.byteLength + " ...")
| |
| 95 | audio.decodeAudioData(data, function(buffer) | |
| 96 | {
| |
| 97 | gmod.print("asdasds")
| |
| 98 | var source = audio.createBufferSource() | |
| 99 | source.buffer = buffer | |
| 100 | source.loop = true | |
| 101 | source.connect(analyser) | |
| 102 | source.noteOn(0) | |
| 103 | ||
| 104 | gmod.print("LOADED AND DECODED")
| |
| 105 | }, | |
| 106 | function(err) | |
| 107 | {
| |
| 108 | gmod.print("decoding error " + err)
| |
| 109 | }) | |
| 110 | }) | |
| 111 | } | |
| 112 | ]] | |
| 113 | ||
| 114 | player.play("http://dl.dropbox.com/u/244444/cdimario.mp3")
| |
| 115 | ||
| 116 | print("hi") |