clean interface
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
import type { SynthEngine } from './SynthEngine';
|
||||
import type { SynthEngine, PitchLock } from './SynthEngine';
|
||||
|
||||
enum OscillatorWaveform {
|
||||
Sine,
|
||||
@ -427,22 +427,33 @@ export class DubSiren implements SynthEngine<DubSirenParams> {
|
||||
return [output, v1Next, v2Next];
|
||||
}
|
||||
|
||||
randomParams(): DubSirenParams {
|
||||
const freqPairs = [
|
||||
[100, 1200],
|
||||
[200, 800],
|
||||
[300, 2000],
|
||||
[50, 400],
|
||||
[500, 3000],
|
||||
[150, 600],
|
||||
];
|
||||
randomParams(pitchLock?: PitchLock): DubSirenParams {
|
||||
let startFreq: number;
|
||||
let endFreq: number;
|
||||
|
||||
const [startFreq, endFreq] = this.randomChoice(freqPairs);
|
||||
const shouldReverse = Math.random() < 0.3;
|
||||
if (pitchLock?.enabled) {
|
||||
// When pitch locked, sweep around the locked frequency
|
||||
startFreq = pitchLock.frequency;
|
||||
endFreq = pitchLock.frequency * (Math.random() < 0.5 ? 0.5 : 2);
|
||||
} else {
|
||||
const freqPairs = [
|
||||
[100, 1200],
|
||||
[200, 800],
|
||||
[300, 2000],
|
||||
[50, 400],
|
||||
[500, 3000],
|
||||
[150, 600],
|
||||
];
|
||||
|
||||
const [freq1, freq2] = this.randomChoice(freqPairs);
|
||||
const shouldReverse = Math.random() < 0.3;
|
||||
startFreq = shouldReverse ? freq2 : freq1;
|
||||
endFreq = shouldReverse ? freq1 : freq2;
|
||||
}
|
||||
|
||||
return {
|
||||
startFreq: shouldReverse ? endFreq : startFreq,
|
||||
endFreq: shouldReverse ? startFreq : endFreq,
|
||||
startFreq,
|
||||
endFreq,
|
||||
sweepCurve: this.randomInt(0, 4) as SweepCurve,
|
||||
waveform: this.randomInt(0, 4) as OscillatorWaveform,
|
||||
pulseWidth: this.randomRange(0.1, 0.9),
|
||||
@ -464,10 +475,27 @@ export class DubSiren implements SynthEngine<DubSirenParams> {
|
||||
};
|
||||
}
|
||||
|
||||
mutateParams(params: DubSirenParams, mutationAmount: number = 0.15): DubSirenParams {
|
||||
mutateParams(params: DubSirenParams, mutationAmount: number = 0.15, pitchLock?: PitchLock): DubSirenParams {
|
||||
let startFreq: number;
|
||||
let endFreq: number;
|
||||
|
||||
if (pitchLock?.enabled) {
|
||||
// When pitch locked, keep one frequency at the locked value
|
||||
if (Math.random() < 0.5) {
|
||||
startFreq = pitchLock.frequency;
|
||||
endFreq = this.mutateValue(params.endFreq, mutationAmount, 20, 5000);
|
||||
} else {
|
||||
startFreq = this.mutateValue(params.startFreq, mutationAmount, 20, 5000);
|
||||
endFreq = pitchLock.frequency;
|
||||
}
|
||||
} else {
|
||||
startFreq = this.mutateValue(params.startFreq, mutationAmount, 20, 5000);
|
||||
endFreq = this.mutateValue(params.endFreq, mutationAmount, 20, 5000);
|
||||
}
|
||||
|
||||
return {
|
||||
startFreq: this.mutateValue(params.startFreq, mutationAmount, 20, 5000),
|
||||
endFreq: this.mutateValue(params.endFreq, mutationAmount, 20, 5000),
|
||||
startFreq,
|
||||
endFreq,
|
||||
sweepCurve: Math.random() < 0.1 ? this.randomInt(0, 4) as SweepCurve : params.sweepCurve,
|
||||
waveform: Math.random() < 0.1 ? this.randomInt(0, 4) as OscillatorWaveform : params.waveform,
|
||||
pulseWidth: this.mutateValue(params.pulseWidth, mutationAmount, 0.05, 0.95),
|
||||
|
||||
Reference in New Issue
Block a user