More fixes for audio output overrun.
authorbruceperens <bruceperens@01035d8c-6547-0410-b346-abe4f91aad63>
Wed, 28 May 2014 19:01:08 +0000 (19:01 +0000)
committerbruceperens <bruceperens@01035d8c-6547-0410-b346-abe4f91aad63>
Wed, 28 May 2014 19:01:08 +0000 (19:01 +0000)
git-svn-id: https://svn.code.sf.net/p/freetel/code@1602 01035d8c-6547-0410-b346-abe4f91aad63

freedv-server/source/codec2.cpp
freedv-server/source/drivers.h
freedv-server/source/platform/linux/alsa.cpp
freedv-server/source/platform/linux/audio_in_alsa.cpp
freedv-server/source/run.cpp
freedv-server/source/tone.cpp

index 44c5c0f3611db63325e83d8d458b093b9a6128d1..e1b0bd12913f34d72ffeb772f932b1b18cada271 100644 (file)
@@ -163,7 +163,7 @@ namespace FreeDV {
   static std::ostream &
   Codec2Enumerator(std::ostream & stream)
   {
-    stream << "\"codec2:1400\" (1200,1300,1400,1600,2400,3200)" << std::endl;
+    stream << "\"codec2:1600\" (1200,1300,1400,1600,2400,3200)" << std::endl;
     return stream;
   }
 
index a8a233a64d80eb70ff9648bf8b1b188f019c6b7a..0682e5b800a58956c43a78429d5b7833ce4d0470 100644 (file)
@@ -59,21 +59,21 @@ const unsigned int  SampleRate = 48000;
 ///
 const unsigned int     SamplesPerMillisecond = ((double)SampleRate / 1000.0);
 
-/// The audio frame duration in milliseconds. The audio interfaces will
-/// use this as a period size. It should be 1/2 of the smallest codec frame
-/// size we expect to use.
-const unsigned int     AudioFrameDuration = 10;
 
 /// The number of audio samples in an audio frame. Audio frames must be a
 /// power of two (this is a common hardware requirement) and must be shorter
 /// than any codec/modem frame in the program.
 const unsigned int     AudioFrameSamples = 512;
 
+/// The audio frame duration in milliseconds. The audio interfaces will
+/// use this as a period size.
+const unsigned int     AudioFrameDuration = ((double)SampleRate / (double)AudioFrameSamples);
+
 /// The number of audio samples in the maximum-duration frame.
 /// This must be a power of two (this is a common hardware requirement) and
 /// must be at least twice the value of AudioFrameSamples.
 ///
-const unsigned int     MaximumFrameSamples = 32768;
+const unsigned int     MaximumFrameSamples = AudioFrameSamples * 2;
 
 /// Allocate memory and copy a string into it, so that it is permanently
 /// stored.
index 5ce142d2966a4c947d9b0a87600576e43c933a8b..e38c46a8c8bccaab2e47320bab9f33a195230898 100644 (file)
@@ -233,15 +233,18 @@ namespace FreeDV {
  
     error = open_by_longname(&handle, name, stream, mode);
     if ( error < 0 ) {
-      error = snd_pcm_open(
-       &handle,
-       name,
-       stream,
-       mode);
-
-       if ( error < 0 )
-         return 0;
+      if ( strcmp(name, "default") == 0
+      || strncmp(name, "hw:", 3) == 0
+      || strncmp(name, "plughw:", 7) == 0 ) {
+        error = snd_pcm_open(
+         &handle,
+         name,
+         stream,
+         mode);
+      }
     }
+    if ( error < 0 )
+      return 0;
  
     try {
       if ( (error = snd_pcm_hw_params_malloc(&hw_params)) < 0 )
index 0bd9174d13440cd55ede21a1bea061d82d3fd27a..e5a194f683673922b9cf095bcedbfec2b8f90536 100644 (file)
@@ -23,7 +23,7 @@ namespace FreeDV {
   ///
   class AudioInALSA : public AudioInput {
   private:
-    static const int   overlong_delay = AudioFrameSamples * 4;
+    static const int   overlong_delay = AudioFrameSamples * 8;
 
     snd_pcm_t *                handle;
     char * const       parameters;
index 46e25b46f778509568a70d683141252cacab2dca..52231027a6f3c814c1509c4617c9ba40e107b5ac 100644 (file)
@@ -363,6 +363,7 @@ namespace FreeDV {
     }
 
     if ( out_fifo.get_available() > 0 ) {
+      // std::cerr << out_fifo.get_available() / 2 << ' ';
       // There are samples queued for the loudspeaker. Wake when there is room
       // in its buffer.
       if ( output_fd_base < 0 ) {
@@ -441,7 +442,7 @@ namespace FreeDV {
         struct timespec        request;
         struct timespec remainder;
         request.tv_sec = 0;
-        request.tv_nsec = AudioFrameDuration * 1000000;
+       request.tv_nsec = AudioFrameDuration * 1000000;
         nanosleep(&request, &remainder);
       }
 
index 12e4aac357820dea83b53cbb05387ccdab5f39e1..d2c66c26cbd03370fa74f70f4ea2577d3d6370be 100644 (file)
@@ -17,7 +17,7 @@ namespace FreeDV {
   ///
   class Tone : public AudioInput {
   private:
-    unsigned int       clock;
+    unsigned long long clock;
 
     struct tone_info {
       float    frequency;
@@ -133,7 +133,7 @@ namespace FreeDV {
        value * master_amplitude * ((1 << 15) - 1));
       array[i] = v;
     }
-    clock = (clock + length) % SampleRate;
+    clock = (clock + length);
 
     return length;
   }