-
Notifications
You must be signed in to change notification settings - Fork 2
/
newsender.py
executable file
·49 lines (41 loc) · 1.03 KB
/
newsender.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
#!/usr/bin/python
import pyaudio
import sys
import struct
import math
FORMAT = pyaudio.paFloat32
CHANNELS = 1
SAMPLE_RATE = 48000
FREQ = 4000
CYCLES_PER_BIT = 8
BIT = int(SAMPLE_RATE*CYCLES_PER_BIT/FREQ)
CHUNK = int(16 * BIT)
p = pyaudio.PyAudio()
stream = p.open(format = FORMAT,
channels = CHANNELS,
rate = SAMPLE_RATE,
input = False,
output = True,
frames_per_buffer = CHUNK)
TIME = 0 # seconds
while True:
chunkdata = ""
# make every bit
bitcount = 0
sign = 1
while bitcount < CHUNK/BIT:
bitdata = ""
framecount = 0
while framecount < BIT:
value = sign * .5 * math.cos( FREQ * TIME * (2 * math.pi) )
bitdata += struct.pack( 'f', value )
TIME += 1.0 / SAMPLE_RATE
framecount += 1
chunkdata += bitdata
sign = -sign
bitcount += 1
# print "Wrote %d bits" % bitcount
stream.write(chunkdata)
stream.stop_stream()
stream.close()
p.terminate()