Exemplo n.º 1
0
    def test_bandwidth(self):
        enc = encoder.create(48000, 2, constants.APPLICATION_AUDIO)

        # Set bandwidth
        i = -2
        self.assertRaises(OpusError, lambda: encoder.ctl(enc, ctl.set_bandwidth, i))
        i = constants.BANDWIDTH_FULLBAND+1
        self.assertRaises(OpusError, lambda: encoder.ctl(enc, ctl.set_bandwidth, i))
        i = constants.BANDWIDTH_NARROWBAND
        encoder.ctl(enc, ctl.set_bandwidth, i)
        i = constants.BANDWIDTH_FULLBAND
        encoder.ctl(enc, ctl.set_bandwidth, i)
        i = constants.BANDWIDTH_WIDEBAND
        encoder.ctl(enc, ctl.set_bandwidth, i)
        i = constants.BANDWIDTH_MEDIUMBAND
        encoder.ctl(enc, ctl.set_bandwidth, i)

        # Get bandwidth
        i = -12345
        value = encoder.ctl(enc, ctl.get_bandwidth)
        self.assertIn(value, (constants.BANDWIDTH_FULLBAND, constants.BANDWIDTH_MEDIUMBAND, constants.BANDWIDTH_WIDEBAND,
            constants.BANDWIDTH_NARROWBAND, constants.AUTO))

        encoder.ctl(enc, ctl.set_bandwidth, constants.AUTO)

        encoder.destroy(enc)
Exemplo n.º 2
0
    def test_max_bandwidth(self):
        enc = encoder.create(48000, 2, constants.APPLICATION_AUDIO)

        i = -2
        self.assertRaises(OpusError, lambda: encoder.ctl(enc, ctl.set_max_bandwidth, i))
        i = constants.BANDWIDTH_FULLBAND + 1
        self.assertRaises(OpusError, lambda: encoder.ctl(enc, ctl.set_max_bandwidth, i))
        i = constants.BANDWIDTH_NARROWBAND
        encoder.ctl(enc, ctl.set_max_bandwidth, i)
        i = constants.BANDWIDTH_FULLBAND
        encoder.ctl(enc, ctl.set_max_bandwidth, i)
        i = constants.BANDWIDTH_WIDEBAND
        encoder.ctl(enc, ctl.set_max_bandwidth, i)
        i = constants.BANDWIDTH_MEDIUMBAND
        encoder.ctl(enc, ctl.set_max_bandwidth, i)

        i = -12345
        value = encoder.ctl(enc, ctl.get_max_bandwidth)
        self.assertIn(
            value,
            (
                constants.BANDWIDTH_FULLBAND,
                constants.BANDWIDTH_MEDIUMBAND,
                constants.BANDWIDTH_WIDEBAND,
                constants.BANDWIDTH_NARROWBAND,
                constants.AUTO,
            ),
        )

        encoder.destroy(enc)
Exemplo n.º 3
0
    def test_unimplemented(self):
        enc = encoder.create(48000, 2, constants.APPLICATION_AUDIO)
        try:
            encoder.ctl(enc, ctl.unimplemented)
        except OpusError as e:
            self.assertEqual(e.code, constants.UNIMPLEMENTED)

        encoder.destroy(enc)
Exemplo n.º 4
0
    def test_unimplemented(self):
        enc = encoder.create(48000, 2, constants.APPLICATION_AUDIO)
        try:
            encoder.ctl(enc, ctl.unimplemented)
        except OpusError as e:
            self.assertEqual(e.code, constants.UNIMPLEMENTED)

        encoder.destroy(enc)
Exemplo n.º 5
0
    def test_bitrate(self):
        enc = encoder.create(48000, 2, constants.APPLICATION_AUDIO)

        encoder.ctl(enc, ctl.set_bitrate, 1073741832)

        value = encoder.ctl(enc, ctl.get_bitrate)
        self.assertLess(value, 700000)
        self.assertGreater(value, 256000)

        encoder.destroy(enc)

        self.check_setget(ctl.set_bitrate, ctl.get_bitrate, (-12345, 0), (500, 256000))
