Make dither noise as a value between -0.5 and 0.5 and add this
to the scaled samples.
For this, we first need to do the scaling and then the CLAMP to
the target depth. This optimizes to the same code but allows us
to avoid under and overflows when we add the dither noise.
Add more dithering methods.
Expose a dither.method property on audioconvert. Disable dither when
the target depth > 16.
We need to do dithering and noise when converting f32 to the
target format. This is more natural because we can work in 32 bits
integers instead of floats.
This will also make it possible to actually calculate the error between
source and target values and implement some sort of feedback and
noise shaping later.
Move the noise setting in the dither struct so that it can be
handled separately.
Setup dither separately.
Set used cpu_flags in structures after setup.
The quantize is the amount of bits we want to keep from the original
signal, subtract the amount of bits for noise. Clamp this to 0 (all
noise).
Calculate the scale factor better with powf() and avoid overflows.
Fixes#2479
Rename empty.noise -> dither.noise and always add this amount of noise
when > 0. This also adds the noise to silent sounds, not only when
nothing is connected because that would also be a problem when an amp
needs to be kept alive with an non-0 signal.
Rename noise -> dither because we can use this also for dithering later.
See #705
PipeWire v0.3.7 or later hits assertion at alsa-lib mixer API due to
wrong handling of removal event for mixer element.
wireplumber: mixer.c:149: hctl_elem_event_handler: Assertion `bag_empty(bag)' failed.
The removal event is defined as '~0U', thus it's not distinguished from
the other type of event just by bitwise operator.
At the removal event, class implementator for mixer API should detach
mixer element from hcontrol element in callback handler since alsa-lib
has assertion to check the list of mixer elements for a hcontrol element
is empty or not after calling all of handlers. In detail, please refer to
MR to alsa-lib:
* https://github.com/alsa-project/alsa-lib/pull/244
This commit fixes the above two issues. The issue can be regenerated by
`samples/ctl` Python 3 script of alsa-gobject.
* https://github.com/alsa-project/alsa-gobject/
It adds some user-defined elements into sound card 0. When terminated by
SIGINT signal, it removes the elements. Then PulseAudio dies due to the
assertion.
Fixes: 1612f5e4d2 ("alsa-acp: Add libacp based card device")
Using `int` results in UndefinedBehaviorSanitizer errors
when `noise::intensity` is 31 as that would shift the 1 into
the sign bit of a signed integer type.
It is valid for V4L2 devices to not implement any controls. QUERYCTRL
returns ENOTTY in these cases. Enumerating the controls must not fail in
these cases but return no controls.
Add an empty.noise option that specifies the number of bits to
use for noise when the input signal is pure silence.
Some amplifiers can go into suspend mode pretty easily when they
get pure silence. With empty.noise = 1, audioconvert will now generate
a bitpattern that can keep those amplifiers alive, together with
disabling suspend in the session manager.
Fixes#705
Add an EMPTY chunk flag to mark a piece of memory as 'empty'. For audio
this means silence.
Use the empty flag to avoid mixing 0 samples.
Set the empty flag in output buffers on audioconvert.
this->monitor enabled adds an additional port in reconfigure_mode. If
there was already the maximum 64, this will crash.
Make maximum number of ports one larger than max channels to avoid
problems.
Use the NEAREST flag when setting a format. This only works for raw
formats and will update the format with the nearest accepted rate
or channels. We can then query the real configured format and use that
for the converter.
This makes things work when a driver tells us it can do 44100Hz but then
refuses and changes the rate to 48000.
See #2197, #2457, #2455, rhbz#2096193
When there is no input, mix up to a quantum of data. Otherwise we might
send too much data to the next node and cause a delay if it does not
handle this.
When we end up in a case where we are running 0 handles, such as when we
have a stereo filter but we want mono output, emit an error until we can
reasonably handle this case.
`client_update_quirks()` may modify `client::props` depending
on the "pulse.rules" section defined in the configuration file,
which means that it can change the value corresponding to the
"application.name" key. Therefore, `client::name` needs to
be queried after that.
`client::name` points to a string that is owned by `client::props`,
so when the property list is updated, it needs to be refreshed as well.
Otherwise, various use-after-frees can be triggered, for example:
==1471586==ERROR: AddressSanitizer: heap-use-after-free on address 0x60200007e7d0 at pc 0x7f14390755d0 bp 0x7ffe23edee30 sp 0x7ffe23ede5a8
READ of size 3 at 0x60200007e7d0 thread T0
#0 0x7f14390755cf in printf_common /usr/src/debug/gcc/libsanitizer/sanitizer_common/sanitizer_common_interceptors_format.inc:553
#1 0x7f1439077215 in __interceptor_vsnprintf /usr/src/debug/gcc/libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc:1665
#2 0x7f1434ead47d in spa_vscnprintf ../spa/include/spa/utils/string.h:239
#3 0x7f1434eae2ae in impl_log_logtv ../spa/plugins/support/logger.c:138
#4 0x7f14385cacc7 in pw_log_logt ../src/pipewire/log.c:135
#5 0x7f1433aef8e9 in do_set_profile ../src/modules/module-protocol-pulse/pulse-server.c:4656
#6 0x7f1433b0af4d in handle_packet ../src/modules/module-protocol-pulse/server.c:109
#7 0x7f1433b0e747 in do_read ../src/modules/module-protocol-pulse/server.c:276
#8 0x7f1433b0eb04 in on_client_data ../src/modules/module-protocol-pulse/server.c:306
#9 0x7f1434ec56a0 in source_io_func ../spa/plugins/support/loop.c:442
#10 0x7f1434ec4a21 in loop_iterate ../spa/plugins/support/loop.c:430
#11 0x7f14385dc23d in pw_main_loop_run ../src/pipewire/main-loop.c:148
#12 0x55b065d73722 in main ../src/daemon/pipewire.c:131
#13 0x7f143742928f (/usr/lib/libc.so.6+0x2928f)
#14 0x7f1437429349 in __libc_start_main (/usr/lib/libc.so.6+0x29349)
#15 0x55b065d722a4 in _start (./src/daemon/pipewire-pulse+0x42a4)
0x60200007e7d0 is located 0 bytes inside of 16-byte region [0x60200007e7d0,0x60200007e7e0)
freed by thread T0 here:
#0 0x7f14390be672 in __interceptor_free /usr/src/debug/gcc/libsanitizer/asan/asan_malloc_linux.cpp:52
#1 0x7f14386a775a in do_replace ../src/pipewire/properties.c:414
#2 0x7f14386a785e in pw_properties_set ../src/pipewire/properties.c:441
#3 0x7f14386a658b in pw_properties_update ../src/pipewire/properties.c:309
#4 0x7f1433adb055 in do_update_proplist ../src/modules/module-protocol-pulse/pulse-server.c:3246
#5 0x7f1433b0af4d in handle_packet ../src/modules/module-protocol-pulse/server.c:109
#6 0x7f1433b0e747 in do_read ../src/modules/module-protocol-pulse/server.c:276
#7 0x7f1433b0eb04 in on_client_data ../src/modules/module-protocol-pulse/server.c:306
#8 0x7f1434ec56a0 in source_io_func ../spa/plugins/support/loop.c:442
#9 0x7f1434ec4a21 in loop_iterate ../spa/plugins/support/loop.c:430
#10 0x7f14385dc23d in pw_main_loop_run ../src/pipewire/main-loop.c:148
#11 0x55b065d73722 in main ../src/daemon/pipewire.c:131
#12 0x7f143742928f (/usr/lib/libc.so.6+0x2928f)
previously allocated by thread T0 here:
#0 0x7f1439072faa in __interceptor_strdup /usr/src/debug/gcc/libsanitizer/asan/asan_interceptors.cpp:439
#1 0x7f14386a6fe2 in do_replace ../src/pipewire/properties.c:394
#2 0x7f14386a785e in pw_properties_set ../src/pipewire/properties.c:441
#3 0x7f1433a6c52d in read_props ../src/modules/module-protocol-pulse/message.c:147
#4 0x7f1433a6f467 in message_get ../src/modules/module-protocol-pulse/message.c:359
#5 0x7f1433ab3191 in do_set_client_name ../src/modules/module-protocol-pulse/pulse-server.c:1030
#6 0x7f1433b0af4d in handle_packet ../src/modules/module-protocol-pulse/server.c:109
#7 0x7f1433b0e747 in do_read ../src/modules/module-protocol-pulse/server.c:276
#8 0x7f1433b0eb04 in on_client_data ../src/modules/module-protocol-pulse/server.c:306
#9 0x7f1434ec56a0 in source_io_func ../spa/plugins/support/loop.c:442
#10 0x7f1434ec4a21 in loop_iterate ../spa/plugins/support/loop.c:430
#11 0x7f14385dc23d in pw_main_loop_run ../src/pipewire/main-loop.c:148
#12 0x55b065d73722 in main ../src/daemon/pipewire.c:131
#13 0x7f143742928f (/usr/lib/libc.so.6+0x2928f)