7876 Commits

Author SHA1 Message Date
Chris Robinson
87682e7cb2 Update a comment 2021-04-11 17:32:14 -07:00
Chris Robinson
f403fbd2e9 Fix UHJ encoding/decoding factors
Classic B-Format uses scaling factors W=1, X=sqrt(2), Y=sqrt(2), and Z=sqrt(2),
which is +3dB louder than FuMa. The base factors are designed assuming classic
scaling, so encoding a 0dBFS FuMa signal without accounting for this would
result in the UHJ signal peaking at about -3dBFS. Similarly, decoding UHJ to
FuMa B-Format would be +3dB louder than intended.

So encoding needs to implicitly boost the signal by +3dB, and decoding needs to
attenuate by -3dB.
2021-04-11 17:09:52 -07:00
Chris Robinson
4af6cfac7d Use per-HRIR delay alignment for B-Format-to-HRTF
For HOA signals, the number of responses used with slightly varying delays
causes noticeable attenuation in the higher frequencies because of destructive
phase interference. This is not a result of minimum phase alignment (attempts
to compensate for minimum phase had negligible results), nor does it affect
first-order signals (which only has 4 unique responses on each side).

This alternate alignment is only used when doing second-order rendering for
HRTF output, which is not the default with HRTF. It's likely not very ideal,
but it's necessary to prevent second-order rendering with HRTF from sounding
muffled.
2021-04-09 11:36:58 -07:00
Chris Robinson
f8299c60ec Log the reset exception error 2021-04-07 16:17:03 -07:00
Chris Robinson
44a6e1f858 Add RESTRICT to some pointers
And update some comments
2021-04-04 07:27:53 -07:00
Chris Robinson
c7f3a02956 Add an option to decode stereo as UHJ in alffplay 2021-04-02 07:21:17 -07:00
Chris Robinson
a2c45f8928 Advertise the in-progress AL_SOFT_UHJ extension 2021-04-01 08:20:47 -07:00
Chris Robinson
c6dbc487b3 Rename Uhj2Encoder to UhjEncoder 2021-04-01 05:37:54 -07:00
Chris Robinson
e457018921 Avoid passing an array of pointers 2021-04-01 03:44:26 -07:00
Chris Robinson
f33edc3b30 Add support for 4-channel UHJ
Also add the SOFT moniker to the new macros
2021-03-31 21:02:30 -07:00
Chris Robinson
b5e36007f1 Handle 3-channel UHJ audio buffers 2021-03-31 10:03:31 -07:00
Chris Robinson
35a0f2665f Decode UHJ buffers to B-Format for mixing
This should also have an adjustment for the shelf filter. Although it's not
clear what the appropriate adjustments should be.
2021-03-31 09:37:30 -07:00
Chris Robinson
8793055e66 Start an interface for providing UHJ audio
Currently only 2-channel UHJ, which gets treated as stereo.
2021-03-31 05:37:56 -07:00
Chris Robinson
051d6fb243 Combine some duplicate code 2021-03-30 07:04:06 -07:00
Chris Robinson
7b2f194490 Rename a couple class members 2021-03-28 23:45:16 -07:00
Chris Robinson
e32b551944 Remove some unnecessary includes 2021-03-28 06:10:45 -07:00
Chris Robinson
8ab5e5dba2 Move the UHJ phase shifter to a common header 2021-03-28 06:09:11 -07:00
Chris Robinson
819e0297ff Add the export definitions to the library projects
Instead of the config.h header.
2021-03-28 01:47:27 -07:00
Chris Robinson
f045694ce0 Add an option to change the UHJ decoder method
For 2-channel UHJ, two decoding equations are provided in the original paper.
The alternative one is most often referenced for 2-channel UHJ decoding, but
the original/general one can also be used by assuming T is fully attenuated
(which the format allows for, as T can be variably attenuated by a factor
between 0 and 1 to deal with an imperfect transmission medium).

Neither method can be perfect for 2-channel UHJ, it's irrevocably lossy to the
original source, but my subjective testing indicates the general equation
produces less audibly errant results.
2021-03-26 02:55:45 -07:00
Chris Robinson
d681573803 Fix a comment typo 2021-03-24 04:34:01 -07:00
Chris Robinson
d732a8831e Update the UHJ decoding coefficients 2021-03-24 00:24:10 -07:00
Chris Robinson
9a31dcf84f Don't add the resampler prepadding to the source size to load 2021-03-23 19:55:44 -07:00
Chris Robinson
ae43e628fb Add support for decoding 3- and 4-channel UHJ audio
There are no known file formats intended to support 3- and 4-channel UHJ, but
it is possible to store them in various audio files when a player/decoder is
aware of what it's dealing with. So there's no reason not to have it as an
option.
2021-03-21 19:37:24 -07:00
Chris Robinson
b8ede345f3 Don't assume two input channels in uhjdecoder 2021-03-21 12:36:56 -07:00
Chris Robinson
c3ee678945 Add a utility to decode UHJ sound files to AMB
Currently only supports 2-channel UHJ, and the produced .amb files shouldn't be
played as normal B-Format (decoded 2-channel UHJ needs to use different shelf
filters).
2021-03-21 02:03:45 -07:00
Chris Robinson
f0726f471f Use float formats in examples/alstreamcb
libsndfile apparently has issues reading floating-point wave files as 16-bit
samples (produces silence). Even on other file formats, reading float samples
as integer samples has no over/underflow protection, so this is better for
those formats too.
2021-03-21 01:38:38 -07:00
Chris Robinson
7c697b9178 Fix the UHJ all-pass delay
For real this time. The non-all-passed signal needs a one-sample delay over the
all-passed signal. Because of the way the all-pass FIR filter is structured,
it wouldn't otherwise use the last buffered sample, allowing it to be shifted
forward in time by one sample.

