]> git.parisson.com Git - timeside.git/commitdiff
Fix PEP8 on timeside/decoder/ with autopep8
authorThomas Fillon <thomas@parisson.com>
Tue, 22 Apr 2014 13:26:24 +0000 (15:26 +0200)
committerThomas Fillon <thomas@parisson.com>
Tue, 22 Apr 2014 13:26:24 +0000 (15:26 +0200)
timeside/decoder/array.py
timeside/decoder/core.py
timeside/decoder/file.py
timeside/decoder/live.py
timeside/decoder/utils.py

index bb66dbf3179255ee72cfe7ce0c80f9cecf5e6dd1..4dacc4cbe10a3fc6e94952dbf0dd5e1c7a4eb4e0 100644 (file)
@@ -31,10 +31,11 @@ from timeside.decoder.core import *
 
 
 class ArrayDecoder(Decoder):
+
     """ Decoder taking Numpy array as input"""
     implements(IDecoder)
 
-    output_blocksize = 8*1024
+    output_blocksize = 8 * 1024
 
     # IProcessor methods
 
@@ -117,7 +118,7 @@ class ArrayDecoder(Decoder):
         for index in xrange(0,
                             nb_frames * self.output_blocksize,
                             self.output_blocksize):
-            yield (self.samples[index:index+self.output_blocksize], False)
+            yield (self.samples[index:index + self.output_blocksize], False)
 
         yield (self.samples[nb_frames * self.output_blocksize:], True)
 
@@ -125,12 +126,12 @@ class ArrayDecoder(Decoder):
     def process(self):
         return self.frames.next()
 
-    ## IDecoder methods
+    # IDecoder methods
     @interfacedoc
     def format(self):
         import re
         base_type = re.search('^[a-z]*', self.samples.dtype.name).group(0)
-        return 'audio/x-raw-'+base_type
+        return 'audio/x-raw-' + base_type
 
     @interfacedoc
     def metadata(self):
index 60355e2a31a40190abcc144108b81081a13e4eda..f3f9afbdea38708db899f28c6354056d60b62bc2 100644 (file)
@@ -44,6 +44,7 @@ QUEUE_SIZE = 10
 
 
 class Decoder(Processor):
+
     """General abstract base class for Decoder
     """
     implements(IDecoder)
@@ -113,4 +114,3 @@ class Decoder(Processor):
 
     def stop(self):
         self.src.send_event(gst.event_new_eos())
-
index 87baf6729255df399aea26719c9fc581205a5fe7..62d8ecf995e1568d095e136ac71d9af587fe3ec2 100644 (file)
@@ -32,11 +32,13 @@ from timeside.decoder.core import *
 from timeside.tools.gstutils import MainloopThread
 import threading
 
+
 class FileDecoder(Decoder):
+
     """ gstreamer-based decoder """
     implements(IDecoder)
 
-    output_blocksize = 8*1024
+    output_blocksize = 8 * 1024
 
     pipeline = None
     mainloopthread = None
@@ -49,7 +51,6 @@ class FileDecoder(Decoder):
         return "gst_dec"
 
     def __init__(self, uri, start=0, duration=None, stack=False):
