Skip to content

Instantly share code, notes, and snippets.

View jussi-kalliokoski's full-sized avatar

Jussi Kalliokoski jussi-kalliokoski

View GitHub Profile
@jussi-kalliokoski
jussi-kalliokoski / moz-load-file.js
Created April 18, 2012 06:12
Load an audio file into a Float32Array using Audio Data API
function mozLoadFile (url, callback) {
function throwAsync (err) {
setTimeout(function () {
callback(typeof err === 'string' ?
Error(err) : err);
}, 0);
}
function onaudioavailable (e) {
loadedmetadata();
@jussi-kalliokoski
jussi-kalliokoski / osclfodel.js
Created April 6, 2012 16:42
audiolib.js: simple automation and effects
/* First, we need a Sink */
var dev = Sink();
/* So, here we'll create an oscillator and an LFO to control the oscillator FM. */
var osc = audioLib.Oscillator(dev.sampleRate, 440);
var lfo = audioLib.Oscillator(dev.sampleRate, 0.1);
/*
Then we'll put a delay effect after the oscillator.
Note that we have to use createBufferBased() to make a multi-channel effect.
@jussi-kalliokoski
jussi-kalliokoski / Makefile
Created March 30, 2012 19:55
sudo make me a sandwich
NOOP := rm -f
me:
@$(NOOP)
a:
@$(NOOP)
sandwich:
@if [ `whoami` = "root" ]; then echo "one sandwich coming right up!"; else echo "hah, make me!"; fi
@jussi-kalliokoski
jussi-kalliokoski / pointers.c
Created March 30, 2012 18:57
Pointers in JavaScript
#include <stdlib.h>
#include <stdio.h>
int main () {
char *c = (char *)malloc(sizeof(char) * 16);
char *cc = c;
for (int i=0; i<16; i++) {
printf("%d\n", cc[0]);
@jussi-kalliokoski
jussi-kalliokoski / line165
Created March 22, 2012 13:00
gdb stacktrace for node-cubeb
#0 0x000000000056b1ad in v8::HandleScope::HandleScope() ()
#1 0x00007ffff59da056 in CubebStream::DataCB (stream=0xc806f0, user=0xc80480, buffer=0x7fffef4cc040, nframes=11113) at ../src/stream.cpp:165
#2 0x00007ffff57cf82e in stream_request_callback (s=0xc80740, nbytes=22226, u=0xc806f0) at src/cubeb_pulse.c:107
#3 0x00007ffff55b1b4c in ?? () from /usr/lib/libpulse.so.0
#4 0x00007ffff514c303 in ?? () from /usr/lib/libpulsecommon-1.1.so
#5 0x00007ffff514c673 in pa_pdispatch_run () from /usr/lib/libpulsecommon-1.1.so
#6 0x00007ffff55951ed in ?? () from /usr/lib/libpulse.so.0
#7 0x00007ffff5150f19 in ?? () from /usr/lib/libpulsecommon-1.1.so
#8 0x00007ffff55a7c8e in pa_mainloop_dispatch () from /usr/lib/libpulse.so.0
#9 0x00007ffff55a8055 in pa_mainloop_iterate () from /usr/lib/libpulse.so.0
@jussi-kalliokoski
jussi-kalliokoski / detach.c
Created March 18, 2012 13:17
Custom control structure 'detach' with accidental return.
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#define detach if (fork()); else for (;; exit(0))
int calculate () {
detach {
sleep(1);
return 5;
@jussi-kalliokoski
jussi-kalliokoski / example.js
Created February 6, 2012 16:11
A simple proposal for the interfaces needed for useful MIDI access
// Example usage, a MIDI proxy that picks the first available MIDI input and routes its messages to the first MIDI outputs
navigator.getUserMedia({midi: true}, function (MIDIAccess) {
try {
var input = MIDIAccess.getInput(MIDIAccess.enumerateInputs()[0]);
var output = MIDIAccess.getOutput(MIDIAccess.enumerateInputs()[0]);
} catch (e) {
console.error("Couldn't find suitable MIDI devices");
}
@jussi-kalliokoski
jussi-kalliokoski / test.js
Created January 31, 2012 11:13
Light-weight Vector class for JS
/* JS SHELL */
if (typeof load !== 'undefined') {
load('./vector.js');
/* NODEJS */
} else if (typeof require !== 'undefined') {
Vector = require('./vector.js');
print = function () {
return console.log.apply(console, arguments);
};
/* BROWSER */
@jussi-kalliokoski
jussi-kalliokoski / number-math.js
Created January 25, 2012 19:30
Extend Number.prototype with Math functions
(function (define, names) {
if (!define || !names.forEach) return;
names.forEach(function (name) {
define(Number.prototype, name, {
value: function () {
return Math[name].apply(
Math,
[this].concat([].slice.call(arguments))
@jussi-kalliokoski
jussi-kalliokoski / setImmediate.js
Created January 22, 2012 14:48
A small shim for the setImmediate() that creates a callback similar to process.nextTick() on node.js
(function (global, prefixes, timeouts, id, i) {
if (typeof process !== 'undefined' && process && process.nextTick) {
global.setImmediate = function (callback, args) {
var i = id;
timeouts[id] = {
c: callback,
a: args || [],
};