1<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2<html xmlns="http://www.w3.org/1999/xhtml">
3<head>
4<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
5<meta http-equiv="X-UA-Compatible" content="IE=9"/>
6<meta name="generator" content="Doxygen 1.8.15"/>
7<meta name="viewport" content="width=device-width, initial-scale=1"/>
8<title>Oboe: include/oboe/LatencyTuner.h Source File</title>
9<link href="tabs.css" rel="stylesheet" type="text/css"/>
10<script type="text/javascript" src="jquery.js"></script>
11<script type="text/javascript" src="dynsections.js"></script>
12<link href="search/search.css" rel="stylesheet" type="text/css"/>
13<script type="text/javascript" src="search/searchdata.js"></script>
14<script type="text/javascript" src="search/search.js"></script>
15<link href="doxygen.css" rel="stylesheet" type="text/css" />
16</head>
17<body>
18<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
19<div id="titlearea">
20<table cellspacing="0" cellpadding="0">
21 <tbody>
22 <tr style="height: 56px;">
23  <td id="projectalign" style="padding-left: 0.5em;">
24   <div id="projectname">Oboe
25   &#160;<span id="projectnumber">1.5</span>
26   </div>
27   <div id="projectbrief">A library for creating real-time audio apps on Android</div>
28  </td>
29 </tr>
30 </tbody>
31</table>
32</div>
33<!-- end header part -->
34<!-- Generated by Doxygen 1.8.15 -->
35<script type="text/javascript">
36/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
37var searchBox = new SearchBox("searchBox", "search",false,'Search');
38/* @license-end */
39</script>
40<script type="text/javascript" src="menudata.js"></script>
41<script type="text/javascript" src="menu.js"></script>
42<script type="text/javascript">
43/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
44$(function() {
45  initMenu('',true,false,'search.php','Search');
46  $(document).ready(function() { init_search(); });
47});
48/* @license-end */</script>
49<div id="main-nav"></div>
50<!-- window showing the filter options -->
51<div id="MSearchSelectWindow"
52     onmouseover="return searchBox.OnSearchSelectShow()"
53     onmouseout="return searchBox.OnSearchSelectHide()"
54     onkeydown="return searchBox.OnSearchSelectKey(event)">
55</div>
56
57<!-- iframe showing the search results (closed by default) -->
58<div id="MSearchResultsWindow">
59<iframe src="javascript:void(0)" frameborder="0"
60        name="MSearchResults" id="MSearchResults">
61</iframe>
62</div>
63
64<div id="nav-path" class="navpath">
65  <ul>
66<li class="navelem"><a class="el" href="dir_d44c64559bbebec7f509842c48db8b23.html">include</a></li><li class="navelem"><a class="el" href="dir_768f6301d9838e45d679001914ab2803.html">oboe</a></li>  </ul>
67</div>
68</div><!-- top -->
69<div class="header">
70  <div class="headertitle">
71<div class="title">LatencyTuner.h</div>  </div>
72</div><!--header-->
73<div class="contents">
74<div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno">    1</span>&#160;<span class="comment">/*</span></div><div class="line"><a name="l00002"></a><span class="lineno">    2</span>&#160;<span class="comment"> * Copyright 2017 The Android Open Source Project</span></div><div class="line"><a name="l00003"></a><span class="lineno">    3</span>&#160;<span class="comment"> *</span></div><div class="line"><a name="l00004"></a><span class="lineno">    4</span>&#160;<span class="comment"> * Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);</span></div><div class="line"><a name="l00005"></a><span class="lineno">    5</span>&#160;<span class="comment"> * you may not use this file except in compliance with the License.</span></div><div class="line"><a name="l00006"></a><span class="lineno">    6</span>&#160;<span class="comment"> * You may obtain a copy of the License at</span></div><div class="line"><a name="l00007"></a><span class="lineno">    7</span>&#160;<span class="comment"> *</span></div><div class="line"><a name="l00008"></a><span class="lineno">    8</span>&#160;<span class="comment"> *      http://www.apache.org/licenses/LICENSE-2.0</span></div><div class="line"><a name="l00009"></a><span class="lineno">    9</span>&#160;<span class="comment"> *</span></div><div class="line"><a name="l00010"></a><span class="lineno">   10</span>&#160;<span class="comment"> * Unless required by applicable law or agreed to in writing, software</span></div><div class="line"><a name="l00011"></a><span class="lineno">   11</span>&#160;<span class="comment"> * distributed under the License is distributed on an &quot;AS IS&quot; BASIS,</span></div><div class="line"><a name="l00012"></a><span class="lineno">   12</span>&#160;<span class="comment"> * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.</span></div><div class="line"><a name="l00013"></a><span class="lineno">   13</span>&#160;<span class="comment"> * See the License for the specific language governing permissions and</span></div><div class="line"><a name="l00014"></a><span class="lineno">   14</span>&#160;<span class="comment"> * limitations under the License.</span></div><div class="line"><a name="l00015"></a><span class="lineno">   15</span>&#160;<span class="comment"> */</span></div><div class="line"><a name="l00016"></a><span class="lineno">   16</span>&#160;</div><div class="line"><a name="l00017"></a><span class="lineno">   17</span>&#160;<span class="preprocessor">#ifndef OBOE_LATENCY_TUNER_</span></div><div class="line"><a name="l00018"></a><span class="lineno">   18</span>&#160;<span class="preprocessor">#define OBOE_LATENCY_TUNER_</span></div><div class="line"><a name="l00019"></a><span class="lineno">   19</span>&#160;</div><div class="line"><a name="l00020"></a><span class="lineno">   20</span>&#160;<span class="preprocessor">#include &lt;atomic&gt;</span></div><div class="line"><a name="l00021"></a><span class="lineno">   21</span>&#160;<span class="preprocessor">#include &lt;cstdint&gt;</span></div><div class="line"><a name="l00022"></a><span class="lineno">   22</span>&#160;<span class="preprocessor">#include &quot;oboe/Definitions.h&quot;</span></div><div class="line"><a name="l00023"></a><span class="lineno">   23</span>&#160;<span class="preprocessor">#include &quot;oboe/AudioStream.h&quot;</span></div><div class="line"><a name="l00024"></a><span class="lineno">   24</span>&#160;</div><div class="line"><a name="l00025"></a><span class="lineno">   25</span>&#160;<span class="keyword">namespace </span><a class="code" href="namespaceoboe.html">oboe</a> {</div><div class="line"><a name="l00026"></a><span class="lineno">   26</span>&#160;</div><div class="line"><a name="l00041"></a><span class="lineno"><a class="line" href="classoboe_1_1_latency_tuner.html">   41</a></span>&#160;<span class="keyword">class </span><a class="code" href="classoboe_1_1_latency_tuner.html">LatencyTuner</a> {</div><div class="line"><a name="l00042"></a><span class="lineno">   42</span>&#160;<span class="keyword">public</span>:</div><div class="line"><a name="l00043"></a><span class="lineno">   43</span>&#160;</div><div class="line"><a name="l00049"></a><span class="lineno">   49</span>&#160;    <span class="keyword">explicit</span> <a class="code" href="classoboe_1_1_latency_tuner.html#a0263b9a55825c0a403653b2b508073ea">LatencyTuner</a>(<a class="code" href="classoboe_1_1_audio_stream.html">AudioStream</a> &amp;stream);</div><div class="line"><a name="l00050"></a><span class="lineno">   50</span>&#160;</div><div class="line"><a name="l00057"></a><span class="lineno">   57</span>&#160;    <span class="keyword">explicit</span> <a class="code" href="classoboe_1_1_latency_tuner.html#a0263b9a55825c0a403653b2b508073ea">LatencyTuner</a>(<a class="code" href="classoboe_1_1_audio_stream.html">AudioStream</a> &amp;stream, int32_t maximumBufferSize);</div><div class="line"><a name="l00058"></a><span class="lineno">   58</span>&#160;</div><div class="line"><a name="l00067"></a><span class="lineno">   67</span>&#160;    <a class="code" href="namespaceoboe.html#a486512e787b609c80ba4436f23929af1">Result</a> <a class="code" href="classoboe_1_1_latency_tuner.html#ad2be756965e6a9af3114008eda892174">tune</a>();</div><div class="line"><a name="l00068"></a><span class="lineno">   68</span>&#160;</div><div class="line"><a name="l00077"></a><span class="lineno">   77</span>&#160;    <span class="keywordtype">void</span> <a class="code" href="classoboe_1_1_latency_tuner.html#a6c0142e08dc65eda8f758b4794450867">requestReset</a>();</div><div class="line"><a name="l00078"></a><span class="lineno">   78</span>&#160;</div><div class="line"><a name="l00084"></a><span class="lineno">   84</span>&#160;    <span class="keywordtype">bool</span> <a class="code" href="classoboe_1_1_latency_tuner.html#a45c013fd6787ad09d328385d6314c4d4">isAtMaximumBufferSize</a>();</div><div class="line"><a name="l00085"></a><span class="lineno">   85</span>&#160;</div><div class="line"><a name="l00091"></a><span class="lineno"><a class="line" href="classoboe_1_1_latency_tuner.html#adc96aa53b18a051b6ccdacb838139bf8">   91</a></span>&#160;    <span class="keywordtype">void</span> <a class="code" href="classoboe_1_1_latency_tuner.html#adc96aa53b18a051b6ccdacb838139bf8">setMinimumBufferSize</a>(int32_t bufferSize) {</div><div class="line"><a name="l00092"></a><span class="lineno">   92</span>&#160;        mMinimumBufferSize = bufferSize;</div><div class="line"><a name="l00093"></a><span class="lineno">   93</span>&#160;    }</div><div class="line"><a name="l00094"></a><span class="lineno">   94</span>&#160;</div><div class="line"><a name="l00095"></a><span class="lineno">   95</span>&#160;    int32_t getMinimumBufferSize()<span class="keyword"> const </span>{</div><div class="line"><a name="l00096"></a><span class="lineno">   96</span>&#160;        <span class="keywordflow">return</span> mMinimumBufferSize;</div><div class="line"><a name="l00097"></a><span class="lineno">   97</span>&#160;    }</div><div class="line"><a name="l00098"></a><span class="lineno">   98</span>&#160;</div><div class="line"><a name="l00108"></a><span class="lineno"><a class="line" href="classoboe_1_1_latency_tuner.html#a2684b30205126c8acd2f75d01cce05db">  108</a></span>&#160;    <span class="keywordtype">void</span> <a class="code" href="classoboe_1_1_latency_tuner.html#a2684b30205126c8acd2f75d01cce05db">setBufferSizeIncrement</a>(int32_t sizeIncrement) {</div><div class="line"><a name="l00109"></a><span class="lineno">  109</span>&#160;        mBufferSizeIncrement = sizeIncrement;</div><div class="line"><a name="l00110"></a><span class="lineno">  110</span>&#160;    }</div><div class="line"><a name="l00111"></a><span class="lineno">  111</span>&#160;</div><div class="line"><a name="l00112"></a><span class="lineno">  112</span>&#160;    int32_t getBufferSizeIncrement()<span class="keyword"> const </span>{</div><div class="line"><a name="l00113"></a><span class="lineno">  113</span>&#160;        <span class="keywordflow">return</span> mBufferSizeIncrement;</div><div class="line"><a name="l00114"></a><span class="lineno">  114</span>&#160;    }</div><div class="line"><a name="l00115"></a><span class="lineno">  115</span>&#160;</div><div class="line"><a name="l00116"></a><span class="lineno">  116</span>&#160;<span class="keyword">private</span>:</div><div class="line"><a name="l00117"></a><span class="lineno">  117</span>&#160;</div><div class="line"><a name="l00124"></a><span class="lineno">  124</span>&#160;    <span class="keywordtype">void</span> reset();</div><div class="line"><a name="l00125"></a><span class="lineno">  125</span>&#160;</div><div class="line"><a name="l00126"></a><span class="lineno">  126</span>&#160;    <span class="keyword">enum class</span> State {</div><div class="line"><a name="l00127"></a><span class="lineno">  127</span>&#160;        Idle,</div><div class="line"><a name="l00128"></a><span class="lineno">  128</span>&#160;        Active,</div><div class="line"><a name="l00129"></a><span class="lineno">  129</span>&#160;        AtMax,</div><div class="line"><a name="l00130"></a><span class="lineno">  130</span>&#160;        Unsupported</div><div class="line"><a name="l00131"></a><span class="lineno">  131</span>&#160;    } ;</div><div class="line"><a name="l00132"></a><span class="lineno">  132</span>&#160;</div><div class="line"><a name="l00133"></a><span class="lineno">  133</span>&#160;    <span class="comment">// arbitrary number of calls to wait before bumping up the latency</span></div><div class="line"><a name="l00134"></a><span class="lineno">  134</span>&#160;    <span class="keyword">static</span> constexpr int32_t kIdleCount = 8;</div><div class="line"><a name="l00135"></a><span class="lineno">  135</span>&#160;    <span class="keyword">static</span> constexpr int32_t kDefaultNumBursts = 2;</div><div class="line"><a name="l00136"></a><span class="lineno">  136</span>&#160;</div><div class="line"><a name="l00137"></a><span class="lineno">  137</span>&#160;    AudioStream           &amp;mStream;</div><div class="line"><a name="l00138"></a><span class="lineno">  138</span>&#160;    State                 mState = State::Idle;</div><div class="line"><a name="l00139"></a><span class="lineno">  139</span>&#160;    int32_t               mMaxBufferSize = 0;</div><div class="line"><a name="l00140"></a><span class="lineno">  140</span>&#160;    int32_t               mPreviousXRuns = 0;</div><div class="line"><a name="l00141"></a><span class="lineno">  141</span>&#160;    int32_t               mIdleCountDown = 0;</div><div class="line"><a name="l00142"></a><span class="lineno">  142</span>&#160;    int32_t               mMinimumBufferSize;</div><div class="line"><a name="l00143"></a><span class="lineno">  143</span>&#160;    int32_t               mBufferSizeIncrement;</div><div class="line"><a name="l00144"></a><span class="lineno">  144</span>&#160;    std::atomic&lt;int32_t&gt;  mLatencyTriggerRequests{0}; <span class="comment">// TODO user atomic requester from AAudio</span></div><div class="line"><a name="l00145"></a><span class="lineno">  145</span>&#160;    std::atomic&lt;int32_t&gt;  mLatencyTriggerResponses{0};</div><div class="line"><a name="l00146"></a><span class="lineno">  146</span>&#160;};</div><div class="line"><a name="l00147"></a><span class="lineno">  147</span>&#160;</div><div class="line"><a name="l00148"></a><span class="lineno">  148</span>&#160;} <span class="comment">// namespace oboe</span></div><div class="line"><a name="l00149"></a><span class="lineno">  149</span>&#160;</div><div class="line"><a name="l00150"></a><span class="lineno">  150</span>&#160;<span class="preprocessor">#endif // OBOE_LATENCY_TUNER_</span></div><div class="ttc" id="classoboe_1_1_latency_tuner_html_a2684b30205126c8acd2f75d01cce05db"><div class="ttname"><a href="classoboe_1_1_latency_tuner.html#a2684b30205126c8acd2f75d01cce05db">oboe::LatencyTuner::setBufferSizeIncrement</a></div><div class="ttdeci">void setBufferSizeIncrement(int32_t sizeIncrement)</div><div class="ttdef"><b>Definition:</b> LatencyTuner.h:108</div></div>
75<div class="ttc" id="classoboe_1_1_latency_tuner_html_a6c0142e08dc65eda8f758b4794450867"><div class="ttname"><a href="classoboe_1_1_latency_tuner.html#a6c0142e08dc65eda8f758b4794450867">oboe::LatencyTuner::requestReset</a></div><div class="ttdeci">void requestReset()</div></div>
76<div class="ttc" id="classoboe_1_1_audio_stream_html"><div class="ttname"><a href="classoboe_1_1_audio_stream.html">oboe::AudioStream</a></div><div class="ttdef"><b>Definition:</b> AudioStream.h:44</div></div>
77<div class="ttc" id="classoboe_1_1_latency_tuner_html_a45c013fd6787ad09d328385d6314c4d4"><div class="ttname"><a href="classoboe_1_1_latency_tuner.html#a45c013fd6787ad09d328385d6314c4d4">oboe::LatencyTuner::isAtMaximumBufferSize</a></div><div class="ttdeci">bool isAtMaximumBufferSize()</div></div>
78<div class="ttc" id="classoboe_1_1_latency_tuner_html_a0263b9a55825c0a403653b2b508073ea"><div class="ttname"><a href="classoboe_1_1_latency_tuner.html#a0263b9a55825c0a403653b2b508073ea">oboe::LatencyTuner::LatencyTuner</a></div><div class="ttdeci">LatencyTuner(AudioStream &amp;stream)</div></div>
79<div class="ttc" id="classoboe_1_1_latency_tuner_html_ad2be756965e6a9af3114008eda892174"><div class="ttname"><a href="classoboe_1_1_latency_tuner.html#ad2be756965e6a9af3114008eda892174">oboe::LatencyTuner::tune</a></div><div class="ttdeci">Result tune()</div></div>
80<div class="ttc" id="namespaceoboe_html_a486512e787b609c80ba4436f23929af1"><div class="ttname"><a href="namespaceoboe.html#a486512e787b609c80ba4436f23929af1">oboe::Result</a></div><div class="ttdeci">Result</div><div class="ttdef"><b>Definition:</b> Definitions.h:131</div></div>
81<div class="ttc" id="classoboe_1_1_latency_tuner_html"><div class="ttname"><a href="classoboe_1_1_latency_tuner.html">oboe::LatencyTuner</a></div><div class="ttdef"><b>Definition:</b> LatencyTuner.h:41</div></div>
82<div class="ttc" id="classoboe_1_1_latency_tuner_html_adc96aa53b18a051b6ccdacb838139bf8"><div class="ttname"><a href="classoboe_1_1_latency_tuner.html#adc96aa53b18a051b6ccdacb838139bf8">oboe::LatencyTuner::setMinimumBufferSize</a></div><div class="ttdeci">void setMinimumBufferSize(int32_t bufferSize)</div><div class="ttdef"><b>Definition:</b> LatencyTuner.h:91</div></div>
83<div class="ttc" id="namespaceoboe_html"><div class="ttname"><a href="namespaceoboe.html">oboe</a></div><div class="ttdef"><b>Definition:</b> AudioStream.h:31</div></div>
84</div><!-- fragment --></div><!-- contents -->
85<!-- start footer part -->
86<hr class="footer"/><address class="footer"><small>
87Generated by &#160;<a href="http://www.doxygen.org/index.html">
88<img class="footer" src="doxygen.png" alt="doxygen"/>
89</a> 1.8.15
90</small></address>
91</body>
92</html>
93