Exemplo n.º 6
0
    def check_setget(self, set, get, bad, good):
        enc = encoder.create(48000, 2, constants.APPLICATION_AUDIO)

        for value in bad:
            self.assertRaises(OpusError, lambda: encoder.ctl(enc, set, value))

        for value in good:
            encoder.ctl(enc, set, value)
            result = encoder.ctl(enc, get)
            self.assertEqual(value, result)

        encoder.destroy(enc)
Exemplo n.º 7
0
    def test_bitrate(self):
        enc = encoder.create(48000, 2, constants.APPLICATION_AUDIO)

        encoder.ctl(enc, ctl.set_bitrate, 1073741832)

        value = encoder.ctl(enc, ctl.get_bitrate)
        self.assertLess(value, 700000)
        self.assertGreater(value, 256000)

        encoder.destroy(enc)

        self.check_setget(ctl.set_bitrate, ctl.get_bitrate, (-12345, 0), (500, 256000))
Exemplo n.º 8
0
    def check_setget(self, set, get, bad, good):
        enc = encoder.create(48000, 2, constants.APPLICATION_AUDIO)

        for value in bad:
            self.assertRaises(OpusError, lambda: encoder.ctl(enc, set, value))

        for value in good:
            encoder.ctl(enc, set, value)
            result = encoder.ctl(enc, get)
            self.assertEqual(value, result)

        encoder.destroy(enc)
Exemplo n.º 9
0
    def test_create(self):
        try:
            encoder.create(48000, 2, constants.AUTO)
        except OpusError as e:
            self.assertEqual(e.code, constants.BAD_ARG)

        enc = encoder.create(48000, 2, constants.APPLICATION_VOIP)
        encoder.destroy(enc)

        enc = encoder.create(48000, 2, constants.APPLICATION_RESTRICTED_LOWDELAY)
        i = encoder.ctl(enc, ctl.get_lookahead)
        # TODO: rewrite that code
        # if(err!=OPUS_OK || i<0 || i>32766)test_failed();
        encoder.destroy(enc)

        enc = encoder.create(48000, 2, constants.APPLICATION_AUDIO)
        i = encoder.ctl(enc, ctl.get_lookahead)
        # TODO: rewrite that code
        # err=opus_encoder_ctl(enc,OPUS_GET_LOOKAHEAD(&i));
        # if(err!=OPUS_OK || i<0 || i>32766)test_failed();
        encoder.destroy(enc)
Exemplo n.º 10
0
    def test_create(self):
        try:
            encoder.create(48000, 2, constants.AUTO)
        except OpusError as e:
            self.assertEqual(e.code, constants.BAD_ARG)

        enc = encoder.create(48000, 2, constants.APPLICATION_VOIP)
        encoder.destroy(enc)

        enc = encoder.create(48000, 2, constants.APPLICATION_RESTRICTED_LOWDELAY)
        i = encoder.ctl(enc, ctl.get_lookahead)
        # TODO: rewrite that code
        # if(err!=OPUS_OK || i<0 || i>32766)test_failed();
        encoder.destroy(enc)

        enc = encoder.create(48000, 2, constants.APPLICATION_AUDIO)
        i = encoder.ctl(enc, ctl.get_lookahead)
        # TODO: rewrite that code
        # err=opus_encoder_ctl(enc,OPUS_GET_LOOKAHEAD(&i));
        # if(err!=OPUS_OK || i<0 || i>32766)test_failed();
        encoder.destroy(enc)
Exemplo n.º 11
0
 def test_encode_float(self):
     enc = encoder.create(48000, 2, constants.APPLICATION_AUDIO)
     data = chr(0)*ctypes.sizeof(ctypes.c_float)*2*960
     encoder.encode_float(enc, data, 960, len(data))
     encoder.destroy(enc)
Exemplo n.º 12
0
 def __del__(self):
     if hasattr(self, '_state'):
         # Destroying state only if __init__ completed successfully
         encoder.destroy(self._state)
Exemplo n.º 13
0
 def test_encode_float(self):
     enc = encoder.create(48000, 2, constants.APPLICATION_AUDIO)
     data = chr(0) * ctypes.sizeof(ctypes.c_float) * 2 * 960
     encoder.encode_float(enc, data, 960, len(data))
     encoder.destroy(enc)