]> git.parisson.com Git - timeside.git/commitdiff
Doc: Add a tutorial on second pass with ArrayDecoder + fix bug in Waveform analyzer
authorThomas Fillon <thomas@parisson.com>
Thu, 12 Dec 2013 14:42:10 +0000 (15:42 +0100)
committerThomas Fillon <thomas@parisson.com>
Thu, 12 Dec 2013 14:42:10 +0000 (15:42 +0100)
README.rst
doc/source/tutorial/ArrayDecoder.rst [new file with mode: 0644]
doc/source/tutorial/index.rst
timeside/analyzer/waveform.py

index 8025a1009b917df9f0d1769967e41a5cdec1d39d..09c895054ac022bd282c7c5554b9dd1d0f2d4710 100644 (file)
@@ -22,7 +22,7 @@ We just **need** a python library to:
 * **Draw** various fancy waveforms, spectrograms and other cool graphers,
 * **Transcode** audio data in various media formats and stream them through web apps,
 * **Playback** and **interact** **on demand** through a smart high-level HTML5 extensible player,
-* **Index**, **tag** and **organize semantic metadata** (see `Telemeta <http://telemeta.org>`_ which embed TimeSide).
+* **Index**, **tag** and **organize semantic metadata** (see `Telemeta <http://telemeta.org>`_ which embeds TimeSide).
 
 Here is a schematic diagram of the TimeSide engine architecture:
 
diff --git a/doc/source/tutorial/ArrayDecoder.rst b/doc/source/tutorial/ArrayDecoder.rst
new file mode 100644 (file)
index 0000000..6a37158
--- /dev/null
@@ -0,0 +1,44 @@
+.. This file is part of TimeSide
+   @author: Thomas Fillon
+
+===============================================
+ Running a pipe with previously decoded frames
+===============================================
+
+Example of use of the  :class:`ArrayDecoder <timeside.decoder.core.ArrayDecoder>` and  :class:`Waveform analyzer <timeside.analyzer.waveform.Waveform>` to run a pipe with previously frames from memory on a second pass
+
+First, setup a  :class:`FileDecoder <timeside.decoder.core.FileDecoder>` on an audio file:
+
+>>> import timeside
+>>> import numpy as np
+>>> 
+>>> audio_file = 'http://github.com/yomguy/timeside-samples/raw/master/samples/sweep.mp3'
+>>> 
+>>> file_decoder = timeside.decoder.FileDecoder(audio_file)
+
+Then, setup an arbitrary analyzer to check that both decoding process are equivalent and a :class:`Waveform analyzer <timeside.analyzer.waveform.Waveform>` which result will store the decoded frames:
+
+>>> pitch_on_file = timeside.analyzer.AubioPitch()
+>>> waveform = timeside.analyzer.Waveform()
+
+And run the pipe:
+
+>>> (file_decoder | pitch_on_file | waveform).run()
+
+To run the second pass, we need to get back the decoded samples and the original samplerate and pass them to :class:`ArrayDecoder <timeside.decoder.core.ArrayDecoder>`:
+
+>>> samples = waveform.results['waveform_analyzer'].data
+>>> samplerate = waveform.results['waveform_analyzer'].frame_metadata.samplerate
+>>> array_decoder = timeside.decoder.ArrayDecoder(samples=samples, samplerate=samplerate)
+
+Then we can run a second pipe with the previously decoded frames and pass the frames to the same analyzer:
+
+>>> pitch_on_array = timeside.analyzer.AubioPitch()
+>>> (array_decoder | pitch_on_array).run()
+
+To assert that the frames passed to the two analyzers are the same, we check that the results of these analyzers are equivalent:
+
+>>> np.allclose(pitch_on_file.results['aubio_pitch.pitch'].data,
+...             pitch_on_array.results['aubio_pitch.pitch'].data)
+True
+
index 19142c47220fc0a40d4a11c774a1586d79667551..333e314515c3ef2687b79fdfc960eb4a1d75abfb 100644 (file)
@@ -13,5 +13,6 @@ Contents:
 
       Quick start <quick_start>
       Usage of AnalyzerResult <AnalyzerResult>
+      Running a pipe with previously decoded frames <ArrayDecoder>
 
 
index 30fd4df51b4e411783620c98510da430daa13f12..e1289f0bb098534015a0f29b96e26333f4d53327 100644 (file)
@@ -31,8 +31,8 @@ class Waveform(Analyzer):
 
     def __init__(self):
         super(Waveform, self).__init__()
-        self.input_blocksize = 2048
-        self.input_stepsize = self.input_blocksize / 2
+#        self.input_blocksize = 2048
+#        self.input_stepsize = self.input_blocksize / 2
 
     @interfacedoc
     def setup(self, channels=None, samplerate=None,
@@ -58,13 +58,13 @@ class Waveform(Analyzer):
     def unit():
         return ""
 
-    @downmix_to_mono
-    @frames_adapter
+#    @downmix_to_mono
+#    @frames_adapter
     def process(self, frames, eod=False):
         self.values.append(frames)
         return frames, eod
 
     def post_process(self):
         waveform = self.new_result(data_mode='value', time_mode='framewise')
-        waveform.data_object.value = np.asarray(self.values).flatten()
+        waveform.data_object.value = np.vstack(self.values)
         self.pipe.results.add(waveform)