PageRenderTime 21ms CodeModel.GetById 16ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/sfxr/RandomMutator.hx

http://github.com/tong/sfxr
Haxe | 36 lines | 31 code | 4 blank | 1 comment | 22 complexity | e43aa10abbb417d2c0cc5d4d8beafa52 MD5 | raw file
 1package sfxr;
 2
 3class RandomMutator {
 4	
 5	public static function run( synth : Synth, mutation : Float = 0.05 ) {
 6		//synth.deleteCache();
 7		if( rand() ) synth.startFrequency += Math.random() * mutation*2 - mutation;
 8		if( rand() ) synth.minFrequency += Math.random() * mutation*2 - mutation;
 9		if( rand() ) synth.slide += Math.random() * mutation*2 - mutation;
10		if( rand() ) synth.deltaSlide += Math.random() * mutation*2 - mutation;
11		if( rand() ) synth.squareDuty += Math.random() * mutation*2 - mutation;
12		if( rand() ) synth.dutySweep += Math.random() * mutation*2 - mutation;
13		if( rand() ) synth.vibratoDepth += Math.random() * mutation*2 - mutation;
14		if( rand() ) synth.vibratoSpeed += Math.random() * mutation*2 - mutation;
15		if( rand() ) synth.attackTime += Math.random() * mutation*2 - mutation;
16		if( rand() ) synth.sustainTime += Math.random() * mutation*2 - mutation;
17		if( rand() ) synth.decayTime += Math.random() * mutation*2 - mutation;
18		if( rand() ) synth.sustainPunch += Math.random() * mutation*2 - mutation;
19		if( rand() ) synth.lpFilterCutoff += Math.random() * mutation*2 - mutation;
20		if( rand() ) synth.lpFilterCutoffSweep += Math.random() * mutation*2 - mutation;
21		if( rand() ) synth.lpFilterResonance += Math.random() * mutation*2 - mutation;
22		if( rand() ) synth.hpFilterCutoff += Math.random() * mutation*2 - mutation;
23		if( rand() ) synth.hpFilterCutoffSweep += Math.random() * mutation*2 - mutation;
24		if( rand() ) synth.phaserOffset += Math.random() * mutation*2 - mutation;
25		if( rand() ) synth.phaserSweep += Math.random() * mutation*2 - mutation;
26		if( rand() ) synth.repeatSpeed += Math.random() * mutation*2 - mutation;
27		if( rand() ) synth.changeSpeed += Math.random() * mutation*2 - mutation;
28		if( rand() ) synth.changeAmount += Math.random() * mutation*2 - mutation;
29		synth.validate();
30	}
31	
32	static inline function rand( ratio : Float = 0.5 ) : Bool {
33		return Math.random() < ratio;
34	}
35	
36}