Try this instead; it should work on any OS and generate a .wav file you can play. (It’s better than putting up a recording because you can play with the parameters, put in your own tune, etc.)
import math, random, struct, wave
from math import sin,cos,exp,pi
filename = '/home/dgerard/something.wav' # replace with something sensible
def add_note(t,p,d,v):
# t is time in seconds, p is pitch in Hz, d is duration in seconds
# v is volume in arbitrary (amplitude) units
i0 = int(44100*t)
i1 = int(44100*(t+d))
if len(signal)<i1: signal.extend([0 for i in range(len(signal),i1)])
for i in range(i0,i1):
dt = i/44100.-t
if dt<0.02: f = dt/0.02 # attack: 0..1 over 20ms
elif dt<0.2: f = exp(-(dt-0.02)/0.18) # decay: 1..1/e over 180ms
elif dt<d-0.2: f = exp(-1) # sustain: 1/e
else: f = exp(-1)*(d-dt)/0.2 # release: 1/e..0 over 200ms
signal[i] += f*v*(sin(2*pi*p*dt)+0.2*sin(6*pi*p*dt)+0.06*sin(10*pi*p*dt))
def save_signal():
m = max(abs(x) for x in signal)
d = [int(30000./m*x) for x in signal]
w = wave.open(filename, "wb")
w.setparams((1,2,44100,len(signal),'NONE','noncompressed'))
w.writeframes(''.join(struct.pack('h',x) for x in d))
w.close()
signal = []
t=0
for (p,d) in [(4,1),(5,1),(7,3),(None,1), (4,1),(5,1),(7,3),(None,1), (4,1),(7,1),(12,2),(11,2),(9,2),(9,2),(7,1),(None,1), (2,1),(4,1),(5,3),(None,1), (2,1),(4,1),(5,3),(None,1), (2,1),(5,1),(11,1),(9,1),(7,2),(11,2),(12,4)]:
if p is not None: add_note(t, 440*2**((p+1*(random.random()-0.5))/12.), 0.3*d+0.1, 1)
t += 0.3*d
save_signal()
signal = []
t=0
for (p,d) in [(4,1),(5,1),(7,3),(None,1), (4,1),(5,1),(7,3),(None,1), (4,1),(7,1),(12,2),(11,2),(9,2),(9,2),(7,1),(None,1), (2,1),(4,1),(5,3),(None,1), (2,1),(4,1),(5,3),(None,1), (2,1),(5,1),(11,1),(9,1),(7,2),(11,2),(12,4)]:
if p is not None: add_note(t, 440*2**(((p+random.choice([-1,0,0,0,1]))+random.random())/12.), 0.3*d+0.1, 1)
t += 0.3*d*math.exp(random.random()*random.random())
save_signal()
It (1) displaces 20% of notes up and 20% of notes down by one semitone, (2) detunes all notes randomly by about +/- a quarter-tone, and (3) inserts random delays, usually quite short but up to a factor of about 1.7 times the length of the preceding note or rest.
[EDITED to add: actually, I think it distorts the pitches just a little too much.]
[FURTHER EDITED: really, it should be tweaked so that when two consecutive notes in the original melody are, say, increasing in pitch, the same is true of the distorted ones. I am too lazy to make this happen. A simpler improvement is to replace the two pitch-diddlings with a single call to random.choice() so that you never get, e.g., a semitone displacement plus a quarter-tone mistuning in the same direction. I also tried making the timbre nastier by putting the partials at non-harmonic frequencies, which does indeed sound quite nasty but not in a particularly hummable way. This doesn’t introduce as much nastiness as it would in music with actual harmony in it; one can make even a perfect fifth sound hideously discordant by messing up the spectrum of the notes. See William Sethares’s excellent book “Tuning, timbre, spectrum, scale” for more details, though he inexplicably gives more attention to making music sound better rather than worse.]
For further fun, get the code to play the lullaby, wait an exponentially distributed time with mean, say, 30 seconds, and then start again with 99% probability.
If you were using this on someone else, starting again would be mandatory. But the only way to build up hope that it will stop in yourself, when you know how the code works, is to add a small chance of stopping.
Edit: upon further consideration, the distribution should be Pareto or something with a similarly heavy tail.
Personally, I find random changes a little disorienting even if I’m expecting them (like a deceptive cadence in a familiar piece). Though this feeling of disorientation is not unpleasant, so a simple loop would be more annoying for me too.
I didn’t find the result all that unpleasant. Probably because the sound file was still pretty close to what the intervals/notes were “supposed” to be, my brain categorized them into the right categories. It would have been worse if I perceived them as “completely wrong” intervals (as in a seventh instead of a fourth) rather than just “out-of-tune” intevals.
I’m not sure that the word “creation” is quite right (except in so far as for some musically-minded people it may bring to mind the other words “representation of chaos”) but yes, I’m afraid it is.
I can’t get this to work in Wine. Could you please put up a recording? Thank you :-)
Try this instead; it should work on any OS and generate a .wav file you can play. (It’s better than putting up a recording because you can play with the parameters, put in your own tune, etc.)
This is quite Quirrellicious:
It (1) displaces 20% of notes up and 20% of notes down by one semitone, (2) detunes all notes randomly by about +/- a quarter-tone, and (3) inserts random delays, usually quite short but up to a factor of about 1.7 times the length of the preceding note or rest.
[EDITED to add: actually, I think it distorts the pitches just a little too much.]
[FURTHER EDITED: really, it should be tweaked so that when two consecutive notes in the original melody are, say, increasing in pitch, the same is true of the distorted ones. I am too lazy to make this happen. A simpler improvement is to replace the two pitch-diddlings with a single call to random.choice() so that you never get, e.g., a semitone displacement plus a quarter-tone mistuning in the same direction. I also tried making the timbre nastier by putting the partials at non-harmonic frequencies, which does indeed sound quite nasty but not in a particularly hummable way. This doesn’t introduce as much nastiness as it would in music with actual harmony in it; one can make even a perfect fifth sound hideously discordant by messing up the spectrum of the notes. See William Sethares’s excellent book “Tuning, timbre, spectrum, scale” for more details, though he inexplicably gives more attention to making music sound better rather than worse.]
For further fun, get the code to play the lullaby, wait an exponentially distributed time with mean, say, 30 seconds, and then start again with 99% probability.
If you were using this on someone else, starting again would be mandatory. But the only way to build up hope that it will stop in yourself, when you know how the code works, is to add a small chance of stopping.
Edit: upon further consideration, the distribution should be Pareto or something with a similarly heavy tail.
Please post a recording, for those of us who don’t want to have to set up whole programming environments to watch a Youtube video.
I’ve made a recording with SuperCollider using almost the same algorithm as in the Python script above, here’s the link /watch?v=wjZRM6KgGbE.
It loses much of the impact when you intentionally seek it out, I think. The lullaby loop midi I found to be more annoying than the errors.
Still, thanks for posting that—it’s certainly interesting.
Listening to something is not at all the same as listening to something for seven hours.
Personally, I find random changes a little disorienting even if I’m expecting them (like a deceptive cadence in a familiar piece). Though this feeling of disorientation is not unpleasant, so a simple loop would be more annoying for me too.
“unavailable”: what gives?
Oh well, I guess bad music isn’t actually so annoying… I tried it and it didn’t bother me at all.
Apparently I’m not quite as good at tormenting people as Lord Voldemort. Oh well, can’t win ’em all.
I didn’t find the result all that unpleasant. Probably because the sound file was still pretty close to what the intervals/notes were “supposed” to be, my brain categorized them into the right categories. It would have been worse if I perceived them as “completely wrong” intervals (as in a seventh instead of a fourth) rather than just “out-of-tune” intevals.
Whooo, that is awesome.
So simple, and yet so awful … you’re onto sheer antimusical gold here.
Awesome. Is this your creation?
I’m not sure that the word “creation” is quite right (except in so far as for some musically-minded people it may bring to mind the other words “representation of chaos”) but yes, I’m afraid it is.