From a4567b213aedd41bdb53c5f3f91d6f5525a9da75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Teemu=20P=C3=A4=C3=A4kk=C3=B6nen?= Date: Tue, 19 Oct 2021 23:08:13 +0300 Subject: [PATCH] Add LFO module and control inputs for delay --- client/src/components/modules/Delay.tsx | 12 +++++++ client/src/components/modules/LFO.tsx | 42 +++++++++++++++++++++++++ client/src/moduleMap.ts | 2 ++ client/worklets/Delay.ts | 8 ++--- 4 files changed, 59 insertions(+), 5 deletions(-) create mode 100644 client/src/components/modules/LFO.tsx diff --git a/client/src/components/modules/Delay.tsx b/client/src/components/modules/Delay.tsx index 50471a1..c6efef9 100644 --- a/client/src/components/modules/Delay.tsx +++ b/client/src/components/modules/Delay.tsx @@ -42,6 +42,18 @@ class Delay extends Component implements IModule { + + diff --git a/client/src/components/modules/LFO.tsx b/client/src/components/modules/LFO.tsx new file mode 100644 index 0000000..ef2868f --- /dev/null +++ b/client/src/components/modules/LFO.tsx @@ -0,0 +1,42 @@ +import { h, Component } from 'kaiku' +import { IModule } from '../../types' +import { getAudioContext } from '../../audio' +import { WorkletNode } from '../../worklets' +import Socket from '../module-parts/Socket' +import Module from '../module-parts/Module' +import Knob from '../module-parts/Knob' +import { connectKnobToParam } from '../../modules' + +import { ModuleInputs, ModuleOutputs } from '../module-parts/ModuleSockets' +type Props = { + id: string +} + +class LFO extends Component implements IModule { + node: OscillatorNode + + constructor(props: Props) { + super(props) + const audioContext = getAudioContext() + this.node = audioContext.createOscillator() + this.node.start() + + connectKnobToParam(props.id, 'frequency', this.node.frequency) + } + + render({ id }: Props) { + return ( + + + + + + + + + + ) + } +} + +export default LFO diff --git a/client/src/moduleMap.ts b/client/src/moduleMap.ts index de20deb..ac3c40f 100644 --- a/client/src/moduleMap.ts +++ b/client/src/moduleMap.ts @@ -7,6 +7,7 @@ import BiquadFilter from './components/modules/Filter' import Sequencer from './components/modules/Sequencer' import Mixer from './components/modules/Mixer' import Delay from './components/modules/Delay' +import LFO from './components/modules/LFO' export const moduleMap = { AudioOut, @@ -18,4 +19,5 @@ export const moduleMap = { Sequencer, Mixer, Delay, + LFO, } as const diff --git a/client/worklets/Delay.ts b/client/worklets/Delay.ts index 17d59fa..fa51674 100644 --- a/client/worklets/Delay.ts +++ b/client/worklets/Delay.ts @@ -2,8 +2,6 @@ const getParameterValueAtSample = (parameter: Float32Array, sample: number) => { return parameter.length === 1 ? parameter[0] : parameter[sample] } -const lerp = (a: number, b: number, t: number) => a + t * (b - a) - const resample = ( src: Float32Array, dst: Float32Array, @@ -16,8 +14,8 @@ const resample = ( const srcI = ~~srcPos const t = srcPos - srcI const a = src[srcI] - const b = src[srcI + 1] - dst[i] = lerp(a, b, t) + const b = src[(srcI + 1) % srcLen] + dst[i] = a + t * (b - a) } } @@ -28,7 +26,7 @@ class Delay extends AudioWorkletProcessor { minValue: 0.01, maxValue: 10, defaultValue: 0.1, - automationRate: 'k-rate', + automationRate: 'a-rate', }, { name: 'feedBack',