def test_get_pitch(self): decoder = Decoder(48000, 2) self.assertIn(decoder.pitch, (-1, 0)) packet = chr(63 << 2) + chr(0) + chr(0) decoder.decode(packet, frame_size=960) self.assertIn(decoder.pitch, (-1, 0)) packet = chr(1) + chr(0) + chr(0) decoder.decode(packet, frame_size=960) self.assertIn(decoder.pitch, (-1, 0))
def test_decode(self): decoder = Decoder(48000, 2) packet = chr((63 << 2) + 3) + chr(49) for j in range(2, 51): packet += chr(0) try: decoder.decode(packet, frame_size=960) except OpusError as e: self.assertEqual(e.code, constants.INVALID_PACKET) packet = chr(63 << 2) + chr(0) + chr(0) try: decoder.decode(packet, frame_size=60) except OpusError as e: self.assertEqual(e.code, constants.BUFFER_TOO_SMALL) try: decoder.decode(packet, frame_size=480) except OpusError as e: self.assertEqual(e.code, constants.BUFFER_TOO_SMALL) try: decoder.decode(packet, frame_size=960) except OpusError: self.fail("Decode failed")