Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add nperiods property to Driver #113

Merged
merged 5 commits into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ server = jack_server.Server(
device="BuiltInSpeakerDevice",
rate=48000,
period=1024,
# nperiods=2 # Work only with `alsa` driver
)
server.start()

Expand Down Expand Up @@ -93,6 +94,12 @@ Sampling rate.

Buffer size.

#### `nperiods: int`

Number of periods. 2 is right for motherboard, PCI, PCI-X, etc.; 3 for USB ([source](https://wiki.archlinux.org/title/JACK_Audio_Connection_Kit)).

Can be helpful when tailoring performance on jittery systems.

#### `params: dict[str, jack_server.Parameter]`

Driver parameters mapped by name.
Expand Down
10 changes: 10 additions & 0 deletions src/jack_server/_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,15 @@ def period(self) -> int:
def period(self, __value: int) -> None:
self.params["period"].value = __value

@property
def nperiods(self) -> int: # pragma: no cover (works only with alsa driver)
return cast(int, self.params["nperiods"].value)

@nperiods.setter
def nperiods(
self, __value: int
) -> None: # pragma: no cover (works only with alsa driver)
self.params["nperiods"].value = __value

def __repr__(self) -> str:
return f"<jack_server.Driver name={self.name}>"
9 changes: 8 additions & 1 deletion src/jack_server/_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ def __init__(
device: str | SetByJack = SetByJack_,
rate: SampleRate | SetByJack = SetByJack_,
period: int | SetByJack = SetByJack_,
nperiods: int | SetByJack = SetByJack_,
) -> None:
self._created = False
self._opened = False
Expand All @@ -68,11 +69,17 @@ def __init__(
if not isinstance(realtime, SetByJack):
self.realtime = realtime
if not isinstance(device, SetByJack):
self.driver.device = device # pragma: no cover (can't set driver on dummy driver that used in CI)
self.driver.device = (
device # pragma: no cover (does not work with dummy driver)
)
if not isinstance(rate, SetByJack):
self.driver.rate = rate
if not isinstance(period, SetByJack):
self.driver.period = period
if not isinstance(
nperiods, SetByJack
): # pragma: no cover (works only with alsa driver)
self.driver.nperiods = nperiods

def _create(
self,
Expand Down