4 # Sound output parameters
7 sampling_freq
= 44100 #Hz
9 # Frequency generator parameters
13 # Proxmark3 parameters
14 pm3_client
="/usr/local/bin/proxmark3"
15 pm3_reader_dev_file
="/dev/ttyACM0"
16 pm3_tune_cmd
="hf tune"
22 from select
import select
23 from subprocess
import Popen
, DEVNULL
, PIPE
29 # For paFloat32 sample values must be in range [-1.0, 1.0]
30 stream
= p
.open(format
=pyaudio
.paFloat32
,
35 # Initial voltage to frequency values
41 # Spawn the Proxmark3 client
42 pm3_proc
= Popen([pm3_client
, pm3_reader_dev_file
, "-c", pm3_tune_cmd
], bufsize
=0, env
={}, stdin
=DEVNULL
, stdout
=PIPE
, stderr
=DEVNULL
)
45 # Read voltages from the Proxmark3, generate the sine wave, output to soundcard
46 sample_buf
= [0.0 for x
in range(0, sample_buf_size
)]
51 # Read Proxmark3 client's stdout and extract voltage values
52 if(select([pm3_proc
.stdout
], [], [], 0)[0]):
54 b
= pm3_proc
.stdout
.read(256).decode("ascii")
58 if c
in "0123456789 mV":
62 if mv_recbuf
[-3:] == " mV":
63 v
= int(mv_recbuf
[:-3]) / 1000
69 # Recalculate the audio frequency to generate
70 out_freq
= (max_freq
- min_freq
) * (max_v
- v
) / (max_v
- min_v
) \
73 # Generate the samples and write them to the soundcard
74 sinevs
= out_freq
/ sampling_freq
* numpy
.pi
* 2
77 sinev
= sinev
if sinev
< numpy
.pi
* 2 else sinev
- numpy
.pi
* 2
78 i
= (i
+ 1) % sample_buf_size
80 stream
.write((numpy
.sin(sample_buf
) * volume
).
81 astype(numpy
.float32
).tobytes())