diff options
author | Benjamin Schwartz <bens@alum.mit.edu> | 2007-09-19 03:05:44 (GMT) |
---|---|---|
committer | Benjamin Schwartz <bens@alum.mit.edu> | 2007-09-19 03:05:44 (GMT) |
commit | 83b0d210fa2d2ceed836ca3452ae7bab88f7fa5f (patch) | |
tree | dfc0011ab9f5c4e3c896ffdb75981845dcd0399a /arange.py | |
parent | d0e549f64c6e21c7969ee1fc277661798677fd7b (diff) |
Add an Interface
Diffstat (limited to 'arange.py')
-rwxr-xr-x | arange.py | 28 |
1 files changed, 18 insertions, 10 deletions
@@ -93,8 +93,8 @@ def LFSR(R, taps, m): returns a num.array of length m """ - #o = num.resize(num.array([], num.Bool), (m)) #numpy-only - o = num.resize(num.array([], num.UInt8), (m)) + o = num.resize(num.array([], num.bool), (m)) #numpy-only + #o = num.resize(num.array([], num.UInt8), (m)) if len(taps) == 2: a = taps[0] b = taps[1] @@ -132,9 +132,10 @@ def write_wav(o): w = wave.open(f) w.setparams((2,1,REC_HZ,0, 'NONE', 'NONE')) n = num.size(o) - q = num.zeros((2*n), num.UInt8) - #q[::2] = o*255 #numpy-only - q[::2] = (o*255).tolist() + #q = num.zeros((2*n), num.UInt8) #Numeric or old numpy + q = num.zeros((2*n), num.uint8) #new numpy + q[::2] = o*255 #numpy-only + #q[::2] = (o*255).tolist() q[1::2] = 128 w.writeframes(q.tostring()) return f @@ -144,13 +145,18 @@ def play_wav(fname): This void function plays the file named fname and does not return until after playback has completed. """ + print "about to get player" player = gst.element_factory_make("playbin", 'player') + print "about to get bus" bus = player.get_bus() + print "about to start playing" player.set_property('uri','file://'+fname) player.set_state(gst.STATE_PLAYING) + print "about to wait for EOS" bus.poll(gst.MESSAGE_EOS,-1) + print "cleaning up" player.set_state(gst.STATE_NULL) def record_while_playing(play_name, t): @@ -321,7 +327,7 @@ def recvall(s, n): Attempt to receive n bytes from socket s. Return received message. Fails with "Assertion failed" if a message of incorrect length is received. """ - assert type(s) == socket._socketobject + #assert type(s) == socket._socketobject received = '' while len(received) < n: q = s.recv(n - len(received)) @@ -334,7 +340,7 @@ def recvmsg(s, message): Attempt to receive a specific message from a socket. Returns a boolean indicating whether or not that message was received. """ - assert type(s) == socket._socketobject + #assert type(s) == socket._socketobject return (message == recvall(s, len(message))) def measure_dt_simul(s, am_server): @@ -346,7 +352,7 @@ def measure_dt_simul(s, am_server): practice, due to nonlinearities in the speakers and microphones, it is not usable. """ - assert type(s) == socket._socketobject + #assert type(s) == socket._socketobject R = (num.zeros((MLS_INDEX)) == 0) mls = compute_mls(R) if am_server: @@ -409,7 +415,7 @@ def measure_dt_seq(s, am_server): recording are analyzed separately. This method is much more tolerant of low-quality speaker systems and is known to work. """ - assert type(s) == socket._socketobject + #assert type(s) == socket._socketobject R = (num.zeros((MLS_INDEX)) == 0) mls = compute_mls(R) mls_rev = mls[::-1] @@ -445,7 +451,9 @@ def measure_dt_seq(s, am_server): playtime = float(2**MLS_INDEX)/REC_HZ #seconds ringdown = 0.5 #seconds if am_server: + print "about to play_wav" play_wav(mls_wav_file.name) + print "played wav" time.sleep(ringdown) t3 = time.time() time.sleep(t2-t1) @@ -561,4 +569,4 @@ def interactive_mode(): #n=get_noise_echo(4) #print e[getpeak(e)] #print n[getpeak(n)] -interactive_mode() +#interactive_mode() |