Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

equalizer: Fix high CPU usage by waiting a tiny bit in case of no dat…

…a fetched from soundcard
  • Loading branch information...
commit f83be378124a5dd98379f405ad60ef461376095a 1 parent 987e4c8
Petr Baudis authored December 30, 2013

Showing 1 changed file with 4 additions and 1 deletion. Show diff stats Hide diff stats

  1. 5  host_python/equalizer.py
5  host_python/equalizer.py
@@ -88,6 +88,7 @@ def print_usage():
88 88
 SAMPLE_SIZE = CHUNK_SIZE*HISTORY_SIZE
89 89
 FREQ_STEP = float(RATE) / (CHUNK_SIZE * HISTORY_SIZE)
90 90
 PIXEL_FREQ_RANGE = math.pow(float(MAX_FREQ) / MIN_FREQ, 1.0/EPIXELS)
  91
+CHUNK_PERIOD = 1.0 / (RATE / CHUNK_SIZE)
91 92
 
92 93
 def with_stream(  fnc ):
93 94
 
@@ -141,7 +142,9 @@ def loop( stream ):
141 142
     
142 143
     while work:
143 144
         try: data = stream.read(CHUNK_SIZE)
144  
-        except IOError: continue
  145
+        except IOError:
  146
+            time.sleep(CHUNK_PERIOD)
  147
+            continue
145 148
         nowtrig = datetime.now().microsecond / 50000
146 149
         if (nowtrig == nexttrig):
147 150
             continue

0 notes on commit f83be37

Please sign in to comment.
Something went wrong with that request. Please try again.