Commit graph

3318 commits

Author SHA1 Message Date
Pauli Virtanen 8f0478a2ce bluez5: sco-source: deal with incomplete CVSD frames
Rarely BT adapter may send CVSD packets with incomplete frames.  Ignore
such packets, as it's not clear if they contain valid data at all.
2022-08-05 13:12:24 +00:00
Wim Taymans 54b499b1cf alsa: do the right log level checks
spa_log_level_enabled does not work when a custom log level has
been set. Use spa_log_level_topic_enabled instead.
2022-08-05 15:03:22 +02:00
Wim Taymans 73073eb33f alsa: redirect alsa output to log file
Make a custom snd_output object that redirects output to the log
file.
2022-08-05 14:01:37 +02:00
Wim Taymans 0dc5a08bfd alsa: debug hw_params 2022-08-05 13:00:44 +02:00
Wim Taymans a9ced45d4b acp: add debug for open and close
Debug open and close calls.
Make pa_alsa_close to close the device.
2022-08-05 12:31:28 +02:00
Wim Taymans 34c1c1614e alsa: add some more debug
See #2614
2022-08-04 14:25:24 +02:00
Wim Taymans 1118c35956 acp: handle some more mixer NULL cases
These are in pulseaudio handled with asserts.

Fixes #2612
2022-08-04 09:06:28 +02:00
Wim Taymans 6c5ec409bf audioconvert: Improve buffer params
Scale the default size of the buffer with the sample rate conversion
factor.
2022-08-03 17:21:48 +02:00
Wim Taymans 6144d037ce acp: handle NULL mixer_handle
It can be NULL for some UCM configs.

Fixes #2612
2022-08-03 12:34:13 +02:00
Wim Taymans e22e522ab8 alsa-pcm: limit the target to the buffer size
Don't try to wait for more samples than can fit in the ringbuffer.

See #2603
2022-08-03 12:22:38 +02:00
Wim Taymans a23d154952 audioconvert: always use DSP rate on DSP ports
Always use the DSP rate on DSP ports for format conversion, not the
previous used rate.

This avoids some resampler reconfiguration as it negotiates a non-passthrough
rate conversion and then switches to passthrough when the rate correction is
done to match the graph rate.

See #2614
2022-08-03 11:32:10 +02:00
Frédéric Danis e7f17e1523 bluez5: use lower case for UUIDs
BlueZ uses lower case version for the UUIDs in its DBus interface.
This will simplify future UUID tests.
2022-08-03 06:15:54 +00:00
Frédéric Danis 76adcfaabe bluez5: Add AAC decoder 2022-08-02 11:12:25 +02:00
Isa Mert Gurbuz f32017c874 bluez5: Disable hw-volume for Soundcore Motion B 2022-08-01 19:34:39 +00:00
Pauli Virtanen 3579857a64 bluez5: opus: tweak ABR
Count retry from last non-good interval.  Minimum retry interval 5sec.
2022-08-01 19:23:07 +00:00
Pauli Virtanen 5724d405d6 bluez5: opus: better default bitrates
Use smaller bitrate caps, as it's not necessary to use all bandwidth
available.
2022-08-01 19:23:07 +00:00
Barnabás Pőcze aab15433c8 spa: aec: rename first argument of methods in spa_audio_aec_methods
The first parameter is a pointer to the object implementing the aec
interface, the name `object` is better than `data`.
2022-07-23 08:58:18 +00:00
Barnabás Pőcze 44e7817702 spa: aec: mark aec method tables const 2022-07-23 08:58:18 +00:00
Barnabás Pőcze c2d357b5af spa: aec: null: remove unnecessary cast 2022-07-23 08:58:18 +00:00
Barnabás Pőcze e88df3a324 spa: aec: null: initialize variable when defined 2022-07-23 08:58:18 +00:00
Barnabás Pőcze 98c0092ee7 spa: aec: null: specify vtable version 2022-07-23 08:58:18 +00:00
Barnabás Pőcze c9cc2fe6dc spa: aec: mark handle factory objects static 2022-07-23 08:58:18 +00:00
Barnabás Pőcze a506ddd799 spa: aec: webrtc: use static_cast to cast from void * 2022-07-23 08:58:18 +00:00
Barnabás Pőcze 35c011b955 spa: aec: webrtc: simplify webrtc_get_spa_bool() 2022-07-23 08:58:18 +00:00
Huang-Huang Bao c5bce24f01
bluez5: correct type of arguments to a dbus function
The 3rd "value" arguments to dbus_message_iter_append_basic() should be the address of a basic-typed value.

Fixes #2591
2022-07-23 16:35:01 +08:00
Frédéric Danis 343ae88bbf bluez5: Simplify DBus append_basic_* helpers
String key is used in all calls to append_basic_variant_dict_entry() and
append_basic_array_variant_dict_entry().
2022-07-22 19:10:26 +00:00
Frédéric Danis e560468800 bluez5: Removed unused variables in meson.build 2022-07-22 18:46:35 +02:00
Wim Taymans b1b8b0985a audioconvert: fix rounding on arm neon
Add the neon functions to the test
2022-07-21 17:24:55 +02:00
Pauli Virtanen 67c41336db bluez5: fix minor issues / warnings
Make static analysis happier.
2022-07-21 07:12:22 +00:00
Wim Taymans 38b3d027ec audioconvert: remove S32_SCALE
We don't use it, we use S24_SCALE and then shift. Also adjust the
S32_MIN and S32_MAX values, based on S24 values.
2022-07-20 17:45:34 +02:00
Barnabás Pőcze 5cdf4d6c64 spa: libcamera: remove unnecessary cast 2022-07-20 10:48:24 +00:00
Barnabás Pőcze 8bccad3ade spa: libcamera: only add "api.libcamera.location" property when available 2022-07-20 10:48:24 +00:00
Barnabás Pőcze 4072f63ab6 spa: libcamera: make cameraLoc() return a static string
There is no compelling reason to use `std::string`.
2022-07-20 10:48:24 +00:00
Barnabás Pőcze 237174b7f2 spa: libcamera: mark two functions static
`cameraLoc()` and `cameraModel()` are only used in one
translation unit.
2022-07-20 10:48:24 +00:00
Barnabás Pőcze 89d5d51bb3 spa: libcamera: fix build error due to return type change
libcamera commit 1c4d4801850559d6f919eef5c2ffbaf7675dbc46
changed the return type of libcamera::ControlList::get()
to be std::optional<T>. Adapt the code to this change.

