예제 #1
0
 def test_unimplemented(self):
     dec = decoder.create(48000, 2)
     try:
         decoder.ctl(dec, ctl.unimplemented)
     except OpusError as e:
         self.assertEqual(e.code, constants.UNIMPLEMENTED)
     decoder.destroy(dec)
예제 #2
0
 def test_unimplemented(self):
     dec = decoder.create(48000, 2)
     try:
         decoder.ctl(dec, ctl.unimplemented)
     except OpusError as e:
         self.assertEqual(e.code, constants.UNIMPLEMENTED)
     decoder.destroy(dec)
예제 #3
0
    def test_get_pitch(self):
        dec = decoder.create(48000, 2)

        i = decoder.ctl(dec, ctl.get_pitch)
        self.assertIn(i, (-1, 0))

        packet = chr(63 << 2) + chr(0) + chr(0)
        decoder.decode(dec, packet, 3, 960, False)
        i = decoder.ctl(dec, ctl.get_pitch)
        self.assertIn(i, (-1, 0))

        packet = chr(1) + chr(0) + chr(0)
        decoder.decode(dec, packet, 3, 960, False)
        i = decoder.ctl(dec, ctl.get_pitch)
        self.assertIn(i, (-1, 0))

        decoder.destroy(dec)
예제 #4
0
    def test_get_pitch(self):
        dec = decoder.create(48000, 2)

        i = decoder.ctl(dec, ctl.get_pitch)
        self.assertIn(i, (-1, 0))

        packet = chr(63<<2)+chr(0)+chr(0)
        decoder.decode(dec, packet, 3, 960, False)
        i = decoder.ctl(dec, ctl.get_pitch)
        self.assertIn(i, (-1, 0))

        packet = chr(1)+chr(0)+chr(0)
        decoder.decode(dec, packet, 3, 960, False)
        i = decoder.ctl(dec, ctl.get_pitch)
        self.assertIn(i, (-1, 0))

        decoder.destroy(dec)
예제 #5
0
class Decoder(object):

    def __init__(self, fs, channels):
        """
        Parameters:
            fs : sampling rate
            channels : number of channels
        """

        self._fs = fs
        self._channels = channels
        self._state = decoder.create(fs, channels)

    def __del__(self):
        if hasattr(self, '_state'):
            # Destroying state only if __init__ completed successfully
            decoder.destroy(self._state)

    def reset_state(self):
        """Resets the codec state to be equivalent to a freshly initialized state"""

        decoder.ctl(self._state, ctl.reset_state)

    def decode(self, data, frame_size, decode_fec=False):
        return decoder.decode(self._state, data, len(data), frame_size, decode_fec, channels=self._channels)

    def decode_float(self, data, frame_size, decode_fec=False):
        return decoder.decode_float(self._state, data, len(data), frame_size, decode_fec, channels=self._channels)

    # CTL interfaces

    _get_final_range = lambda self: decoder.ctl(self._state, ctl.get_final_range)

    final_range = property(_get_final_range)

    _get_bandwidth = lambda self: decoder.ctl(self._state, ctl.get_bandwidth)

    bandwidth = property(_get_bandwidth)

    _get_pitch = lambda self: decoder.ctl(self._state, ctl.get_pitch)

    pitch = property(_get_pitch)

    _get_lsb_depth = lambda self: decoder.ctl(self._state, ctl.get_lsb_depth)

    _set_lsb_depth = lambda self, x: decoder.ctl(self._state, ctl.set_lsb_depth, x)

    lsb_depth = property(_get_lsb_depth, _set_lsb_depth)

    _get_gain = lambda self: decoder.ctl(self._state, ctl.get_gain)

    _set_gain = lambda self, x: decoder.ctl(self._state, ctl.set_gain, x)

    gain = property(_get_gain, _set_gain)
예제 #6
0
    def test_gain(self):
        dec = decoder.create(48000, 2)

        i = decoder.ctl(dec, ctl.get_gain)
        self.assertEqual(i, 0)

        try:
            decoder.ctl(dec, ctl.set_gain, -32769)
        except OpusError as e:
            self.assertEqual(e.code, constants.BAD_ARG)

        try:
            decoder.ctl(dec, ctl.set_gain, 32768)
        except OpusError as e:
            self.assertEqual(e.code, constants.BAD_ARG)

        decoder.ctl(dec, ctl.set_gain, -15)
        i = decoder.ctl(dec, ctl.get_gain)
        self.assertEqual(i, -15)

        decoder.destroy(dec)
예제 #7
0
    def test_gain(self):
        dec = decoder.create(48000, 2)

        i = decoder.ctl(dec, ctl.get_gain)
        self.assertEqual(i, 0)

        try:
            decoder.ctl(dec, ctl.set_gain, -32769)
        except OpusError as e:
            self.assertEqual(e.code, constants.BAD_ARG)

        try:
            decoder.ctl(dec, ctl.set_gain, 32768)
        except OpusError as e:
            self.assertEqual(e.code, constants.BAD_ARG)

        decoder.ctl(dec, ctl.set_gain, -15)
        i = decoder.ctl(dec, ctl.get_gain)
        self.assertEqual(i, -15)

        decoder.destroy(dec)
예제 #8
0
    def reset_state(self):
        """Resets the codec state to be equivalent to a freshly initialized state"""

        decoder.ctl(self._state, ctl.reset_state)
예제 #9
0
 def test_get_bandwidth(self):
     dec = decoder.create(48000, 2)
     value = decoder.ctl(dec, ctl.get_bandwidth)
     self.assertEqual(value, 0)
     decoder.destroy(dec)
예제 #10
0
 def test_get_final_range(self):
     dec = decoder.create(48000, 2)
     decoder.ctl(dec, ctl.get_final_range)
     decoder.destroy(dec)
예제 #11
0
 def test_reset_state(self):
     dec = decoder.create(48000, 2)
     decoder.ctl(dec, ctl.reset_state)
     decoder.destroy(dec)
예제 #12
0
 def test_get_bandwidth(self):
     dec = decoder.create(48000, 2)
     value = decoder.ctl(dec, ctl.get_bandwidth)
     self.assertEqual(value, 0)
     decoder.destroy(dec)
예제 #13
0
 def test_get_final_range(self):
     dec = decoder.create(48000, 2)
     decoder.ctl(dec, ctl.get_final_range)
     decoder.destroy(dec)
예제 #14
0
 def test_reset_state(self):
     dec = decoder.create(48000, 2)
     decoder.ctl(dec, ctl.reset_state)
     decoder.destroy(dec)