Skip to content

Instantly share code, notes, and snippets.

@srikumarks
srikumarks / sendMIDIMessage.html
Created September 6, 2012 06:20
sendMIDIMessage() wrapper speed
<script>
var sendMIDIMessage = (function () {
var counter = 0;
return function (arr) {
counter++;
if (counter % 1000000 === 0) {
console.log(counter + " messages");
}
};
}());
@srikumarks
srikumarks / webview.go
Created October 1, 2012 04:50
A simple local file server written in Go
// This code is hereby placed in the PUBLIC DOMAIN.
package main
import "fmt"
import "net/http"
import "os"
// A very simple go local file server.
// 1. Serves on port 8000
// 2. Serves files relative to the directory in which you run the server.
@srikumarks
srikumarks / arc.js
Created October 17, 2012 17:55
The arc challenge using IO.WebServer.js
// This server doesn't suffer from the problem
// mentioned in http://arclanguage.org/item?id=1263
//
// Run by placing this file alongside IO.WebServer.js
// and IO.js and invoking node as -
// node arc.js
//
// Then visit http://localhost:9000/said in your browser.
var IO = require('./IO.WebServer.js');
@srikumarks
srikumarks / matrix-dimension.js
Created December 16, 2012 04:05
Getting the dimensions of a multidimensional JS array.
// Assumes a valid matrix and returns its dimension array.
// Won't work for irregular matrices, but is cheap.
function dim(mat) {
if (mat instanceof Array) {
return [mat.length].concat(dim(mat[0]));
} else {
return [];
}
}
@srikumarks
srikumarks / drift.html
Created January 26, 2013 08:54
(Web Audio API) A test to see if accumulating sample time drifts away from AudioContext.currentTime.
<script>
var ac = new webkitAudioContext;
var j = ac.createScriptProcessor(1024, 1, 1);
var startTime, startTimeGrabbed = false, samples = 0, sampleCountTime = 0, frames = 0;
j.onaudioprocess = function (event) {
if (!startTimeGrabbed) {
startTime = ac.currentTime;
samples = 0;
@srikumarks
srikumarks / multi-channel-sinewave-test.html
Created May 7, 2013 04:49
Fixed multi-channel sine wave test of Web Audio API glitching.
<!DOCTYPE HTML>
<body>
<script>
var N = 1;
try {
var ctx = new AudioContext();
} catch (e) {
ctx = new webkitAudioContext();
}
@srikumarks
srikumarks / AudioContextPatch.js
Created June 11, 2013 00:45
Get an AudioContext class that has "future compatible" names for methods.
// Gets the AudioContext class when in a browser environment.
function getAudioContext() {
try {
var AC = (window.AudioContext || window.webkitAudioContext || window.mozAudioContext);
function myAC() {
var ac = new AC();
// Future compatible names.
ac.createGain = ac.createGainNode = (ac.createGain || ac.createGainNode);
@srikumarks
srikumarks / simple-ping.js
Created June 14, 2013 06:44
Simple Ping using Web Audio API
var audioContext = new AudioContext();
var kFreq = 660, kDecayTime = 0.5, kStartTime = 1.5, kGain = 0.25;
var oscNode = audioContext.createOscillator();
oscNode.frequency.value = kFreq;
var gainNode = audioContext.createGain();
gainNode.gain.value = kGain;
gainNode.gain.setTargetAtTime(0.0, audioContext.currentTime, kDecayTime);
oscNode.connect(gainNode);
gainNode.connect(audioContext.destination);
oscNode.start(audioContext.currentTime + kStartTime); // Start a little into the future.
@srikumarks
srikumarks / AudioContextMonkeyPatch.js
Last active December 18, 2015 11:59
AudioContext monkey patch that makes old style and new style names available simultaneously.
/* Copyright (c) 2013, Srikumar K. S. ([email protected])
* All rights reserved.
*
* Licensed under the MIT License -
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
@srikumarks
srikumarks / cspdemo.html
Last active December 19, 2015 17:38
So called "CSP" using IO.js. Implements the "dramatic .. fall-out-of-your-chair" example shown in http://swannodette.github.io/2013/07/12/communicating-sequential-processes/
<div id="render"></div>
<!-- Take these from https://github.com/srikumarks/IO.js -->
<script src="IO.js"></script>
<script src="IO.Browser.js"></script>
<script>
// The rendering process that writes out the array passed to
// it into the div element with id = 'render'.
var render = IO.do([
function (arr) {
if (arr.length > 10) {