Skip to content

Instantly share code, notes, and snippets.

View diegovgsilva95's full-sized avatar

Diego Silva diegovgsilva95

View GitHub Profile
@diegovgsilva95
diegovgsilva95 / map_number.mjs
Created September 26, 2022 20:37
Map number
export function mapNumber(v, fn, fx, tn, tx, constrain = true){
if(fx == fn)
return v < fn ? tn : tx;
v = (v - fn) / (fx - fn);
if(constrain)
v = Math.min(1, Math.max(0, v));
@diegovgsilva95
diegovgsilva95 / index.js
Created September 17, 2021 03:59
Algorithm for phase adjustment between waves with two different frequencies
/**
* @protected {number} lastFrequency => In hertz, initialized as 0
* @protected {number} sampleRate => Audio output sample rate (e.g.: 8000 for 8KHz, 16000 for 16KHz, 44100 for 44.1KHz, 48000 for 48KHz and so on)
* @protected {number} frame => Current accumulative sample index
* @protected {number} offset => Accumulative phase, initialized as 0
*
* @param {number} frequency in hertz
*
* @returns {number} sample (-1 <= sample <= 1)
*/
@robinrendle
robinrendle / reset.css
Last active July 24, 2021 01:20
A CSS reset with sane defaults
/*Box sizing (the nuclear option) */
*, *:before, *:after {
-ms-box-sizing: border-box;
-webkit-box-sizing: border-box;
-moz-box-sizing:border-box;
box-sizing: border-box;
}
/* Fix font rendering defaults */
html, button {