Python synthesizer stuff
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

54 lines
1.6KB

  1. from ysynth import *
  2. import sys
  3. synth = YSynth()
  4. #synth.set_graph(Sin(440 + 110 * Sin(1)))
  5. #synth.set_graph((Saw(440) + Sin(550)) * 0.25)
  6. #synth.set_graph(Square(220) * 0.5)
  7. #synth.set_graph(Sin(440 + 44 * Sin(4) + 110 * Square(0.5)) * 0.1)
  8. #synth.set_graph(Sin(440 * (Saw(0.5) + 1.0) * 0.5) * 0.05)
  9. #synth.set_graph(Sin(220) * 0.5)
  10. #synth.set_graph(Pulse(220) * 0.25)
  11. #synth.set_graph(Sin(440) * 0.25)
  12. #synth.set_graph(WhiteNoise() * 1.0)
  13. # Should sound vagely similar to a flanged whitenoise signal
  14. #noise = WhiteNoise()
  15. #synth.set_graph((noise + noise[50 + 100 * (Sin(0.1) + 1)]) * 0.5 * (RevSaw(2) + 1) * 0.5)
  16. #synth.set_graph(Sin(440) * RevSaw(5) * 0.2)
  17. #synth.set_graph((Sin(440) * 0.5, Sin(220) * 0.5))
  18. #synth.set_graph(Sin((440, 220)) * 0.5)
  19. def short_pulse(shortness, silence):
  20. z = (Square(2. ** shortness) + 1) * 0.5
  21. for i in xrange(silence):
  22. z = z * (Square(2. ** (shortness - i)) + 1) * 0.5
  23. return z
  24. # Echo effect
  25. #sine_pulse = Sin(440) * short_pulse(3, 4) * 1.0
  26. #sine_pulse = sine_pulse * 0.9 + sine_pulse[2000] * 0.1
  27. #synth.set_graph(sine_pulse)
  28. def harmonics(osc, freq, count):
  29. return reduce(lambda a, b: a + b,
  30. (osc(freq * i) for i in xrange(1, count + 2))) \
  31. / (count + 1)
  32. # MP3 playback
  33. #synth.set_graph(MP3Stream('hoi.mp3'))
  34. # Crossfade between 2 songs
  35. #fade = (Sin(0.5) + 1) * 0.5
  36. #synth.set_graph(MP3Stream(sys.argv[1]) * fade + MP3Stream(sys.argv[2]) * (1 - fade))
  37. # The following code causes more buggy behaviour.
  38. #x = Sin(440)
  39. #for i in xrange(1, 15):
  40. # x += Sin(440 + x)
  41. #synth.set_graph(x / 41 * 0.5)
  42. user = UserSignal(440)
  43. synth.set_graph(Sin(user) * 0.2)