Appending patch....

On Fri, Jun 20, 2008 at 8:15 AM, Rusty Lynch <[EMAIL PROTECTED]> wrote:
> Description
> ----------------------------------
> When attempting to play audio via ALSA with a bluetooth headset,
> the audio quality is extremely poor.  This is due to the fact that the
> bluez-utiles implementation need for audio to be sent with buffer frame sizes
> that are aligned with channels*sample-width*bits-per-sample.
>
> The following patch will isolated the audio session buffer creation
> code such that an ALSA based implementation will force the audio buffer
> size to work for the above conditions.
>
> This will fix https://bugs.helixcommunity.org/show_bug.cgi?id=8405
>
> Files Modified
> ----------------------------------
> client/audiosvc/hxaudses.cpp
>
> Branches
> ---------------------------------
> HEAD, Atlas310, Atlas341
>
>
>
>  --rusty
>



-- 

 --rusty
Description
----------------------------------
When attempting to play audio via ALSA with a bluetooth headset,
the audio quality is extremely poor.  This is due to the fact that the 
bluez-utiles implementation need for audio to be sent with buffer frame sizes
that are aligned with channels*sample-width*bits-per-sample.

The following patch will isolated the audio session buffer creation 
code such that an ALSA based implementation will force the audio buffer
size to work for the above conditions.

This will fix https://bugs.helixcommunity.org/show_bug.cgi?id=8405

Files Modified
----------------------------------
client/audiosvc/hxaudses.cpp

Branches
---------------------------------
HEAD, Atlas310, Atlas341

Index: hxaudses.cpp
===================================================================
RCS file: /cvsroot/client/audiosvc/hxaudses.cpp,v
retrieving revision 1.79.2.1
diff -u -r1.79.2.1 hxaudses.cpp
--- hxaudses.cpp	3 Oct 2007 17:23:30 -0000	1.79.2.1
+++ hxaudses.cpp	20 Jun 2008 14:52:42 -0000
@@ -2065,13 +2065,14 @@
         (((m_DeviceFmt.uChannels * ((m_DeviceFmt.uBitsPerSample==8)?1:2) *  m_DeviceFmt.ulSamplesPerSec)
           / 1000.0) * m_ulGranularity);
 
+    ULONG32 ulExtraGranularity = 1;
+#if !defined(HELIX_FEATURE_ALSA)
     /* Number of samples required at output should be a multiple of 8 if
      * sampling rate is 8K/16K/32K...or a multiple of 11 for 11K/22K...
      * This is needed since the resamplerequires works reliably ONLY if
      * this condition is true. Ken is working on this problem. This is
      * an interim fix
      */
-    ULONG32 ulExtraGranularity = 1;
     if (m_DeviceFmt.ulSamplesPerSec % 8 == 0)
     {
         ulExtraGranularity = 8;
@@ -2090,7 +2091,22 @@
  ((m_DeviceFmt.uBitsPerSample==8)?1:2) * m_DeviceFmt.ulSamplesPerSec)
                                                  / 1000.0);
     }
- 
+#else // HELIX_FEATURE_ALSA
+    /* For some ALSA configurations (like when using a bluetooth headset)
+     * holing unaligned audio frames will result in audio distortion
+     */
+    ulExtraGranularity = 8;
+    ULONG32 ulFrames = m_ulBytesPerGran * 8/(m_DeviceFmt.uChannels * m_DeviceFmt.uBitsPerSample);
+    ULONG32 ulMultiple = 2 * ulExtraGranularity * m_DeviceFmt.uChannels;
+
+    if ((ulFrames % ulMultiple) != 0)
+    {
+	ulFrames -= ulFrames % ulMultiple;
+	m_ulBytesPerGran = ulFrames * (m_DeviceFmt.uChannels * m_DeviceFmt.uBitsPerSample)/8;
+	m_dGranularity = (double) m_ulBytesPerGran / (double)((double)(m_DeviceFmt.uChannels * ((m_DeviceFmt.uBitsPerSample==8)?1:2) * m_DeviceFmt.ulSamplesPerSec) / 1000.0);
+    }
+#endif
+    
     // Readjust the max size of the block
     m_ActualDeviceFmt.uMaxBlockSize = (UINT16) m_ulBytesPerGran;
 
_______________________________________________
Audio-dev mailing list
[email protected]
http://lists.helixcommunity.org/mailman/listinfo/audio-dev

Reply via email to