From ce078f493f953a85b739a9dda790ff78540f1315 Mon Sep 17 00:00:00 2001 From: kris Date: Thu, 21 Mar 2019 22:41:05 +0000 Subject: [PATCH] Start to flesh out function docstrings, add some more type annotations. --- transcoder/audio.py | 13 +++++++++++++ transcoder/symbol_table.py | 11 ++++++++--- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/transcoder/audio.py b/transcoder/audio.py index 04b8084..fd65f50 100644 --- a/transcoder/audio.py +++ b/transcoder/audio.py @@ -25,6 +25,12 @@ class Audio: normalization or self._normalization()) # type: float def _decode(self, f, buf) -> np.array: + """ + + :param f: + :param buf: + :return: + """ data = np.frombuffer(buf, dtype='int16').astype( 'float32').reshape((f.channels, -1), order='F') @@ -39,6 +45,9 @@ class Audio: We compute the 2.5th and 97.5th percentiles i.e. only 2.5% of samples will clip. + + :param read_bytes: + :return: """ raw = bytearray() with audioread.audio_open(self.filename) as f: @@ -52,6 +61,10 @@ class Audio: return 16384. / norm def audio_stream(self) -> Iterator[int]: + """ + + :return: + """ with audioread.audio_open(self.filename) as f: for buf in f.read_data(128 * 1024): a = self._decode(f, buf) diff --git a/transcoder/symbol_table.py b/transcoder/symbol_table.py index 097cd85..0644233 100644 --- a/transcoder/symbol_table.py +++ b/transcoder/symbol_table.py @@ -1,15 +1,20 @@ """Parses the cc65 .dbg output to extract symbol addresses.""" -from typing import Dict +from typing import Dict, TextIO class SymbolTable: """Parse cc65 debug file to extract symbol table.""" def __init__(self, debugfile: str = None): - self.debugfile = debugfile + self.debugfile = debugfile # type: str - def parse(self, iostream=None) -> Dict: + def parse(self, iostream: TextIO = None) -> Dict: + """ + + :param iostream: + :return: + """ syms = {} if not iostream: