Skip to content

Instantly share code, notes, and snippets.

View nick-thompson's full-sized avatar

Nick Thompson nick-thompson

View GitHub Profile
import React, { useState, useEffect, useRef, useContext } from 'react';
import VisibilitySensor from 'react-visibility-sensor';
import { el, resolve } from '@elemaudio/core';
import srvb from '@elemaudio/srvb';
import Chrome from '../components/Chrome';
import Article from '../components/Article';
import ResizingCanvas from '../components/ResizingCanvas';
import { RenderContext, RenderContextProvider } from './RenderContext';
@nick-thompson
nick-thompson / Freeverb.js
Created April 4, 2022 15:23
An implementation of the Freeverb algorithm in JavaScript using Elementary Audio.
/* First, our Schroeder-Moorer filtered-feedback comb-filters
*
* @param {string} name – for identifying our feedback taps
* @param {number} size – for defining our feedback tap lengths
* @param {Node | number} feedback: [0, 1) – how long the reverb should ring out
* @param {Node | number} damping : [0, 1) – pole position of the lowpass filter
* @param {Node} xn – input signal to filter
*
* @see https://ccrma.stanford.edu/~jos/pasp/Feedback_Comb_Filters.html
*/
@nick-thompson
nick-thompson / Synth.js
Created December 14, 2021 17:47
An example Elementary pattern for writing "MIDI Events" to an in-memory sequence-based synthesizer that ultimately renders its output as a series of el.seq nodes.
// A simple polyphonic Synth which records note events against internal
// sequence data.
//
// After recording a series of events, call the render function to build
// a series of synth voices based on the aggregated sequence data.
export default class Synth {
constructor(key, numVoices) {
this.voices = Array.from({length: numVoices}).map(function(x, i) {
return {
key: `${key}:v:${i}`,
@nick-thompson
nick-thompson / ModMatrix.cpp
Created July 13, 2018 22:16
Modulation Matrix Implementation
template <int Rows, int Cols, typename FloatType>
class ModulationMatrix
{
public:
//==============================================================================
ModulationMatrix (std::array<std::array<FloatType*, Cols>, Rows> params) : m_rawMatrixParams(params) {}
~ModulationMatrix () {}
//==============================================================================
/** Returns the internal raw parameter matrix. */
@nick-thompson
nick-thompson / MatrixMath.js
Last active April 17, 2018 00:03
Some sketchwork on gaussian blur processing on a simple matrix. Kernel generation and convolution. Original work: https://jsfiddle.net/2e9o35xc/53/
/** Calculate and return the euclidean distance between two points. */
function hypot(xi, yi, xf, yf) {
return Math.sqrt(Math.pow(xi - xf, 2) + Math.pow(yi - yf, 2));
}
/** Generates an identity matrix of size (dim x dim). */
function eye(dim) {
var mat = new Array(dim * dim);
for (var i = 0; i < dim; i++) {
@nick-thompson
nick-thompson / fiddle.css
Last active March 18, 2018 12:37 — forked from anonymous/fiddle.css
Animated hexagon in polar coordinates with a superimposed naive sawtooth signal. (source: https://jsfiddle.net/tx1kfuae/42/)
body {
background-color: #222;
}
#canvas {
border: 1px solid #eee;
}
}
@nick-thompson
nick-thompson / .block
Last active January 10, 2017 16:46 — forked from mbostock/.block
Point-Along-Path Interpolation
license: gpl-3.0
// New version
async.parallel([
stores[BY_SEQ_STORE].put.bind(null, formatSeq(doc.metadata.seq, doc.data),
stores[DOC_STORE].put.bind(null, doc.metadata.id, doc.metadata)
], function(err) {
results.push(doc);
return saveUpdateSeq(callback2);
});
// Old version
bootstrap:
@curl -X POST -H 'Content-Type: application/json' -d @bootstrap.json \
https://nick-thompson.cloudant.com/_replicate
update:
@./scripts/update.js
@nick-thompson
nick-thompson / index.js
Created July 18, 2013 18:48
requirebin sketch
var context = new webkitAudioContext()
, node = context.createOscillator()
, Overdrive = require("wa-overdrive")
, overdrive = new Overdrive(context, {
preBand: 1.0,
color: 4000,
drive: 0.8,
postCut: 8000
});