Python audioop 模块,alaw2lin() 实例源码

我们从Python开源项目中,提取了以下19个代码示例,用于说明如何使用audioop.alaw2lin()

项目:zippy    作者:securesystemslab    | 项目源码 | 文件源码
def test_alaw2lin(self):
        # Cursory
        d = audioop.lin2alaw(data[0], 1)
        self.assertEqual(audioop.alaw2lin(d, 1), data[0])
        if endian == 'big':
            self.assertEqual(audioop.alaw2lin(d, 2),
                             b'\x00\x08\x01\x08\x02\x10')
            self.assertEqual(audioop.alaw2lin(d, 4),
                             b'\x00\x08\x00\x00\x01\x08\x00\x00\x02\x10\x00\x00')
        else:
            self.assertEqual(audioop.alaw2lin(d, 2),
                             b'\x08\x00\x08\x01\x10\x02')
            self.assertEqual(audioop.alaw2lin(d, 4),
                             b'\x00\x00\x08\x00\x00\x00\x08\x01\x00\x00\x10\x02')
项目:zippy    作者:securesystemslab    | 项目源码 | 文件源码
def test_wrongsize(self):
        data = b'abc'
        state = None
        for size in (-1, 3, 5):
            self.assertRaises(audioop.error, audioop.ulaw2lin, data, size)
            self.assertRaises(audioop.error, audioop.alaw2lin, data, size)
            self.assertRaises(audioop.error, audioop.adpcm2lin, data, size, state)
项目:zippy    作者:securesystemslab    | 项目源码 | 文件源码
def _alaw2lin(self, data):
        import audioop
        return audioop.alaw2lin(data, 2)
项目:oil    作者:oilshell    | 项目源码 | 文件源码
def test_alaw2lin(self):
        encoded = b'\x00\x03\x24\x2a\x51\x54\x55\x58\x6b\x71\x7f'\
                  b'\x80\x83\xa4\xaa\xd1\xd4\xd5\xd8\xeb\xf1\xff'
        src = [-688, -720, -2240, -4032, -9, -3, -1, -27, -244, -82, -106,
               688, 720, 2240, 4032, 9, 3, 1, 27, 244, 82, 106]
        for w in 1, 2, 4:
            self.assertEqual(audioop.alaw2lin(encoded, w),
                             packs[w](*(x << (w * 8) >> 13 for x in src)))

        encoded = ''.join(chr(x) for x in xrange(256))
        for w in 2, 4:
            decoded = audioop.alaw2lin(encoded, w)
            self.assertEqual(audioop.lin2alaw(decoded, w), encoded)
项目:oil    作者:oilshell    | 项目源码 | 文件源码
def test_wrongsize(self):
        data = b'abcdefgh'
        state = None
        for size in (-1, 0, 3, 5, 1024):
            self.assertRaises(audioop.error, audioop.ulaw2lin, data, size)
            self.assertRaises(audioop.error, audioop.alaw2lin, data, size)
            self.assertRaises(audioop.error, audioop.adpcm2lin, data, size, state)
项目:python2-tracer    作者:extremecoders-re    | 项目源码 | 文件源码
def test_alaw2lin(self):
        encoded = b'\x00\x03\x24\x2a\x51\x54\x55\x58\x6b\x71\x7f'\
                  b'\x80\x83\xa4\xaa\xd1\xd4\xd5\xd8\xeb\xf1\xff'
        src = [-688, -720, -2240, -4032, -9, -3, -1, -27, -244, -82, -106,
               688, 720, 2240, 4032, 9, 3, 1, 27, 244, 82, 106]
        for w in 1, 2, 4:
            self.assertEqual(audioop.alaw2lin(encoded, w),
                             packs[w](*(x << (w * 8) >> 13 for x in src)))

        encoded = ''.join(chr(x) for x in xrange(256))
        for w in 2, 4:
            decoded = audioop.alaw2lin(encoded, w)
            self.assertEqual(audioop.lin2alaw(decoded, w), encoded)
