is also an unsigned int - the code works "by chance" as `abs` casts that to an int which overflows and is technically undefined behaviour, for instance for setRate = 44100 and reqRate = 48000.
Thus cast them to int when computing the absolute value to ensure no UB.
dmitrykos [Fri, 11 Dec 2020 13:30:08 +0000 (15:30 +0200)]
wasapi: Fixed underruns in the Exclusive mode on UWP platform (or when timeBeginPeriod does not allow to set 1 ms granularity) by assuming that system timer granularity on UWP equals to 10 msec, make sure time to sleep provided by GetNextSleepTime is aligned to the granularity of the system timer.
Ross Bencina [Thu, 26 Nov 2020 02:46:05 +0000 (13:46 +1100)]
pa_mac_core_utilities: add void to empty function argument list (#355)
Insert "void" in the argument list to turn initializeXRunListenerList and destroyXRunListenerList declarations into valid prototypes. Also update the function definitions to match. Thanks to Paul Boersma.
dmitrykos [Mon, 26 Oct 2020 16:25:10 +0000 (18:25 +0200)]
wasapi: Fixed compilation with MinGW (mingw32): gcc version 6.3.0 (MinGW.org GCC-6.3.0-1), include /mingw-include folder explicitly (when compiling with mingw-w64 the /mingw-include folder must not be included).
dmitrykos [Mon, 26 Oct 2020 14:40:25 +0000 (16:40 +0200)]
wasapi: Support multiple devices in the device list on Windows UWP/WinRT platform. All UWP/WinRT functions are now prefixed as PaWasapiWinrt_ to be clearly visible, therefore PaWasapi_SetDefaultInterfaceId() was renamed to PaWasapiWinrt_SetDefaultDeviceId(). Expanded Important notes regarding UWP/WinRT platform and how to make the fully-functional device list with the corresponding pseudo-code example for easier understanding of the functionality.
Hool, Rory [Thu, 22 Oct 2020 17:53:56 +0000 (13:53 -0400)]
Replace usage of deprecated component manager APIs on 10.6+
These APIs are deprecated in 10.8+ and are disabled on 11.0(10.16)+ https://developer.apple.com/documentation/coreservices/carbon_core/component_manager?language=objc
> "This application, or a library it uses, is using the deprecated Component Manager for hosting Audio Components. This is not supported when rebuilding against the 10.16 or later SDK. Also, this makes the host incompatible with version 3 audio units. Please transition to the API's in AudioComponent.h."
dmitrykos [Thu, 26 Mar 2020 18:50:52 +0000 (20:50 +0200)]
alsa: Introduce possibility to ignore all ALSA plugin devices by setting the environment variable PA_ALSA_IGNORE_ALL_PLUGINS to non-0. Fixed logic of guarding assertion in BuildDeviceList() when only one or none PCM device is available (may occur if PA_ALSA_IGNORE_ALL_PLUGINS is set to non-0 or when device has no any audio device available, including plugin devices).
dmitrykos [Fri, 9 Oct 2020 21:42:20 +0000 (00:42 +0300)]
wasapi: Refactored device list creation, if faulty audio device is reported as active by WASAPI then it will not break device list creation, silenced warnings when compiling for UWP platform.
dmitrykos [Thu, 8 Oct 2020 21:57:23 +0000 (00:57 +0300)]
wasapi: Replace tabs with 4-spaces to comply with PortAudio code style guidelines (http://github.com/PortAudio/portaudio/wiki/ImplementationStyleGuidelines).
Ross Bencina [Thu, 1 Oct 2020 04:08:39 +0000 (14:08 +1000)]
wdmks: ensure that pins that failed creation by PinNew() are set to NULL. Note that PaUtil_AllocateMemory currently calls GlobalAlloc without the GMEM_ZEROINIT flag, so there was no guarantee that filter->pins[pinId] was zero.
wasapi: Improve stability of playback in Polling Shared mode with a low host latency requsted (22 ms):
- Implement workaround for system timer coarse granularity causing underruns by using timeBeginPeriod/timeEndPeriod APIs inside the Event and Poll thread handlers.
- Update next sleep time of the Poll rendering loop dynamically depending on time taken for processing/rendering of audio data into the available host buffer to avoid underruns and fit processing time into periodic polling time slots.
- Add support for time slots logging in Poll mode if PA_WASAPI_LOG_TIME_SLOTS is defined. Fixed audible glitches by preloading the whole host buffer before stream is started.
- Fix audible glitches on stream start by preloading the whole host buffer before stream is started.
Ross Bencina [Mon, 13 May 2019 21:36:24 +0000 (07:36 +1000)]
follow up fix related to 933b05c331 (ticket #263 uninitialized dir variable): fix the three other places where dir parameter wasn't set prior to entry to a snd_pcm_*_get_* function. There is some ambiguity about (a) whether this is intentional (i.e. use the rounding dir returned by previous *_get_* call, the PA source code does not indicate), and (b) whether it is meaningful (i.e. whether *_get_* functions actually use the value upon input -- the ALSA docs are not clear. regarding (a): I don't think it's intentional, i think it was just oversight. In any case thr risk is low: the underlying values of period_size, periods_max, periods_min, are all integer and should not be rounded, get_rate_min/get_rate_max are used only for debug reporting (I've set them to 0,0 for a minimal change from the current code, but -1,1 makes more sense).
wasapi: Add paWinWasapiAutoConvert flag, which sets AUDCLNT_STREAMFLAGS_AUTOCONVERTPCM | AUDCLNT_STREAMFLAGS_SRC_DEFAULT_QUALITY for Shared mode streams.
AUDCLNT_STREAMFLAGS_AUTOCONVERTPCM is required in order to allow for sample rates other than the system mixer configured sample rate. Otherwise, WASAPI is limited to a single system configured sample rate in Shared mode, which is a severe limitation compared to other APIs supported by PortAudio.
AUDCLNT_STREAMFLAGS_SRC_DEFAULT_QUALITY is recommended to be used additionally.
See <https://docs.microsoft.com/en-us/windows/desktop/coreaudio/audclnt-streamflags-xxx-constants> for documentation.
GetClosestFormat is modified to exit early when paWinWasapiAutoConvert is set in Shared mode because we trust the WASAPI conversions to succeed.
We restrict these changes to Windows 7 (and later) because documentation does not clearly state the minimum required Windows version. Windows Vista was not available for testing.
This patch has been in production in OpenMPT (<https://openmpt.org/>) since version 1.27.01.00 (2017-09-27). PortAudio WASAPI Shared mode is the default output device type in OpenMPT for Windows 7 (and later) and also for Wine setups.
dmitrykos [Sat, 9 Mar 2019 10:43:14 +0000 (12:43 +0200)]
wasapi: set IAudioClient2+ properties before GetClosestFormat() in order to avoid failing with unsupported format error if PaWasapiStreamCategory is other than default, for example eAudioCategorySpeech
dmitrykos [Sat, 23 Feb 2019 21:02:38 +0000 (23:02 +0200)]
wasapi: Improved audio output stability in Exclusive mode for some UAC2 DACs with custom USB Audio driver by calculating buffer periodicity being equal (or almost equal) to the requested user frames (Capturing is excluded from this implementation as it has not yet been tested but can be included if tests show the improvement), cleanup/refactor some code to make it better readable
dmitrykos [Mon, 24 Dec 2018 12:20:29 +0000 (14:20 +0200)]
wasapi: new API PaWasapi_SetStreamStateHandler() to be able to catch WASAPI error inside the rendering thread loop (and handle it gracefully, for example restart the stream), protect from dangling pointer during device list update, cleanup header
Etienne Dechamps [Sun, 25 Nov 2018 10:28:56 +0000 (10:28 +0000)]
Treat DirectSound just like any other standard Windows SDK library.
Currently the CMake build system goes through complicated logic to
find the DirectX SDK. This is completely unnecessary, because modern
versions of the Windows SDK include dsound.h and dsound.lib in the
standard paths, so it can be treated just like the other Windows OS
libraries and we can safely assume it is available.
This commit simplifies the logic and will allow the vcpkg portaudio
port to align with portaudio stream, by getting rid of this patch:
https://github.com/Microsoft/vcpkg/blob/95f9ce56f32618cceda97d54af16e3d6c57fc4b3/ports/portaudio/find_dsound.patch
I have verified that PortAudio CMake still builds with this commit
with the following toolchains:
- Windows Visual Studio 2017 native CMake support
- mingw-w64 on Windows (msys2)
- mingw-w64 cross-compiling from Debian Unstable
dmitrykos [Wed, 12 Dec 2018 21:29:44 +0000 (23:29 +0200)]
wasapi: relax check for a latency range when deciding to switch from Event to Poll mode to have 1-21 ms range fine tuneable, add check for a min period when correcting period for UAC1 devices to avoid failure to initialize audio client due to invalid period error
dmitrykos [Mon, 10 Dec 2018 08:50:31 +0000 (10:50 +0200)]
wasapi: get channels count and sample rate from a mix format (IAudioClient::GetMixFormat) for a PaDeviceInfo to circumvent rare cases when WASAPI does not accept format provided PKEY_AudioEngine_DeviceFormat due to a wrong channel count (bug and solution reported by Etienne Dechamps (edechamps), discussion: http://app.assembla.com/spaces/portaudio/git/merge_requests/7024281), new PaWasapi_GetDeviceMixFormat API to get mix format provided by IAudioClient::GetMixFormat
WASAPI: fixed MonoToStereo converter could write beyond the allowed memory region if sample format is packed 24-bit integer, fixed DEF file by adding missing WASAPI API
dmitrykos [Sun, 21 Oct 2018 10:21:28 +0000 (13:21 +0300)]
wasapi: fixed MonoToStereo converter could write beyond the allowed memory region if sample format is packed 24-bit integer, fixed DEF file by adding missing WASAPI API