Commit Graph

263 Commits

Author SHA1 Message Date
Matteo Bernardini
5eed8adfe5 ci: install ALSA headers 2025-12-01 23:26:37 +01:00
Matteo Bernardini
e3e51cc34d ci: install uv 2025-12-01 23:26:37 +01:00
Matteo Bernardini
f6f53ce92a ci: automatically build docs 2025-12-01 23:26:37 +01:00
Matteo Bernardini
38d0882379 chore: split dependency groups 2025-12-01 23:26:37 +01:00
Matteo Bernardini
6822cffcc8 ci: remove unsupported setting 2025-12-01 23:26:37 +01:00
Matteo Bernardini
8c1e370e04 ci: auto-detect package manager to use 2025-12-01 23:26:37 +01:00
Matteo Bernardini
6d17bc92b7 ci: use legacy license definition to allow building on py3.9 2025-12-01 23:26:37 +01:00
Matteo Bernardini
3e41a9eb97 ci: enforce setuptools version 2025-12-01 23:26:37 +01:00
Matteo Bernardini
df8886dde1 ci: ensure alsa headers are installed 2025-12-01 23:26:37 +01:00
Matteo Bernardini
aac2843f73 chore: stub workflow for automatic docs deployment 2025-12-01 23:26:37 +01:00
Matteo Bernardini
7987986ee4 chore: top-level makefile for common dev tasks 2025-12-01 23:26:37 +01:00
Matteo Bernardini
ae93ddc48e ci: workflow to automate releases on tags 2025-12-01 23:26:37 +01:00
Matteo Bernardini
a48389b750 chore: make pyright happy on tests 2025-12-01 23:26:37 +01:00
Matteo Bernardini
0b8db5f46d fix: PCM constructor stubs not coherent with runtime 2025-12-01 23:26:37 +01:00
Matteo Bernardini
6b2c4c22db fix(docs): add sphinx dep, fix version retrieval 2025-12-01 23:26:37 +01:00
Matteo Bernardini
a7896ee069 fix: stub consistency to runtime 2025-12-01 23:26:37 +01:00
Matteo Bernardini
ed83b3e29b chore(deps): add mypy (for stubtest utility) 2025-12-01 23:26:37 +01:00
Matteo Bernardini
e96f550862 fix: use Final for enum constants 2025-12-01 23:26:37 +01:00
Matteo Bernardini
40f4647d8c fix: missing self in type stubs 2025-12-01 23:26:37 +01:00
Matteo Bernardini
3a8c53851d chore(deps): add pyright for type-checking 2025-12-01 23:26:37 +01:00
Matteo Bernardini
f6770e3a42 fix: add ALSAAudioError to type stubs 2025-12-01 23:26:37 +01:00
Matteo Bernardini
0ac28e9eea fix: include doc/ and examples/ in sdist 2025-12-01 23:26:37 +01:00
Matteo Bernardini
fdc5f3782e chore: modernise packaging.
- use pyproject.toml to define project metadata and setuptools-specific configuration, removing the need for a setup.py file
- move sources in conventional src/ directory
- rework stubs so that they're visible downstream. PEP-561 doesn't support top-level .pyi files, so I made a dummy package instead `alsaaudio-stubs`
2025-12-01 23:26:37 +01:00
Matteo Bernardini
6efef83429 chore: move unit tests to conventional directory 2025-12-01 23:26:37 +01:00
Matteo Bernardini
df5c2f4685 chore: move examples to dedicated directory 2025-12-01 23:26:37 +01:00
Lars Immisch
0b3f1f41c7 Prepare 0.11.0
Bump version and update changelog.
0.11.0
2024-05-30 23:15:27 +02:00
Lars Immisch
3e360b1bb7 Update MANIFEST.in for type hints 2024-05-14 20:56:51 +01:00
Lars Immisch
44ccbf839d Fix sphinx warning 2024-05-07 19:07:47 +02:00
Lars Immisch
2c2e43d3d1 Add type hints & docs 2024-05-07 19:07:47 +02:00
Lars Immisch
a142b70033 Reorder for consistency between alsapcm_methods and code
getchannels/setchannels should be together IMO
2024-05-07 19:07:47 +02:00
Lars Immisch
26ba938e04 Make commands optional 2024-04-19 18:32:38 +01:00
Lars Immisch
f5e9d52c74 Add missing attribute 2024-04-19 13:10:39 +01:00
Ville Viinikka
436c31f9fd Add nominal_bits and physical_bits info
Adds the information discussed in pull request #144
2024-03-13 10:59:11 +01:00
Ville Viinikka
eda913b203 Use correct sample bit width
snd_pcm_hw_params_get_sbits gives the number of significant bits, not
the actual number of bits stored. Change to snd_pcm_format_physical_width.

This fixes a bug where, for example on my hardware:
format = 'S32_LE'
significant bits = 24
physical bits = 32

