]> git.parisson.com Git - timeside.git/commitdiff
clean examples, fix test_pipe
authoryomguy <yomguy@parisson.com>
Fri, 18 Jun 2010 22:54:43 +0000 (22:54 +0000)
committeryomguy <yomguy@parisson.com>
Fri, 18 Jun 2010 22:54:43 +0000 (22:54 +0000)
INSTALL
timeside/tests/__init__.py
timeside/tests/api/__init__.py
timeside/tests/api/examples.py
timeside/tests/api/test_pipe.py

diff --git a/INSTALL b/INSTALL
index c622564d9ff72bd361556bdbcb003844301d1903..c5adc7431d3b2a67470cc26b1993eeeddcddd6f6 100644 (file)
--- a/INSTALL
+++ b/INSTALL
@@ -72,7 +72,8 @@ And change only the following variables of the GrapherScheme object::
 
         self.color_scheme = {
             'waveform': [ # Four (R,G,B) tuples for three main color channels for the spectral centroid method
-                        (50,0,200), (0,220,80), (255,224,0), (255,0,0)
+                        (173,173,173), (147,149,196), (77,80,138), (108,66,0)
+                        # this is a purple one
                         ],
             'spectrogram': [
                         (0, 0, 0), (58/4,68/4,65/4), (80/2,100/2,153/2), (90,180,100), (224,224,44), (255,60,30), (255,255,255)
@@ -104,9 +105,11 @@ For example, a normalization and a waveform, from a python shell::
 
 >>> decoder  =  timeside.decoder.FileDecoder('source.wav')
 >>> grapher  =  timeside.grapher.Waveform('image.png')
->>> encoder  =  timeside.encoder.WavEncoder('normalized.wav')
->>> (decoder | grapher | encoder).run()
+>>> analyzer =  timeside.analyzer.MaxLevel()
+>>> encoder  =  timeside.encoder.WavEncoder('output.wav')
+>>> (decoder | grapher | analyzer | encoder).run()
 >>> grapher.render()
+>>> print 'Level:', analyzer.result()
 
 
 See the website for more examples and information about the TimeSide API:
index 2a6b9dbc466558037d79fa771965e7b62cde8c58..09bc2d62ae02128bab286040ca8b16c31e36ffd2 100644 (file)
@@ -1,3 +1,4 @@
+# -*- coding: utf-8 -*-
 
 import unittest
 import sys
@@ -17,7 +18,7 @@ class TestCase(unittest.TestCase):
         for item in list2:
             if not item in list1:
                 self.fail("%s is not in list1" % str(item))
-        
+
 class _TextTestResult(unittest.TestResult):
     """A test result class that can print formatted text results to a stream.
 
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..40a96afc6ff09d58a702b76e3f7dd412fe975e26 100644 (file)
@@ -0,0 +1 @@
+# -*- coding: utf-8 -*-
index d2313878d0392f4ff8d185de33b1525a9fdc212b..747c197d2b70ecdc092a3de971da4376afbdde8f 100644 (file)
@@ -1,136 +1,9 @@
 # -*- coding: utf-8 -*-
+
 from timeside.core import Processor, implements, interfacedoc, FixedSizeInputAdapter
 from timeside.api import *
-from timeside.grapher import *
-from timeside import Metadata
-#from scikits import audiolab
 import numpy
 
-class FileAudiolabDecoder(Processor):
-    """A simple audiolab-based example decoder"""
-    implements(IDecoder)
-
-    @staticmethod
-    @interfacedoc
-    def id():
-        return "test_audiolabdec"
-
-    @interfacedoc
-    def __init__(self, filename):
-        self.filename = filename
-        # The file has to be opened here so that nframes(), samplerate(),
-        # etc.. work before setup() is called.
-        self.file     = audiolab.Sndfile(self.filename, 'r')
-        self.position = 0
-
-    @interfacedoc
-    def setup(self):
-        super(FileDecoder, self).setup()
-        if self.position != 0:
-            self.file.seek(0);
-            self.position = 0
-
-    def release(self):
-        super(FileDecoder, self).release()
-        if self.file:
-            self.file.close()
-            self.file = None
-
-    @interfacedoc
-    def channels(self):
-        return self.file.channels
-
-    @interfacedoc
-    def samplerate(self):
-        return self.file.samplerate
-
-    @interfacedoc
-    def nframes(self):
-        return self.file.nframes
-
-    @interfacedoc
-    def format(self):
-        return self.file.file_format
-
-    @interfacedoc
-    def encoding(self):
-        return self.file.encoding
-    @interfacedoc
-    def resolution(self):
-        resolution = None
-        encoding = self.file.encoding
-
-        if encoding == "pcm8":
-            resolution = 8
-
-        elif encoding == "pcm16":
-            resolution = 16
-        elif encoding == "pcm32":
-            resolution = 32
-
-        return resolution
-
-    @interfacedoc
-    def metadata(self):
-        #TODO
-        return Metadata()
-
-    @interfacedoc
-    def process(self, frames=None, eod=False):
-        if frames:
-            raise Exception("Decoder doesn't accept input frames")
-
-        buffersize = 0x10000
-
-        # Need this because audiolab raises a bogus exception when asked
-        # to read passed the end of the file
-        toread = self.nframes() - self.position
-        if toread > buffersize:
-            toread = buffersize
-
-        frames         = self.file.read_frames(toread)
-        eod            = (toread < buffersize)
-        self.position += toread
-
-        # audiolab returns a 1D array for 1 channel, need to reshape to 2D:
-        if frames.ndim == 1:
-            frames = frames.reshape(len(frames), 1)
-
-        return frames, eod
-
-class MaxLevel(Processor):
-    implements(IValueAnalyzer)
-
-    @interfacedoc
-    def setup(self, channels=None, samplerate=None, nframes=None):
-        super(MaxLevel, self).setup(channels, samplerate, nframes)
-        self.max_value = 0
-
-    @staticmethod
-    @interfacedoc
-    def id():
-        return "test_maxlevel"
-
-    @staticmethod
-    @interfacedoc
-    def name():
-        return "Max level test analyzer"
-
-    @staticmethod
-    @interfacedoc
-    def unit():
-        # power? amplitude?
-        return ""
-
-    def process(self, frames, eod=False):
-        max = frames.max()
-        if max > self.max_value:
-            self.max_value = max
-
-        return frames, eod
-
-    def result(self):
-        return self.max_value
 
 class Gain(Processor):
     implements(IEffect)
@@ -152,199 +25,6 @@ class Gain(Processor):
     def process(self, frames, eod=False):
         return numpy.multiply(frames, self.gain), eod
 
-class WavEncoder(Processor):
-    implements(IEncoder)
-
-    def __init__(self, output):
-        self.file = None
-        if isinstance(output, basestring):
-            self.filename = output
-        else:
-            raise Exception("Streaming not supported")
-
-    @interfacedoc
-    def setup(self, channels=None, samplerate=None, nframes=None):
-        super(WavEncoder, self).setup(channels, samplerate, nframes)
-        if self.file:
-            self.file.close()
-
-        format = audiolab.Format("wav", "pcm16")
-        self.file = audiolab.Sndfile(self.filename, 'w', format=format, channels=channels,
-                                     samplerate=samplerate)
-
-    @staticmethod
-    @interfacedoc
-    def id():
-        return "test_wavenc"
-
-    @staticmethod
-    @interfacedoc
-    def description():
-        return "Hackish wave encoder"
-
-    @staticmethod
-    @interfacedoc
-    def file_extension():
-        return "wav"
-
-    @staticmethod
-    @interfacedoc
-    def mime_type():
-        return "audio/x-wav"
-
-    @interfacedoc
-    def set_metadata(self, metadata):
-        #TODO
-        pass
-
-    @interfacedoc
-    def process(self, frames, eod=False):
-        self.file.write_frames(frames)
-        if eod:
-            self.file.close()
-            self.file = None
-
-        return frames, eod
-
-
-class Waveform(Processor):
-    implements(IGrapher)
-
-    FFT_SIZE = 0x400
-
-    @interfacedoc
-    def __init__(self, width=None, height=None, output=None, bg_color=None, color_scheme=None):
-        if width:
-            self.width = width
-        else:
-            self.width = 1500
-        if height:
-            self.height = height
-        else:
-            self.height = 200
-        self.bg_color = bg_color
-        self.color_scheme = color_scheme
-        self.filename = output
-        self.graph = None
-
-    @staticmethod
-    @interfacedoc
-    def id():
-        return "test_waveform"
-
-    @staticmethod
-    @interfacedoc
-    def name():
-        return "Waveform test"
-
-    @interfacedoc
-    def set_colors(self, background, scheme):
-        self.bg_color = background
-        self.color_scheme = scheme
-
-    @interfacedoc
-    def setup(self, channels=None, samplerate=None, nframes=None):
-        super(Waveform, self).setup(channels, samplerate, nframes)
-        if self.graph:
-            self.graph = None
-        self.graph = WaveformImage(self.width, self.height, self.nframes(), self.samplerate(), self.FFT_SIZE,
-                                    bg_color=self.bg_color, color_scheme=self.color_scheme, filename=self.filename)
-
-    @interfacedoc
-    def process(self, frames, eod=False):
-        self.graph.process(frames, eod)
-        return frames, eod
-
-    @interfacedoc
-    def render(self):
-        if self.filename:
-            self.graph.save()
-        return self.graph.image
-
-
-class Spectrogram(Processor):
-    implements(IGrapher)
-
-    FFT_SIZE = 0x400
-
-    @interfacedoc
-    def __init__(self, width=None, height=None, output=None, bg_color=None, color_scheme=None):
-        if width:
-            self.width = width
-        else:
-            self.width = 1500
-        if height:
-            self.height = height
-        else:
-            self.height = 200
-        self.bg_color = bg_color
-        self.color_scheme = color_scheme
-        self.filename = output
-        self.graph = None
-
-    @staticmethod
-    @interfacedoc
-    def id():
-        return "test_spectrogram"
-
-    @staticmethod
-    @interfacedoc
-    def name():
-        return "Spectrogram test"
-
-    @interfacedoc
-    def set_colors(self, background, scheme):
-        self.bg_color = background
-        self.color_scheme = scheme
-
-    @interfacedoc
-    def setup(self, channels=None, samplerate=None, nframes=None):
-        super(Spectrogram, self).setup(channels, samplerate, nframes)
-        if self.graph:
-            self.graph = None
-        self.graph = SpectrogramImage(self.width, self.height, self.nframes(), self.samplerate(), self.FFT_SIZE,
-                                    bg_color=self.bg_color, color_scheme=self.color_scheme, filename=self.filename)
-
-    @interfacedoc
-    def process(self, frames, eod=False):
-        self.graph.process(frames, eod)
-        return frames, eod
-
-    @interfacedoc
-    def render(self):
-        if self.filename:
-            self.graph.save()
-        return self.graph.image
-
-
-class Duration(Processor):
-    """A rather useless duration analyzer. Its only purpose is to test the
-       nframes characteristic."""
-    implements(IValueAnalyzer)
-
-    @interfacedoc
-    def setup(self, channels, samplerate, nframes):
-        if not nframes:
-            raise Exception("nframes argument required")
-        super(Duration, self).setup(channels, samplerate, nframes)
-
-    @staticmethod
-    @interfacedoc
-    def id():
-        return "test_duration"
-
-    @staticmethod
-    @interfacedoc
-    def name():
-        return "Duration analyzer"
-
-    @staticmethod
-    @interfacedoc
-    def unit():
-        return "seconds"
-
-    def result(self):
-        return self.input_nframes / float(self.input_samplerate)
 
 class FixedInputProcessor(Processor):
     """Processor which does absolutely nothing except illustrating the use
index eaa0850545f7b5a5e2f6d18e731c556a999e108d..7c2404f6899e520c618137bac09aa1ff5e03707c 100644 (file)
@@ -1,4 +1,5 @@
 # -*- coding: utf-8 -*-
+
 from timeside.tests.api.examples import Gain
 from timeside.core import *
 from timeside.decoder import *