/sfxr/RandomMutator.hx

http://github.com/tong/sfxr · Haxe · 36 lines · 31 code · 4 blank · 1 comment · 22 complexity · e43aa10abbb417d2c0cc5d4d8beafa52 MD5 · raw file

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