Enhance FM synthesis + cleaning code architecture
This commit is contained in:
@ -153,11 +153,11 @@ export class AudioPlayer {
|
||||
this.currentMode = mode
|
||||
}
|
||||
|
||||
setAlgorithm(algorithmId: number, lfoRates?: number[]): void {
|
||||
setAlgorithm(algorithmId: number, lfoRates?: number[], pitchLFO?: { waveform: number; depth: number; baseRate: number }): void {
|
||||
this.currentAlgorithm = algorithmId
|
||||
if (this.fmSource) {
|
||||
const algorithm = getAlgorithmById(algorithmId)
|
||||
this.fmSource.setAlgorithm(algorithm, lfoRates)
|
||||
this.fmSource.setAlgorithm(algorithm, lfoRates, pitchLFO)
|
||||
}
|
||||
}
|
||||
|
||||
@ -194,7 +194,8 @@ export class AudioPlayer {
|
||||
const algorithm = getAlgorithmById(this.currentAlgorithm)
|
||||
const patch = formula ? JSON.parse(formula) : null
|
||||
const lfoRates = patch?.lfoRates || undefined
|
||||
this.fmSource.setAlgorithm(algorithm, lfoRates)
|
||||
const pitchLFO = patch?.pitchLFO || undefined
|
||||
this.fmSource.setAlgorithm(algorithm, lfoRates, pitchLFO)
|
||||
this.fmSource.setOperatorLevels(a, b, c, d)
|
||||
this.fmSource.setBaseFrequency(220 * this.currentPitch)
|
||||
this.fmSource.setFeedback(this.currentFeedback)
|
||||
|
||||
@ -34,14 +34,15 @@ export class FMSourceEffect implements Effect {
|
||||
// Parameters handled via specific methods
|
||||
}
|
||||
|
||||
setAlgorithm(algorithm: FMAlgorithm, lfoRates?: number[]): void {
|
||||
setAlgorithm(algorithm: FMAlgorithm, lfoRates?: number[], pitchLFO?: { waveform: number; depth: number; baseRate: number }): void {
|
||||
if (!this.processorNode) return
|
||||
this.processorNode.port.postMessage({
|
||||
type: 'algorithm',
|
||||
value: {
|
||||
id: algorithm.id,
|
||||
ratios: algorithm.frequencyRatios,
|
||||
lfoRates: lfoRates || [0.37, 0.53, 0.71, 0.43]
|
||||
lfoRates: lfoRates || [0.37, 0.53, 0.71, 0.43],
|
||||
pitchLFO: pitchLFO || { waveform: 0, depth: 0.1, baseRate: 2.0 }
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user