More tuning so that more devices work correctly.
authorbruceperens <bruceperens@01035d8c-6547-0410-b346-abe4f91aad63>
Thu, 20 Mar 2014 00:02:51 +0000 (00:02 +0000)
committerbruceperens <bruceperens@01035d8c-6547-0410-b346-abe4f91aad63>
Thu, 20 Mar 2014 00:02:51 +0000 (00:02 +0000)
git-svn-id: https://svn.code.sf.net/p/freetel/code@1457 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 dc91065412602b7f7fb9f48db84c020e1c5719f1..8dd56e1a1c5aa440d209b9f5b4dd850a0c871222 100644 (file)
@@ -85,7 +85,8 @@ namespace FreeDV {
   open_by_longname(
    snd_pcm_t * *       handle,
    const char *                name,
-   snd_pcm_stream_t    stream)
+   snd_pcm_stream_t    stream,
+   int                 mode)
   {
     const int  length = strlen(name);
     int                card_index = -1;
@@ -100,8 +101,8 @@ namespace FreeDV {
   
       if ( snd_card_get_longname(card_index, &longname) == 0 ) {
         if ( strncmp(name, longname, length) == 0 ) {
-          sprintf(device_name, "hw:%d", card_index);
-          return snd_pcm_open(handle, device_name, stream, 0);
+          sprintf(device_name, "plughw:%d", card_index);
+          return snd_pcm_open(handle, device_name, stream, mode);
         }
       }
     }
@@ -148,13 +149,13 @@ namespace FreeDV {
     snd_pcm_t *                handle = 0;
     snd_pcm_hw_params_t *      hw_params = 0;
  
-    error = open_by_longname(&handle, name, stream);
+    error = open_by_longname(&handle, name, stream, mode);
     if ( error < 0 ) {
       error = snd_pcm_open(
        &handle,
        name,
        stream,
-       0);
+       mode);
 
        if ( error < 0 )
          return 0;
index ab43998b1ae8337c490bcd4b50b448510e4e8d6f..26d7fad9889c3689a3b8c4c7599f8b582123552c 100644 (file)
@@ -14,7 +14,7 @@ namespace FreeDV {
   /// Audio input "ALSA", Uses the Linux ALSA Audio API.
   class AudioInALSA : public AudioInput {
   private:
-    static const int   overlong_delay = AudioFrameSamples * 2;
+    static const int   overlong_delay = AudioFrameSamples * 10;
 
     char * const       parameters;
     snd_pcm_t *                handle;
@@ -66,8 +66,8 @@ namespace FreeDV {
      SND_PCM_ACCESS_RW_INTERLEAVED,
      1,
      SampleRate,
-     AudioFrameSamples / 2,
-     AudioFrameSamples);
+     AudioFrameSamples,
+     AudioFrameSamples * 2);
 
     if ( handle == 0 )
       do_throw(-ENODEV);
index d9e30c357482c03f4d187063a9094f6ba372cfe5..556ca6b915e520cdf41d1872bd0e0b2c4e0a30e1 100644 (file)
@@ -66,8 +66,8 @@ namespace FreeDV {
      SND_PCM_ACCESS_RW_INTERLEAVED,
      1,
      SampleRate,
-     AudioFrameSamples / 2,
-     AudioFrameSamples);
+     AudioFrameSamples,
+     AudioFrameSamples * 2);
 
     if ( handle == 0 )
       do_throw(-ENODEV);
@@ -85,10 +85,10 @@ namespace FreeDV {
   AudioOutALSA::write16(const std::int16_t * array, std::size_t length)
   {
     if ( !started ) {
-      // Preload the audio output queue with one frame of silence. This makes
-      // underruns less likely. This delays the output by one frame from where
-      // we would otherwise have started it. Otherwise we tend to underrun
-      // repeatedly at startup time.
+      // Preload the audio output queue with two frames of silence. This makes
+      // underruns less likely. This delays the output from where we would
+      // otherwise have started it. Otherwise we tend to underrun repeatedly
+      // at startup time.
       //
       // Note that all inputs and outputs of the typical user do not run on
       // a shared clock. There is the potential for overruns or underruns
@@ -96,7 +96,7 @@ namespace FreeDV {
       // a shared clock, and the more expensive equipment that supports it,
       // to avoid this problem.
       //
-      int16_t  buf[AudioFrameSamples];
+      int16_t  buf[AudioFrameSamples * 2];
       memset(buf, 0, sizeof(buf));
       snd_pcm_writei(handle, buf, sizeof(buf) / sizeof(*buf));
     }
@@ -153,7 +153,7 @@ namespace FreeDV {
       return AudioFrameSamples;
 
     error = snd_pcm_avail_delay(handle, &available, &delay);
-    if ( delay > (AudioFrameSamples * 3) ) {
+    if ( delay > (AudioFrameSamples * 10) ) {
       const double seconds = (double)delay / (double)SampleRate;
 
       std::cerr << "ALSA output \"" << parameters