Implement start/stop for ALSA devices.
authorbruceperens <bruceperens@01035d8c-6547-0410-b346-abe4f91aad63>
Tue, 22 Apr 2014 02:03:53 +0000 (02:03 +0000)
committerbruceperens <bruceperens@01035d8c-6547-0410-b346-abe4f91aad63>
Tue, 22 Apr 2014 02:03:53 +0000 (02:03 +0000)
git-svn-id: https://svn.code.sf.net/p/freetel/code@1543 01035d8c-6547-0410-b346-abe4f91aad63

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

index 78abee62b32d578c94273196514e5d9dda8d50c1..b5af2f3e4d3fe40f6266ec39abfa736419bbfcec 100644 (file)
@@ -58,6 +58,17 @@ namespace FreeDV {
         /// Read audio from the "short" type.
        virtual std::size_t
                read16(std::int16_t * array, std::size_t length);
+
+        /// Start the audio device.
+        /// Input devices: start digitizing samples for the program to
+       /// subsequently read.
+        virtual void
+               start();
+    
+        /// Stop the audio device.
+        /// Input devices: stop digitizing samples.
+        virtual void
+               stop();
   };
 
   AudioInALSA::AudioInALSA(const char * p)
@@ -151,10 +162,7 @@ namespace FreeDV {
     int                        error;
 
     if ( !started ) {
-      snd_pcm_drop(handle);
-      snd_pcm_prepare(handle);
-      snd_pcm_start(handle);
-      started = true;
+      start();
       return AudioFrameSamples;
     }
 
@@ -190,6 +198,21 @@ namespace FreeDV {
       do_throw(error, "Get Frames Available for Read");
   }
 
+  void
+  AudioInALSA::start()
+  {
+    snd_pcm_drop(handle);
+    snd_pcm_prepare(handle);
+    snd_pcm_start(handle);
+    started = true;
+  }
+
+  void
+  AudioInALSA::stop()
+  {
+    snd_pcm_drop(handle);
+  }
+
   static bool
   initializer()
   {
index b22607fced37deea6efd66afbfa3b9ed2401ad75..3589f154ced95f0bad64b2b00fb2982f99947100 100644 (file)
@@ -54,6 +54,16 @@ namespace FreeDV {
         virtual std::size_t
                ready();
 
+        /// Start the audio device.
+        /// Output devices: prepare for samples to be sent.
+        virtual void
+               start();
+    
+        /// Stop the audio device.
+        /// Output devices: stop playing samples.
+        virtual void
+               stop();
+
         /// Write audio from the "short" type.
        virtual std::size_t
                write16(const std::int16_t * array, std::size_t length);
@@ -195,6 +205,20 @@ namespace FreeDV {
       do_throw(error, "Get Frames Available for Write");
   }
 
+  void
+  AudioOutALSA::start()
+  {
+    snd_pcm_drop(handle);
+    snd_pcm_prepare(handle);
+    started = true;
+  }
+
+  void
+  AudioOutALSA::stop()
+  {
+    snd_pcm_drop(handle);
+  }
+
   static bool
   initializer()
   {