This commit is contained in:
cuu 2018-07-27 10:52:48 +08:00
parent ce9261f409
commit f1961ee5d6

View File

@ -34,6 +34,7 @@ class PIFI(object):
_FIRST_SELECTED_BIN = 5 _FIRST_SELECTED_BIN = 5
_NUMBER_OF_SELECTED_BINS = 1024 _NUMBER_OF_SELECTED_BINS = 1024
_samples_buffer = None
def __init__(self): def __init__(self):
self.sampleSize = self._SAMPLE_SIZE self.sampleSize = self._SAMPLE_SIZE
@ -43,12 +44,17 @@ class PIFI(object):
try: try:
rawSamples = os.read(fifoFile,self.sampleSize) # will return empty lines (non-blocking) rawSamples = os.read(fifoFile,self.sampleSize) # will return empty lines (non-blocking)
if len(rawSamples) < 1: if len(rawSamples) < 1:
# print("Read error") # print("Read error")
return rawSamples pass
else:
self._samples_buffer = rawSamples
except Exception,e: except Exception,e:
pass
if self._samples_buffer == None:
return "" return ""
data = numpy.fromstring(rawSamples, dtype=numpy.int16) data = numpy.fromstring(self._samples_buffer, dtype=numpy.int16)
data = data * numpy.hanning(len(data)) data = data * numpy.hanning(len(data))