From: bruceperens Date: Fri, 25 Apr 2014 21:05:04 +0000 (+0000) Subject: Use the lightweight snd_pcm_avail_update() rather than snd_pcm_avail_delay(). X-Git-Url: http://git.whiteaudio.com/gitweb/?a=commitdiff_plain;h=f0a4471303f396d10ea04f9c195967e5b4cac3d5;p=freetel-svn-tracking.git Use the lightweight snd_pcm_avail_update() rather than snd_pcm_avail_delay(). This isn't guaranteed to synchronize with the hardware, at least on output, but apparently does enough so that in combination with poll() we are provided with period timing. git-svn-id: https://svn.code.sf.net/p/freetel/code@1566 01035d8c-6547-0410-b346-abe4f91aad63 --- diff --git a/freedv-server/source/platform/linux/audio_out_alsa.cpp b/freedv-server/source/platform/linux/audio_out_alsa.cpp index 433dcc37..b00d59e1 100644 --- a/freedv-server/source/platform/linux/audio_out_alsa.cpp +++ b/freedv-server/source/platform/linux/audio_out_alsa.cpp @@ -190,41 +190,14 @@ namespace FreeDV { std::size_t AudioOutALSA::ready() { - for ( unsigned int loop = 0; loop < 10; loop++ ) { - snd_pcm_sframes_t available = 0; - snd_pcm_sframes_t delay = 0; - - const int error = snd_pcm_avail_delay(handle, &available, &delay); - - // If we've not started, allow the first write to be large, but - // not so large that we'll active the overlong-delay code. - if ( !started ) - return AudioFrameSamples * MaximumDelayFrames - FillFrames - 1; - - if ( error ) { - if ( error == -EPIPE ) { - std::cerr << "ALSA output \"" << parameters << "\": ready underrun." << std::endl; - snd_pcm_drop(handle); - started = false; - } - else - do_throw(error, "Get Frames Available for Write"); - } - else if ( delay > (AudioFrameSamples * MaximumDelayFrames) ) { - const double seconds = (double)delay / (double)SampleRate; - - std::cerr << "ALSA output \"" << parameters - << "\": overlong delay, dropped " - << seconds << " seconds of output." << std::endl; - snd_pcm_drop(handle); - started = false; - continue; - } - else - return available; - } - do_throw(0, "Audio output stuck in ready()"); - return 0; // NOTREACHED. + const snd_pcm_sframes_t available = snd_pcm_avail_update(handle); + + // If we've not started, allow the first write to be large, but + // not so large that we'll active the overlong-delay code. + if ( !started ) + return AudioFrameSamples * MaximumDelayFrames - FillFrames - 1; + else + return available; } void