{{+bindTo:partials.standard_nacl_api}}
<h1>pp::AudioConfig Class Reference</h1>
<div id="doxygen-ref">
{{- dummy div to appease doxygen -}}
<div>
<!-- Generated by Doxygen 1.7.6.1 -->
</div>
<!--header-->
<div class="contents">
<!-- doxytag: class="pp::AudioConfig" --><!-- doxytag: inherits="pp::Resource" --><div class="dynheader">
Inheritance diagram for pp::AudioConfig:</div>
<div class="dyncontent">
<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>
<map name="pp_1_1_audio_config_inherit__map" id="pp_1_1_audio_config_inherit__map">
<area shape="rect" id="node2" href="classpp_1_1_resource.html" title="A reference counted module resource." alt="" coords="15,5,119,32"></area></map>
<center><span class="legend">[<a href="graph_legend.html">legend</a>]</span></center></div>
<p><a href="classpp_1_1_audio_config-members.html">List of all members.</a></p>
<h2>
Public Member Functions</h2><table class="memberdecls">
<tr><td class="memItemLeft" align="right" valign="top"> </td><td class="memItemRight" valign="bottom"><a class="el" href="classpp_1_1_audio_config.html#ad7a5caaa08c531acf7e2975a790db98e">AudioConfig</a> ()</td></tr>
<tr><td class="memItemLeft" align="right" valign="top"> </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> &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>
<tr><td class="memItemLeft" align="right" valign="top">PP_AudioSampleRate </td><td class="memItemRight" valign="bottom"><a class="el" href="classpp_1_1_audio_config.html#a988b8489ec9335be25605561d0293813">sample_rate</a> () const </td></tr>
<tr><td class="memItemLeft" align="right" valign="top">uint32_t </td><td class="memItemRight" valign="bottom"><a class="el" href="classpp_1_1_audio_config.html#ad7cb79f7f92993257643574457ee8d0c">sample_frame_count</a> () const </td></tr>
</table><h2>
Static Public Member Functions</h2><table class="memberdecls">
<tr><td class="memItemLeft" align="right" valign="top">static PP_AudioSampleRate </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> &instance)</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">static uint32_t </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> &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>
</table>
<hr /><a name="details" id="details"></a><h2>Detailed Description</h2>
<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>
<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>
<p>A single sample frame on a stereo device means one value for the left channel and one value for the right channel.</p>
<p>Buffer layout for a stereo int16 configuration:</p>
<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>
<p><b>Example:</b> </p>
<div class="fragment"><pre class="fragment"> <span class="comment">// Create an audio config with a supported frame count.</span>
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>(
PP_AUDIOSAMPLERATE_44100, 4096);
<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);
<span class="keywordflow">if</span> (config.is_null())
<span class="keywordflow">return</span> <span class="keyword">false</span>; <span class="comment">// Couldn't configure audio.</span>
<span class="comment">// Then use the config to create your audio resource.</span>
Audio audio(instance, config, callback, user_data);
<span class="keywordflow">if</span> (audio.is_null())
<span class="keywordflow">return</span> <span class="keyword">false</span>; <span class="comment">// Couldn't create audio.</span>
</pre></div> </div><hr /><h2>Constructor & Destructor Documentation</h2>
<a class="anchor" id="ad7a5caaa08c531acf7e2975a790db98e"></a><!-- doxytag: member="pp::AudioConfig::AudioConfig" ref="ad7a5caaa08c531acf7e2975a790db98e" args="()" -->
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname"><a class="el" href="classpp_1_1_audio_config.html#ad7a5caaa08c531acf7e2975a790db98e">pp::AudioConfig::AudioConfig</a> </td>
<td>(</td>
<td class="paramname"></td><td>)</td>
<td></td>
</tr>
</table>
</div>
<div class="memdoc">
<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>
</div>
</div>
<a class="anchor" id="aa6dcb1ed3086502f03d9e1d73124421a"></a><!-- doxytag: member="pp::AudioConfig::AudioConfig" ref="aa6dcb1ed3086502f03d9e1d73124421a" args="(const InstanceHandle &instance, PP_AudioSampleRate sample_rate, uint32_t sample_frame_count)" -->
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname"><a class="el" href="classpp_1_1_audio_config.html#ad7a5caaa08c531acf7e2975a790db98e">pp::AudioConfig::AudioConfig</a> </td>
<td>(</td>
<td class="paramtype">const <a class="el" href="classpp_1_1_instance_handle.html">InstanceHandle</a> & </td>
<td class="paramname"><em>instance</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">PP_AudioSampleRate </td>
<td class="paramname"><em>sample_rate</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">uint32_t </td>
<td class="paramname"><em>sample_frame_count</em> </td>
</tr>
<tr>
<td></td>
<td>)</td>
<td></td><td></td>
</tr>
</table>
</div>
<div class="memdoc">
<p>A constructor that creates an audio config based on the given sample rate and frame count. </p>
<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>
<dl class="params"><dt><b>Parameters:</b></dt><dd>
<table class="params">
<tr><td class="paramdir">[in]</td><td class="paramname">instance</td><td>The instance associated with this resource.</td></tr>
<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>
<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>
</table>
</dd>
</dl>
</div>
</div>
<hr /><h2>Member Function Documentation</h2>
<a class="anchor" id="a53611e94bca5d4a5f7acdd3e5285adb9"></a><!-- doxytag: member="pp::AudioConfig::RecommendSampleFrameCount" ref="a53611e94bca5d4a5f7acdd3e5285adb9" args="(const InstanceHandle &instance, PP_AudioSampleRate sample_rate, uint32_t requested_sample_frame_count)" -->
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">static uint32_t <a class="el" href="classpp_1_1_audio_config.html#a53611e94bca5d4a5f7acdd3e5285adb9">pp::AudioConfig::RecommendSampleFrameCount</a> </td>
<td>(</td>
<td class="paramtype">const <a class="el" href="classpp_1_1_instance_handle.html">InstanceHandle</a> & </td>
<td class="paramname"><em>instance</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">PP_AudioSampleRate </td>
<td class="paramname"><em>sample_rate</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">uint32_t </td>
<td class="paramname"><em>requested_sample_frame_count</em> </td>
</tr>
<tr>
<td></td>
<td>)</td>
<td></td><td><code> [static]</code></td>
</tr>
</table>
</div>
<div class="memdoc">
<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>
<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>
<dl class="params"><dt><b>Parameters:</b></dt><dd>
<table class="params">
<tr><td class="paramdir">[in]</td><td class="paramname">instance</td><td>The instance associated with this resource. </td></tr>
<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>
<tr><td class="paramdir">[in]</td><td class="paramname">requested_sample_frame_count</td><td>A uint32_t requested frame count.</td></tr>
</table>
</dd>
</dl>
<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>
</div>
</div>
<a class="anchor" id="abf073122a1b9ef65f149fda9be57246f"></a><!-- doxytag: member="pp::AudioConfig::RecommendSampleRate" ref="abf073122a1b9ef65f149fda9be57246f" args="(const InstanceHandle &instance)" -->
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">static PP_AudioSampleRate <a class="el" href="classpp_1_1_audio_config.html#abf073122a1b9ef65f149fda9be57246f">pp::AudioConfig::RecommendSampleRate</a> </td>
<td>(</td>
<td class="paramtype">const <a class="el" href="classpp_1_1_instance_handle.html">InstanceHandle</a> & </td>
<td class="paramname"><em>instance</em></td><td>)</td>
<td><code> [static]</code></td>
</tr>
</table>
</div>
<div class="memdoc">
<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>
<p>Applications that use the recommended sample rate might obtain lower latency and higher fidelity output.</p>
<dl class="params"><dt><b>Parameters:</b></dt><dd>
<table class="params">
<tr><td class="paramdir">[in]</td><td class="paramname">instance</td><td>The instance associated with this resource. </td></tr>
</table>
</dd>
</dl>
</div>
</div>
<a class="anchor" id="ad7cb79f7f92993257643574457ee8d0c"></a><!-- doxytag: member="pp::AudioConfig::sample_frame_count" ref="ad7cb79f7f92993257643574457ee8d0c" args="() const " -->
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">uint32_t <a class="el" href="classpp_1_1_audio_config.html#ad7cb79f7f92993257643574457ee8d0c">pp::AudioConfig::sample_frame_count</a> </td>
<td>(</td>
<td class="paramname"></td><td>)</td>
<td> const<code> [inline]</code></td>
</tr>
</table>
</div>
<div class="memdoc">
<p>Getter function for returning the internal sample frame count. </p>
<dl class="return"><dt><b>Returns:</b></dt><dd>A uint32_t containing the sample frame count. </dd></dl>
</div>
</div>
<a class="anchor" id="a988b8489ec9335be25605561d0293813"></a><!-- doxytag: member="pp::AudioConfig::sample_rate" ref="a988b8489ec9335be25605561d0293813" args="() const " -->
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">PP_AudioSampleRate <a class="el" href="classpp_1_1_audio_config.html#a988b8489ec9335be25605561d0293813">pp::AudioConfig::sample_rate</a> </td>
<td>(</td>
<td class="paramname"></td><td>)</td>
<td> const<code> [inline]</code></td>
</tr>
</table>
</div>
<div class="memdoc">
<p>Getter function for returning the internal <code>PP_AudioSampleRate</code> enum. </p>
<dl class="return"><dt><b>Returns:</b></dt><dd>The <code>PP_AudioSampleRate</code> enum. </dd></dl>
</div>
</div>
<hr />The documentation for this class was generated from the following file:<ul>
<li><a class="el" href="audio__config_8h.html">audio_config.h</a></li>
</ul>
</div><!-- contents -->
</div>
{{/partials.standard_nacl_api}}