Commit Graph

438 Commits

Author SHA1 Message Date
Alexandre Ratchov c4b354abd7 Fix off-by-one array access when 64 channel stream is resampled 2021-07-05 14:18:53 +02:00
Alexandre Ratchov 1f42a21368 Drop assembly for 24-bit fixed-point operations
Now i386 compiler is smart enough to generate a single imul
instruction per fixed-point multiplication. This change also allows
24-bit precision to be used on all archs (if -DADATA_BITS=24 is used).

Tested on arm64 by Doug Moss <dougmoss710 at yahoo.com>, thanks

Suggested and ok naddy@
2021-05-31 15:08:02 +02:00
Alexandre Ratchov 0cb3defc3c sndiod: Use proper mode to setup conversions
Now we need to use opt's mode instead of slot's mode as this is the
one used by dev_cycle(). Fixes monitoring mode not working in case
dev->rchan != dev->pchan
2021-04-29 15:15:33 +02:00
Alexandre Ratchov 12b31d021a sndiod: If mode not allowed in opt structure just play/record silence
This is similar to what we do when device is open and its mode doesn't
match requested mode.
2021-04-26 10:08:11 +02:00
Alexandre Ratchov 90684ad458 sndiod: Allocate (free) conversion buffers in slot_attach (slot_detach)
Besides being better coding style, this allows a client to be detached
and then attached to a device with different parameters.
2021-04-23 11:12:35 +02:00
Alexandre Ratchov 9a5092b08e sndiod: Make play-only and rec-only start at the same position
This is necessary to make rec-only device properly work in
full-duplex. Fixes full-duplex clients stuck on rec-only device.
2021-04-23 11:01:05 +02:00
Alexandre Ratchov 1649f75532 sndiod: Use chronological order for {dev,port}_list 2021-03-08 10:25:31 +01:00
Alexandre Ratchov d6a1624f29 sndiod: Initialize dev->master_enabled earlier 2021-03-08 07:14:16 +01:00
Alexandre Ratchov f712cdb11b sndiod: Style tweak: uniformize pattern to access ctlslot_array 2021-03-08 07:04:32 +01:00
Alexandre Ratchov 6869540f3b sndiod: When a slot structure is recycled allocate new control
Trying to rename the program level control is not needed anymore.
When a slot is given to another program, the new ctl_{new,del}()
functions can be used to delete the control of the old program and
create a new one for the new program. Cleaner, simpler.
2021-03-08 06:38:48 +01:00
Alexandre Ratchov 302865ddd8 sndiod: Style tweak: swap if/else code blocks in slot_new() 2021-03-08 06:06:12 +01:00
Alexandre Ratchov 5451c3c55e Move MTC/MMC to its own structure 2021-03-03 10:49:28 +01:00
Alexandre Ratchov ada702087d Move MIDI control endpoint to opt structure 2021-03-03 10:49:28 +01:00
Alexandre Ratchov bb27629080 Move controls list out of the device structure
Use a unique dynamically allocated ctl->addr key and a "scope"
enum to identify controls that belong to different devices.
2021-03-03 10:49:28 +01:00
Alexandre Ratchov 0adedb2a89 sndiod.8: Some article fixes; from eddie youseph and grep through jmc@ 2021-03-03 10:35:54 +01:00
Alexandre Ratchov a6a6dcb57c sndiod: Fix use-after-free causing crash when devices is disconnected 2021-03-03 10:31:20 +01:00
Alexandre Ratchov e5766cbfc0 sndiod: Allow alternative devices to support different modes
Currently sndiod does not allow you to use alternative devices (-F
devices) which support only a subset of the modes of the main (-f)
device.

For example, if you do `sndiod -f rsnd/0 -F rsnd/1` and:
- rsnd/0 is full-duplex (rec + play).
- rsnd/1 is play-only.

Then you will be unable to use rsnd/1 as sndiod deems it incompatible
and refuses to use it (similarly if rsnd/1 is record-only).

This is annoying. It means if you want to use a record-only or play-only
device, you will either have to kill sndiod and restart it specifying
only that device (`sndiod -f rsnd/1` for the above example), or failing
that, downgrade the functionality of the main device (`-m play`).

This diff (a joint effort between ratchov@ and myself) makes mixing
devices with different modes possible. It does this by making both
recording and playing available for all devices, even if the underlying
hardware doesn't support both modes.

For example, if I try to record from a play-only device, then recording
will succeed, but the captured PCM data will be pure silence. Similarly,
if I try to play to a record-only device, then the audio stream will
disappear into the ether.

This is mostly a no-op for sndiod in the default configuration (except
that play-only devices now accept recording clients). If you use
alternative devices (-F), then it's possible for a record-only device to
be found first, which may be confusing if you just want to hear sound.
We can only assume that if you deviate from defaults, then you know what
you are doing.

