Skip to content
This repository has been archived by the owner on Dec 21, 2021. It is now read-only.

Commit

Permalink
updated synthplayer library to improve audio output device selection …
Browse files Browse the repository at this point in the history
…again

new release 5.3
  • Loading branch information
irmen committed Nov 27, 2018
1 parent 3ca66e0 commit c010bfe
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 19 deletions.
2 changes: 1 addition & 1 deletion bouldercaves/game.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from . import audio, synthsamples, tiles, objects, bdcff
from .synthplayer import sample

__version__ = "5.2"
__version__ = "5.3"


class BoulderWindow(tkinter.Tk):
Expand Down
2 changes: 1 addition & 1 deletion bouldercaves/synthplayer/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
__version__ = "1.4"
__version__ = "1.5"
__author__ = "Irmen de Jong"
34 changes: 17 additions & 17 deletions bouldercaves/synthplayer/playback.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ def initialize(self):
sounddevice.default.device["input"] = default_audio_device
default_input = sounddevice.default.device["input"]
default_output = sounddevice.default.device["output"]
if default_input != default_output or default_output == 0:
if default_input != default_output and default_audio_device < 0:
warnings.warn("Trying to determine suitable audio output device. If you don't hear sound, or see "
"errors related to audio output, you'll have to specify the correct device manually.",
category=ResourceWarning)
Expand All @@ -322,7 +322,7 @@ def find_default_output_device(self):
global sounddevice
devices = sounddevice.query_devices()
apis = sounddevice.query_hostapis()
best_device = -1
candidates = []
for did, d in reversed(list(enumerate(devices))):
if d["max_output_channels"] < 2:
continue
Expand All @@ -331,13 +331,13 @@ def find_default_output_device(self):
continue
dname = d["name"].lower()
if dname in ("sysdefault", "default", "front") or "built-in" in dname:
best_device = did
break
elif "generic" in dname or "speakers" in dname or "mme" in dname: # windows
best_device = did
if best_device >= 0:
warnings.warn("chosen output device: "+str(best_device), category=ResourceWarning)
return best_device
candidates.append(did)
elif "generic" in dname or "speakers" in dname or "mme" in dname:
candidates.append(did)
if candidates:
warnings.warn("chosen output device: "+str(candidates[-1]), category=ResourceWarning)
return candidates[-1]
return -1


class Sounddevice_Mix(AudioApi, SounddeviceUtils):
Expand Down Expand Up @@ -558,7 +558,7 @@ def initialize(self):
if default_audio_device < 0:
default_input = self.audio.get_default_input_device_info()
default_output = self.audio.get_default_output_device_info()
if default_input != default_output or default_output == 0:
if default_input != default_output and default_audio_device < 0:
warnings.warn("Trying to determine suitable audio output device. If you don't hear sound, or see "
"errors related to audio output, you'll have to specify the correct device manually.",
category=ResourceWarning)
Expand All @@ -577,7 +577,7 @@ def find_default_output_device(self):
apis = [self.audio.get_host_api_info_by_index(i) for i in range(num_apis)]
num_devices = self.audio.get_device_count()
devices = [self.audio.get_device_info_by_index(i) for i in range(num_devices)]
best_device = -1
candidates = []
for d in reversed(devices):
if d["maxOutputChannels"] < 2:
continue
Expand All @@ -586,13 +586,13 @@ def find_default_output_device(self):
continue
dname = d["name"].lower()
if dname in ("sysdefault", "default", "front") or "built-in" in dname:
best_device = d["index"]
break
candidates.append(d["index"])
elif "generic" in dname or "speakers" in dname or "mme" in dname: # windows
best_device = d["index"]
if best_device >= 0:
warnings.warn("chosen output device: "+str(best_device), category=ResourceWarning)
return best_device
candidates.append(d["index"])
if candidates:
warnings.warn("chosen output device: "+str(candidates[-1]), category=ResourceWarning)
return candidates[-1]
return -1


class PyAudio_Mix(AudioApi, PyAudioUtils):
Expand Down

0 comments on commit c010bfe

Please sign in to comment.