项目:python2-tracer    作者:extremecoders-re    | 项目源码 | 文件源码
def test_wrongsize(self):
        data = b'abcdefgh'
        state = None
        for size in (-1, 0, 3, 5, 1024):
            self.assertRaises(audioop.error, audioop.ulaw2lin, data, size)
            self.assertRaises(audioop.error, audioop.alaw2lin, data, size)
            self.assertRaises(audioop.error, audioop.adpcm2lin, data, size, state)
项目:web_ctp    作者:molebot    | 项目源码 | 文件源码
def test_alaw2lin(self):
        encoded = b'\x00\x03\x24\x2a\x51\x54\x55\x58\x6b\x71\x7f'\
                  b'\x80\x83\xa4\xaa\xd1\xd4\xd5\xd8\xeb\xf1\xff'
        src = [-688, -720, -2240, -4032, -9, -3, -1, -27, -244, -82, -106,
               688, 720, 2240, 4032, 9, 3, 1, 27, 244, 82, 106]
        for w in 1, 2, 4:
            self.assertEqual(audioop.alaw2lin(encoded, w),
                             packs[w](*(x << (w * 8) >> 13 for x in src)))

        encoded = bytes(range(256))
        for w in 2, 4:
            decoded = audioop.alaw2lin(encoded, w)
            self.assertEqual(audioop.lin2alaw(decoded, w), encoded)
项目:web_ctp    作者:molebot    | 项目源码 | 文件源码
def test_wrongsize(self):
        data = b'abcdefgh'
        state = None
        for size in (-1, 0, 3, 5, 1024):
            self.assertRaises(audioop.error, audioop.ulaw2lin, data, size)
            self.assertRaises(audioop.error, audioop.alaw2lin, data, size)
            self.assertRaises(audioop.error, audioop.adpcm2lin, data, size, state)
项目:pefile.pypy    作者:cloudtracer    | 项目源码 | 文件源码
def test_alaw2lin(self):
        encoded = b'\x00\x03\x24\x2a\x51\x54\x55\x58\x6b\x71\x7f'\
                  b'\x80\x83\xa4\xaa\xd1\xd4\xd5\xd8\xeb\xf1\xff'
        src = [-688, -720, -2240, -4032, -9, -3, -1, -27, -244, -82, -106,
               688, 720, 2240, 4032, 9, 3, 1, 27, 244, 82, 106]
        for w in 1, 2, 4:
            self.assertEqual(audioop.alaw2lin(encoded, w),
                             packs[w](*(x << (w * 8) >> 13 for x in src)))

        encoded = ''.join(chr(x) for x in xrange(256))
        for w in 2, 4:
            decoded = audioop.alaw2lin(encoded, w)
            self.assertEqual(audioop.lin2alaw(decoded, w), encoded)
项目:pefile.pypy    作者:cloudtracer    | 项目源码 | 文件源码
def test_wrongsize(self):
        data = b'abcdefgh'
        state = None
        for size in (-1, 0, 3, 5, 1024):
            self.assertRaises(audioop.error, audioop.ulaw2lin, data, size)
            self.assertRaises(audioop.error, audioop.alaw2lin, data, size)
            self.assertRaises(audioop.error, audioop.adpcm2lin, data, size, state)
项目:ouroboros    作者:pybee    | 项目源码 | 文件源码
def test_alaw2lin(self):
        encoded = b'\x00\x03\x24\x2a\x51\x54\x55\x58\x6b\x71\x7f'\
                  b'\x80\x83\xa4\xaa\xd1\xd4\xd5\xd8\xeb\xf1\xff'
        src = [-688, -720, -2240, -4032, -9, -3, -1, -27, -244, -82, -106,
               688, 720, 2240, 4032, 9, 3, 1, 27, 244, 82, 106]
        for w in 1, 2, 3, 4:
            decoded = packs[w](*(x << (w * 8) >> 13 for x in src))
            self.assertEqual(audioop.alaw2lin(encoded, w), decoded)
            self.assertEqual(audioop.alaw2lin(bytearray(encoded), w), decoded)
            self.assertEqual(audioop.alaw2lin(memoryview(encoded), w), decoded)

        encoded = bytes(range(256))
        for w in 2, 3, 4:
            decoded = audioop.alaw2lin(encoded, w)
            self.assertEqual(audioop.lin2alaw(decoded, w), encoded)