Fixes #2575
2022-07-20 10:48:24 +00:00
Wim Taymans 0bf7911b37 audioconvert: tweak resampler window some more
By: Kevin Yin

R->A calculation removed: it wasn't valid anyway. No behavior change.
Placed existing A in there directly.

cosh window -> strangely tweaked exp window: remove the discontinuity
at the border, which is wrong for a window function. If A changes in the
future, this window will be better. With the current A, you will not be
able to tell the difference on any graph. (Of course, it's not a cosh
window anymore.)

Fixes #2574
2022-07-20 10:18:47 +02:00
Wim Taymans 5a8af97a40 audioconvert: use SPA_CLAMPF to clamp floats
It generates better assembler.
2022-07-19 17:59:14 +02:00
Pauli Virtanen 434cc6a90b bluez5: add Opus as a (Pipewire-specific) A2DP vendor codec
Support Opus as A2DP vendor codec.

The specification for vendor A2DP codec is our Pipewire-specific one, so
it is compatible only with devices running Pipewire.
2022-07-19 13:44:56 +00:00
Pauli Virtanen bf52b2acff bluez5: add opus-a2dp-0.5 caps 2022-07-19 13:44:56 +00:00
Pauli Virtanen b6d237fa43 bluez5: add OPUS-A2DP specification 2022-07-19 13:44:56 +00:00
Pauli Virtanen 0dc8255057 bluez5: handle sink vs. source correctly in get_supported_codecs
Make a distinction between sink and source endpoints when determining
supported codecs.
2022-07-19 13:44:56 +00:00
Pauli Virtanen 889d507e9c bluez5: enable logging for codecs
Add codec->set_log for setting the logging object for each codec.

Bump codec API.
2022-07-19 13:44:56 +00:00
Pauli Virtanen d29aafd857 bluez5: enable A2DP duplex volume boost only if codec asks for it
Make A2DP volume boost conditional on a flag the codec sets.

Bump codec API version.
2022-07-19 13:44:56 +00:00
Pauli Virtanen 92b2b44954 bluez5: pass global setting dict to codec select_config / preference_cmp
The device is not know at SelectConfiguration time, so the settings
argument in select_config is currently unused. Pass on a global settings
dict instead, so that codec parameters can be configured.

Also add settings argument to caps_preference_cmp.

Bump codec API version.
2022-07-19 13:44:56 +00:00
Pauli Virtanen a8eb146d39 bluez5: tell the codec whether endpoint is sink or source
Add a flag A2DP_CODEC_FLAG_SINK to incidate a sink endpoint.

Also enum_config and caps_preference_cmp may need to know whether the
codec is being configured for SRC or SNK. Also add the flags argument to
init_props.

Bump codec API version.
2022-07-19 13:44:56 +00:00
Pauli Virtanen 8d66b2b2f7 bluez5: a2dp-source: more duplex codec workarounds
a2dp-sink writing duplex data to the BT socket breaks a2dp-source source
polling, also in A2DP source role. Hence, use the timer-based polling
workaround always in duplex mode.
2022-07-19 13:44:56 +00:00
Pauli Virtanen f593a44069 bluez5: a2dp-sink: support duplex codec
Allow running a2dp-sink using the duplex codec, when the local endpoint
is the A2DP sink.
2022-07-19 13:44:56 +00:00
Wim Taymans aaa015d0c0 avb: fix compilation on big endian 2022-07-19 13:06:52 +02:00
Wim Taymans 3c87541219 Revert "mixer-dsp: mix a quantum of data at a time"
This reverts commit ecc0eecf0f.

The io-position is not actually set or updated on the mixer node so it
might use the wrong values.

Fixes #2525
2022-07-18 21:34:57 +02:00
Pauli Virtanen d82cd959e7 audioconvert: add different channel remap testcase 2022-07-18 20:33:05 +02:00
Pauli Virtanen 977d6e2321 audioconvert: fix input remapping
As currently implemented, input format convert channel remap is no-op.
This is because although the out_datas array is permuted, the original
pointer array is not referred to later on, so the only effect is that
the temporary data array is stored in permuted order.

Fix the permutation by permuting the pointers only for the conversion
step.
2022-07-18 20:31:46 +02:00
Wim Taymans 4eb81b13ac audioconvert: add test
Add test for F32_7p1_remapped to F32P_7p1_remapped

See #1324
2022-07-18 18:55:30 +02:00
Wim Taymans 67754ad3bc meson: remove sse_args from plain c build 2022-07-18 13:00:12 +02:00
Wim Taymans ada39f3048 audioconvert: improve noise bits
Make a new noise method called PATTERN and use it to add a slow (every
1024 samples) repeating pattern of -1, 0.
Only use this method when we don't already use triangular dither.

