5 # Initialize the audio stuff
7 audio
.setoutgain(100) # for speaker
12 savegain
= audio
.getoutgain()
15 x
= raw_input('Hit Enter to sample ' + `n`
+ ' seconds: ')
16 return audio
.read(n
*RATE
)
18 audio
.setoutgain(savegain
)
20 def echo(s
, delay
, gain
):
21 return s
[:delay
] + audio
.add(s
[delay
:], audio
.amplify(s
, gain
, gain
))
28 return loadfp(open(file, 'r'))
33 buf
= fp
.read(16*1024)
42 for i
in a
: sum = sum + i
43 bias
= (sum + len(a
)/2) / len(a
)
44 print 'Bias value:', bias
46 for i
in range(len(a
)):
52 # Think of this as converting the sampling rate from a samples/sec
53 # to b samples/sec. Or, if the input is a bytes long, the output
54 # will be b bytes long.
61 # i, j will walk through y and out (step 1)
62 # ib, ja are i*b, j*a and are kept as close together as possible
75 out
.append((y
[i
]*(ja
-(ib
-b
)) + y
[i
-1]*(ib
-ja
)) / b
)
76 return audio
.num2chr(out
)
78 def sinus(freq
): # return a 1-second sine wave
79 from math
import sin
, pi
80 factor
= 2.0*pi
*float(freq
)/float(RATE
)
83 list[i
] = int(sin(float(i
) * factor
) * 127.0)
84 return audio
.num2chr(list)
87 if '\177' not in s
and '\200' not in s
:
89 num
= audio
.chr2num(s
)
90 extremes
= (-128, 127)
91 for i
in range(1, len(num
)-1):
92 if num
[i
] in extremes
:
93 num
[i
] = (num
[i
-1] + num
[i
+1]) / 2
94 return audio
.num2chr(num
)
97 gday
= load('gday')[1000:6000]
100 for i
in range(1, 10):
102 g
= stretch(gday
, 10, 10-i
)
103 save(g
, 'gday' + `i`
)