Multichannel Windows audio playback problems when C++ 2015-2022 redistributable libraries are installed

Warning to others.
I was using PsychPortAudio through matlab with 8 output channels but when I ported the experiment to another Windows 10 box, it consistently performed incorrectly in specific, reproducible scenarios.
It turned out that the problem was using the 2015-2022 redistributable C++ libraries.
When I switched to the 2015-2019 ones it all worked fine.

Not sure whether this is a bug or an incompatibility at some point - I’d be interested to hear if anyone has any thoughts on the matter - but I thought I’d flag it for others…

Thanks for that heads up to other Windows users of Matlab.

The Matlab mex files for Windows 10+ are currently built with MSVC 2019, and the recommended (and included into PTB’s PsychContributed/ subfolder for reference) runtime is the 2015-2019 one. But I’d have expected the 2015-2022 runtime to just work as well, it being just a superset of the 2015-2019 one. So probably some kind of Microsoft Windows / or MSVC compatibility bug. Or maybe whatever Matlab version you use could have some incompatibilities with 2015-2022 runtimes as well? I don’t know.

The current build system - and only test system for Matlab on Windows - is Windows 10 release 22H2 + MSVC 2019 + Matlab R2022b.

It might be helpful to others to give an idea about the specific, reproducible scenarios and what kind of problems happened, so they can recognize the symptoms.


Hi Mario,

Here’s some more info that may prove useful.

I’m running with R2021b on Windows 10 Enterprise - Intel i5-8500
I have a Creative SoundBlaster X4 USB connected surround sound box. This offers 4 stereo outputs which I split into left/right channels to drive 8 vibrating transducers (DancerDesign) but this can easily be replicated using 4 pairs of stero headphones.
I build a data buffer using MakeBeep() to create 8 rows (one per channel) x 9600 data points for a 0.2 second audio clip @ 48k.
Typlically some channels have a sample from a 100Hz sine wave and the others are all 0 for no sound.
Many combinations of channels being on/off work as expected however:
playing channel 1 & 2 together with 3-8 as 0 always plays 1,2 & 3.(4-8 no sound as expected)
Similarly, playing on only 7&8 results in output on channels 6 & 7&8. (1-5 no sound)
Here’s some sample code.

f = 100; %Hz
srate = 48000;
dur_s = 0.2;
nch = 8;
vol = 0.5;
dev_idx = 9;  % 9 for laptop; 6 for 1.1 pc

Beep = MakeBeep( f, dur_s, srate);
noBeep = zeros(1,length(Beep));

handle = PsychPortAudio('Open', dev_idx, 1, 1, srate, nch);
PsychPortAudio('Volume', handle, vol);

stim = [Beep; Beep; noBeep; noBeep; noBeep; noBeep; noBeep; noBeep];
PsychPortAudio('FillBuffer', handle, stim);

PsychPortAudio('Start', handle, 1, 1, 1);
jd=PsychPortAudio('Stop', handle, 1, 1);

PsychPortAudio('Close', handle);

Note the above errors only happen when I have the 2015-2022 redistributable C++ libraries installed. When I uninstalled them and reverted to the 2015-2019 everything worked as designed.

I doubled checked the PPA docs and don’t think I’m donig anything wrong but happy to be corrected if I am.
I also had a quick look at the psychportaudio C++ source code but unsurprisingly couldn’t see anything obvious (though it’s 20 years since I coded in C)

So, on the face of it it seems that some combination of the 2019-2022 libraries on my HP system with an intel i5-8500 has broken something from the 2015-2019 libs but other possibilities exist.

Hopefully it’s a mistake on my part that can be rectified but thought it was worth flagging in case others experience experience problems.

Please report back if you have anything to add,


That’s a weirdly specific failure that makes no sense at all. You didn’t do anything wrong there, neither is there anything in PTB, PsychPortAudio or the underlying portaudio_x64.dll that could cause this by itself. According to Microsoft docs, the 2015-2022 redistributable is supposed to be a fully backward compatible superset of the 2015-2019 one, so no such errors or bad interactions are to be expected. The current portaudio_x64.dll was last rebuilt for Psychtoolbox in October 2021 when Matlab R2021b was state of the art.

No idea what could cause this. Could be some interaction between Matlab dll’s and the MSVC libs, or also with some user-mode component of the Windows WASAPI sound drivers, or whatever. Afaict Matlab R2022b also assumes/ships MSVC 2019 runtime dll’s, not more recent ones…

Due to the lack of funding by our users, I can not afford spending time to track down such esoteric failure cases anymore. Even on Linux as the recommended operating system I have to cut back on quality and compatibility testing and let some things slip. Neither do I have access to any > 2 channel soundcard for testing.

I guess we’ll just let it sit here, and maybe sometime in the future some other bread-crumbs show up that point to some root cause or solution.


Actually some more thoughts that popped into my head today, if you want to try this - I won’t investigate any further for the time being:

Those MSVC redistributable runtimes are generally used by all applications / dll’s etc. on your system if those were built with MSVC. The problem doesn’t need to be related to PTB or portaudio at all, but could affect any multi-channel sound playback of any application on your system.

  • If the same problem would happen with PTB and Octave 7.3, that would rule out interference with Matlab’s dlls. I’m not sure without explicit checking, if those MSVC runtime are involved on the PPA side at all when used with Octave, as Octave is based on MinGW instead of MSVC, and MinGW provides its own different implementations of C/C++ runtime dlls.
  • If it happens also with the libportaudio.dll shipping with recent Matlab (see release announcement for PTB about that and how to use it) it would rule out anything specific to our bundled portaudio_x64.dll. It would also allow basic use of ASIO as another way to get multi-channel sound on Windows.
  • Playing with different reqlatencyclass parameter in PPA(‘Open’) for selection of different Windows audioo backends or modes of operation may also give different results or might side-step the issue if only certain Windows sound backends (e.g., WASAPI, but not MME) would be affected.

Ofc. in the future it will be difficult for users to avoid the MSVC 2015-2022 redistributables, as more other new applications will be built with MSVC 2022 and depend on (and automatically install) that package, and even so the choice would be between broken sound and broken other applications.