From: Thomas Fillon Date: Tue, 22 Apr 2014 13:26:24 +0000 (+0200) Subject: Fix PEP8 on timeside/decoder/ with autopep8 X-Git-Tag: 0.5.5~1^2~38^2~6 X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=144c60038ff4ee7425528fc181c7dfce83f8d525;p=timeside.git Fix PEP8 on timeside/decoder/ with autopep8 --- diff --git a/timeside/decoder/array.py b/timeside/decoder/array.py index bb66dbf..4dacc4c 100644 --- a/timeside/decoder/array.py +++ b/timeside/decoder/array.py @@ -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): diff --git a/timeside/decoder/core.py b/timeside/decoder/core.py index 60355e2..f3f9afb 100644 --- a/timeside/decoder/core.py +++ b/timeside/decoder/core.py @@ -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()) - diff --git a/timeside/decoder/file.py b/timeside/decoder/file.py index 87baf67..62d8ecf 100644 --- a/timeside/decoder/file.py +++ b/timeside/decoder/file.py @@ -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): diff --git a/timeside/decoder/live.py b/timeside/decoder/live.py index 9252330..ae9b7ba 100644 --- a/timeside/decoder/live.py +++ b/timeside/decoder/live.py @@ -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 - diff --git a/timeside/decoder/utils.py b/timeside/decoder/utils.py index ca801a5..b85030a 100644 --- a/timeside/decoder/utils.py +++ b/timeside/decoder/utils.py @@ -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: