Connect ready() to ALSA. Fix pedantic bug in alsa.cpp .
authorbruceperens <bruceperens@01035d8c-6547-0410-b346-abe4f91aad63>
Sun, 9 Mar 2014 22:07:21 +0000 (22:07 +0000)
committerbruceperens <bruceperens@01035d8c-6547-0410-b346-abe4f91aad63>
Sun, 9 Mar 2014 22:07:21 +0000 (22:07 +0000)
git-svn-id: https://svn.code.sf.net/p/freetel/code@1421 01035d8c-6547-0410-b346-abe4f91aad63

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

index 792c3d4e756fc9fadc26ae0ca859b8860cbe9c62..5dface7064b809af4aef57dcabfc9424ced4a125 100644 (file)
@@ -70,4 +70,4 @@ namespace FreeDV {
   
     return stream;
   }
-};
+}
index 808136e0cc36e892a9f3acdb5b5571fd3ec547a2..084581f4cee2f9c09c8acd4f16d4afc11320cf4e 100644 (file)
@@ -2,6 +2,7 @@
 
 #include "drivers.h"
 #include <alsa/asoundlib.h>
+#include <sys/ioctl.h>
 #include <sstream>
 #include <stdexcept>
 
@@ -15,12 +16,12 @@ namespace FreeDV {
 
   public:
 
-       /// Instantiate the audio sink.
+       /// Instantiate the ALSA audio input.
                AudioInALSA(const char * parameters);
                ~AudioInALSA();
 
-       /// Return the number of audio samples the device can handle in
-       /// a write without blocking.
+       /// Return the number of audio samples the device can provide in
+       /// a read without blocking.
         virtual std::size_t
                ready();
 
@@ -48,9 +49,9 @@ namespace FreeDV {
 
   AudioInALSA::~AudioInALSA()
   {
+    snd_pcm_close(handle);
   }
 
-  // Read audio into the "short" type.
   std::size_t
   AudioInALSA::read16(std::int16_t * array, std::size_t length)
   {
@@ -72,7 +73,12 @@ namespace FreeDV {
   std::size_t
   AudioInALSA::ready()
   {
-    return SIZE_MAX;
+    snd_pcm_sframes_t  available = 0;
+
+    if ( (available = snd_pcm_avail(handle)) <= 0 )
+      return available;
+    else
+      return 0;
   }
 
   static bool
index af12e0c0f06524b552120b7d8252113b4fe09784..623dd234b7f4ab301831d0b28d44f8789067449d 100644 (file)
@@ -2,20 +2,21 @@
 
 #include "drivers.h"
 #include <alsa/asoundlib.h>
+#include <sys/ioctl.h>
 #include <sstream>
 #include <stdexcept>
 
 namespace FreeDV {
   std::ostream & ALSAEnumerate(std::ostream & stream, snd_pcm_stream_t mode);
 
-  /// Audio output "sink", discards the audio, for testing.
+  /// Audio output "ALSA", Uses the Linux ALSA Audio API.
   class AudioOutALSA : public AudioOutput {
   private:
     snd_pcm_t * handle;
 
   public:
 
-       /// Instantiate the audio sink.
+       /// Instantiate the audio output.
                AudioOutALSA(const char * parameters);
                ~AudioOutALSA();
 
@@ -24,7 +25,7 @@ namespace FreeDV {
         virtual std::size_t
                ready();
 
-        /// Write audio into the "short" type.
+        /// Write audio from the "short" type.
        virtual std::size_t
                write16(const std::int16_t * array, std::size_t length);
   };
@@ -48,6 +49,7 @@ namespace FreeDV {
 
   AudioOutALSA::~AudioOutALSA()
   {
+    snd_pcm_close(handle);
   }
 
   // Write audio into the "short" type.
@@ -72,7 +74,12 @@ namespace FreeDV {
   std::size_t
   AudioOutALSA::ready()
   {
-    return SIZE_MAX;
+    snd_pcm_sframes_t  available = 0;
+
+    if ( (available = snd_pcm_avail(handle)) <= 0 )
+      return available;
+    else
+      return 0;
   }
 
   static bool