Commit Graph

171 Commits

Author SHA1 Message Date
Lars Immisch
dc3d6c6183 Handle events in alsamixer_getvolume. Closes #126
This issue can be worked around by calling mixer.handleevents() before calling mixer.getvolume(), but it makes more sense to handle all events before returning the volume.
2023-05-12 02:43:51 +01:00
Oswald Buddenhagen
196ca87a05 assorted improvements (#123)
* fix draining/closing, take 2

commit 8abf06be introduced a pause() prior to draining, in an attempt
to work around clearly broken pulseaudio client behavior for capture
streams (drain() is supposed to imply a stop).

but as the workaround was also applied to playback streams, it would
cause nasty "clicks", as the stream would (obviously) stop before being
resumed for draining.

but draining is actually pointless for capture streams, as we're closing
right afterwards, so the samples are lost anyway.

what's more, destructors are not supposed to wait for anything, so
draining in alsapcm_dealloc() was wrong to start with. so we remove it.
note that this is a minor behavior change, which is reflected by the
adjustment of the playback test to have an explicit close() at the end.

finally, close() was also affected by the pulseaudio bug (which was not
addressed before), so there we make draining exclusive to playback
streams.

* fix memory leaks in *_polldescriptors()

the calloc'd pollfd arrays were not freed.

* fix memory handling in mixer access error paths

in case of error, alsamixer_new() would leak the object, while
alsamixer_list() might crash due to a null pointer.

as a drive-by, make alsamixer_gethandle() `static`.

* fix crashes when accessing already closed devices

PCM.htimestamp() gets the usual exception emission,
Mixer.close() gets a "double invocation" check like PCM.close() has.

* fix deprecation warning about PyEval_InitThreads()

PyEval_InitThreads is a no-op in since python 3.9.

* fix deprecation warning about PyUnicode_AsUnicode()

converting to ascii for the purpose of comparison is inefficient.

* remove redundant snd_pcm_hw_params_any() call

we just called it (and even error-checked it) a few lines above.

* add new high-speed samples rates

closes #89 (but alsa doesn't support 768khz yet).

* drop some pointless comments from the tex => sphinx conversion

amends 5c2a00655.

* remove bogus markup from the documentation

the poll objects are linked properly in a different way, and the
footnote appears outdated.

* unify line spacing in .rst files

one empty line, except for high-level sections, which get two.

while at it, trim whitespace on otherwise empty lines.

* formatting/language fixes in introduction document

* improve terminology document

mention xruns, and rework the definition of periods: concentrate on
relevant information, and remove the misinformation about period size
reduction being not that bad (pedantically, an application could run
somewhat asynchronously to the interrupts by using some timer, and
therefore actually save some of the overhead, but why would one use a
small period size in the first place then?).

also, language and formatting fixes.

* add missing and update incorrect/outdated documentation

for clarity, this includes docs which were previously omitted
(presumably) intentionally, but mark them as comments.

the getrec() and getmute() functions' docs are moved around, so they
appear in pairs with their set*() counterparts, like the *volume() ones
already did.

notably, this also fixes the docu of PCM_FORMAT_U8, which closes #104.

* add some best practices to the docu

addresses #110, among other things.

* purge pydoc from the source

it's been obsolete for a *long* time, and having it redundantly to the
rst sources is bad hygiene. it still contained some useful info, which
has been transplanted to the rst source in the previous commit.

* use data types closer to those of ALSA

this removes lots of casts around snd_pcm_hw_params_get_*() calls

we could go further with that to make the code clean if we enabled all
the warnings, but it doesn't seem worth the effort.

* reduce scope of GIL releases

it's pointless to enclose snd_pcm_close() and snd_pcm_pause(), as these
calls don't sleep.

* reshuffle XRUN recovery somewhat

perform it prior to invoking read()/write() if necessary, not right
after a failure event. this makes things more uniform and predictable.

we don't use snd_pcm_recover() any more, as we used it only for the
EPIPE case anyway, which boils down to snd_pcm_prepare() exactly.
handling ESTRPIPE as well might be desirable, but that's a separate
consideration.

* bump (minor) version

we're about to add new features.

* make period count configurable

the period count is just as important for playback latency as the period
size, so it makes no sense to have only one of them configurable.

as a drive-by, fix up the handling of periods in info() & dumpinfo().

* add PCM.drain()

for playback, this allows making sure that all written frames are
played, without using an external delay.

in principle, it's also usable for capture, but there isn't really a
practical reason to do so, as simply discarding excess captured frames
has no real cost.

* add PCM.state() and associated enum values

in principle, the state is already available from info(), but that's a
rather heavy function for something one might want to query often.

a practical use case might be checking whether a playback stream is done
draining, for example.
2023-04-15 21:45:32 +02:00
Ronald van Elburg
19c9ba3ed9 Fix issue #104 : Update description of PCM_FORMAT_U8: Unsigned 8 bit samples for each channel 2022-11-27 01:56:36 +01:00
Ronald van Elburg
b2f0466dd2 First version documentation PCM.info() method. (#119)
* First version documentation PCM.info() method.

* Add reference to documentation to docstring for PCM.info() method.

* Add extra fields to info dict:
  card_no                      *index of card*                   integer  (negative indicates device not associable with a card)
   device_no                    *index of PCM device*             integer
   subdevice_no                 *index of PCM subdevice*          integer
and update documentation accordingly.

Co-authored-by: Ronald van Elburg <Ronald@SoundAppraisal.eu>
2022-11-26 19:08:32 +01:00
Lars Immisch
6317d9addc Extend name on get_enum (#114) 2022-05-23 09:37:40 +02:00
Lars Immisch
2432089759 Allow longer device names. Closes #114 2022-05-22 22:43:55 +02:00
Lars Immisch
279760add5 Prepare release 0.9.2 0.9.2 2022-05-06 21:33:41 +02:00
Portia Stephens
59a712c486 alsamixer_getvolume: Fix incorrect parenthesis (#112)
* alsamixer_getvolume: Fix incorrect parenthesis

The pcmtypeobj check is overriding the pcmtype if the object is not NULL
or Py_None, making it impossible to get the playback volume. Fix the
paranthesis so that pcmtype is only overwritten when pcmtypeobj is not
set.

* Fix indentation format

Fix the indentation format to match the rest of the project.1

Co-authored-by: Portia <portia.stephens@biamp.com>
2022-05-06 21:28:36 +02:00
Lars Immisch
dfda54642d Prepare 0.9.1 0.9.1 2022-05-03 20:04:26 +01:00
Chris Diamand
3f6fb9844d Support decibel, percentage, and raw volumes in getvolume, setvolume, and getrange (#109)
* Use `pcmtype` keyword for range

Update methods that accept a `direction` argument (i.e.
capture/playback) to get this via positional _or_ keyword arguments.

Code using keyword arguments can be more robust; however the main reason
for this change is to prepare the way for an extra `units` argument to
many of these methods.

Update documentation to consistently use `pcmtype` instead of
a mixture of that and `direction`.

* Support units
2022-03-28 21:46:40 +02:00
Lars Immisch
4d9f6e5b50 Merge pull request #108 from st8ed/fix-polldescriptors
Fix polldescriptors() data types
2022-01-25 15:17:39 +01:00
Kirill Konstantinov
40a4a36b1d Fix polldescriptors() data types 2022-01-25 14:23:21 +03:00
Lars Immisch
38ea69bbaa Merge pull request #100 from soundappraisal/feature_timestamp_mode_and_type
Feature timestamp mode and type
2021-04-12 12:30:23 +02:00
Ronald van Elburg
c8f3916337 On phys_from_sound: Small memory management fixes and code simplification. And add documentation on new functionality. 2021-04-11 15:16:03 +02:00
Ronald van Elburg
f19af8eba0 Remove recordtestchanges. 2021-04-07 12:12:10 +02:00
Ronald van Elburg
b8980d992b Remove recordtestchanges. 2021-04-07 12:10:21 +02:00
Ronald van Elburg
ebd2b5359d Add function to set timestamp mode and type. Add a function to get the alsa version. 2021-04-07 11:59:16 +02:00
Ronald van Elburg
c5f22fd7e0 Second version enable timestamps 2021-04-06 22:48:17 +02:00
Ronald van Elburg
3c3f0af74a First version enable timestamps 2021-04-06 14:31:45 +02:00
Ronald van Elburg
17f3b440cc Show new functions in recordtest.py 2021-04-06 09:09:49 +02:00
Lars Immisch
b2a303121a Merge pull request #98 from soundappraisal/add_timestamp_function
Add timestamp_raw function
2021-04-04 16:27:26 +02:00
Ronald van Elburg
3168833b4e Merge remote-tracking branch 'upstream/master' into add_timestamp_function
# Conflicts:
#	alsaaudio.c
2021-04-02 22:54:18 +02:00
Lars Immisch
c74669850b Merge pull request #92 from soundappraisal/pcm_info_function
Add an PCM.info function: returns pcm properties as a dict
2021-04-02 20:57:15 +02:00
Ronald van Elburg
1a4c0541d7 Change name timestamp_raw fuinction to htimestamp to follow the convention used in the rest of the library: that's the current convention (prefix the name with alsapcm_ for PCM methods). 2021-04-02 13:42:51 +02:00
Ronald van Elburg
e6a6445375 Move creation of dictionary to a point after error handling, when it is relatively certain that the function will succeed.
(cherry picked from commit 1820716a4bc018bb903b95bcf5d7cf83a5ebda9c)
2021-04-02 13:24:55 +02:00
Ronald van Elburg
97f2abcb30 Remove debugging print statement.
(cherry picked from commit dcc43f3da7bf4d083cc6cab18ae464261fadc53f)
2021-04-02 13:24:55 +02:00
Ronald van Elburg
a53ffd0d4f Fix potential memory leaks on new info function.
(cherry picked from commit ade9dd5923edd65c1fcdf2298e8ad024daf66e2a)
2021-04-02 13:24:55 +02:00
Ronald van Elburg
da71e01f9c Remove unused code from timestamp_raw function. 2021-03-31 16:27:55 +02:00
Ronald van Elburg
f6736ec43a first version timestamp function
(cherry picked from commit 21d0527c7b91723b3bfc87ea889bd599dff12576)

# Conflicts:
#	alsaaudio.c
2020-11-02 19:32:34 +01:00
Ronald van Elburg
e48b294b84 PCM.info function: added format, mode and type fields. Also added a doc string describing the info function. 2020-10-28 22:01:04 +01:00
Lars Immisch
d037297632 Merge pull request #91 from soundappraisal/master
Fix #51: Only return valid part of the buffer in the read function
2020-10-27 12:47:36 +01:00
Ronald van Elburg
c8e7261e94 Add an PCM.info function returning the information now printed by dumpinfo as a dictionary. Removed double entry from dumpinfo. 2020-10-27 12:41:59 +01:00
Ronald van Elburg
5c481b4094 Fix #51: Only return valid part of the buffer in the read function; avoid unnecesssary work by only changing size when needed 2020-09-30 15:58:19 +02:00
Ronald van Elburg
1e3c7f3fd0 Fix #51: Only return valid part of the buffer in the read function 2020-09-30 15:11:10 +02:00
Lars Immisch
0ae60f80f3 Better pcm_type deduction in alsamixer_getvolume
Closes #87
2020-07-16 23:36:50 +02:00
Lars Immisch
4018ab4f6c Fix copypasta. 2020-07-16 23:36:12 +02:00
Lars Immisch
07f84a8e95 Move CHANGES to markdown, remove NOTES.md (doc/README.md replaces it) 2020-07-13 22:27:06 +02:00
Lars Immisch
d83e829de1 Formatting and fixed upload description. 2020-07-13 22:18:32 +02:00
Lars Immisch
62e5515341 Document the release process. 0.9.0 2020-07-13 22:00:44 +02:00
Lars Immisch
ed027a6141 More output for playwav 2020-07-13 20:42:25 +01:00
Lars Immisch
5302dc524d Cleanup warnings 2020-07-13 20:59:49 +02:00
Lars Immisch
b17b36be50 Better error messages in tests 2020-07-13 20:51:59 +02:00
Lars Immisch
08bdce9ed9 Tests for Depreciations 2020-07-13 20:20:28 +02:00
Lars Immisch
0224c8a308 Inline documentation (and .gitignore) 2020-07-10 00:54:24 +02:00
Lars Immisch
f07627543c Update documentation 2020-07-10 00:45:57 +02:00
Lars Immisch
df889b94ef Don't use setrate etc. in samples. 2020-07-09 21:22:06 +02:00
Lars Immisch
2a21bf6c42 Support all essential parameters in alsapcm_new. 2020-07-08 22:39:46 +02:00
Lars Immisch
8084297926 Merge pull request #83 from stalkerg/master
fix generate switch capabilities
2020-05-25 12:58:03 +02:00
stalkerg
8fbc04e18d fix generate switch capabilities 2020-05-21 17:21:40 +09:00
Lars Immisch
8ed9f924cd Attempt to fix #45 2020-04-23 21:36:29 +01:00