This commit is contained in:
Jade (Rose) Rowland 2024-03-03 00:37:33 -05:00
parent 8a7d72bf24
commit 7383dca9ee
2 changed files with 38 additions and 91 deletions

View file

@ -26,7 +26,9 @@ const noises = ['pink', 'white', 'brown', 'crackle'];
export function registerSynthSounds() { export function registerSynthSounds() {
[...waveforms].forEach((s, i) => { [...waveforms].forEach((s, i) => {
registerSound(s, (begin, value, onended) => { registerSound(
s,
(begin, value, onended) => {
const ac = getAudioContext(); const ac = getAudioContext();
let { note, freq, duration } = value; let { note, freq, duration } = value;
note = note || 36; note = note || 36;
@ -66,7 +68,9 @@ export function registerSynthSounds() {
// envGain?.stop(time); // envGain?.stop(time);
}, },
}; };
}); },
{ type: 'synth', prebake: true },
);
}); });
[...noises].forEach((s) => { [...noises].forEach((s) => {

View file

@ -111,29 +111,6 @@ class DistortProcessor extends AudioWorkletProcessor {
registerProcessor('distort-processor', DistortProcessor); registerProcessor('distort-processor', DistortProcessor);
// class SupersawProcessor extends AudioWorkletProcessor {
// static get parameterDescriptors() {
// return [
// { name: 'distort', defaultValue: 0 },
// { name: 'postgain', defaultValue: 1 },
// ];
// }
// constructor() {
// super();
// }
// process(inputs, outputs, parameters) {
// const output = outputs[0];
// let saw = (x, t) => ((x * t % 1) - 0.5) * 2
// }
// }
// registerProcessor('supersaw-processor', SupersawProcessor);
const saw = (v) => v - Math.floor(v);
const twoPI = Math.PI * 2;
const polyBlep = (t, dt) => { const polyBlep = (t, dt) => {
// 0 <= t < 1 // 0 <= t < 1
if (t < dt) { if (t < dt) {
@ -155,25 +132,6 @@ const polyBlep = (t, dt) => {
} }
}; };
const inc = () => {
t += freqInSecondsPerSample;
t -= bitwiseOrZero(t);
};
const square_number = (x) => {
return x * x;
};
const blep = (t, dt) => {
if (t < dt) {
return -square_number(t / dt - 1);
} else if (t > 1 - dt) {
return square_number((t - 1) / dt + 1);
} else {
return 0;
}
};
const polySaw = (t, dt) => { const polySaw = (t, dt) => {
// Correct phase, so it would be in line with sin(2.*M_PI * t) // Correct phase, so it would be in line with sin(2.*M_PI * t)
t += 0.5; t += 0.5;
@ -184,8 +142,6 @@ const polySaw = (t, dt) => {
// return naive_saw; // return naive_saw;
}; };
const saw2 = (x, t) => (((x * t) % 1) - 0.5) * 2;
class BetterOscillatorProcessor extends AudioWorkletProcessor { class BetterOscillatorProcessor extends AudioWorkletProcessor {
constructor() { constructor() {
super(); super();
@ -252,9 +208,6 @@ class BetterOscillatorProcessor extends AudioWorkletProcessor {
const output = outputs[0]; const output = outputs[0];
for (let i = 0; i < output[0].length; i++) { for (let i = 0; i < output[0].length; i++) {
// const blep = polyBlep(this.phase, frequency / sampleRate);
// console.log(blep);
// const out = saw2(frequency, this.phase / sampleRate);
const out = polySaw(this.phase, frequency / sampleRate); const out = polySaw(this.phase, frequency / sampleRate);
output[0][i] = out; output[0][i] = out;
@ -264,16 +217,6 @@ class BetterOscillatorProcessor extends AudioWorkletProcessor {
this.phase = this.phase - 1; this.phase = this.phase - 1;
} }
} }
// for (let i = 0; i < outlen; x++) {
// const val = saw2(frequency, this.phase)
// // out[x] = 2 * saw(dt + this.phase) - 1;
// // out[x] = polySaw(this.phase, dt);
// }
// this.phase = this.phase + dt * outlen;
// this.phase %= sampleRate;
return true; return true;
// for (let z = 0; z < outputs.length; z++) { // for (let z = 0; z < outputs.length; z++) {