See #2540
2022-07-18 11:41:57 +02:00
Wim Taymans 57f63feb92 audioconvert: Fix Wannamaker name 2022-07-18 10:22:21 +02:00
Wim Taymans 9dbd016f9d audioconvert: fix compilation warnings 2022-07-17 13:15:00 +02:00
Wim Taymans a4db745a7e audioconvert: improve noise shaping
Reorganize things a little so we can add more noise shapers.
Add sloped triangular noise.
Add wanamaker3 noise shaping.
2022-07-15 12:36:15 +02:00
Wim Taymans a458b39774 tests: add test for rounding 2022-07-14 10:48:37 +02:00
Wim Taymans 419517fd55 audioconvert: build C versions with -Ofast and -ffast-math
Move resampler implementations to a -c version.
Compile some of the functions with other flags to make them more
optimized.
2022-07-14 10:07:07 +02:00
Wim Taymans 0ba3e7c5db audioconvert: round instead of truncate, to reduce distortion
See #2543
2022-07-13 20:56:13 +02:00
Wim Taymans d18428f8bb audiconvert: make macros for conversions
Make a common macro for float to int and int to float so that we can
change the algorithms easily.
2022-07-13 18:10:25 +02:00
Wim Taymans 4062077472 avb: remove wrong cargs
Fix a typo
2022-07-13 13:14:07 +02:00
Wim Taymans e82145aeae spa-resample: don't flush too much
Also clamp the amount of input samples we push when flushing. do several
rounds of zero pushing until we have flushed enough.
Handle the cases where no input is needed or no output is generated.

Fixes crashes when downsampling from 96000 to 1000 Hz or so.
2022-07-13 12:02:12 +02:00
Fabian Vogt ed88cad583 spa/alsa-udev: Check accessibility of pcm devices as well
The order of attribute changes is random, so it's possible that controlCX is
accessible before the other devices, which marks the device as available but it
actually fails to open. Only consider the device accessible if both control and
PCM devices can be accessed.

This requires reacting to ATTRIB changes of pcm devices as well now.

Fixes #2534
2022-07-13 09:17:08 +00:00
Wim Taymans 52281b9a7e alsa: check the offset against the size of the buffer
We need to check the last offset against the size of the buffer, not the
remaining size in the buffer.

When the writing is split, this could cause the buffer to be reused
wrongly.

See #2536
2022-07-13 09:37:01 +02:00
Wim Taymans 11bc60a53d spa-resample: handle init errors 2022-07-12 17:39:58 +02:00
Wim Taymans ce9a912f1a audioconvert: set scale to cutoff when upsampling 2022-07-12 17:39:14 +02:00
Pauli Virtanen d6a7db8020 bluez5: mark HFP/HSP streams with media.role=Communication 2022-07-12 14:04:31 +00:00
Pauli Virtanen 6e37110efd bluez5: adjust source rate control
Use different filter function than spa_dll for the rate control.
Also use a longer window for spike determination.
2022-07-12 13:55:54 +00:00
Wim Taymans ee84f96915 audioconvert: tweak the resampler a bit 2022-07-12 14:35:23 +02:00
Wim Taymans f043922b24 avb: implement maap
Implement the maap state machine.
Use maap for the destination address of talker streams.
2022-07-12 12:27:22 +02:00
Wim Taymans 9f25adc0f6 avb: use spa dll 2022-07-12 12:27:22 +02:00
Wim Taymans af4875eb47 avb: remove libavtp dependency 2022-07-12 12:27:21 +02:00
Wim Taymans c79fddf007 avb: handle xruns better
Don't stop early, fill gaps with silence.
2022-07-12 12:27:21 +02:00
Wim Taymans 87053365ea avb: handle sink follower
We need to flush out the packets when we are a follower and when we get
data because our timer is not running as a sink.
2022-07-12 12:27:21 +02:00
Wim Taymans 4d6c71bf12 avb: use iovec to read from ringbuffer 2022-07-12 12:27:21 +02:00
Wim Taymans 5c3629a165 avb: add follower mode
As a follower we disable our own timer and produce a buffer from what we
have when _process is called.
2022-07-12 12:27:21 +02:00
Wim Taymans ff5201ef3d avb: check seq
Avoid infinite loops.
Check sequence number and warn
Use 32 frames per pdu in example.
2022-07-12 12:27:21 +02:00
Wim Taymans 200f591a3d avb: add source 2022-07-12 12:27:21 +02:00
Wim Taymans 552a0056b5 avb: more work
Handle properties.
Fix format negotiation.
Wait in underrun.
2022-07-12 12:27:21 +02:00
Wim Taymans 537a38355a avb: more work 2022-07-12 12:27:21 +02:00
Wim Taymans f95b8263e6 avb: more improvements 2022-07-12 12:27:21 +02:00
Wim Taymans 1adc94df11 start of AVB support 2022-07-12 12:27:21 +02:00
Wim Taymans 6a8fd7024e audioconvert: add and use AVX2 clamp macros 2022-07-12 10:45:41 +02:00
Wim Taymans 7745346292 audioconvert: add sse2 s16 dither functions 2022-07-12 10:34:13 +02:00
Wim Taymans c31928c5f0 audioconvert: add and use CLAMP macros 2022-07-12 10:33:37 +02:00
Wim Taymans c35006f040 audioconvert: move scaling to setup 2022-07-11 17:50:20 +02:00
Wim Taymans 68f883ff77 audioconvert: fix dither scale
Rectangular dither should be [-0.5, 0.5]
Triangular dither should be [-1.0, 1.0]
Noise should add extra bits.
2022-07-11 17:19:28 +02:00
Wim Taymans e313149f7f audioconvert: improve SSE2 dither generation 2022-07-11 16:41:12 +02:00
Wim Taymans 277addcca6 audioconvert: add triangular dither 2022-07-11 16:28:51 +02:00
Wim Taymans 9a5a71dda9 tests: add test for noise 2022-07-11 15:49:44 +02:00
Wim Taymans 03f918bf15 udev: prefix vendor.id and product.id with 0x
They are hex strings so prefix them with 0x to make sure they get
handled like that in properties.

