kopia lustrzana https://github.com/AlexFWulff/awulff-pico-playground
More release comments
rodzic
64501dac6c
commit
e0c98d544a
|
@ -5,8 +5,8 @@ import base64
|
||||||
import io
|
import io
|
||||||
|
|
||||||
if __name__=="__main__":
|
if __name__=="__main__":
|
||||||
infile = "/Users/alex/Desktop/float-test/noise"
|
infile = "/Users/alex/Desktop/float-test/stop-2"
|
||||||
outfile = "/Users/alex/Desktop/float-test/noise.wav"
|
outfile = "/Users/alex/Desktop/float-test/stop.wav"
|
||||||
|
|
||||||
f = open(infile, "r")
|
f = open(infile, "r")
|
||||||
|
|
||||||
|
@ -23,13 +23,19 @@ if __name__=="__main__":
|
||||||
dt = np.dtype(np.float32)
|
dt = np.dtype(np.float32)
|
||||||
dt = dt.newbyteorder('<')
|
dt = dt.newbyteorder('<')
|
||||||
|
|
||||||
|
# It appears that a few bytes are lost during the serial data
|
||||||
|
# transmission. This causes all the float data to be messed up
|
||||||
|
# after a byte loss, so if we detect strange float values then
|
||||||
|
# skip those THREE bytes (because one is lost)
|
||||||
data = np.zeros(int(len(byte_data)/4), dtype=dt)
|
data = np.zeros(int(len(byte_data)/4), dtype=dt)
|
||||||
num_idx = 0
|
num_idx = 0
|
||||||
byte_idx = 0
|
byte_idx = 0
|
||||||
while byte_idx < len(byte_data)-4:
|
while byte_idx < len(byte_data)-4:
|
||||||
num = np.frombuffer(byte_data[byte_idx:byte_idx+4], dtype=dt)
|
num = np.frombuffer(byte_data[byte_idx:byte_idx+4], dtype=dt)
|
||||||
|
# Data coming off pico should be normalized between -1 and 1.
|
||||||
|
# If it's not, we know that there was some data loss.
|
||||||
if (num > 1 or num < -1):
|
if (num > 1 or num < -1):
|
||||||
print("Skipped one")
|
#print("Skipped one")
|
||||||
byte_idx = byte_idx + 3
|
byte_idx = byte_idx + 3
|
||||||
else:
|
else:
|
||||||
data[num_idx] = num[0]
|
data[num_idx] = num[0]
|
||||||
|
|
Ładowanie…
Reference in New Issue