Merge pull request #1331 from Guilhem7/master
[RRG-proxmark3.git] / tools / pm3_pm32wav.py
blob75c94dc4c08bb82feaece663c2cfc0c65677426c
1 #!/usr/bin/env python3
3 # Simple script to convert pm3 traces to something audible
4 sampleRate = 16000.0 # hertz, so we're scaling the 125kHz to 16kHz
5 default_repeat = 10
7 import sys
8 import numpy as np
9 import wave
10 import struct
12 with open(sys.argv[1]) as pm3:
13 data = np.fromfile(pm3, dtype=int, sep="\n")
15 if len(sys.argv) > 2:
16 repeat = int(sys.argv[2], 10)
17 else:
18 repeat = default_repeat
20 ofile = sys.argv[1].replace('pm3', 'wav')
21 if ofile == sys.argv[1]:
22 ofile = sys.argv[1]+'.wav'
23 obj = wave.open(ofile,'w')
24 obj.setnchannels(1) # mono
25 obj.setsampwidth(2)
26 obj.setframerate(sampleRate)
27 factor = (2**16)//512
28 for i in range(repeat):
29 for d in data:
30 try:
31 obj.writeframesraw( struct.pack('<h', d*factor) )
32 except:
33 print("B:" , d, d*factor)
34 raise
35 obj.close()