Also, remove a couple unnecessary buffers.
2021-03-20 03:14:10 -07:00
Chris Robinson
063da94bd8 Load/convert samples from all channels at once for mixing
This uses a bit more memory (each voice needs to hold buffers for the
deinterleaved samples of each channel, instead of just one buffer for the
current channel being mixed on the device), but it will allow for handling
formats that need or prefer their channels decoded together.
2021-03-19 23:15:27 -07:00
kcat
f7f2999960
Merge pull request #543 from ilya-fedin/dont-force-app-name
Don't force application name with pulseaudio
2021-03-17 21:22:46 -07:00
Ilya Fedin
b7ff1de48e Don't force application name with pulseaudio 2021-03-18 04:34:57 +04:00
Chris Robinson
743f0931c6 Don't activate the WASAPI device when initially opening it 2021-03-17 17:03:35 -07:00
Chris Robinson
f11fef9ee5 Avoid returning objects with a reference parameter 2021-03-16 22:40:23 -07:00
Chris Robinson
24b030d6bd Check that CoCreateInstance succeeds 2021-03-16 16:56:11 -07:00
Chris Robinson
e5833a9a68 Fix UHJ FIR filter alignment 2021-03-15 22:11:35 -07:00
Chris Robinson
c1f0555fef Workaround mingw complaining about the %z formatter 2021-03-12 03:14:29 -08:00
Chris Robinson
ca0a6024a3 Avoid shadowing variable names 2021-03-11 04:59:58 -08:00
Chris Robinson
e43bbbd3b8 Declare the attribute counts closer to where they are 2021-03-10 02:46:01 -08:00
Chris Robinson
d750983a58 Prevent querying the capture device name from a playback device
And vice-versa.
2021-03-09 07:09:27 -08:00
Chris Robinson
5e481e7654 Don't verify and hold a device reference in alcRenderSamplesSOFT
NULL devices are still checked, but invalid non-NULL device handles will invoke
undefined behavior, as will attempting to close the device while the function
is being executed (modifying the device state while the function is being
called was inadvertently already UB, and will now remain so).

This change is solely so alcRenderSamplesSOFT can be used in a buffer callback,
and other places that need functions to be real-time safe. The verification
requires locking to access the device list, which isn't allowed in a real-time
callback.
2021-03-09 06:01:27 -08:00
Chris Robinson
e824c808a0 Add a function/extension to reopen a playback device 2021-03-09 05:52:40 -08:00
Chris Robinson
e6c7cdc1ba Initialize the new audio unit before disposing the old one 2021-03-09 02:55:01 -08:00
Chris Robinson
1d57db6836 Move the ComPtr wrapper to a common header 2021-03-08 22:47:50 -08:00
Chris Robinson
730c964029 Allow calling BackendBase::open multiple times on playback devices
It will not be called while the device is running. If the first call succeeds,
a subsequent call that happens to fail must leave the existing device state as
it was so it can be resumed.

This is a rough first pass. It will fail when trying to re-open the same device
which can only be opened once (for instance, with direct hardware access, on
hardware that doesn't do its own mixing). Some backends won't guarantee the new
device is usable until the reset() or start() call.
2021-03-08 22:29:40 -08:00
Chris Robinson
0f7ed495e1 Use a fast native type for the backup popcount 2021-03-02 22:58:36 -08:00
Chris Robinson
ffc3859a8d Use the correct lock when allocating filters 2021-03-02 19:59:33 -08:00
Chris Robinson
727503acdb Avoid making BSincPointsMax public 2021-03-01 17:48:07 -08:00
Chris Robinson
9f349c21e7 Avoid cutting off the last bsinc filter coefficient 2021-03-01 01:03:44 -08:00
Chris Robinson
6102cdae02 Avoid trying to get the app path when it fails on Windows too 2021-02-27 17:10:50 -08:00
Chris Robinson
4179633440 Avoid calling readlink on platforms that don't support it
Also don't keep trying to find the path+name if it fails the first time.
2021-02-27 13:09:43 -08:00
Chris Robinson
6e676b81d5 Avoiding cutting all bsinc resampler output at scale 0
This is mostly for the SampleConverter, used by some capture backends. When
recording at really low rates, like 5512hz, with a device capturing at a higher
rate like 44100hz or 48000hz, it hits the filter's downscaling limit and
produces pure silence.

In such cases, it's better to just accept some aliasing noise so that the app
will still get some recognizable audio. The alternative would be to scale the
desired rate by 2x, 3x, etc until it's above the bsinc limit, then take every
2nd, 3rd, etc sample of the result as if by an extra simpler resampler pass.
2021-02-24 22:21:18 -08:00