Fixes #2527
2022-07-11 11:55:42 +02:00
Wim Taymans cbbc4baa3f json: avoid converting random string to floats
Only allow the json float characters when converting to float.
This avoids NAN, INF, 0xffe4 etc to be seen as a json float.
2022-07-11 11:50:58 +02:00
Wim Taymans bdfde2fdf0 Revert "spa: leave vendor.id and product.id in hex"
This reverts commit 0d33760b71.
2022-07-11 11:23:08 +02:00
Wim Taymans dd1d5960b4 audioconvert: implement f64s
Add swapping functions for f64s.
Fix the awkward interleave/deinterleave names for 32s.
2022-07-11 10:58:51 +02:00
Wim Taymans bc1789c3ea Revert "acp: sync with pulseaudio"
This reverts commit 57f0fdf746.

This seems to cause problems and needs to mature a bit more in
pulseaudio it seems.
2022-07-11 10:03:01 +02:00
Wim Taymans 8fe83e5304 audiomixer: optimize avx mixer some more
Add avx mixer to test and benchmark
Rework and unroll the avx mixer some more.
The SSE one is 10 times faster than the C one, The AVX is 20 times
faster. The SSE2 function is 5 times faster than the C one.
2022-07-10 23:13:24 +02:00
Wim Taymans 7a0445cb28 audiomixer: improve sse and sse2 mixer
Add mixer benchmark.
Improve sse and sse2 mixer function by removin some read/write to the
temporary buffer at the expense of more scattered reads.
2022-07-10 21:15:34 +02:00
Wim Taymans 5fbda82cc3 spa: tweak SPA_MIN and SPA_MAX
This generates much better assembler because it can use a cmov in
more cases.
2022-07-09 20:35:47 +02:00
Pauli Virtanen fe7c6bcef9 bluez5: volume changes from headset should be saved
User changing volume via headset buttons should be treated on the same
level as changing from desktop UI.  Also initial headset volume should
be considered saved (even though session managers currently ignore the
initial route values on route restore).

Mark route as saved on volume events.
2022-07-09 18:19:45 +00:00
Pauli Virtanen 77959a2c1c bluez5: get initial node volume from transport
When emitting node, get initial volumes from transport hardware volume,
if available.

The session manager usually overrides these immediately with saved
values, but it's better to show the HW volume when the node first
appears.
2022-07-09 18:19:45 +00:00
Pauli Virtanen d82b3d6479 bluez5: backend-native: set HFP/HSP volume when connecting
The HFP/HSP HW volume on the device is not necessarily what we think it
is.

Sync the device volume to our value at connect time.
2022-07-09 18:19:45 +00:00
Pauli Virtanen 276c4bc554 bluez5: use separate routes for HFP and A2DP
The A2DP and HFP profiles may have different volume curves, so trying to
convert volumes between the two can produce undesirable volume spikes.
For example, when one of them is using hardware volume and the other
software.

Fix by separating HFP and A2DP routes.
2022-07-09 18:19:45 +00:00
Wim Taymans bb2f054d43 tests: add missing file 2022-07-09 20:16:15 +02:00
Wim Taymans abd6806d71 tests: add sse and sse2 versions to tests 2022-07-09 20:11:46 +02:00
Wim Taymans 371b5a1836 audiomixer: rewrite the mixer functions
Let the mixer functions accumulate the intermediate results into a
larger size variable and then clamp to the final precission. This avoids
distortions because of intermediate clamping.

Although the access pattern of the reads are no longer sequential, the
writes are sequential and we don't need to read intermediate values.
Together with the avoided clamping this is probably faster overall.

Add a unit test for the various cases.
2022-07-09 18:11:13 +02:00
Wim Taymans 3ffb9f4b26 audioconvert: improve s24_32 and u24_32 conversion
We should ignore the upper 8 bits, so first shift them out and then
use the s32/u32 conversion functions.
Add a test for this.
2022-07-09 18:07:49 +02:00
Wim Taymans 20172bfbe6 spa: add comment about prefetch 2022-07-08 17:02:46 +02:00
Lucas Holt 4c3f5a7655 When adding MidnightBSD support, I inversed the condition here. 2022-07-08 12:25:58 +02:00
Wim Taymans a1fac201e3 audioconvert: don't use uninitialized max_out
Move the calculation of the expected max output size before collecting
the buffers and doing the monitor ports so that we can get the size
correct.
2022-07-08 11:31:22 +02:00
Wim Taymans e53eefef0d stream: implement prefetch
When the audioconverter needs more data, let it return NEED_DATA. This
can happen before the ports actually have consumed all the input data.
For example, then the next cycle would require 1024 samples but there
are currently only 16 samples queued, the next cycle will consume the
16 samples and then need another buffer to produce output.

For rt streams, this is not a problem because a new buffer will be
fetched in the next cycle synchronously.

When the stream is async, we can use this NEED_DATA to prefetch a
new buffer so that we have one in the next cycle.

This fixes hickups with async streams that provide random sized
buffers.
2022-07-08 10:48:29 +02:00
Wim Taymans 9714ce83d4 audioconvert: only consume what is needed
Move the setup of the output buffers first.
Then figure out how many samples we need to produce and consume.
Make sure we use the resampler to only convert the input samples that
are needed to produce the output samples.

Fixes some muddled sound with mpv when upmixing.
2022-07-08 10:45:44 +02:00
Wim Taymans 7b01068837 audioconvert: consume right amount of input samples
When we are not using the resampler, we consume the same amount of
input samples as output samples.