项目:ouroboros    作者:pybee    | 项目源码 | 文件源码
def test_wrongsize(self):
        data = b'abcdefgh'
        state = None
        for size in (-1, 0, 5, 1024):
            self.assertRaises(audioop.error, audioop.ulaw2lin, data, size)
            self.assertRaises(audioop.error, audioop.alaw2lin, data, size)
            self.assertRaises(audioop.error, audioop.adpcm2lin, data, size, state)
项目:ouroboros    作者:pybee    | 项目源码 | 文件源码
def _alaw2lin(self, data):
        import audioop
        return audioop.alaw2lin(data, 2)
项目:ndk-python    作者:gittor    | 项目源码 | 文件源码
def test_alaw2lin(self):
        encoded = b'\x00\x03\x24\x2a\x51\x54\x55\x58\x6b\x71\x7f'\
                  b'\x80\x83\xa4\xaa\xd1\xd4\xd5\xd8\xeb\xf1\xff'
        src = [-688, -720, -2240, -4032, -9, -3, -1, -27, -244, -82, -106,
               688, 720, 2240, 4032, 9, 3, 1, 27, 244, 82, 106]
        for w in 1, 2, 4:
            self.assertEqual(audioop.alaw2lin(encoded, w),
                             packs[w](*(x << (w * 8) >> 13 for x in src)))

        encoded = ''.join(chr(x) for x in xrange(256))
        for w in 2, 4:
            decoded = audioop.alaw2lin(encoded, w)
            self.assertEqual(audioop.lin2alaw(decoded, w), encoded)
项目:ndk-python    作者:gittor    | 项目源码 | 文件源码
def test_wrongsize(self):
        data = b'abcdefgh'
        state = None
        for size in (-1, 0, 3, 5, 1024):
            self.assertRaises(audioop.error, audioop.ulaw2lin, data, size)
            self.assertRaises(audioop.error, audioop.alaw2lin, data, size)
            self.assertRaises(audioop.error, audioop.adpcm2lin, data, size, state)
项目:kbe_server    作者:xiaohaoppy    | 项目源码 | 文件源码
def test_alaw2lin(self):
        encoded = b'\x00\x03\x24\x2a\x51\x54\x55\x58\x6b\x71\x7f'\
                  b'\x80\x83\xa4\xaa\xd1\xd4\xd5\xd8\xeb\xf1\xff'
        src = [-688, -720, -2240, -4032, -9, -3, -1, -27, -244, -82, -106,
               688, 720, 2240, 4032, 9, 3, 1, 27, 244, 82, 106]
        for w in 1, 2, 3, 4:
            decoded = packs[w](*(x << (w * 8) >> 13 for x in src))
            self.assertEqual(audioop.alaw2lin(encoded, w), decoded)
            self.assertEqual(audioop.alaw2lin(bytearray(encoded), w), decoded)
            self.assertEqual(audioop.alaw2lin(memoryview(encoded), w), decoded)

        encoded = bytes(range(256))
        for w in 2, 3, 4:
            decoded = audioop.alaw2lin(encoded, w)
            self.assertEqual(audioop.lin2alaw(decoded, w), encoded)
项目:kbe_server    作者:xiaohaoppy    | 项目源码 | 文件源码
def test_wrongsize(self):
        data = b'abcdefgh'
        state = None
        for size in (-1, 0, 5, 1024):
            self.assertRaises(audioop.error, audioop.ulaw2lin, data, size)
            self.assertRaises(audioop.error, audioop.alaw2lin, data, size)
            self.assertRaises(audioop.error, audioop.adpcm2lin, data, size, state)
项目:kbe_server    作者:xiaohaoppy    | 项目源码 | 文件源码
def _alaw2lin(self, data):
        import audioop
        return audioop.alaw2lin(data, 2)