Merge pull request #59 from cuu/master

modification in the music spectrum
This commit is contained in:
GNU 2018-07-27 11:45:07 +08:00 committed by GitHub
commit c25c74a0bc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 2889 deletions

File diff suppressed because it is too large Load Diff

View File

@ -34,21 +34,27 @@ class PIFI(object):
_FIRST_SELECTED_BIN = 5
_NUMBER_OF_SELECTED_BINS = 1024
_samples_buffer = None
def __init__(self):
self.sampleSize = self._SAMPLE_SIZE
self.samplingRate = self._SAMPLING_RATE
def GetSpectrum(self,fifoFile,trim_by=10,log_scale=False,div_by=100):
def GetSpectrum(self,fifoFile,trim_by=4,log_scale=False,div_by=100):
try:
rawSamples = os.read(fifoFile,self.sampleSize) # will return empty lines (non-blocking)
if len(rawSamples) < 1:
# print("Read error")
return rawSamples
# print("Read error")
pass
else:
self._samples_buffer = rawSamples
except Exception,e:
pass
if self._samples_buffer == None:
return ""
data = numpy.fromstring(rawSamples, dtype=numpy.int16)
data = numpy.fromstring(self._samples_buffer, dtype=numpy.int16)
data = data * numpy.hanning(len(data))
@ -201,7 +207,7 @@ class MPDSpectrumPage(Page):
#print("sleeping... 0.01")
time.sleep(0.01)
self.read_retry+=1
if self.read_retry > 40:
if self.read_retry > 20:
os.close(self._FIFO)
self._FIFO = os.open(self._PIFI._MPD_FIFO, os.O_RDONLY | os.O_NONBLOCK)
self.read_retry = 0
@ -354,8 +360,9 @@ class MPDSpectrumPage(Page):
if len(spects) == 0:
return
# print("spects:",spects)
step = int( round( len( spects ) / meterNum) )
# print(len(spects))
self._bbs = []
for i in range(0,meterNum):

View File

@ -422,7 +422,7 @@ def socket_thread(main_screen):
if callable( current_page_key_down_cb ):
main_screen._CurrentPage.KeyDown(escevent)
if tokens[0].lower() == "quit":
if tokens[0].lower() == "quit": #eg: echo "quit" | socat - UNIX-CONNECT:/tmp/gameshell
conn.close()
on_exit_cb = getattr(main_screen,"OnExitCb",None)
if on_exit_cb != None:
@ -488,7 +488,7 @@ def big_loop():
gobject.timeout_add(3000,title_bar.GObjectRoundRobin)
# socket_thread(main_screen)
socket_thread(main_screen)
gobject_loop()