@@ -1750,63 +1750,29 @@ static void CalculateBufferSettings( unsigned long *hostBufferSizeFrames,
1750
1750
unsigned long maximumPollingPeriodFrames = (unsigned long )(sampleRate * PA_DS_MAXIMUM_POLLING_PERIOD_SECONDS );
1751
1751
unsigned long pollingJitterFrames = (unsigned long )(sampleRate * PA_DS_POLLING_JITTER_SECONDS );
1752
1752
1753
- if ( userFramesPerBuffer == paFramesPerBufferUnspecified )
1753
+ unsigned long adjustedSuggestedOutputLatencyFrames = suggestedOutputLatencyFrames ;
1754
+ if ( userFramesPerBuffer != paFramesPerBufferUnspecified && isFullDuplex )
1754
1755
{
1755
- unsigned long targetBufferingLatencyFrames = max ( suggestedInputLatencyFrames , suggestedOutputLatencyFrames );
1756
-
1757
- * pollingPeriodFrames = targetBufferingLatencyFrames / 4 ;
1758
- if ( * pollingPeriodFrames < minimumPollingPeriodFrames )
1759
- {
1760
- * pollingPeriodFrames = minimumPollingPeriodFrames ;
1761
- }
1762
- else if ( * pollingPeriodFrames > maximumPollingPeriodFrames )
1763
- {
1764
- * pollingPeriodFrames = maximumPollingPeriodFrames ;
1765
- }
1766
-
1767
- * hostBufferSizeFrames = * pollingPeriodFrames
1768
- + max ( * pollingPeriodFrames + pollingJitterFrames , targetBufferingLatencyFrames );
1756
+ /* In full duplex streams we know that the buffer adapter adds userFramesPerBuffer
1757
+ extra fixed latency. so we subtract it here as a fixed latency before computing
1758
+ the buffer size. being careful not to produce an unrepresentable negative result.
1759
+ */
1760
+ adjustedSuggestedOutputLatencyFrames -= min ( userFramesPerBuffer , adjustedSuggestedOutputLatencyFrames );
1769
1761
}
1770
- else
1771
- {
1772
- unsigned long targetBufferingLatencyFrames = suggestedInputLatencyFrames ;
1773
- if ( isFullDuplex )
1774
- {
1775
- /* In full duplex streams we know that the buffer adapter adds userFramesPerBuffer
1776
- extra fixed latency. so we subtract it here as a fixed latency before computing
1777
- the buffer size. being careful not to produce an unrepresentable negative result.
1778
1762
1779
- Note: this only works as expected if output latency is greater than input latency.
1780
- Otherwise we use input latency anyway since we do max(in,out).
1781
- */
1763
+ const unsigned long targetBufferingLatencyFrames = max ( suggestedInputLatencyFrames , adjustedSuggestedOutputLatencyFrames );
1782
1764
1783
- if ( userFramesPerBuffer < suggestedOutputLatencyFrames )
1784
- {
1785
- unsigned long adjustedSuggestedOutputLatencyFrames =
1786
- suggestedOutputLatencyFrames - userFramesPerBuffer ;
1765
+ * pollingPeriodFrames = ( userFramesPerBuffer == paFramesPerBufferUnspecified ) ?
1766
+ targetBufferingLatencyFrames / 4 :
1767
+ max ( max ( 1 , userFramesPerBuffer / 4 ), targetBufferingLatencyFrames / 16 );
1768
+ * pollingPeriodFrames = min ( max ( * pollingPeriodFrames , minimumPollingPeriodFrames ), maximumPollingPeriodFrames ) ;
1787
1769
1788
- /* maximum of input and adjusted output suggested latency */
1789
- if ( adjustedSuggestedOutputLatencyFrames > targetBufferingLatencyFrames )
1790
- targetBufferingLatencyFrames = adjustedSuggestedOutputLatencyFrames ;
1791
- }
1792
- }
1793
- else
1794
- {
1795
- /* maximum of input and output suggested latency */
1796
- if ( suggestedOutputLatencyFrames > suggestedInputLatencyFrames )
1797
- targetBufferingLatencyFrames = suggestedOutputLatencyFrames ;
1798
- }
1799
-
1800
- * hostBufferSizeFrames = userFramesPerBuffer
1801
- + max ( userFramesPerBuffer + pollingJitterFrames , targetBufferingLatencyFrames );
1802
-
1803
- * pollingPeriodFrames = max ( max (1 , userFramesPerBuffer / 4 ), targetBufferingLatencyFrames / 16 );
1804
-
1805
- if ( * pollingPeriodFrames > maximumPollingPeriodFrames )
1806
- {
1807
- * pollingPeriodFrames = maximumPollingPeriodFrames ;
1808
- }
1809
- }
1770
+ const unsigned long intendedUserFramesPerBuffer =
1771
+ (userFramesPerBuffer == paFramesPerBufferUnspecified ) ?
1772
+ * pollingPeriodFrames :
1773
+ userFramesPerBuffer ;
1774
+ * hostBufferSizeFrames = intendedUserFramesPerBuffer
1775
+ + max ( intendedUserFramesPerBuffer + pollingJitterFrames , targetBufferingLatencyFrames );
1810
1776
}
1811
1777
1812
1778
0 commit comments