Fixes #2519
2022-07-08 09:23:31 +02:00
Wim Taymans df40c9bf6a fmt-ops: express 32 bits formats in terms of 32_24 bits formats 2022-07-07 20:11:08 +02:00
Wim Taymans 0343e0da73 fmt-ops: fix some missing shifts and min/max 2022-07-07 18:57:03 +02:00
Wim Taymans b8a4bf880f audioconvert: use 24 bits for 32 formats
The float only preserves 24 bits so use this. Otherwise we get overflows
and errors in clang.
2022-07-07 18:38:32 +02:00
Wim Taymans f9660f5e8f audiomixer: clean up mixer functions
Use the same limits as the format converter.
Use a struct for 24bits.
Use macros to generate the mixers.
2022-07-07 13:12:50 +02:00
Wim Taymans 4a82cb74e8 resample: switch to cosh window function 2022-07-07 12:26:45 +02:00
Wim Taymans 57f0fdf746 acp: sync with pulseaudio 2022-07-07 12:23:28 +02:00
Wim Taymans 273c95d71b resample: tweak cosh parameter, this look really good 2022-07-07 10:18:52 +02:00
Wim Taymans 74bed47a56 audioconvert: don't leak converter data 2022-07-06 21:06:55 +02:00
Wim Taymans 08d918432f tests: add more audioconvert remap test
Add tests for all permutations of input/output remappings.
2022-07-06 20:57:04 +02:00
Wim Taymans 4036b8a3f0 tests: add audioconvert test
Add a little test framework for writing end-to-end audioconvert tests.
2022-07-06 19:20:16 +02:00
Pauli Virtanen df2c5d6a14 alsa: fix uninitialized variable 2022-07-06 14:36:22 +00:00
Pauli Virtanen 783fbc507b bluez5: fix minor error handling/warning issues 2022-07-06 14:36:22 +00:00
Wim Taymans 84d2b2ce3a audioconvert: optimize remapping paths
Remove the redundant remap array.
First set up the array with remapped output pointers in case we
can do passthrough output. Make sure stages write to the remapped
array in passthrough.
Remap the input array after unpack/convert.
This avoid an input and output memcpy in the common case of
remapping.
2022-07-06 15:20:13 +02:00
Wim Taymans 0b351aab99 audioconvert: use blackman window again
I'm not convinced the cosh window is better and it causes some weird
nan numbers in some cases.

See #2483
2022-07-06 09:57:52 +02:00
Wim Taymans 76350cebef audioconvert: fix PROP_INFO
The description needs to be set. The name is the unique name of the
property and the id the predefined property id.

Fixes #2488
2022-07-05 20:41:01 +02:00
Carlos Rafael Giani 7e44909741 alsa: add lower rate bound for DSD playback
This prevents errors when trying to play at a rate
that's lower than DSD64 (the lowest rate available).
2022-07-05 16:56:50 +00:00
Wim Taymans 651f4af0ae audioadapter: ask more data when converter empty
When we are actively driving the stream and the converter needs more
data, call the stream process function again to get it so that we
don't underrun.

Fixes #2494
2022-07-05 17:54:44 +02:00
Wim Taymans 987784b629 tests: add test for s24/u24 swap 2022-07-05 16:34:22 +02:00
Pauli Virtanen e1cb7c6fb2 bluez5: sco-source: implement sco-source the same way as a2dp-source 2022-07-05 14:21:04 +00:00
Pauli Virtanen 51356ea3d0 bluez5: a2dp-source: separate clock from recv + handle buffering
a2dp-source as driver does not produce regularly spaced graph cycles,
because A2DP is not isochronous. This causes e.g. crackling for alsa
etc. that expect regular timings. It also does not rate match.

Change a2dp-source to trigger graph on regular intervals. Change recv to
only accumulate data to a buffer, and put data to buffers in process().

Rate match with DLL, keeping average buffer level constant.  Keep track
of jitter to determine a safe target value.
2022-07-05 14:21:04 +00:00
Pauli Virtanen 459a1114f1 bluez5: sco-io: we should always read from socket
Not reading from the socket appears to cause messages to pile up to some
limit, which causes problems if we start the source after some point.
2022-07-05 14:21:04 +00:00
Pauli Virtanen 02bdfcb115 bluez5: ad2p-sink: adjust debug log message
timeout -> timer, since "timeout" looks like error to users
2022-07-05 14:21:04 +00:00
Frédéric Danis 036bb13474 audioconvert: Fix s24/u24 byte swapping 2022-07-05 14:06:31 +00:00
Wim Taymans c4cc13c094 audioconvert: use right scale value
Disable assert, it seems to fail on clang.
2022-07-05 16:02:24 +02:00
Wim Taymans f62244d7a9 audioconvert: tweak more conversion constants
Tweak some more constants to make lossless conversions work.
Add some tests for lossless conversion.
Add some more tests.
2022-07-05 15:50:05 +02:00
Wim Taymans 22317da685 audioconvert: tweak conversion constants
Tweak the conversion constants a bit so that they handle the
extreme ranges a bit better.
Align the C and vector instructions.
Reactivate the unit test asserts when a conversion fails.
2022-07-05 12:20:02 +02:00
Wim Taymans e3951cc1f1 audioconvert: fix pack/unpack of s24/u24
Copy the values into the right place in the struct.
2022-07-05 12:18:57 +02:00
Wim Taymans 12bee0edf8 audioconvert: fix channel remapping
Do the channel remapping to the cannonical format when we
deinterleave/interleave instead. Otherwise we would completely skip
the remapping when we have interleaved input.

Fixes #2502, #2490
2022-07-04 17:38:20 +02:00
Wim Taymans ffedc2d1e8 null-sink: add option to debug memory 2022-07-04 13:38:07 +02:00
Wim Taymans 67f648cc66 audioconvert: handle NAN from window function
The window function can generate NAN, convert those to 0.0.

Fixes #2491
2022-07-03 20:37:48 +02:00
Wim Taymans a2521bb3e0 audioconvert: fix draining
When we get something else that a drain status as input, bring us back
to the non-drained state.

When we are draining, don't remove the drained flag on the input
io status. This needs to be cleared by the host when the draining is
finished.

Fixes speaker-test
2022-07-01 21:49:13 +02:00
Wim Taymans 9af9450888 audioconvert: ensure temp buffers are large enough
Ensure that our temporary buffers can hold at least quantum_limit
samples. When no output or input is connected, we can generate up
to a quantum_limit of silence, which requires all the buffers to
be scaled correctly.