the program will segfault because the allocated buffer is too small.
2024-02-20 18:31:00 +01:00
Lars Immisch
0aba948277 Whitespace cleanup.
I ended up using Visual Studio Code and did a global regex replace
` +\n` -> `\n` (StackOverflow)
2024-02-20 18:08:09 +01:00
Oswald Buddenhagen
9b7b767594 fix docu typo 2024-02-06 00:39:15 +01:00
Oswald Buddenhagen
db87f2ced5 document new avail() and polldescriptors_revents() PCM functions
amends 43a94b3 and 5221311.
2024-02-06 00:39:15 +01:00
Oswald Buddenhagen
f179db2d9b de-duplicate PCM.info() documentation
... and move the dumpinfo() docu.

amends 4e098da - clearly, i'm blind.
2024-02-06 00:39:15 +01:00
Oswald Buddenhagen
420b538321 improve documentation of PCM c'tor and info() method
reformulate and redistribute the information, somewhat inspired by text
provided by Ronald van Elburg in response to issue #110.
2024-02-06 00:39:15 +01:00
Oswald Buddenhagen
ae5c4aad9b add xrun handling to the examples
it's very primitive, but it shows adequately what can happen and what to
do about it minimally (that is, complain and move on).
2024-02-06 00:39:15 +01:00
Oswald Buddenhagen
d23b26b2e5 isine example: fix stereo handling (#42)
while it's usually not actually necessary to generate a stereo signal
(alsa's default plughw device will happily duplicate it for us), we
still do it for demo purposes, just because.

a more realistic demo would actually use numpy, as that's what the
library will most likely be used with, but anyway.
2024-02-06 00:39:15 +01:00
Oswald Buddenhagen
1d63226e56 isine example: simplify calculations in generate()
i found them a tad hard to follow ...
2024-02-06 00:39:15 +01:00
Oswald Buddenhagen
664f81a777 isine example: simplify thread run loop
avoid code duplication.
2024-02-06 00:39:15 +01:00
Oswald Buddenhagen
eb51d11619 isine example: actually play some tones
the thread in the background actually needs time to do something
sensible. this is most easily achieved by simply sleeping in the
foreground thread.

i addition to the 440 Hz tone, also play 1 kHz, to demonstrate how
the change() function is used.
2024-02-06 00:39:15 +01:00
Oswald Buddenhagen
2f74e8e8a4 isine example: fix use of deprecated Thread.setDaemon() 2024-02-06 00:39:15 +01:00
Oswald Buddenhagen
6f52de9da0 isine example: remove questionable setting of period size
there is no need to be pedantic about the period size, especially with
a blocking device. what's more, attempting to set it on an already
playing device would error out, and it would be rather counter-
productive to temporarily stop it.
2024-02-06 00:39:15 +01:00
Oswald Buddenhagen
8fb33ddd49 improve write() underrun handling, take 2
we *really* should not paper over underruns, as they require attention.
however, the previous attempt (c2a6b6e) caused an exception to be thrown
(see #130), which was a bit excessive, and was consequently reverted
(438e52e).

so instead we make the handling consistent with what we do in read():
return the verbatim -EPIPE in this case. this can be simply ignored, and
the next write will resume the stream, so this is mostly backwards-
compatible (the failing write will be discarded and would need
repeating, but that will just cause a skip after the interruption,
which does not seem particularly relevant).

as a drive-by, again stop using snd_pcm_recover(), as it still just
obfuscates the snd_pcm_prepare() call it does in the end.
2024-02-05 23:01:30 +01:00
Oswald Buddenhagen
691c1d9b23 fix return value of PCM.write() on success (#137)
the `else` branch of the return value handling cascade got lost in
commit 438e52e, leading to us returning None on success.

rather than restoring the old code exactly, delay the construction
of the final return code object. this is more consistent with
alsapcm_read() and overall nicer.
2024-02-05 23:01:30 +01:00
Oswald Buddenhagen
061c297f4b remove stray snd_pcm_prepare() call from alsapcm_write()
this came from 438e52e, which tried to partially revert c2a6b6e, but
inserted a chunk that actually belonged to alsapcm_drop(). the latter
does not need to be restored, as we now handle SND_PCM_STATE_SETUP prior
to reading/writing.
2024-02-05 23:01:30 +01:00
Oswald Buddenhagen
8ff3e169cd unbreak read buffer overrun handling
my commit c2a6b6e broke it big time; we'd now just paper over overruns.
:}

the previous handling was fundamentally correct, needing only two
adjustments:
- to recover from drop()/drain(), we need to call snd_pcm_prepare() when
  the stream state is SND_PCM_STATE_SETUP. notably, we must not do this
  when the state is SND_PCM_STATE_XRUN.
- we should error-check the unlikely case that the recovery from an xrun
  fails.

that way we now have two snd_pcm_prepare() call sites in read(), which
looks a bit messy, but it's actually correct.

as a drive-by, simplify the return value check of snd_pcm_prepare() -
values higher than zero are impossible.
2024-02-05 23:01:30 +01:00