]> git.parisson.com Git - timeside.git/commitdiff
timeside/analyzer/: factorise max_level and rms_level
authorPaul Brossier <piem@piem.org>
Mon, 15 Apr 2013 22:35:10 +0000 (17:35 -0500)
committerPaul Brossier <piem@piem.org>
Mon, 15 Apr 2013 22:35:10 +0000 (17:35 -0500)
tests/test_analyzer_level.py [new file with mode: 0755]
tests/test_max_level.py [deleted file]
timeside/analyzer/__init__.py
timeside/analyzer/level.py [new file with mode: 0644]
timeside/analyzer/max_level.py [deleted file]
timeside/analyzer/mean_level.py [deleted file]

diff --git a/tests/test_analyzer_level.py b/tests/test_analyzer_level.py
new file mode 100755 (executable)
index 0000000..d1e4553
--- /dev/null
@@ -0,0 +1,30 @@
+#! /usr/bin/env python
+
+from unit_timeside import *
+from timeside.decoder import *
+from timeside.analyzer.level import Level
+
+class TestAnalyzerLevel(TestCase):
+
+    def setUp(self):
+        self.analyzer = Level()
+
+    def testOnSweep(self):
+        "runs on sweep"
+        self.source = os.path.join (os.path.dirname(__file__),  "samples", "sweep.wav")
+
+    def testOnGuitar(self):
+        "runs on guitar"
+        self.source = os.path.join (os.path.dirname(__file__),  "samples", "guitar.wav")
+
+    def tearDown(self):
+        decoder = FileDecoder(self.source)
+        (decoder | self.analyzer).run()
+        results = self.analyzer.results()
+        print results
+        #print results.to_yaml()
+        #print results.to_json()
+        #print results.to_xml()
+
+if __name__ == '__main__':
+    unittest.main(testRunner=TestRunner())
diff --git a/tests/test_max_level.py b/tests/test_max_level.py
deleted file mode 100755 (executable)
index d55f6f7..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-#! /usr/bin/env python
-
-from unit_timeside import *
-from timeside.decoder import *
-from timeside.analyzer.max_level import MaxLevel
-
-class TestAubioMelEnergy(TestCase):
-
-    def setUp(self):
-        self.analyzer = MaxLevel()
-
-    def testOnSweep(self):
-        "runs on sweep"
-        self.source = os.path.join (os.path.dirname(__file__),  "samples", "sweep.wav")
-
-    def testOnGuitar(self):
-        "runs on guitar"
-        self.source = os.path.join (os.path.dirname(__file__),  "samples", "guitar.wav")
-
-    def tearDown(self):
-        decoder = FileDecoder(self.source)
-        (decoder | self.analyzer).run()
-        results = self.analyzer.results()
-        print results
-        #print results.to_yaml()
-        #print results.to_json()
-        #print results.to_xml()
-
-if __name__ == '__main__':
-    unittest.main(testRunner=TestRunner())
index 8a50f369d6c9252faa1832a8a113c7743871a50b..95001c32d3e7ebfe2e8830969d9bd8a49455e988 100644 (file)
@@ -1,7 +1,6 @@
 # -*- coding: utf-8 -*-
 
-from max_level import *
-from mean_level import *
+from level import *
 from dc import *
 from aubio_temporal import *
 from aubio_pitch import *
