Alsadius comments on Harry Potter and the Methods of Rationality discussion thread, part 15, chapter 84 - Less Wrong

3 Post author: FAWS 11 April 2012 03:39AM

You are viewing a comment permalink. View the original post to see all comments and the full post content.

Comments (1221)

You are viewing a single comment's thread. Show more comments above.

Comment author: gjm 12 April 2012 11:04:44PM 10 points [-]

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()
Comment author: Alsadius 13 April 2012 03:43:19AM 1 point [-]

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.

Comment author: fgenj 16 April 2012 02:50:58AM 4 points [-]

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.

Comment author: Alsadius 16 April 2012 03:32:56AM 1 point [-]

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.

Comment author: Percent_Carbon 16 April 2012 06:24:46AM 1 point [-]

It loses much of the impact when you intentionally seek it out, I think.

Listening to something is not at all the same as listening to something for seven hours.

Comment author: fgenj 16 April 2012 07:45:41PM 0 points [-]

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.

Comment author: zerker2000 23 January 2013 10:17:03AM 0 points [-]

"unavailable": what gives?