This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Oscillator { | |
constructor(waveFunction, frequency) { | |
const tableLength = Math.round(sampleRate / frequency); | |
const table = new Float32Array(tableLength); | |
for (let i = 0; i < tableLength; i++) { | |
table[i] = waveFunction(i / tableLength); | |
} | |
this.table = table; | |
this.period = tableLength / sampleRate; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Basic implementation of Phase Distortion Synthesis, like as was used in the Casio CZ series. | |
* By Elizabeth Hudnott. | |
*/ | |
const TWO_PI = 2 * Math.PI; | |
const TIME_CONSTANTS = Math.log(2 ** (1023 / 128)); | |
function cosine(phase) { | |
return -Math.cos(TWO_PI * phase); |