classpp_1_1_audio_config.html revision cedac228d2dd51db4b79ea1e72c7f249408ee061
1{{+bindTo:partials.standard_nacl_api}}
2<h1>pp::AudioConfig Class Reference</h1>
3<div id="doxygen-ref">
4{{- dummy div to appease doxygen -}}
5  <div>
6<!-- Generated by Doxygen 1.7.6.1 -->
7
8
9
10</div>
11<!--header-->
12<div class="contents">
13<!-- doxytag: class="pp::AudioConfig" --><!-- doxytag: inherits="pp::Resource" --><div class="dynheader">
14Inheritance diagram for pp::AudioConfig:</div>
15<div class="dyncontent">
16<div class="center"><img src="classpp_1_1_audio_config__inherit__graph.png" border="0" usemap="#pp_1_1_audio_config_inherit__map" alt="Inheritance graph" /></div>
17<map name="pp_1_1_audio_config_inherit__map" id="pp_1_1_audio_config_inherit__map">
18<area shape="rect" id="node2" href="classpp_1_1_resource.html" title="A reference counted module resource." alt="" coords="15,5,119,35"></area></map>
19<center><span class="legend">[<a href="graph_legend.html">legend</a>]</span></center></div>
20<p><a href="classpp_1_1_audio_config-members.html">List of all members.</a></p>
21<h2>
22Public Member Functions</h2><table class="memberdecls">
23
24<tr><td class="memItemLeft" align="right" valign="top">&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classpp_1_1_audio_config.html#ad7a5caaa08c531acf7e2975a790db98e">AudioConfig</a> ()</td></tr>
25<tr><td class="memItemLeft" align="right" valign="top">&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classpp_1_1_audio_config.html#aa6dcb1ed3086502f03d9e1d73124421a">AudioConfig</a> (const <a class="el" href="classpp_1_1_instance_handle.html">InstanceHandle</a> &amp;instance, PP_AudioSampleRate <a class="el" href="classpp_1_1_audio_config.html#a988b8489ec9335be25605561d0293813">sample_rate</a>, uint32_t <a class="el" href="classpp_1_1_audio_config.html#ad7cb79f7f92993257643574457ee8d0c">sample_frame_count</a>)</td></tr>
26<tr><td class="memItemLeft" align="right" valign="top">PP_AudioSampleRate&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classpp_1_1_audio_config.html#a988b8489ec9335be25605561d0293813">sample_rate</a> () const </td></tr>
27<tr><td class="memItemLeft" align="right" valign="top">uint32_t&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classpp_1_1_audio_config.html#ad7cb79f7f92993257643574457ee8d0c">sample_frame_count</a> () const </td></tr>
28</table><h2>
29Static Public Member Functions</h2><table class="memberdecls">
30<tr><td class="memItemLeft" align="right" valign="top">static PP_AudioSampleRate&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classpp_1_1_audio_config.html#abf073122a1b9ef65f149fda9be57246f">RecommendSampleRate</a> (const <a class="el" href="classpp_1_1_instance_handle.html">InstanceHandle</a> &amp;instance)</td></tr>
31<tr><td class="memItemLeft" align="right" valign="top">static uint32_t&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classpp_1_1_audio_config.html#a53611e94bca5d4a5f7acdd3e5285adb9">RecommendSampleFrameCount</a> (const <a class="el" href="classpp_1_1_instance_handle.html">InstanceHandle</a> &amp;instance, PP_AudioSampleRate <a class="el" href="classpp_1_1_audio_config.html#a988b8489ec9335be25605561d0293813">sample_rate</a>, uint32_t requested_sample_frame_count)</td></tr>
32</table>
33<hr /><a name="details" id="details"></a><h2>Detailed Description</h2>
34<div class="textblock"><p>A 16 bit stereo <a class="el" href="classpp_1_1_audio_config.html" title="A 16 bit stereo AudioConfig resource.">AudioConfig</a> resource. </p>
35<p>Refer to the <a href="/native-client/devguide/coding/audio.html">Audio </a>chapter in the Developer's Guide for information on using this interface.</p>
36<p>A single sample frame on a stereo device means one value for the left channel and one value for the right channel.</p>
37<p>Buffer layout for a stereo int16 configuration:</p>
38<p><code>int16_t *buffer16;</code> <code>buffer16[0]</code> is the first left channel sample. <code>buffer16[1]</code> is the first right channel sample. <code>buffer16[2]</code> is the second left channel sample. <code>buffer16[3]</code> is the second right channel sample. <code>...</code> <code>buffer16[2 * (sample_frame_count - 1)]</code> is the last left channel sample. <code>buffer16[2 * (sample_frame_count - 1) + 1]</code> is the last right channel sample. Data will always be in the native endian format of the platform.</p>
39<p><b>Example:</b> </p>
40<div class="fragment"><pre class="fragment"> <span class="comment">// Create an audio config with a supported frame count.</span>
41 uint32_t <a class="code" href="classpp_1_1_audio_config.html#ad7cb79f7f92993257643574457ee8d0c" title="Getter function for returning the internal sample frame count.">sample_frame_count</a> = <a class="code" href="classpp_1_1_audio_config.html#a53611e94bca5d4a5f7acdd3e5285adb9" title="RecommendSampleFrameCount() returns a supported frame count closest to the requested count...">AudioConfig::RecommendSampleFrameCount</a>(
42    PP_AUDIOSAMPLERATE_44100, 4096);
43  <a class="code" href="classpp_1_1_audio_config.html#ad7a5caaa08c531acf7e2975a790db98e" title="An empty constructor for an AudioConfig resource.">AudioConfig</a> config(PP_AUDIOSAMPLERATE_44100, sample_frame_count);
44  <span class="keywordflow">if</span> (config.is_null())
45    <span class="keywordflow">return</span> <span class="keyword">false</span>;  <span class="comment">// Couldn&#39;t configure audio.</span>
46
47   <span class="comment">// Then use the config to create your audio resource.</span>
48  Audio audio(instance, config, callback, user_data);
49   <span class="keywordflow">if</span> (audio.is_null())
50     <span class="keywordflow">return</span> <span class="keyword">false</span>;  <span class="comment">// Couldn&#39;t create audio.</span>
51</pre></div> </div><hr /><h2>Constructor &amp; Destructor Documentation</h2>
52<a class="anchor" id="ad7a5caaa08c531acf7e2975a790db98e"></a><!-- doxytag: member="pp::AudioConfig::AudioConfig" ref="ad7a5caaa08c531acf7e2975a790db98e" args="()" -->
53<div class="memitem">
54<div class="memproto">
55<table class="memname">
56<tr>
57<td class="memname"><a class="el" href="classpp_1_1_audio_config.html#ad7a5caaa08c531acf7e2975a790db98e">pp::AudioConfig::AudioConfig</a> </td>
58<td>(</td>
59<td class="paramname"></td><td>)</td>
60<td></td>
61</tr>
62</table>
63</div>
64<div class="memdoc">
65<p>An empty constructor for an <code><a class="el" href="classpp_1_1_audio_config.html" title="A 16 bit stereo AudioConfig resource.">AudioConfig</a></code> resource. </p>
66</div>
67</div>
68<a class="anchor" id="aa6dcb1ed3086502f03d9e1d73124421a"></a><!-- doxytag: member="pp::AudioConfig::AudioConfig" ref="aa6dcb1ed3086502f03d9e1d73124421a" args="(const InstanceHandle &amp;instance, PP_AudioSampleRate sample_rate, uint32_t sample_frame_count)" -->
69<div class="memitem">
70<div class="memproto">
71<table class="memname">
72<tr>
73<td class="memname"><a class="el" href="classpp_1_1_audio_config.html#ad7a5caaa08c531acf7e2975a790db98e">pp::AudioConfig::AudioConfig</a> </td>
74<td>(</td>
75<td class="paramtype">const <a class="el" href="classpp_1_1_instance_handle.html">InstanceHandle</a> &amp;&#160;</td>
76<td class="paramname"><em>instance</em>, </td>
77</tr>
78<tr>
79<td class="paramkey"></td>
80<td></td>
81<td class="paramtype">PP_AudioSampleRate&#160;</td>
82<td class="paramname"><em>sample_rate</em>, </td>
83</tr>
84<tr>
85<td class="paramkey"></td>
86<td></td>
87<td class="paramtype">uint32_t&#160;</td>
88<td class="paramname"><em>sample_frame_count</em>&#160;</td>
89</tr>
90<tr>
91<td></td>
92<td>)</td>
93<td></td><td></td>
94</tr>
95</table>
96</div>
97<div class="memdoc">
98<p>A constructor that creates an audio config based on the given sample rate and frame count. </p>
99<p>If the rate and frame count aren't supported, the resulting resource will be <a class="el" href="classpp_1_1_resource.html#a859068e34cdc2dc0b78754c255323aa9" title="This functions determines if this resource is invalid or uninitialized.">is_null()</a>. You can pass the result of <a class="el" href="classpp_1_1_audio_config.html#a53611e94bca5d4a5f7acdd3e5285adb9" title="RecommendSampleFrameCount() returns a supported frame count closest to the requested count...">RecommendSampleFrameCount()</a> as the sample frame count.</p>
100<dl class="params"><dt><b>Parameters:</b></dt><dd>
101<table class="params">
102<tr><td class="paramdir">[in]</td><td class="paramname">instance</td><td>The instance associated with this resource.</td></tr>
103<tr><td class="paramdir">[in]</td><td class="paramname">sample_rate</td><td>A <code>PP_AudioSampleRate</code> which is either <code>PP_AUDIOSAMPLERATE_44100</code> or <code>PP_AUDIOSAMPLERATE_48000</code>.</td></tr>
104<tr><td class="paramdir">[in]</td><td class="paramname">sample_frame_count</td><td>A uint32_t frame count returned from the <code>RecommendSampleFrameCount</code> function. </td></tr>
105</table>
106</dd>
107</dl>
108</div>
109</div>
110<hr /><h2>Member Function Documentation</h2>
111<a class="anchor" id="a53611e94bca5d4a5f7acdd3e5285adb9"></a><!-- doxytag: member="pp::AudioConfig::RecommendSampleFrameCount" ref="a53611e94bca5d4a5f7acdd3e5285adb9" args="(const InstanceHandle &amp;instance, PP_AudioSampleRate sample_rate, uint32_t requested_sample_frame_count)" -->
112<div class="memitem">
113<div class="memproto">
114<table class="memname">
115<tr>
116<td class="memname">static uint32_t <a class="el" href="classpp_1_1_audio_config.html#a53611e94bca5d4a5f7acdd3e5285adb9">pp::AudioConfig::RecommendSampleFrameCount</a> </td>
117<td>(</td>
118<td class="paramtype">const <a class="el" href="classpp_1_1_instance_handle.html">InstanceHandle</a> &amp;&#160;</td>
119<td class="paramname"><em>instance</em>, </td>
120</tr>
121<tr>
122<td class="paramkey"></td>
123<td></td>
124<td class="paramtype">PP_AudioSampleRate&#160;</td>
125<td class="paramname"><em>sample_rate</em>, </td>
126</tr>
127<tr>
128<td class="paramkey"></td>
129<td></td>
130<td class="paramtype">uint32_t&#160;</td>
131<td class="paramname"><em>requested_sample_frame_count</em>&#160;</td>
132</tr>
133<tr>
134<td></td>
135<td>)</td>
136<td></td><td><code> [static]</code></td>
137</tr>
138</table>
139</div>
140<div class="memdoc">
141<p><a class="el" href="classpp_1_1_audio_config.html#a53611e94bca5d4a5f7acdd3e5285adb9" title="RecommendSampleFrameCount() returns a supported frame count closest to the requested count...">RecommendSampleFrameCount()</a> returns a supported frame count closest to the requested count. </p>
142<p>The sample frame count determines the overall latency of audio. Smaller frame counts will yield lower latency, but higher CPU utilization. Supported sample frame counts will vary by hardware and system (consider that the local system might be anywhere from a cell phone or a high-end audio workstation). Sample counts less than <code>PP_AUDIOMINSAMPLEFRAMECOUNT</code> and greater than <code>PP_AUDIOMAXSAMPLEFRAMECOUNT</code> are never supported on any system, but values in between aren't necessarily valid. This function will return a supported count closest to the requested value for use in the constructor.</p>
143<dl class="params"><dt><b>Parameters:</b></dt><dd>
144<table class="params">
145<tr><td class="paramdir">[in]</td><td class="paramname">instance</td><td>The instance associated with this resource. </td></tr>
146<tr><td class="paramdir">[in]</td><td class="paramname">sample_rate</td><td>A <code>PP_AudioSampleRate</code> which is either <code>PP_AUDIOSAMPLERATE_44100</code> or <code>PP_AUDIOSAMPLERATE_48000</code>. </td></tr>
147<tr><td class="paramdir">[in]</td><td class="paramname">requested_sample_frame_count</td><td>A uint32_t requested frame count.</td></tr>
148</table>
149</dd>
150</dl>
151<dl class="return"><dt><b>Returns:</b></dt><dd>A uint32_t containing the recommended sample frame count if successful. If the sample frame count or bit rate is not supported, this function will fail and return 0. </dd></dl>
152</div>
153</div>
154<a class="anchor" id="abf073122a1b9ef65f149fda9be57246f"></a><!-- doxytag: member="pp::AudioConfig::RecommendSampleRate" ref="abf073122a1b9ef65f149fda9be57246f" args="(const InstanceHandle &amp;instance)" -->
155<div class="memitem">
156<div class="memproto">
157<table class="memname">
158<tr>
159<td class="memname">static PP_AudioSampleRate <a class="el" href="classpp_1_1_audio_config.html#abf073122a1b9ef65f149fda9be57246f">pp::AudioConfig::RecommendSampleRate</a> </td>
160<td>(</td>
161<td class="paramtype">const <a class="el" href="classpp_1_1_instance_handle.html">InstanceHandle</a> &amp;&#160;</td>
162<td class="paramname"><em>instance</em></td><td>)</td>
163<td><code> [static]</code></td>
164</tr>
165</table>
166</div>
167<div class="memdoc">
168<p><a class="el" href="classpp_1_1_audio_config.html#abf073122a1b9ef65f149fda9be57246f" title="RecommendSampleRate() returns the native sample rate used by the audio system.">RecommendSampleRate()</a> returns the native sample rate used by the audio system. </p>
169<p>Applications that use the recommended sample rate might obtain lower latency and higher fidelity output.</p>
170<dl class="params"><dt><b>Parameters:</b></dt><dd>
171<table class="params">
172<tr><td class="paramdir">[in]</td><td class="paramname">instance</td><td>The instance associated with this resource. </td></tr>
173</table>
174</dd>
175</dl>
176</div>
177</div>
178<a class="anchor" id="ad7cb79f7f92993257643574457ee8d0c"></a><!-- doxytag: member="pp::AudioConfig::sample_frame_count" ref="ad7cb79f7f92993257643574457ee8d0c" args="() const " -->
179<div class="memitem">
180<div class="memproto">
181<table class="memname">
182<tr>
183<td class="memname">uint32_t <a class="el" href="classpp_1_1_audio_config.html#ad7cb79f7f92993257643574457ee8d0c">pp::AudioConfig::sample_frame_count</a> </td>
184<td>(</td>
185<td class="paramname"></td><td>)</td>
186<td> const<code> [inline]</code></td>
187</tr>
188</table>
189</div>
190<div class="memdoc">
191<p>Getter function for returning the internal sample frame count. </p>
192<dl class="return"><dt><b>Returns:</b></dt><dd>A uint32_t containing the sample frame count. </dd></dl>
193</div>
194</div>
195<a class="anchor" id="a988b8489ec9335be25605561d0293813"></a><!-- doxytag: member="pp::AudioConfig::sample_rate" ref="a988b8489ec9335be25605561d0293813" args="() const " -->
196<div class="memitem">
197<div class="memproto">
198<table class="memname">
199<tr>
200<td class="memname">PP_AudioSampleRate <a class="el" href="classpp_1_1_audio_config.html#a988b8489ec9335be25605561d0293813">pp::AudioConfig::sample_rate</a> </td>
201<td>(</td>
202<td class="paramname"></td><td>)</td>
203<td> const<code> [inline]</code></td>
204</tr>
205</table>
206</div>
207<div class="memdoc">
208<p>Getter function for returning the internal <code>PP_AudioSampleRate</code> enum. </p>
209<dl class="return"><dt><b>Returns:</b></dt><dd>The <code>PP_AudioSampleRate</code> enum. </dd></dl>
210</div>
211</div>
212<hr />The documentation for this class was generated from the following file:<ul>
213<li><a class="el" href="audio__config_8h.html">audio_config.h</a></li>
214</ul>
215</div><!-- contents -->
216</div>
217{{/partials.standard_nacl_api}}
218