configurable audio device
This commit is contained in:
parent
42abc269b2
commit
d9f06edb1e
3 changed files with 14 additions and 4 deletions
2
.vscode/launch.json
vendored
2
.vscode/launch.json
vendored
|
@ -11,7 +11,7 @@
|
|||
"program": "beamshow.py",
|
||||
"console": "integratedTerminal",
|
||||
"justMyCode": true,
|
||||
"args": ["-w","-b"]
|
||||
"args": ["-w","-b","-a","Notepad"]
|
||||
}
|
||||
]
|
||||
}
|
12
beamshow.py
12
beamshow.py
|
@ -21,6 +21,7 @@ def print_displays() -> None:
|
|||
class Beamshow:
|
||||
def __init__(
|
||||
self,
|
||||
audio_device_name: str,
|
||||
render3d: bool,
|
||||
window: bool,
|
||||
trails: bool,
|
||||
|
@ -45,7 +46,7 @@ class Beamshow:
|
|||
|
||||
pg.display.init()
|
||||
self.window, self.background = self.initialize()
|
||||
self.audio = AudioProcess()
|
||||
self.audio = AudioProcess(audio_device_name)
|
||||
|
||||
def initialize(self) -> Tuple[pg.Surface, pg.Surface]:
|
||||
recreate_effect = (
|
||||
|
@ -278,6 +279,14 @@ def app_main() -> None:
|
|||
argparser = ArgumentParser(
|
||||
description="beamshow - Render a light show for a video projector"
|
||||
)
|
||||
argparser.add_argument(
|
||||
"-a",
|
||||
"--audio",
|
||||
metavar="NAME",
|
||||
type=str,
|
||||
required=True,
|
||||
help="The audio device to use. Can be any substring",
|
||||
)
|
||||
argparser.add_argument(
|
||||
"--3d",
|
||||
dest="render3d",
|
||||
|
@ -323,6 +332,7 @@ def app_main() -> None:
|
|||
print_displays()
|
||||
|
||||
show = Beamshow(
|
||||
audio_device_name=args.audio,
|
||||
render3d=args.render3d,
|
||||
window=args.window,
|
||||
trails=args.trails,
|
||||
|
|
|
@ -17,13 +17,13 @@ def find_audio_device(p: pa.PyAudio, api: int, name: str) -> dict:
|
|||
|
||||
|
||||
class AudioProcess:
|
||||
def __init__(self):
|
||||
def __init__(self, device_name: str):
|
||||
self.pa = pa.PyAudio()
|
||||
|
||||
self.win_s = 1024
|
||||
self.hop_s = self.win_s // 2
|
||||
|
||||
i_dev = find_audio_device(self.pa, pa.paWASAPI, "Notepad")
|
||||
i_dev = find_audio_device(self.pa, pa.paWASAPI, device_name)
|
||||
self.rate = int(i_dev["defaultSampleRate"])
|
||||
self.a_source = self.pa.open(
|
||||
rate=self.rate,
|
||||
|
|
Loading…
Add table
Reference in a new issue