From edd@
2021-03-03 10:22:38 +01:00
Alexandre Ratchov 350db6ce41 sndiod: Disable autovol by default and set default volume to 127
The previous behavior of automatically decreasing playback volume
when new programs start playing can be achieved with '-w on'.
2021-03-03 10:16:12 +01:00
Alexandre Ratchov 7534418e78 Make audio clients use struct opt to reach the device 2021-03-03 07:43:34 +01:00
Alexandre Ratchov a78ec25e07 Make control clients use struct opt to reach the device 2021-03-03 07:43:34 +01:00
Alexandre Ratchov 1e1589d70e Rename ctlslot->mask to ctlslot->self to match the rest of the code 2021-03-03 07:43:34 +01:00
Alexandre Ratchov e891595ec7 Order opt_list in opt_new() call order, limit items to OPT_NMAX 2021-03-03 07:43:34 +01:00
Alexandre Ratchov 8e99cca36c Move the options list out of the device structure 2021-03-03 07:43:34 +01:00
Alexandre Ratchov 4710960bbe Move the control client state out of the device structure 2021-03-03 07:43:34 +01:00
Alexandre Ratchov 8bb6267fdb Move the audio clients state out of the device structure 2021-03-03 07:43:34 +01:00
Alexandre Ratchov 2cd5b8e0ab Disconnect MIDI clients controlling disconnected audio device 2021-01-28 11:11:23 +01:00
Alexandre Ratchov ea692625ea Dont attempt to drain disconnected clients 2021-01-28 11:11:23 +01:00
Alexandre Ratchov 6f741dab61 In slot_xxx(), store dev pointer in local variable 2021-01-28 11:11:23 +01:00
Alexandre Ratchov fd4c58aae7 Use everywhere the same pattern to handle fractional clock ticks
No behavior change; the code change is to make the maths easier to
proofread
2021-01-28 11:11:23 +01:00
Alexandre Ratchov 63d4639f9a Make slot_{attach,detach}() the opposite of each other
No bahavior change, but this makes the code is much easier.

Now, slot_attach() moves slot's clock forward and puts the slot on
device list; slot_detach() does the opposite: remove from device list
and move clock backwards.
2021-01-28 11:11:23 +01:00
Alexandre Ratchov ae76a1f941 Drop/move unused prototypes for slot_xxx() 2021-01-28 11:11:23 +01:00
Alexandre Ratchov ac7ddc5301 Drop unused dev_nctl() function 2021-01-27 11:57:35 +01:00
Alexandre Ratchov b1c2df5d9c aucat, sndiod: const-ify lookup tables
From naddy@
2021-01-13 17:30:19 +01:00
Alexandre Ratchov 21580f56b5 Clip 16-bit resampled signal as there's no room for filter overshoots 2021-01-11 14:46:32 +01:00
Alexandre Ratchov 2996dcdc03 Use a 8-th order FIR low-pass filter for resampling 2020-12-20 11:01:27 +01:00
Alexandre Ratchov 40cdc42e22 Check sample signedness when setting up format conversions.
Fixes confusion between s16 and u16 found in aucat and analysed by
James Cook <falsifian at falsifian.org>. Thanks.
2020-12-10 22:05:56 +01:00
Alexandre Ratchov c888f2750b Don't add server.device knob if there's only one audio device 2020-07-19 13:13:40 +02:00
Alexandre Ratchov e79f8b5c2f Fix initial alternate device number
The initial alternate device number was set to 1 (instead of -1),
causing device number 1 to be skipped the first time sndiod is used.
2020-07-19 13:07:26 +02:00
Alexandre Ratchov f96882d62d Remove server/ group, rename device.select to server.device 2020-06-27 10:30:20 +02:00
Alexandre Ratchov 24d12842ac Add server/ group for device.select control 2020-06-26 09:20:09 +02:00
Alexandre Ratchov 9a446c6b72 Allow alternate devices to be switched with sndioctl 2020-06-18 06:27:36 +02:00
Alexandre Ratchov 14b0682012 Add SIOCTL_SEL control type 2020-06-16 07:51:45 +02:00
Alexandre Ratchov 9bfc9cf713 Don't try to open device that's already open 2020-06-16 07:34:42 +02:00
Alexandre Ratchov f29a76bc19 On error, drop clients and close the device only if it's still open
Fixes crashes when USB devices are disconnected, caused by an attempt
to close the already closed device: it was closed once when its ref
counter drops to zero (after the last client is disconnected) and once
with an explicit call to dev_close() on the error code-path.

The same pattern was used for MIDI ports, it's fixed as well.
2020-06-12 17:26:38 +02:00
Alexandre Ratchov f330fa3d4a If no -f options are used, expose first 4 midi(4) devices to sndiod clients
A single default device could be set at ./configure time with
the --default-dev option
2020-04-30 19:06:13 +02:00
Alexandre Ratchov 5750e312db sndiod: Record if a client belongs to a session 2020-04-30 16:33:08 +02:00
Alexandre Ratchov 5736faa146 Get a reference to the device when "snd/N" MIDI ports are opened
As the master output level control is not in software any longer the
device needs to opened for adjustments to work.
2020-04-30 16:27:32 +02:00
Alexandre Ratchov 343f13e33f Make sure devices are properly closed in case of an error
Fixes possible crashes if the contol device fails, while the audio
device continues to work.
2020-04-24 13:35:33 +02:00
Alexandre Ratchov 54839e409a Properly log CTL_NONE controls 2020-04-15 14:41:21 +02:00
Alexandre Ratchov 573c328527 Don't forget to notify clients when a control is removed 2020-04-15 14:24:59 +02:00