Boilerplate for ZZFX Synth support
This commit is contained in:
parent
2dc079b950
commit
c3f27d1ad9
5 changed files with 655 additions and 1 deletions
|
|
@ -1,4 +1,5 @@
|
|||
import { getAudioContext } from './superdough.mjs';
|
||||
import * as zzfx from 'zzfx';
|
||||
|
||||
export function gainNode(value) {
|
||||
const node = getAudioContext().createGain();
|
||||
|
|
@ -6,6 +7,28 @@ export function gainNode(value) {
|
|||
return node;
|
||||
}
|
||||
|
||||
export const getZZFX = ({ wave, freq, t, params}) => {
|
||||
params.frequency = freq;
|
||||
params.shape = {
|
||||
'zsine': 0,
|
||||
'ztri': 1,
|
||||
'zsaw': 2,
|
||||
'ztan': 3,
|
||||
'znoise': 4,
|
||||
}[wave];
|
||||
const samples = zzfx.buildSamples(...params);
|
||||
const context = getAudioContext();
|
||||
const buffer = context.createBuffer(
|
||||
samples.length,
|
||||
samples[0].length,
|
||||
context.sampleRate
|
||||
);
|
||||
const source = context.createBufferSource();
|
||||
return {
|
||||
node: source,
|
||||
stop: (time) => source.stop(time), buffer}
|
||||
}
|
||||
|
||||
export const getOscillator = ({ s, freq, t }) => {
|
||||
// make oscillator
|
||||
const o = getAudioContext().createOscillator();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue