PortAudio / portaudio

PortAudio is a cross-platform, open-source C language library for real-time audio input and output.
Other
1.39k stars 291 forks source link

PaStreamParameters suggestedLatency < 0.0 behavior is not specified and not handled correctly #856

Open RossBencina opened 9 months ago

RossBencina commented 9 months ago

The documentation for PaStreamParameters suggestedLatency does not mention negative latencies.

I have not reviewed all host APIs but at least pa_win_wmme.c and pa_win_ds.c assume that suggestedLatency is non-negative, and directly assign to an unsigned long (BAD!!), for example in pa_win_ds.c:

unsigned long suggestedInputLatencyFrames, suggestedOutputLatencyFrames;
...
suggestedInputLatencyFrames = (unsigned long)(inputParameters->suggestedLatency * sampleRate);
...
suggestedOutputLatencyFrames = (unsigned long)(outputParameters->suggestedLatency * sampleRate);

There is equivalent code in pa_win_wmme.c.

The fix should be to clamp to 0, e.g.

if (inputParameters->suggestedLatency >= 0.0)
   suggestedInputLatencyFrames = (unsigned long)(inputParameters->suggestedLatency * sampleRate);
else
   suggestedInputLatencyFrames = 0;

TODO:

There is already a PR which will fix this for PA/PulseAudio #849

RossBencina commented 5 months ago

Related #99