clean interface
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
import type { SynthEngine } from './SynthEngine';
|
||||
import type { SynthEngine, PitchLock } from './SynthEngine';
|
||||
|
||||
interface BenjolinParams {
|
||||
// Core oscillators
|
||||
@ -808,7 +808,7 @@ export class Benjolin implements SynthEngine<BenjolinParams> {
|
||||
}
|
||||
}
|
||||
|
||||
randomParams(): BenjolinParams {
|
||||
randomParams(pitchLock?: PitchLock): BenjolinParams {
|
||||
// Choose a random preset configuration
|
||||
const preset = Math.floor(Math.random() * PRESET_COUNT);
|
||||
|
||||
@ -818,7 +818,9 @@ export class Benjolin implements SynthEngine<BenjolinParams> {
|
||||
// Generate full parameter set with preset biases
|
||||
const params: BenjolinParams = {
|
||||
// Core oscillators
|
||||
osc1Freq: presetParams.osc1Freq ?? (20 + Math.random() * 800),
|
||||
osc1Freq: pitchLock?.enabled
|
||||
? pitchLock.frequency
|
||||
: presetParams.osc1Freq ?? (20 + Math.random() * 800),
|
||||
osc2Freq: presetParams.osc2Freq ?? (30 + Math.random() * 1200),
|
||||
osc1Wave: presetParams.osc1Wave ?? Math.random(),
|
||||
osc2Wave: presetParams.osc2Wave ?? Math.random(),
|
||||
@ -876,17 +878,17 @@ export class Benjolin implements SynthEngine<BenjolinParams> {
|
||||
return params;
|
||||
}
|
||||
|
||||
mutateParams(params: BenjolinParams): BenjolinParams {
|
||||
mutateParams(params: BenjolinParams, mutationAmount?: number, pitchLock?: PitchLock): BenjolinParams {
|
||||
const mutated = { ...params };
|
||||
|
||||
// Determine mutation strength based on current "stability"
|
||||
const stability = (params.crossMod1to2 + params.crossMod2to1) / 2 +
|
||||
params.runglerChaos + params.evolutionDepth;
|
||||
const mutationAmount = stability > 1.5 ? 0.05 : stability < 0.5 ? 0.2 : 0.1;
|
||||
const mutAmount = mutationAmount ?? (stability > 1.5 ? 0.05 : stability < 0.5 ? 0.2 : 0.1);
|
||||
|
||||
// Helper for correlated mutations
|
||||
const mutateValue = (value: number, min: number, max: number, correlation = 1): number => {
|
||||
const delta = (Math.random() - 0.5) * mutationAmount * (max - min) * correlation;
|
||||
const delta = (Math.random() - 0.5) * mutAmount * (max - min) * correlation;
|
||||
return Math.max(min, Math.min(max, value + delta));
|
||||
};
|
||||
|
||||
@ -895,9 +897,15 @@ export class Benjolin implements SynthEngine<BenjolinParams> {
|
||||
|
||||
if (strategy < 0.3) {
|
||||
// Mutate frequency relationships
|
||||
const freqRatio = mutated.osc2Freq / mutated.osc1Freq;
|
||||
mutated.osc1Freq = mutateValue(mutated.osc1Freq, 20, 2000);
|
||||
mutated.osc2Freq = mutated.osc1Freq * mutateValue(freqRatio, 0.5, 4);
|
||||
if (pitchLock?.enabled) {
|
||||
mutated.osc1Freq = pitchLock.frequency;
|
||||
const freqRatio = mutated.osc2Freq / params.osc1Freq;
|
||||
mutated.osc2Freq = mutated.osc1Freq * mutateValue(freqRatio, 0.5, 4);
|
||||
} else {
|
||||
const freqRatio = mutated.osc2Freq / mutated.osc1Freq;
|
||||
mutated.osc1Freq = mutateValue(mutated.osc1Freq, 20, 2000);
|
||||
mutated.osc2Freq = mutated.osc1Freq * mutateValue(freqRatio, 0.5, 4);
|
||||
}
|
||||
|
||||
// Correlate cross-mod amounts
|
||||
const crossModDelta = (Math.random() - 0.5) * mutationAmount;
|
||||
|
||||
Reference in New Issue
Block a user