Fixes a segfault in mpv.
2022-07-01 15:25:37 +02:00
Wim Taymans e0b3e06bea audioconvert: remove unused field 2022-07-01 12:40:19 +02:00
Wim Taymans 817d5bd7a4 audioconvert: simplify 24 bits handling
Make a new uint42_t and int24_t type and use that to handle 24 bits
samples. This makes it easier because we can iterate and copy the
structs like other types.
2022-07-01 12:25:58 +02:00
Wim Taymans 06b1cf8663 audioconvert: implement (de)interleave with existing functions 2022-06-30 18:24:05 +02:00
Wim Taymans afd8e8823e audioconvert: use macros to generate code
Most of the outer loops are all the same.
2022-06-30 17:49:44 +02:00
Wim Taymans 0d33760b71 spa: leave vendor.id and product.id in hex
There is no reason to store this as anything other than the original
hex string. Especially for compatibility with pulseaudio.

See !1298
2022-06-30 08:38:52 +02:00
Wim Taymans a44c600ade resample: use cosh window function
Seem to produce a little sharper cutoff.

Fixes #2483
2022-06-29 18:03:40 +02:00
Wim Taymans 9b37142ef6 audioconvert: implement noise shaping
To compare the results:

  pw-cat -r test.wav --format=u8 -P '{ dither.method=none }'

vs:

  pw-cat -r test.wav --format=u8 -P '{ dither.method=shaped5 }'
2022-06-29 17:33:37 +02:00
Wim Taymans 7701786016 audioconvert: demote a debug log to trace_fp 2022-06-29 17:30:04 +02:00
Wim Taymans 0b62cea4f9 audioconvert: use faster noise generator 2022-06-29 14:33:58 +02:00
Wim Taymans 938f2b123e audioconvert: improve format conversion
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.
2022-06-29 14:10:15 +02:00
Wim Taymans d23b96b033 audioconvert: fix some compiler warnings 2022-06-29 14:08:30 +02:00
Wim Taymans 0b73fa97d0 audioconvert: use loop for channelmix method enum 2022-06-29 14:05:48 +02:00
Wim Taymans 22d02a7891 audioconvert: dither in 24 bits
This saves some shifts.
2022-06-28 17:15:27 +02:00
Wim Taymans 7a0f201dc7 audioconvert: set right flags for functions 2022-06-28 17:02:15 +02:00
Wim Taymans 6b49bded3a audioconvert: move dither and noise to fmt-ops
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.
2022-06-28 16:55:50 +02:00
Wim Taymans 51f4f1fb69 audioconvert: expose the selected function names
And debug them.
2022-06-28 16:50:14 +02:00
Wim Taymans 048e10ee3b audioconvert: expose upmix-method in PROP_INFO 2022-06-28 11:32:05 +02:00
Wim Taymans a84bf672e8 audioconvert: add dither passthrough flag 2022-06-28 11:31:40 +02:00
Wim Taymans b5e0151cc0 audioconvert: add dither noise setting in dither struct
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.
2022-06-28 10:52:31 +02:00
Wim Taymans b7e26002be audiocovert: improve dither 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
2022-06-28 10:11:46 +02:00
Wim Taymans 67c2202044 audioconvert: improve setup of quantization
Use the quantize value to specify how many bits to quantize to.
2022-06-27 20:03:30 +02:00
Wim Taymans 916050aacd audioconvert: handle errors 2022-06-27 20:03:30 +02:00
Wim Taymans 00998ffd7e audioconvert: ensure alignment
Allocate a little bit more data to ensure alignment and overread of the
dither data.
Ensure sse2 can load aligned data in all cases.
2022-06-27 17:18:23 +02:00
Wim Taymans b41d52cfd1 audioconvert: optimize dither
Add sse2 dither optimization
2022-06-27 14:15:01 +02:00
Wim Taymans 9f55708e9d audioconvert: Always apply noise when asked
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
2022-06-27 11:19:01 +02:00
Wim Taymans abcf7cb8d8 add some SPA_LIKELY 2022-06-27 09:37:33 +02:00
Takashi Sakamoto e3b6534872 acp: avoid assertion at alsa-lib mixer API when element removal
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")
2022-06-27 10:17:30 +09:00
Barnabás Pőcze 1ac02db6a9 spa: audioconvert: ensure that noise::intesity is not too big
Shifting by 64 or more would not fit into `uint64_t`.
2022-06-24 16:27:43 +02:00
Barnabás Pőcze bb205d3d85 spa: audioconvert: use unsigned 64-bit integer for creating divisor
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.
2022-06-24 16:27:43 +02:00
Barnabás Pőcze 43f7831d14 spa: audioconvert: use SPA_N_ELEMENTS in noise_init() 2022-06-24 16:27:39 +02:00
Michael Tretter a745374232 v4l2: fix port param enumeration for devices without controls
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.
2022-06-24 12:16:05 +00:00
Michael Tretter edd41d8259 v4l2: close v4l2 device on error
The device needs to be closed when the enum_controls function is exited,
but is not closed if the VIDIOC_QUERYCTRL fails. Fix it.
2022-06-24 12:16:05 +00:00
Wim Taymans 13ccccbfbd audioconvert: add missing file 2022-06-24 14:15:17 +02:00
Wim Taymans 1c6cb049ce audioconvert: add an option generate silence noise
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
2022-06-24 13:45:35 +02:00
Wim Taymans 9430df0ba6 channelmix: undefine the function macro 2022-06-24 13:45:35 +02:00
Wim Taymans 974ab5348e audioconvert: reset props before parsing config
Or else we undo all settings from the config params.
2022-06-24 13:45:35 +02:00
Wim Taymans f2dee23085 buffer: add EMPTY chunk flag
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.
2022-06-24 11:09:01 +02:00
Wim Taymans 71f3c759f4 audiomixer: support offset and clamp size 2022-06-24 10:41:30 +02:00
Wim Taymans f6938d8364 alsa: simplify writing
We don't use the input buffers as ringbuffers, so remove that
code and simpify fomr things.
2022-06-24 10:38:13 +02:00
Wim Taymans da95043002 channelmix: guard against invalid channels 2022-06-23 11:40:22 +02:00
Wim Taymans cc463da63e audioadapter: adjust max input ports
The control port adds an extra input port.
2022-06-23 11:39:27 +02:00
Wim Taymans a365b19110 audioconvert: handle too many channels earlier 2022-06-23 11:28:27 +02:00
Pauli Virtanen 6bfe9a362c audioconvert: avoid crash on 64 channels + monitor enabled
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.
2022-06-23 09:11:25 +00:00
Wim Taymans 0f62d3442c alsa: handle driver bugs better
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
2022-06-23 10:20:49 +02:00
Wim Taymans ecc0eecf0f mixer-dsp: mix a quantum of data at a time
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.
2022-06-22 15:50:56 +02:00
Wim Taymans a427e602bd audioconvert: in merge mode, flush input
In merge mode we handle 1 quantum and then flush the input and
output. Fixes a case were samples were cut at the start.
2022-06-22 15:48:09 +02:00
Wim Taymans a13f65f583 alsa-seq: disable the running status
Running status is not something we want in the PipeWire graph.
2022-06-20 16:18:42 +02:00
Wim Taymans 25d9039f2e alsa-seq: handle midi event decoder errors 2022-06-20 16:12:49 +02:00
Wim Taymans 40f50deae9 alsa: remove NoteOn 0-velocity fixup
Pass MIDI events as they are.

