Skip to content

Commit

Permalink
Merge branch 'hjespersen/set-nperiods'
Browse files Browse the repository at this point in the history
  • Loading branch information
vrslev committed Jan 31, 2024
2 parents b22dbb7 + 40d2466 commit 580c18f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
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

0 comments on commit 580c18f

Please sign in to comment.