Use the lightweight snd_pcm_avail_update() rather than snd_pcm_avail_delay().
authorbruceperens <bruceperens@01035d8c-6547-0410-b346-abe4f91aad63>
Fri, 25 Apr 2014 21:05:04 +0000 (21:05 +0000)
committerbruceperens <bruceperens@01035d8c-6547-0410-b346-abe4f91aad63>
Fri, 25 Apr 2014 21:05:04 +0000 (21:05 +0000)
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

freedv-server/source/platform/linux/audio_out_alsa.cpp

index 433dcc37c566ff0b1789f2a85804fdc43a88dd60..b00d59e1d9615ac5d8d680e1e1751ca8148106af 100644 (file)
@@ -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