From dc1650953976a643f8048898073b1980a3bb08d0 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Wed, 25 Sep 2019 15:02:40 +0200 Subject: [PATCH] Simple script to convert pm3 traces to something audible, thanks @rfidiot for the idea --- tools/pm3_pm32wav.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100755 tools/pm3_pm32wav.py diff --git a/tools/pm3_pm32wav.py b/tools/pm3_pm32wav.py new file mode 100755 index 000000000..75c94dc4c --- /dev/null +++ b/tools/pm3_pm32wav.py @@ -0,0 +1,35 @@ +#!/usr/bin/env python3 + +# Simple script to convert pm3 traces to something audible +sampleRate = 16000.0 # hertz, so we're scaling the 125kHz to 16kHz +default_repeat = 10 + +import sys +import numpy as np +import wave +import struct + +with open(sys.argv[1]) as pm3: + data = np.fromfile(pm3, dtype=int, sep="\n") + +if len(sys.argv) > 2: + repeat = int(sys.argv[2], 10) +else: + repeat = default_repeat + +ofile = sys.argv[1].replace('pm3', 'wav') +if ofile == sys.argv[1]: + ofile = sys.argv[1]+'.wav' +obj = wave.open(ofile,'w') +obj.setnchannels(1) # mono +obj.setsampwidth(2) +obj.setframerate(sampleRate) +factor = (2**16)//512 +for i in range(repeat): + for d in data: + try: + obj.writeframesraw( struct.pack('