-
Notifications
You must be signed in to change notification settings - Fork 1
/
tone_measurement.py
67 lines (55 loc) · 1.64 KB
/
tone_measurement.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/env python
# Chat Client (Test)
import sys
import soundrxtx
import thread
(p, stream) = soundrxtx.tone.init()
global state
global prev_freq
global str_buf
global bit_str_buf
global total_bit_str
global freq_found
state = 0
prev_freq = 0
str_buf = ""
bit_str_buf = ""
total_bit_str = ""
freq_found = False
def process_freq(freq):
global state
global prev_freq
global str_buf
global bit_str_buf
global total_bit_str
global freq_found
#print "FOUND FREQ: %i (Bsize: %i)" % (freq, len(bit_str_buf))
#if freq != prev_freq:
# print "FOUND FREQ: %i (Bsize: %i)" % (freq, len(bit_str_buf))
prev_freq = freq
if freq == tone:
freq_found = True
'''if (len(bit_str_buf) % 8 == 0) and (len(bit_str_buf) != 0):
sys.stdout.write(soundrxtx.textconvert.binary_to_ASCII(bit_str_buf))
sys.stdout.flush()
total_bit_str += bit_str_buf
print "bits: %s" % bit_str_buf
bit_str_buf = ""'''
def play_tone(tone):
soundrxtx.tone.play_tone(tone, 1, 0.5, soundrxtx.tone.audio_rate, stream)
global tone
tone = 100
#tone = 1450
if len(sys.argv) > 1:
tone = int(sys.argv[1])
while tone < 10000:
(pr, streamr) = soundrxtx.recognize.init()
print "Testing tone %i!" % tone
freq_found = False
# recognize_live(p, stream, time_len, freq_to_detect, find_freq_func)
thread.start_new_thread( play_tone, (tone, ) )
soundrxtx.recognize.recognize_live(pr, streamr, 0.5, [tone, tone-50, tone-100, tone+50, tone+100], process_freq)
if freq_found == True:
print " !! Found tone %i!" % tone
soundrxtx.recognize.end((pr, streamr))
tone += 25