コード例 #1
0
ファイル: plugins.py プロジェクト: antiface/dsp-testbed
class LowPassFilterTest(unittest.TestCase):
    def setUp(self):
        self.p1 = LowPassFilter()
        self.s1 = DiracSource()

        self.p2 = LowPassFilter()
        self.s2 = SineSource(freq=400, amp=1.0)

        self.p3 = LowPassFilter()
        self.s3 = SineSource(freq=40, amp=1.0)

    def test_on_dirac(self):
        chunk = list(islice(self.s1.read(), 0, 100))
        proc = self.p1.process(chunk)
        # Lets check if IIR filter is really infinite.
        self.assertTrue(abs(proc[-1][0]) > 0.001)

    def test_on_sin(self):
        # A bit weird way to check if LP filter passing low frequences
        # Freq for filter is 150 Hz, so:
        # 400 Hz freq should be dimmed
        chunk_len = self.s2.rate / 400
        chunk = list(islice(self.s2.read(), 0, chunk_len * 2))
        proc = self.p2.process(chunk)
        self.assertTrue(max(map(lambda x: abs(x[0]), proc)) < 0.3)

        # 40 Hz should be pretty much left intact
        chunk_len = self.s2.rate / 40
        chunk = list(islice(self.s3.read(), 0, chunk_len * 2))
        proc = self.p3.process(chunk)
        self.assertTrue(max(map(lambda x: abs(x[0]), proc)) > 0.8)
コード例 #2
0
ファイル: plugins.py プロジェクト: antiface/dsp-testbed
    def setUp(self):
        self.p1 = LowPassFilter()
        self.s1 = DiracSource()

        self.p2 = LowPassFilter()
        self.s2 = SineSource(freq=400, amp=1.0)

        self.p3 = LowPassFilter()
        self.s3 = SineSource(freq=40, amp=1.0)