Synopsis:

  The alsa driver wasn't working, it would only write a partial buffer
  before returning from _WriteBytes(). This resulted in an assert for
  debug builds and choppy cricket sounds for release builds. The
  following patch fixes this by making ALSA write the whole buffer
  before returning.

  I have noticed that the ALSA driver uses about 100% cpu on my system
  when using ALSA as opposed to OSS which uses only about 20%. The
  increase is all SYS time as oppose to user time. The user time for
  both OSS and ALSA are the same.



Files Modified:

           audio/device/platform/unix/audlinux_alsa.cpp


Platforms and Profiles Affected:

          linux only.


Branch: HEAD, 150Cay(after branch).



Index: platform/unix/audlinux_alsa.cpp
===================================================================
RCS file: /cvsroot/audio/device/platform/unix/audlinux_alsa.cpp,v
retrieving revision 1.4
diff -u -w -r1.4 audlinux_alsa.cpp
--- platform/unix/audlinux_alsa.cpp     28 Sep 2004 21:04:17 -0000      1.4
+++ platform/unix/audlinux_alsa.cpp     8 Mar 2005 19:48:44 -0000
@@ -856,6 +856,8 @@
     int err = 0;
     unsigned int frames_written = 0;
     snd_pcm_sframes_t num_frames;
+    ULONG32 ulBytesToWrite = ulBuffLength;
+    ULONG32 ulBytesWrote = 0;

     lCount = 0;

@@ -874,15 +876,19 @@
         return m_wLastError;
     }

-    num_frames = snd_pcm_bytes_to_frames(m_pAlsaPCMHandle, ulBuffLength);

     do
     {
+        num_frames = snd_pcm_bytes_to_frames(m_pAlsaPCMHandle, ulBytesToWrite);
         err = snd_pcm_writei( m_pAlsaPCMHandle, buffer, num_frames );
+
         if (err >= 0)
         {
             frames_written = err;
-            lCount = snd_pcm_frames_to_bytes (m_pAlsaPCMHandle, 
frames_written);
+            ulBytesWrote = snd_pcm_frames_to_bytes (m_pAlsaPCMHandle, 
frames_written);
+            buffer += ulBytesWrote;
+            ulBytesToWrite -= ulBytesWrote;
+            lCount += ulBytesWrote;
         }
         else
         {
@@ -906,8 +912,9 @@
                 m_wLastError = RA_AOE_DEVBUSY;
             }
         }
-    } while (err == -EAGAIN);
+    } while (err == -EAGAIN || (err>0 && ulBytesToWrite>0));

+    HX_ASSERT( lCount == ulBuffLength );
     return m_wLastError;
 }


_______________________________________________ Audio-dev mailing list [email protected] http://lists.helixcommunity.org/mailman/listinfo/audio-dev

Reply via email to