JACK requires NoteOn 0-velocity midi events to be patched to NoteOff
events for compatibility with LV2 plugins. Let's do this patchup in
the JACK layer then and add an option to disable it.

It's best to pass the midi messages unmodified and then patch them up
wherever they need patching up.
2022-06-20 15:51:33 +02:00
Wim Taymans d13a206866 audioconvert: fix resampler in_offset
Only advance the in_offset with the number of samples that were consumed
by the resampler. In case when the resampler is filling up an old
buffer, this can be less than n_samples.

Fixes a2dp source and possibly others.
2022-06-20 12:33:52 +02:00
Lucas Holt 6a15a02ec2 Add support for MidnightBSD
Fix build issue

Fix build issue
2022-06-19 18:22:47 +00:00
Barnabás Pőcze 492a328227 spa: audioconvert: free resampler
resample::free() needs to be called in `impl_clear()` otherwise the
resampler's private data is leaked when the audioconvert instance is destroyed.
2022-06-16 19:49:50 +02:00
Barnabás Pőcze 96d0902dc8 spa: ffmpeg: set spa_handle_factory::version
Initialize the version with the `SPA_VERSION_HANDLE_FACTORY` macro.
This way `spa-inspect` can properly inspect the factory.
2022-06-16 17:29:42 +02:00
Barnabás Pőcze de5a85d808 spa: ffmpeg: implement spa_handle::clear
Implement the spa_handle::clear method for both the encoder and decoder.
At the moment, they both do nothing.
2022-06-16 17:29:20 +02:00
Barnabás Pőcze f2bd2ef6fb spa: ffmpeg: implement spa_handle_factory::get_size
This method is necessary for the creation of a handle,
so implement it for both the encoder and decoder.
2022-06-16 17:28:23 +02:00
Barnabás Pőcze 6cb8fb899d spa: ffmpeg: move some function declarations to a header
Move the declarations for `spa_ffmpeg_{dec,enc}_init` to the
"ffmpeg.h" header file. This way the implementation is checked
against the signature.
2022-06-16 17:27:36 +02:00
Barnabás Pőcze 1a21da9898 spa: tools: spa-inspect: clear and free handles
Call the handle's `clear()` method after it has been
inspected, and free the allocated storage for the handle.
2022-06-16 16:59:40 +02:00
Wim Taymans 3cb5fab176 audioconvert: rework the control loop
Use the offset to skip entries in the sequence array.
Use one loop to handle intermediate and trailing samples.
Fixes an issue where the last chunk of a sequence would be ignored.
2022-06-16 16:45:32 +02:00
Wim Taymans e0af67b670 examples: fix spelling mistake 2022-06-16 16:40:47 +02:00
Wim Taymans de2e819fec audioconvert2: rename to audioconvert 2022-06-16 09:19:05 +02:00
Wim Taymans cf04bb573c audioconvert: remove old plugins 2022-06-16 09:16:49 +02:00
Wim Taymans f74b59b39f examples: fix volume fade in and out with control 2022-06-16 09:09:27 +02:00
Wim Taymans c160cd0176 audioconvert2: implement control port
Add a control port when requested in the PortConfig.
Fix the sequence loop.
Make a copy of the sample pointers before changing them.
2022-06-16 09:09:27 +02:00
Wim Taymans 5a60fd7041 audioconvert2: remove unused monitor field 2022-06-16 09:09:27 +02:00
Wim Taymans 194b8e2d97 audioconvert2: emit param change when volume changes 2022-06-16 09:09:27 +02:00
Wim Taymans 0ec41e60ef audioconvert2: fix for quantum changes
Use the offset as the buffer size.
Use the amount of requested - amount of used samples as queued samples.
2022-06-16 09:09:27 +02:00
Wim Taymans 708b57aa64 examples: add control support to adapter
Based on patches by Julian Bouzas  in !222
2022-06-16 09:09:27 +02:00
Wim Taymans fa9baa6488 examples: fix up adapter-control
Negotiate format, then buffers.
Give quantum-limit as a property when making nodes.
Set clock and position io and fill in rate and duration.
2022-06-16 09:09:27 +02:00
Wim Taymans db49021104 audioconvert2: add control port processing 2022-06-16 09:09:27 +02:00
Wim Taymans d5c28149f1 audioconvert2: fix in/out queued samples 2022-06-16 09:09:27 +02:00
Wim Taymans 7fe15ee5db audioconvert2: add beginnings of control ports 2022-06-16 09:09:27 +02:00
Wim Taymans d3baa16559 audioconvert2: reset node in Flush/Suspend 2022-06-16 09:09:27 +02:00
Wim Taymans 8e6a8a705b audioconvert2: clamp in and output samples
Make sure we don't read or write more samples than available in the
buffers.
2022-06-16 09:09:27 +02:00
Wim Taymans 9e93fe3c36 audioconvert2: remap volumes to right channels
We get the volumes with a channelmap of the input/output, remap this to
the channelmixer internal layout.
2022-06-16 09:09:27 +02:00
Wim Taymans 50c37cc801 audioconvert2: rearrange some code
Move some code around so that we don't have to prepare the output
buffers when there is no input to process.
2022-06-16 09:09:27 +02:00
Wim Taymans d5e333eea7 audioconvert2: in merge mode, always process quant samples 2022-06-16 09:09:27 +02:00
Wim Taymans c4d77d421a audioconver2: process monitor ports immediately 2022-06-16 09:09:27 +02:00
Wim Taymans f45f1acd82 audioconvert2: use the position rate as resampler rate
For the DSP inputs, use the position rate.
2022-06-16 09:09:27 +02:00
Wim Taymans 58abc1ec15 audioconvert2: Improvements
Suggest 2 buffers by default.
Improve rate match flow.
monitor does not need the out_offset
Update rate match when we know the queued samples.
2022-06-16 09:09:27 +02:00
Wim Taymans 2352ae33c3 audioconvert2: add queueing
Use in and out offset to read/write partial input/output.
2022-06-16 09:09:27 +02:00
Wim Taymans d728076d33 audioconvert2: handle drain 2022-06-16 09:09:27 +02:00
Wim Taymans 1c4058b947 audioconvert2: clamp offset and size 2022-06-16 09:09:27 +02:00
Wim Taymans 229a7b6019 audioconvert2: fix default settings 2022-06-16 09:09:27 +02:00
Wim Taymans f2c1fe106d audioconvert2: more fixes 2022-06-16 09:09:27 +02:00
Wim Taymans 3806cdaa6f audioconvert2: more improvements
Use a wildcard rate for DSP ports.
Handle wildcards for rate and channels.
Calculate required in/out samples using quantum
Limit monitor and output number of samples.
2022-06-16 09:09:27 +02:00
Wim Taymans c0f34e9d9d audioconvert2: set blocks a stride for DSP ports
They might not get connected and negotiated but we still need to
use empty buffers in that case.
2022-06-16 09:09:27 +02:00
Wim Taymans 2d6bf00acc audioconvert2: add options 2022-06-16 09:09:27 +02:00
Wim Taymans 75ebdbdfa0 audioconvert2: start working on monitor ports 2022-06-16 09:09:27 +02:00
Wim Taymans db2cbdf906 audioconvert2: DSP mode without format gives no ports 2022-06-16 09:09:27 +02:00
Wim Taymans d53311099f audioconvert2: format is optional for convert mode 2022-06-16 09:09:27 +02:00
Wim Taymans e78a93d358 audioconvert2: fix audio rate property 2022-06-16 09:09:27 +02:00
Wim Taymans 9babdee6cd audioconvert2: do input and output remapping
We remap the input channels to our cannonical layout and then remap it
to the target layout.
2022-06-16 09:09:27 +02:00
Wim Taymans 922a088129 audioconvert2: handle volume 2022-06-16 09:09:27 +02:00
Wim Taymans 0099b80098 audioconvert2: add properties 2022-06-16 09:09:27 +02:00
Wim Taymans 8cb0d9fd7b audioconvert: add channelmix and resample 2022-06-16 09:09:27 +02:00
Wim Taymans 399f638eb1 audioconvert: more work 2022-06-16 09:09:27 +02:00
Wim Taymans 7f9ddd0f15 Add audioconvert2 2022-06-16 09:09:27 +02:00
Ole Salscheider 3695611b20 channelmix: Assign slev in mixing matrix when generating side/rear from front
This way, PSD upmixing sounds much more natural and is in line with the
original publication.
2022-06-14 10:58:25 +00:00
Peter Oliver d3597ed149 alsa: Disable IEC958 on Audioengine HD3
As discussed in #2112.
2022-06-14 06:58:41 +00:00
Wim Taymans 8e1f0628f7 channelmix: add 3p1_2 and use this for quad conversions
Simplify some SSE versions
2022-06-13 20:35:00 +02:00
Ole Salscheider 5dc4434dc7 channelmix: Implement PSD upmixing for stereo -> quad
Fixes #2436.
2022-06-13 14:19:23 +00:00
Ole Salscheider 354a04c91d Channel mixer: Remove channelmix_f32_2_4_sse
It does not have PSD upmixing implemented and does not allow to disable
the simple upmixing algorithm either.

Fixes #2438.
2022-06-13 14:19:23 +00:00
Wim Taymans a1d4b41c34 channelmix: fix control handling
We need to use the control type of the control we're actually going
to use.
2022-06-13 16:17:53 +02:00
Frédéric Danis 8bd1d4c7c9 bluez5: Fix LC3plus plugin build
LC3PLus plugin should not depend on LDAC C args to build
2022-06-10 18:16:49 +02:00
Wim Taymans b99c71262e alsa: force same clock only for pro audio profile
Assume that capture and playback nodes from a device have different
clocks. This enables the adative resampler to match them. A lot of devices
actually have slightly different rates and would work out of the box
with this fix.

Make an exception when the card is configured in the pro audio profile.
Then we force the same clock on all device nodes and avoid resampling
and rate matching. This can still be changed with a session manager
override.
2022-06-08 17:03:50 +02:00