def test_SDL_GetAudioDeviceName(self): devices = {} # Reset audio subsystem SDL_Quit() SDL_Init(0) for index in range(audio.SDL_GetNumAudioDrivers()): # Get input/output device names for each audio driver drivername = audio.SDL_GetAudioDriver(index) os.environ["SDL_AUDIODRIVER"] = drivername.decode("utf-8") # Need to reinitialize subsystem for each driver SDL_InitSubSystem(SDL_INIT_AUDIO) driver = audio.SDL_GetCurrentAudioDriver() if driver is not None: driver = driver.decode("utf-8") devices[driver] = {'input': [], 'output': []} outnum = audio.SDL_GetNumAudioDevices(False) innum = audio.SDL_GetNumAudioDevices(True) for x in range(outnum): name = audio.SDL_GetAudioDeviceName(x, False) assert name is not None devices[driver]['output'].append(name.decode('utf-8')) for x in range(innum): name = audio.SDL_GetAudioDeviceName(x, True) assert name is not None devices[driver]['input'].append(name.decode('utf-8')) SDL_QuitSubSystem(SDL_INIT_AUDIO) print("Available audio drivers and devices:") for driver in devices.keys(): print(driver) print(" - input: {0}".format(str(devices[driver]['input']))) print(" - output: {0}".format(str(devices[driver]['output'])))
def test_SDL_GetNumAudioDevices(self): os.environ["SDL_AUDIODRIVER"] = "dummy" SDL_InitSubSystem(SDL_INIT_AUDIO) outnum = audio.SDL_GetNumAudioDevices(False) self.assertGreaterEqual(outnum, 1) innum = audio.SDL_GetNumAudioDevices(True) self.assertGreaterEqual(innum, 0) SDL_QuitSubSystem(SDL_INIT_AUDIO)
def test_SDL_GetNumAudioDevices(self): os.environ["SDL_AUDIODRIVER"] = "dummy" if SDL_InitSubSystem(SDL_INIT_AUDIO) != 0: self.skipTest('Audio subsystem not supported') outnum = audio.SDL_GetNumAudioDevices(False) self.assertGreaterEqual(outnum, 1) innum = audio.SDL_GetNumAudioDevices(True) self.assertGreaterEqual(innum, 0) SDL_QuitSubSystem(SDL_INIT_AUDIO)
def test_SDL_GetAudioDeviceName(self): os.environ["SDL_AUDIODRIVER"] = "dummy" SDL_InitSubSystem(SDL_INIT_AUDIO) outnum = audio.SDL_GetNumAudioDevices(False) for x in range(outnum): name = audio.SDL_GetAudioDeviceName(x, False) self.assertIsNotNone(name) innum = audio.SDL_GetNumAudioDevices(True) for x in range(innum): name = audio.SDL_GetAudioDeviceName(x, True) self.assertIsNotNone(name) # self.assertRaises(SDLError, audio.get_audio_device_name, -1) # self.assertRaises(SDLError, audio.get_audio_device_name, -1, True) SDL_QuitSubSystem(SDL_INIT_AUDIO)
def test_Mix_OpenAudioDevice(): SDL_Init(sdl2.SDL_INIT_AUDIO) sdlmixer.Mix_Init(0) # Get names of all audio output devices for current driver ndevices = audio.SDL_GetNumAudioDevices(0) devices = [audio.SDL_GetAudioDeviceName(i, 0) for i in range(0, ndevices)] # Open and close each avaliable output device fmt = sdlmixer.MIX_DEFAULT_FORMAT flags = audio.SDL_AUDIO_ALLOW_ANY_CHANGE for device in devices: ret = sdlmixer.Mix_OpenAudioDevice(22050, fmt, 2, 1024, device, flags) assert ret == 0 sdlmixer.Mix_CloseAudio() sdlmixer.Mix_Quit() SDL_Quit()
def test_SDL_OpenCloseAudioDevice(self): os.environ["SDL_AUDIODRIVER"] = "dummy" SDL_InitSubSystem(SDL_INIT_AUDIO) reqspec = audio.SDL_AudioSpec(44100, audio.AUDIO_U16SYS, 2, 8192, self.audiocallback, None) outnum = audio.SDL_GetNumAudioDevices(0) for x in range(outnum): spec = audio.SDL_AudioSpec() name = audio.SDL_GetAudioDeviceName(x, 0) self.assertIsNotNone(name) deviceid = audio.SDL_OpenAudioDevice(None, 0, reqspec, ctypes.byref(spec), 1) self.assertGreaterEqual(deviceid, 2) self.assertIsInstance(spec, audio.SDL_AudioSpec) self.assertEqual(spec.format, reqspec.format) self.assertEqual(spec.freq, reqspec.freq) self.assertEqual(spec.channels, reqspec.channels) audio.SDL_CloseAudioDevice(deviceid) SDL_QuitSubSystem(SDL_INIT_AUDIO)
def test_SDL_OpenCloseAudioDevice(self): #TODO: Add tests for callback fmt = audio.AUDIO_F32 if sys.platform == "darwin" else audio.AUDIO_U16SYS reqspec = audio.SDL_AudioSpec(44100, fmt, 2, 1024) outnum = audio.SDL_GetNumAudioDevices(0) for x in range(outnum): spec = audio.SDL_AudioSpec(0, 0, 0, 0) name = audio.SDL_GetAudioDeviceName(x, 0) assert name is not None deviceid = audio.SDL_OpenAudioDevice( name, 0, reqspec, ctypes.byref(spec), audio.SDL_AUDIO_ALLOW_ANY_CHANGE) err = SDL_GetError() assert deviceid >= 2 assert isinstance(spec, audio.SDL_AudioSpec) assert spec.format in audio.AUDIO_FORMATS assert spec.freq > 0 assert spec.channels > 0 assert spec.samples > 0 audio.SDL_CloseAudioDevice(deviceid)
def test_SDL_GetNumAudioDevices(self): outnum = audio.SDL_GetNumAudioDevices(False) assert outnum >= 1 innum = audio.SDL_GetNumAudioDevices(True) assert innum >= 0