Skip to content

Commit

Permalink
Added Web Audio Demo.
Browse files Browse the repository at this point in the history
  • Loading branch information
0xfe committed Aug 13, 2011
1 parent 1e5194d commit 7b4a525
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 9 deletions.
18 changes: 18 additions & 0 deletions go/slices.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package main

import ("fmt")

func sum(arr []int) int {
total := 0

for i := 0; i < len(arr); i++ {
total += arr[i]
}

return total
}

func main() {
total := sum([]int{105, 4, 3, 2, 1})
fmt.Printf("Total = %d\n", total);
}
35 changes: 26 additions & 9 deletions go/wscript
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,32 @@ def configure(ctx):
ctx.env.GOC = "6g"
ctx.env.GOL = "6l"

def go(ctx, source, target):
go_compile = "${GOC} -o ${TGT} ${SRC}"
go_link = "${GOL} -o ${TGT} ${SRC}"
def build(ctx):
sources = ["echo.go", "hello.go", "slices.go"]

object_file = target + ".6"
for file in sources:
# Files with ".go" extensions are automatically compiled and linked
ctx(source=file)

ctx(rule=go_compile, source=source, target=object_file)
ctx(rule=go_link, source=object_file, target=target)
# Remove .bin extension from file
binary = file.replace(".go", "")
ctx(rule="mv ${SRC} ${TGT}", source=(binary + ".bin"), target=binary)

def build(ctx):
go(ctx, "hello.go", "hello")
go(ctx, "echo.go", "echo")
"""
Code to automatically compile and link files with ".go" as their extension.
"""

from waflib import TaskGen

TaskGen.declare_chain(
name = "goc",
rule = "${GOC} -o ${TGT} ${SRC}",
ext_in = ".go",
ext_out = ".6")

TaskGen.declare_chain(
name = "gol",
rule = "${GOL} -o ${TGT} ${SRC}",
ext_in = ".6",
ext_out = ".bin",
reentrant = False)
43 changes: 43 additions & 0 deletions www/audio.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js">
</script>

<script>
var context = new webkitAudioContext();
var snare = new ArrayBuffer();

function playAudio() {
var source = context.createBufferSource();
source.buffer = buffer;
source.connect(context.destination);
source.noteOn(0);

$("#clickme").text("Thanks!");
}

function loadAudio() {
$.ajax({
url: "audio/snare.wav",
success: function(data) {
snare = context.createBuffer(data, true);
$("#clickme").text("Click Me!");
$("#clickme").click(playAudio);
},
dataType: "arraybuffer"
});
return snare;
};


$(function() { loadAudio() });

</script>
</head>

<body>
<h1>Boo</h1>

<a href="#" id="clickme">Loading...</a>
</body>
</html>
Binary file added www/audio/snare.wav
Binary file not shown.

0 comments on commit 7b4a525

Please sign in to comment.