From 797a22d9749d9734b52ee10b04e0712992fd4fd9 Mon Sep 17 00:00:00 2001 From: Stephen Sinclair Date: Mon, 20 Dec 2010 16:23:05 -0500 Subject: [PATCH] ALSA: Don't set the number of periods unless it was requested in stream options. --- RtAudio.cpp | 25 +++++++++++++++---------- 1 files changed, 15 insertions(+), 10 deletions(-) diff --git a/RtAudio.cpp b/RtAudio.cpp index 78259e9..9823a9d 100644 --- a/RtAudio.cpp +++ b/RtAudio.cpp @@ -5677,16 +5677,21 @@ bool RtApiAlsa :: probeDeviceOpen( unsigned int device, StreamMode mode, unsigne } *bufferSize = periodSize; - if ( options && options->flags & RTAUDIO_MINIMIZE_LATENCY ) periods = 2; - else periods = totalSize / *bufferSize; - // Even though the hardware might allow 1 buffer, it won't work reliably. - if ( periods < 2 ) periods = 2; - result = snd_pcm_hw_params_set_periods_near( phandle, hw_params, &periods, &dir ); - if ( result < 0 ) { - snd_pcm_close( phandle ); - errorStream_ << "RtApiAlsa::probeDeviceOpen: error setting periods for device (" << name << "), " << snd_strerror( result ) << "."; - errorText_ = errorStream_.str(); - return FAILURE; + // Set the number of periods if requested + if ( options && (options->flags & RTAUDIO_MINIMIZE_LATENCY + || options->numberOfBuffers > 0) ) + { + if ( options && options->flags & RTAUDIO_MINIMIZE_LATENCY ) periods = 2; + else periods = totalSize / *bufferSize; + // Even though the hardware might allow 1 buffer, it won't work reliably. + if ( periods < 2 ) periods = 2; + result = snd_pcm_hw_params_set_periods_near( phandle, hw_params, &periods, &dir ); + if ( result < 0 ) { + snd_pcm_close( phandle ); + errorStream_ << "RtApiAlsa::probeDeviceOpen: error setting periods for device (" << name << "), " << snd_strerror( result ) << "."; + errorText_ = errorStream_.str(); + return FAILURE; + } } // If attempting to setup a duplex stream, the bufferSize parameter -- 1.7.1