damped_blender.py 1.6 KB

12345678910111213141516171819202122232425262728
  1. #!/usr/bin/env python
  2. from wavebender import *
  3. from itertools import *
  4. def ncycles(iterable, n):
  5. "Returns the sequence elements n times"
  6. return chain.from_iterable(repeat(tuple(iterable), n))
  7. def waves():
  8. l = int(44100*0.4) # each note lasts 0.4 seconds
  9. return cycle(chain(ncycles(chain(islice(damped_wave(frequency=440.0, amplitude=0.1, length=int(l/4)), l),
  10. islice(damped_wave(frequency=261.63, amplitude=0.1, length=int(l/4)), l),
  11. islice(damped_wave(frequency=329.63, amplitude=0.1, length=int(l/4)), l)), 3),
  12. islice(damped_wave(frequency=440.0, amplitude=0.1, length=3*l), 3*l),
  13. ncycles(chain(islice(damped_wave(frequency=293.66, amplitude=0.1, length=int(l/4)), l),
  14. islice(damped_wave(frequency=261.63, amplitude=0.1, length=int(l/4)), l),
  15. islice(damped_wave(frequency=293.66, amplitude=0.1, length=int(l/4)), l)), 2),
  16. chain(islice(damped_wave(frequency=293.66, amplitude=0.1, length=int(l/4)), l),
  17. islice(damped_wave(frequency=329.63, amplitude=0.1, length=int(l/4)), l),
  18. islice(damped_wave(frequency=293.66, amplitude=0.1, length=int(l/4)), l)),
  19. islice(damped_wave(frequency=261.63, amplitude=0.1, length=3*l), 3*l)))
  20. channels = ((waves(),), (waves(), white_noise(amplitude=0.001),))
  21. samples = compute_samples(channels, None)
  22. write_wavefile(stdout, samples, None)