diff --git a/timeside/analyzer/level.py b/timeside/analyzer/level.py
new file mode 100644 (file)
index 0000000..ed585ce
--- /dev/null
@@ -0,0 +1,65 @@
+# -*- coding: utf-8 -*-
+#
+# Copyright (c) 2007-2009 Guillaume Pellerin <yomguy@parisson.com>
+# Copyright (c) 2009 Olivier Guilyardi <olivier@samalyse.com>
+
+# This file is part of TimeSide.
+
+# TimeSide is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 2 of the License, or
+# (at your option) any later version.
+
+# TimeSide is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with TimeSide.  If not, see <http://www.gnu.org/licenses/>.
+
+# Author: Guillaume Pellerin <yomguy@parisson.com>
+
+from timeside.core import Processor, implements, interfacedoc, FixedSizeInputAdapter
+from timeside.analyzer.core import *
+from timeside.api import IValueAnalyzer
+import numpy
+
+
+class Level(Processor):
+    implements(IValueAnalyzer)
+
+    @interfacedoc
+    def setup(self, channels=None, samplerate=None, blocksize=None, totalframes=None):
+        super(Level, self).setup(channels, samplerate, blocksize, totalframes)
+        # max_level
+        self.max_value = 0
+        # rms_level
+        self.mean_values = numpy.array([])
+
+    @staticmethod
+    @interfacedoc
+    def id():
+        return "level_analyzer"
+
+    @staticmethod
+    @interfacedoc
+    def name():
+        return "level analyzer"
+
+    def process(self, frames, eod=False):
+        if frames.size:
+            # max_level
+            max_value = frames.max()
+            if max_value > self.max_value:
+                self.max_value = max_value
+            # rms_level
+            self.mean_values = numpy.append(self.mean_values, numpy.mean(numpy.square(frames)))
+        return frames, eod
+
+    def results(self):
+        max_level = AnalyzerResult(id = "max_level", name = "Max level", unit = "dBFS")
+        max_level.value = numpy.round(20*numpy.log10(self.max_value), 3)
+        rms_level = AnalyzerResult(id = "rms_level", name = "RMS level", unit = "dBFS")
+        rms_level.value = numpy.round(20*numpy.log10(numpy.sqrt(numpy.mean(self.mean_values))), 3)
+        return AnalyzerResultContainer([max_level, rms_level])
diff --git a/timeside/analyzer/max_level.py b/timeside/analyzer/max_level.py
deleted file mode 100644 (file)
index d280326..0000000
+++ /dev/null
@@ -1,57 +0,0 @@
-# -*- coding: utf-8 -*-
-#
-# Copyright (c) 2007-2009 Guillaume Pellerin <yomguy@parisson.com>
-# Copyright (c) 2009 Olivier Guilyardi <olivier@samalyse.com>
-
-# This file is part of TimeSide.
-
-# TimeSide is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 2 of the License, or
-# (at your option) any later version.
-
-# TimeSide is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-
-# You should have received a copy of the GNU General Public License
-# along with TimeSide.  If not, see <http://www.gnu.org/licenses/>.
-
-# Author: Guillaume Pellerin <yomguy@parisson.com>
-
-from timeside.core import Processor, implements, interfacedoc, FixedSizeInputAdapter
-from timeside.analyzer.core import *
-from timeside.api import IValueAnalyzer
-import numpy
-
-
-class MaxLevel(Processor):
-    implements(IValueAnalyzer)
-
-    @interfacedoc
-    def setup(self, channels=None, samplerate=None, blocksize=None, totalframes=None):
-        super(MaxLevel, self).setup(channels, samplerate, blocksize, totalframes)
-        self.value = 0
-
-    @staticmethod
-    @interfacedoc
-    def id():
-        return "maxlevel_analyzer"
-
-    @staticmethod
-    @interfacedoc
-    def name():
-        return "Max level analyzer"
-
-    def process(self, frames, eod=False):
-        if frames.size:
-            max = frames.max()
-            if max > self.value:
-                self.value = max
-        return frames, eod
-
-    def results(self):
-        result = AnalyzerResult(id = "maxlevel", name = "Max level", unit = "dBFS")
-        result.value = numpy.round(20*numpy.log10(self.value), 3)
-        return AnalyzerResultContainer([result])
diff --git a/timeside/analyzer/mean_level.py b/timeside/analyzer/mean_level.py
deleted file mode 100644 (file)
index 33bae26..0000000
+++ /dev/null
@@ -1,60 +0,0 @@
-# -*- coding: utf-8 -*-
-#
-# Copyright (c) 2007-2009 Guillaume Pellerin <yomguy@parisson.com>
-
-# This file is part of TimeSide.
-
-# TimeSide is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 2 of the License, or
-# (at your option) any later version.
-
-# TimeSide is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-
-# You should have received a copy of the GNU General Public License
-# along with TimeSide.  If not, see <http://www.gnu.org/licenses/>.
-
-# Author: Guillaume Pellerin <yomguy@parisson.com>
-
-from timeside.core import Processor, implements, interfacedoc, FixedSizeInputAdapter
-from timeside.analyzer.core import *
-from timeside.api import IValueAnalyzer
-import numpy
-
-
-class MeanLevel(Processor):
-    implements(IValueAnalyzer)
-
-    @interfacedoc
-    def setup(self, channels=None, samplerate=None, blocksize=None, totalframes=None):
-        super(MeanLevel, self).setup(channels, samplerate, blocksize, totalframes)
-        self.values = numpy.array([])
-
-    @staticmethod
-    @interfacedoc
-    def id():
-        return "rmslevel"
-
-    @staticmethod
-    @interfacedoc
-    def name():
-        return "RMS level"
-
-    @staticmethod
-    @interfacedoc
-    def unit():
-        return "dBFS"
-
-    def __str__(self):
-        return "%s %s" % (str(self.value), unit())
-
-    def process(self, frames, eod=False):
-        if frames.size:
-            self.values = numpy.append(self.values, numpy.mean(numpy.square(frames)))
-        return frames, eod
-
-    def result(self):
-        return numpy.round(20*numpy.log10(numpy.sqrt(numpy.mean(self.values))), 3)