-
         """
         Construct a new FileDecoder
 
@@ -124,17 +125,19 @@ class FileDecoder(Decoder):
                             ! audioconvert name=audioconvert
                             ! audioresample
                             ! appsink name=sink sync=False async=True
-                            '''.format(uri = self.uri,
-                                       uri_start = np.uint64(round(self.uri_start * gst.SECOND)),
-                                       uri_duration = np.int64(round(self.uri_duration * gst.SECOND)))
-                                       # convert uri_start and uri_duration to nanoseconds
+                            '''.format(uri=self.uri,
+                                       uri_start=np.uint64(
+                                           round(self.uri_start * gst.SECOND)),
+                                       uri_duration=np.int64(round(self.uri_duration * gst.SECOND)))
+                                       # convert uri_start and uri_duration to
+                                       # nanoseconds
         else:
             # Create the pipe with standard Gstreamer uridecodebin
             self.pipe = ''' uridecodebin name=src uri={uri}
                            ! audioconvert name=audioconvert
                            ! audioresample
                            ! appsink name=sink sync=False async=True
-                           '''.format(uri = self.uri)
+                           '''.format(uri=self.uri)
 
         self.pipeline = gst.parse_launch(self.pipe)
 
@@ -186,7 +189,7 @@ class FileDecoder(Decoder):
 
         self.discovered_cond.acquire()
         while not self.discovered:
-            #print 'waiting'
+            # print 'waiting'
             self.discovered_cond.wait()
         self.discovered_cond.release()
 
@@ -237,7 +240,8 @@ class FileDecoder(Decoder):
                 self.output_channels = self.input_channels
             self.input_duration = length / 1.e9
 
-            self.input_totalframes = int(self.input_duration * self.input_samplerate)
+            self.input_totalframes = int(
+                self.input_duration * self.input_samplerate)
             if "x-raw-float" in caps.to_string():
                 self.input_width = caps[0]["width"]
             else:
@@ -270,15 +274,17 @@ class FileDecoder(Decoder):
     def _on_new_buffer_cb(self, sink):
         buf = sink.emit('pull-buffer')
         new_array = gst_buffer_to_numpy_array(buf, self.output_channels)
-        #print 'processing new buffer', new_array.shape
+        # print 'processing new buffer', new_array.shape
         if self.last_buffer is None:
             self.last_buffer = new_array
         else:
-            self.last_buffer = np.concatenate((self.last_buffer, new_array), axis=0)
+            self.last_buffer = np.concatenate(
+                (self.last_buffer, new_array), axis=0)
         while self.last_buffer.shape[0] >= self.output_blocksize:
             new_block = self.last_buffer[:self.output_blocksize]
             self.last_buffer = self.last_buffer[self.output_blocksize:]
-            #print 'queueing', new_block.shape, 'remaining', self.last_buffer.shape
+            # print 'queueing', new_block.shape, 'remaining',
+            # self.last_buffer.shape
             self.queue.put([new_block, False])
 
     @interfacedoc
@@ -304,7 +310,7 @@ class FileDecoder(Decoder):
             self.stack = False
             self.from_stack = True
 
-    ## IDecoder methods
+    # IDecoder methods
 
     @interfacedoc
     def format(self):
index 925233008e6c7e22b2c9075e5fabd83a1aa13c00..ae9b7ba21d827d76dc4050d968d2b75294d0a52d 100644 (file)
@@ -33,10 +33,11 @@ from timeside.tools.gstutils import MainloopThread
 
 
 class LiveDecoder(Decoder):
+
     """ gstreamer-based decoder from live source"""
     implements(IDecoder)
 
-    output_blocksize = 8*1024
+    output_blocksize = 8 * 1024
 
     pipeline = None
     mainloopthread = None
@@ -47,7 +48,6 @@ class LiveDecoder(Decoder):
         return "gst_live_dec"
 
     def __init__(self, num_buffers=-1, input_src='autoaudiosrc'):
-
         """
         Construct a new LiveDecoder capturing audio from alsasrc
 
@@ -156,7 +156,7 @@ class LiveDecoder(Decoder):
 
         self.discovered_cond.acquire()
         while not self.discovered:
-            #print 'waiting'
+            # print 'waiting'
             self.discovered_cond.wait()
         self.discovered_cond.release()
 
@@ -200,7 +200,8 @@ class LiveDecoder(Decoder):
                 self.output_channels = self.input_channels
             self.input_duration = length / 1.e9
 
-            self.input_totalframes = int(self.input_duration * self.input_samplerate)
+            self.input_totalframes = int(
+                self.input_duration * self.input_samplerate)
             if "x-raw-float" in caps.to_string():
                 self.input_width = caps[0]["width"]
             else:
@@ -234,15 +235,17 @@ class LiveDecoder(Decoder):
         buf = sink.emit('pull-buffer')
         new_array = gst_buffer_to_numpy_array(buf, self.output_channels)
 
-        #print 'processing new buffer', new_array.shape
+        # print 'processing new buffer', new_array.shape
         if self.last_buffer is None:
             self.last_buffer = new_array
         else:
-            self.last_buffer = np.concatenate((self.last_buffer, new_array), axis=0)
+            self.last_buffer = np.concatenate(
+                (self.last_buffer, new_array), axis=0)
         while self.last_buffer.shape[0] >= self.output_blocksize:
             new_block = self.last_buffer[:self.output_blocksize]
             self.last_buffer = self.last_buffer[self.output_blocksize:]
-            #print 'queueing', new_block.shape, 'remaining', self.last_buffer.shape
+            # print 'queueing', new_block.shape, 'remaining',
+            # self.last_buffer.shape
             self.queue.put([new_block, False])
 
     @interfacedoc
@@ -269,7 +272,7 @@ class LiveDecoder(Decoder):
             self.from_stack = True
         pass
 
-    ## IDecoder methods
+    # IDecoder methods
 
     @interfacedoc
     def format(self):
@@ -292,4 +295,3 @@ class LiveDecoder(Decoder):
     def metadata(self):
         # TODO check
         return self.tags
-
index ca801a571950d47a31c1ca115a88271ad1aa1c6d..b85030ab445274e0bf0ff5cb95bbda4bda139bc0 100644 (file)
@@ -28,7 +28,9 @@ from __future__ import division
 
 import numpy as np
 
+
 class Noise(object):
+
     """A class that mimics audiolab.sndfile but generates noise instead of reading
     a wave file. Additionally it can be told to have a "broken" header and thus crashing
     in the middle of the file. Also useful for testing ultra-short files of 20 samples."""
@@ -60,7 +62,7 @@ class Noise(object):
         else:
             will_read = frames_to_read
         self.seekpoint += will_read
-        return np.random.random(will_read)*2 - 1
+        return np.random.random(will_read) * 2 - 1
 
 
 def path2uri(path):
@@ -73,7 +75,8 @@ def path2uri(path):
     >>> path2uri('C:\Windows\my_file.wav')
     'file:///C%3A%5CWindows%5Cmy_file.wav'
     """
-    import urlparse, urllib
+    import urlparse
+    import urllib
 
     return urlparse.urljoin('file:', urllib.pathname2url(path))
 
@@ -126,7 +129,7 @@ def get_media_uri_info(uri):
     uri_discoverer = Discoverer(GST_DISCOVER_TIMEOUT)
     try:
         uri_info = uri_discoverer.discover_uri(uri)
-    except  GError as e:
+    except GError as e:
         raise IOError(e)
     info = dict()
 
@@ -136,9 +139,9 @@ def get_media_uri_info(uri):
     audio_streams = uri_info.get_audio_streams()
     info['streams'] = []
     for stream in audio_streams:
-        stream_info = {'bitrate': stream.get_bitrate (),
-                       'channels': stream.get_channels (),
-                       'depth': stream.get_depth (),
+        stream_info = {'bitrate': stream.get_bitrate(),
+                       'channels': stream.get_channels(),
+                       'depth': stream.get_depth(),
                        'max_bitrate': stream.get_max_bitrate(),
                        'samplerate': stream.get_sample_rate()
                        }
@@ -213,7 +216,7 @@ def sha1sum_url(url):
     sha1 = hashlib.sha1()
     chunk_size = sha1.block_size * 8192
 
-    max_file_size = 10*1024*1024  # 10Mo limit in case of very large file
+    max_file_size = 10 * 1024 * 1024  # 10Mo limit in case of very large file
 
     total_read = 0
     with closing(urllib.urlopen(url)) as url_obj: