Esempio n. 1
0
    def test_create_destroy_context(self):
        device = alc.open_device()

        #self.assertRaises(TypeError, alc.create_context, None, None)
        #self.assertRaises(TypeError, alc.create_context, 1234, None)
        #self.assertRaises(TypeError, alc.create_context, "Test", None)
        #self.assertRaises(TypeError, alc.create_context, device, 1234)
        #self.assertRaises(TypeError, alc.create_context, device, "Test")

        ctx = alc.create_context(device)
        self.assertEqual(alc.get_error(device), alc.ALC_NO_ERROR)
        self.assertIsInstance(ctx, alc.ALCcontext)
        alc.destroy_context(ctx)
        self.assertEqual(alc.get_error(device), alc.ALC_NO_ERROR)

        ctx = alc.create_context(device, None)
        self.assertEqual(alc.get_error(device), alc.ALC_NO_ERROR)
        self.assertIsInstance(ctx, alc.ALCcontext)
        alc.destroy_context(ctx)
        self.assertEqual(alc.get_error(device), alc.ALC_NO_ERROR)

        ctx = alc.create_context(device, [alc.ALC_FREQUENCY, 11025])
        self.assertEqual(alc.get_error(device), alc.ALC_NO_ERROR)
        self.assertIsInstance(ctx, alc.ALCcontext)
        alc.destroy_context(ctx)
        self.assertEqual(alc.get_error(device), alc.ALC_NO_ERROR)

        self.assertTrue(alc.close_device(device))
Esempio n. 2
0
 def __init__(self, device=None):
     """Creates a new SoundSink for a specific audio output device."""
     super(SoundSink, self).__init__()
     self.componenttypes = (SoundSource, )
     if isinstance(device, alc.ALCdevice):
         self._hasopened = False
         self.device = device
     else:
         self.device = alc.open_device(device)
         self._hasopened = True
     self.context = alc.create_context(self.device)
     self.activate()
     self._sources = {}
     self._buffers = {}
Esempio n. 3
0
def run():
    if len (sys.argv) < 2:
        print ("Usage: %s wavefile" % os.path.basename(sys.argv[0]))
        print ("    Using an example wav file...")
        wavefp = wave.open(RESOURCES.get("hey.wav"))
    else:
        wavefp = wave.open(sys.argv[1], "rb")

    channels = wavefp.getnchannels()
    bitrate = wavefp.getsampwidth() * 8
    samplerate = wavefp.getframerate()
    wavbuf = wavefp.readframes(wavefp.getnframes())
    formatmap = {
        (1, 8) : al.AL_FORMAT_MONO8,
        (2, 8) : al.AL_FORMAT_STEREO8,
        (1, 16): al.AL_FORMAT_MONO16,
        (2, 16) : al.AL_FORMAT_STEREO16,
    }
    alformat = formatmap[(channels, bitrate)]

    device = alc.open_device()
    context = alc.create_context(device)
    alc.make_context_current(context)

    sources = al.gen_sources(1)

    al.source_f(sources[0], al.AL_PITCH, 1)
    al.source_f(sources[0], al.AL_GAIN, 1)
    al.source_3f(sources[0], al.AL_POSITION, 0, 0, 0)
    al.source_3f(sources[0], al.AL_VELOCITY, 0, 0, 0)

    buffers = al.gen_buffers(1)

    al.buffer_data(buffers[0], alformat, wavbuf, samplerate)
    al.source_queue_buffers(sources[0], buffers)
    al.source_play(sources[0])

    state = al.get_source_i(sources[0], al.AL_SOURCE_STATE)
    while state == al.AL_PLAYING:
        print("playing the file...")
        time.sleep(1)
        state = al.get_source_i(sources[0], al.AL_SOURCE_STATE)
    print("done")

    al.delete_sources(sources)
    al.delete_buffers(buffers)
    alc.destroy_context(context)
    alc.close_device(device)
Esempio n. 4
0
    def test_get_context_device(self):
        self.assertRaises((AttributeError, TypeError),
                          alc.get_context_device, None)
        self.assertRaises((AttributeError, TypeError),
                          alc.get_context_device, "Test")
        self.assertRaises((AttributeError, TypeError),
                          alc.get_context_device, None)

        device = alc.open_device()
        ctx = alc.create_context(device)
        dev = alc.get_context_device(ctx)
        self.assertIsInstance(dev, alc.ALCdevice)
        self.assertEqual(alc.get_error(device), alc.ALC_NO_ERROR)
        self.assertEqual(alc.get_error(dev), alc.ALC_NO_ERROR)
        alc.destroy_context(ctx)
        self.assertTrue(alc.close_device(device))
Esempio n. 5
0
    def test_make_context_current_get_current_context(self):
        self.assertRaises((AttributeError, TypeError),
                          alc.make_context_current, None)
        self.assertRaises((AttributeError, TypeError),
                          alc.make_context_current, "Test")
        self.assertRaises((AttributeError, TypeError),
                          alc.make_context_current, 1234)

        device = alc.open_device()
        self.assertIsNone(alc.get_current_context())

        ctx = alc.create_context(device)
        self.assertTrue(alc.make_context_current(ctx))
        cur = alc.get_current_context()
        self.assertIsInstance(cur, alc.ALCcontext)
        alc.destroy_context(ctx)
        self.assertFalse(alc.make_context_current(ctx))
        self.assertIsNone(alc.get_current_context())

        self.assertTrue(alc.close_device(device))
Esempio n. 6
0
    def test_open_close_device(self):
        dev = alc.open_device("invalid device name :-)")
        self.assertIsNone(dev)
        self.assertRaises((AttributeError, TypeError), alc.close_device, dev)
        self.assertRaises((AttributeError, TypeError), alc.close_device, "Test")
        self.assertRaises((AttributeError, TypeError), alc.close_device, 12345)

        dev = alc.open_device(None)
        errval = alc.get_error(dev)
        self.assertEqual(errval, alc.ALC_NO_ERROR)

        # Closing a device with an attached context should not work according
        # to the OpenAL specification.
        ctx = alc.create_context(dev)

        # The test below ideally should work, however the SI
        # implementation as well as openal-soft close the device without
        # caring about any context attached to it.
        # All contexts are implicitly destroyed.
        #
        # self.assertFalse(alc.close_device(self._device))

        alc.destroy_context(ctx)
        self.assertTrue(alc.close_device(dev))