# Duration of each note $\pm \epsilon$

Apologies if this has been asked before, but I can't seem to find a solution. I have a little track - eg:

With[{li = {0, 4, 7, 12}}, With[{aa = (Flatten@
Join[(li + 12 #) & /@ Range@2, (li - 12 #) & /@ Range@2])},
Sound[(SoundNote[#, 1/2, "Cello"] & /@ Transpose@{RandomSample[#, 4] &@aa,
RandomSample[#, 4] &@aa}) & /@ Range@8]]]


but I would like to slightly randomize the length each note plays (it used to be called humanising the sound as far as I recall!), ie, so that each note/ chord plays for $\dfrac{1}{2}\pm \epsilon$ seconds as opposed to each being equal.

Simply replace the 1/2 with 1/2 plus a RandomReal, and I think you get the desired effect:

eps = 1/10;
With[{li = {0, 4, 7, 12}},
With[{aa = (Flatten@Join[(li + 12 #) & /@ Range@2, (li - 12 #) & /@ Range@2])},
Sound[(SoundNote[#, 1/2 + RandomReal[{-eps, eps}], "Cello"] & /@
Transpose@{RandomSample[#, 4] &@aa, RandomSample[#, 4] &@aa}) & /@ Range@8]]]


This sounds like it does the right thing, but I won't necessarily guarantee it, since I'm having trouble disentangling exactly what each piece of your code does.

With[{li = {0, 4, 7, 12}, eps = 0.25},
With[{aa = (Flatten@Join[(li + 12 #) & /@ Range@2, (li - 12 #) & /@ Range@2])},
Sound[(SoundNote[#, 1/2 + RandomReal[{-eps, eps}], "Cello"] & /@
Transpose@{RandomSample[#, 4] &@aa, RandomSample[#, 4] &@aa}) & /@ Range@8]]]

• Nice decision :) – eldo Nov 30 '15 at 21:41