Skip to content

Commit

Permalink
Add LFO module and control inputs for delay
Browse files Browse the repository at this point in the history
  • Loading branch information
oamaok committed Oct 19, 2021
1 parent b20737f commit a4567b2
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 5 deletions.
12 changes: 12 additions & 0 deletions client/src/components/modules/Delay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,18 @@ class Delay extends Component<Props> implements IModule {
<Knob moduleId={id} name="wet" min={0} max={1} initial={0.5} />
<Knob moduleId={id} name="dry" min={0} max={1} initial={1} />
<ModuleInputs>
<Socket
moduleId={id}
type="input"
name="Feedback"
node={this.node.parameters.get('feedBack')}
/>
<Socket
moduleId={id}
type="input"
name="Delay"
node={this.node.parameters.get('delayTime')}
/>
<Socket moduleId={id} type="input" name="In" node={this.node} />
</ModuleInputs>
<ModuleOutputs>
Expand Down
42 changes: 42 additions & 0 deletions client/src/components/modules/LFO.tsx
Original file line number Diff line number Diff line change
@@ -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<Props> 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 (
<Module id={id} name="LFO" width={120}>
<Knob moduleId={id} name="frequency" min={0.01} max={10} initial={1} />

<ModuleInputs></ModuleInputs>

<ModuleOutputs>
<Socket moduleId={id} type="output" name="out" node={this.node} />
</ModuleOutputs>
</Module>
)
}
}

export default LFO
2 changes: 2 additions & 0 deletions client/src/moduleMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -18,4 +19,5 @@ export const moduleMap = {
Sequencer,
Mixer,
Delay,
LFO,
} as const
8 changes: 3 additions & 5 deletions client/worklets/Delay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)
}
}

Expand All @@ -28,7 +26,7 @@ class Delay extends AudioWorkletProcessor {
minValue: 0.01,
maxValue: 10,
defaultValue: 0.1,
automationRate: 'k-rate',
automationRate: 'a-rate',
},
{
name: 'feedBack',
Expand Down

0 comments on commit a4567b2

Please sign in to comment.