Beispiel #1
0
 def setup(self,
           channels=None,
           samplerate=None,
           blocksize=None,
           totalframes=None):
     super(Grapher, self).setup(channels, samplerate, blocksize,
                                totalframes)
     self.sample_rate = samplerate
     self.higher_freq = self.sample_rate / 2
     self.block_size = blocksize
     self.total_frames = totalframes
     self.image = Image.new("RGBA", (self.image_width, self.image_height),
                            self.bg_color)
     self.samples_per_pixel = self.total_frames / float(self.image_width)
     self.buffer_size = int(round(self.samples_per_pixel, 0))
     self.pixels_adapter = FixedSizeInputAdapter(self.buffer_size,
                                                 1,
                                                 pad=False)
     self.pixels_adapter_totalframes = self.pixels_adapter.blocksize(
         self.total_frames)
     self.spectrum = Spectrum(self.fft_size, self.sample_rate,
                              self.block_size, self.total_frames,
                              self.lower_freq, self.higher_freq,
                              numpy.hanning)
     self.pixel = self.image.load()
     self.draw = ImageDraw.Draw(self.image)
Beispiel #2
0
    def testSizeMultiple(self):
        "Test a stream which contain a multiple number of buffers"
        adapter = FixedSizeInputAdapter(4, 2)

        self.assertIOEquals(adapter, self.data[0:20], True,
            [self.data[0:4], self.data[4:8], self.data[8:12], self.data[12:16], self.data[16:20]],
            True)
Beispiel #3
0
    def testPadding(self):
        "Test automatic padding support"
        adapter = FixedSizeInputAdapter(4, 2, pad=True)

        self.assertEqual(len(self.data) + 2, adapter.blocksize(len(self.data)))

        self.assertIOEquals(adapter, self.data[0:21], False, [
            self.data[0:4], self.data[4:8], self.data[8:12], self.data[12:16],
            self.data[16:20]
        ], False)

        self.assertIOEquals(adapter, self.data[21:22], True,
                            [[[20, 42], [21, 43], [0, 0], [0, 0]]], True)
Beispiel #4
0
    def testTwoChannels(self):
        "Test simple stream with two channels"
        adapter = FixedSizeInputAdapter(4, 2)

        self.assertEquals(len(self.data), adapter.blocksize(len(self.data)))

        self.assertIOEquals(adapter, self.data[0:1], False, [])
        self.assertIOEquals(adapter, self.data[1:5], False, [self.data[0:4]], False)
        self.assertIOEquals(adapter, self.data[5:12], False, [self.data[4:8], self.data[8:12]], False)
        self.assertIOEquals(adapter, self.data[12:13], False, [])
        self.assertIOEquals(adapter, self.data[13:14], False, [])
        self.assertIOEquals(adapter, self.data[14:18], False, [self.data[12:16]], False)
        self.assertIOEquals(adapter, self.data[18:20], False, [self.data[16:20]], False)
        self.assertIOEquals(adapter, self.data[20:21], False, [])
        self.assertIOEquals(adapter, self.data[21:22], True, [self.data[20:22]], True)