F:\PortAudio\portaudio>git diff
diff --git a/src/hostapi/alsa/pa_linux_alsa.c b/src/hostapi/alsa/pa_linux_alsa.c
index d642ba0..e23a423 100644
--- a/src/hostapi/alsa/pa_linux_alsa.c
+++ b/src/hostapi/alsa/pa_linux_alsa.c
@@ -850,6 +850,7 @@ static PaError GropeDevice( snd_pcm_t* pcm, int isPlug, StreamDirection mode, in
PaError result = paNoError;
snd_pcm_hw_params_t *hwParams;
snd_pcm_uframes_t alsaBufferFrames, alsaPeriodFrames;
+ int nearDir = 0;
unsigned int minChans = 0;
unsigned int maxChans = 0;
int* minChannels, * maxChannels;
@@ -960,7 +961,8 @@ static PaError GropeDevice( snd_pcm_t* pcm, int isPlug, StreamDirection mode, in
alsaBufferFrames = 512;
alsaPeriodFrames = 128;
ENSURE_( alsa_snd_pcm_hw_params_set_buffer_size_near( pcm, hwParams, &alsaBufferFrames ), paUnanticipatedHostError );
- ENSURE_( alsa_snd_pcm_hw_params_set_period_size_near( pcm, hwParams, &alsaPeriodFrames, NULL ), paUnanticipatedHostError );
+ nearDir = 0;
+ ENSURE_( alsa_snd_pcm_hw_params_set_period_size_near( pcm, hwParams, &alsaPeriodFrames, &nearDir ), paUnanticipatedHostError );
*defaultLowLatency = (double) (alsaBufferFrames - alsaPeriodFrames) / defaultSr;
/* Base the high latency case on values four times larger */
@@ -971,7 +973,8 @@ static PaError GropeDevice( snd_pcm_t* pcm, int isPlug, StreamDirection mode, in
ENSURE_( SetApproximateSampleRate( pcm, hwParams, &approximateSampleRate ), paUnanticipatedHostError );
defaultSr = (double) approximateSampleRate;
ENSURE_( alsa_snd_pcm_hw_params_set_buffer_size_near( pcm, hwParams, &alsaBufferFrames ), paUnanticipatedHostError );
- ENSURE_( alsa_snd_pcm_hw_params_set_period_size_near( pcm, hwParams, &alsaPeriodFrames, NULL ), paUnanticipatedHostError );
+ nearDir = 0;
+ ENSURE_( alsa_snd_pcm_hw_params_set_period_size_near( pcm, hwParams, &alsaPeriodFrames, &nearDir ), paUnanticipatedHostError );
*defaultHighLatency = (double) (alsaBufferFrames - alsaPeriodFrames) / defaultSr;
*minChannels = (int)minChans;
As part of our review of #524 we notice that
GropeDeviceis passingNULLfor thealsa_snd_pcm_hw_params_set_period_size_neardirection parameter (lower/higher/match). We're not sure about that. Was changed from uninitialized var to NULL in #268Possibly we should change it to pass the address of an int set to zero (see patch below) -- rationale being to match what we do when opening the stream. However it is unclear whether this would give the same behavior. The ALSA docs don't mention passing NULL: https://www.alsa-project.org/alsa-doc/alsa-lib/pcm_2pcm_8c.html#a9162045265f283c532634506456cab09 however the test program linked by the ALSA docs does pass
NULL(written as0): https://www.alsa-project.org/alsa-doc/alsa-lib/_2test_2latency_8c-example.html#a14Note that alsa-lib seems to treat passing
NULLthe same as passing&intwhereint dir=0;