From 0445ee518c8421d8d19682f6c17fe0cef4119fa3 Mon Sep 17 00:00:00 2001 From: Thomas Fillon Date: Tue, 21 Oct 2014 11:25:57 +0200 Subject: [PATCH] Fix doctest and add plot example to spectrogram --- doc/source/conf.py | 8 +++++++- doc/source/tutorial/frames_stack.rst | 2 +- doc/source/tutorial/quick_start.rst | 2 +- timeside/analyzer/level.py | 7 ++++++- timeside/analyzer/spectrogram.py | 30 ++++++++++++++++++++++------ timeside/encoder/audiosink.py | 4 ++-- 6 files changed, 41 insertions(+), 12 deletions(-) diff --git a/doc/source/conf.py b/doc/source/conf.py index d36a1ed..349d6c3 100644 --- a/doc/source/conf.py +++ b/doc/source/conf.py @@ -26,7 +26,13 @@ sys.path.insert(0, os.path.abspath('../../')) # Add any Sphinx extension module names here, as strings. They can be extensions # coming with Sphinx (named 'sphinx.ext.*') or your custom ones. -extensions = ['sphinx.ext.autodoc', 'sphinx.ext.coverage', 'sphinx.ext.viewcode', 'sphinx.ext.autosummary', 'sphinx.ext.doctest', 'numpydoc'] +extensions = ['sphinx.ext.autodoc', + 'sphinx.ext.coverage', + 'sphinx.ext.viewcode', + 'sphinx.ext.autosummary', + 'sphinx.ext.doctest', 'numpydoc', + 'matplotlib.sphinxext.mathmpl', + 'matplotlib.sphinxext.plot_directive'] doctest_path = os.path.abspath('../../') doctest_global_setup = ''' diff --git a/doc/source/tutorial/frames_stack.rst b/doc/source/tutorial/frames_stack.rst index b14002f..4d50a0d 100644 --- a/doc/source/tutorial/frames_stack.rst +++ b/doc/source/tutorial/frames_stack.rst @@ -23,7 +23,7 @@ Setup an arbitrary analyzer to check that decoding process from file and from st >>> pitch = get_processor('aubio_pitch')() >>> pipe = (decoder | pitch) >>> print pipe.processors #doctest: +ELLIPSIS -[gst_dec-{}, aubio_pitch-{}] +[gst_dec-{}, aubio_pitch-{"blocksize_s": 0.0, "stepsize_s": 0.0}] Run the pipe: diff --git a/doc/source/tutorial/quick_start.rst b/doc/source/tutorial/quick_start.rst index c8207ff..bbbb3ac 100644 --- a/doc/source/tutorial/quick_start.rst +++ b/doc/source/tutorial/quick_start.rst @@ -62,4 +62,4 @@ analysis and encoding: >>> encoders = get_processor('gst_mp3_enc')('sweep.mp3') | get_processor('gst_flac_enc')('sweep.flac') >>> (decoder | levels | encoders).run() >>> print levels.results - {'...': AnalyzerResult(id_metadata=IdMetadata(id='level.max', name='Level Max', unit='dBFS', description='', date='...', version='...', author='TimeSide', proc_uuid='...', res_uuid='...'), data_object=GlobalValueObject(value=array([-6.021]), y_value=array([], dtype=float64)), audio_metadata=AudioMetadata(uri='.../sweep.wav', start=0.0, duration=8.0, is_segment=False, sha1='...', channels=2, channelsManagement=''), parameters={}), '...': AnalyzerResult(id_metadata=IdMetadata(id='level.rms', name='Level RMS', unit='dBFS', description='', date='...', version='...', author='TimeSide', proc_uuid='...', res_uuid='...'), data_object=GlobalValueObject(value=array([-9.856]), y_value=array([], dtype=float64)), audio_metadata=AudioMetadata(uri='.../sweep.wav', start=0.0, duration=8.0, is_segment=False, sha1='...', channels=2, channelsManagement=''), parameters={})} + {'...': AnalyzerResult(id_metadata=IdMetadata(id='level.max', name='Level Max', unit='dBFS', description='', date='...', version='...', author='TimeSide', proc_uuid='...', res_uuid='...'), data_object=GlobalValueObject(value=array([ 0.]), y_value=array([], dtype=float64)), audio_metadata=AudioMetadata(uri='.../sweep.wav', start=0.0, duration=8.0, is_segment=False, sha1='...', channels=2, channelsManagement=''), parameters={}), '...': AnalyzerResult(id_metadata=IdMetadata(id='level.rms', name='Level RMS', unit='dBFS', description='', date='...', version='...', author='TimeSide', proc_uuid='...', res_uuid='...'), data_object=GlobalValueObject(value=array([-2.995]), y_value=array([], dtype=float64)), audio_metadata=AudioMetadata(uri='.../sweep.wav', start=0.0, duration=8.0, is_segment=False, sha1='...', channels=2, channelsManagement=''), parameters={})} diff --git a/timeside/analyzer/level.py b/timeside/analyzer/level.py index 9b4cc4c..edf4775 100644 --- a/timeside/analyzer/level.py +++ b/timeside/analyzer/level.py @@ -29,7 +29,8 @@ from timeside.analyzer.utils import MACHINE_EPSILON class Level(Analyzer): - """RMS level analyzer""" + """RMS level analyzer + """ implements(IValueAnalyzer) @interfacedoc @@ -93,3 +94,7 @@ class Level(Analyzer): rms_level.data_object.value = np.round(20 * np.log10(rms_val), 3) self.add_result(rms_level) + +if __name__ == "__main__": + import doctest + print doctest.testmod(verbose=True) diff --git a/timeside/analyzer/spectrogram.py b/timeside/analyzer/spectrogram.py index 10a745a..33a3459 100644 --- a/timeside/analyzer/spectrogram.py +++ b/timeside/analyzer/spectrogram.py @@ -18,6 +18,7 @@ # along with TimeSide. If not, see . # Author: Paul Brossier + from __future__ import division from timeside.core import implements, interfacedoc from timeside.analyzer.core import Analyzer @@ -26,12 +27,12 @@ from timeside.analyzer.preprocessors import downmix_to_mono, frames_adapter from timeside.tools.parameters import Int, HasTraits from timeside.tools.buffering import BufferTable - import numpy as np class Spectrogram(Analyzer): - """Spectrogram analyzer + """ + Spectrogram analyzer Parameters ---------- @@ -44,15 +45,31 @@ class Spectrogram(Analyzer): Examples -------- - >>> import timeside + >>> from timeside.core import get_processor >>> from timeside.tools.data_samples import samples as ts_samples >>> audio_source = ts_samples['sweep.wav'] - >>> decoder = timeside.decoder.file.FileDecoder(uri=audio_source) - >>> spectrogram = timeside.analyzer.spectrogram.Spectrogram(input_blocksize=2048, input_stepsize=1024) + >>> decoder = get_processor('gst_dec')(uri=audio_source) + >>> spectrogram = get_processor('spectrogram_analyzer')(input_blocksize=2048, input_stepsize=1024) >>> pipe = (decoder | spectrogram) >>> pipe.run() + + .. plot:: + + import timeside + from timeside.core import get_processor + from timeside.tools.data_samples import samples as ts_samples + audio_source = ts_samples['sweep.wav'] + decoder = get_processor('gst_dec')(uri=audio_source) + spectrogram = get_processor('spectrogram_analyzer')(input_blocksize=2048, + input_stepsize=1024) + pipe = (decoder | spectrogram) + pipe.run() + res = spectrogram.results['spectrogram_analyzer'] + res.render() + + """ implements(IAnalyzer) @@ -122,4 +139,5 @@ class Spectrogram(Analyzer): if __name__ == "__main__": import doctest - doctest.testmod() + import timeside + doctest.testmod(timeside.analyzer.spectrogram, verbose=True) diff --git a/timeside/encoder/audiosink.py b/timeside/encoder/audiosink.py index 8dd6d78..b8fa80f 100644 --- a/timeside/encoder/audiosink.py +++ b/timeside/encoder/audiosink.py @@ -99,5 +99,5 @@ class AudioSink(GstEncoder): if __name__ == "__main__": import doctest - - doctest.testmod() + import timeside + doctest.testmod(timeside.decoder.live, verbose=True) -- 2.39.5