Pepper_47_C++_interfaces
Public Member Functions | Static Public Member Functions | List of all members
pp::AudioConfig Class Reference

#include <audio_config.h>

Inheritance diagram for pp::AudioConfig:
Inheritance graph
Collaboration diagram for pp::AudioConfig:
Collaboration graph

Public Member Functions

 AudioConfig ()
 An empty constructor for an AudioConfig resource. More...
 
 AudioConfig (const InstanceHandle &instance, PP_AudioSampleRate sample_rate, uint32_t sample_frame_count)
 
PP_AudioSampleRate sample_rate () const
 
uint32_t sample_frame_count () const
 
- Public Member Functions inherited from pp::Resource
 Resource ()
 The default constructor. More...
 
 Resource (const Resource &other)
 
virtual ~Resource ()
 Destructor. More...
 
Resourceoperator= (const Resource &other)
 
bool is_null () const
 
PP_Resource pp_resource () const
 
PP_Resource detach ()
 

Static Public Member Functions

static PP_AudioSampleRate RecommendSampleRate (const InstanceHandle &instance)
 
static uint32_t RecommendSampleFrameCount (const InstanceHandle &instance, PP_AudioSampleRate sample_rate, uint32_t requested_sample_frame_count)
 

Additional Inherited Members

- Protected Member Functions inherited from pp::Resource
 Resource (PP_Resource resource)
 
 Resource (PassRef, PP_Resource resource)
 
void PassRefFromConstructor (PP_Resource resource)
 
void Clear ()
 Sets this resource to null. This releases ownership of the resource. More...
 

Detailed Description

A 16 bit stereo AudioConfig resource. Refer to the Audio chapter in the Developer's Guide for information on using this interface.

A single sample frame on a stereo device means one value for the left channel and one value for the right channel.

Buffer layout for a stereo int16 configuration:

int16_t *buffer16; buffer16[0] is the first left channel sample. buffer16[1] is the first right channel sample. buffer16[2] is the second left channel sample. buffer16[3] is the second right channel sample. ... buffer16[2 * (sample_frame_count - 1)] is the last left channel sample. buffer16[2 * (sample_frame_count - 1) + 1] is the last right channel sample. Data will always be in the native endian format of the platform.

Example:

// Create an audio config with a supported frame count.
PP_AUDIOSAMPLERATE_44100, 4096);
AudioConfig config(PP_AUDIOSAMPLERATE_44100, sample_frame_count);
if (config.is_null())
return false; // Couldn't configure audio.
// Then use the config to create your audio resource.
Audio audio(instance, config, callback, user_data);
if (audio.is_null())
return false; // Couldn't create audio.

Definition at line 57 of file audio_config.h.

Constructor & Destructor Documentation

pp::AudioConfig::AudioConfig ( )

An empty constructor for an AudioConfig resource.

Definition at line 25 of file audio_config.cc.

pp::AudioConfig::AudioConfig ( const InstanceHandle instance,
PP_AudioSampleRate  sample_rate,
uint32_t  sample_frame_count 
)

A constructor that creates an audio config based on the given sample rate and frame count. If the rate and frame count aren't supported, the resulting resource will be is_null(). You can pass the result of RecommendSampleFrameCount() as the sample frame count.

Parameters
[in]instanceThe instance associated with this resource.
[in]sample_rateA PP_AudioSampleRate which is either PP_AUDIOSAMPLERATE_44100 or PP_AUDIOSAMPLERATE_48000.
[in]sample_frame_countA uint32_t frame count returned from the RecommendSampleFrameCount function.

Definition at line 30 of file audio_config.cc.

References pp::Resource::PassRefFromConstructor(), pp::InstanceHandle::pp_instance(), sample_frame_count(), and sample_rate().

Member Function Documentation

uint32_t pp::AudioConfig::RecommendSampleFrameCount ( const InstanceHandle instance,
PP_AudioSampleRate  sample_rate,
uint32_t  requested_sample_frame_count 
)
static

RecommendSampleFrameCount() returns a supported frame count closest to the requested count. 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 PP_AUDIOMINSAMPLEFRAMECOUNT and greater than PP_AUDIOMAXSAMPLEFRAMECOUNT 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.

Parameters
[in]instanceThe instance associated with this resource.
[in]sample_rateA PP_AudioSampleRate which is either PP_AUDIOSAMPLERATE_44100 or PP_AUDIOSAMPLERATE_48000.
[in]requested_sample_frame_countA uint32_t requested frame count.
Returns
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.

Definition at line 57 of file audio_config.cc.

References pp::InstanceHandle::pp_instance(), and sample_rate().

PP_AudioSampleRate pp::AudioConfig::RecommendSampleRate ( const InstanceHandle instance)
static

RecommendSampleRate() returns the native sample rate used by the audio system. Applications that use the recommended sample rate might obtain lower latency and higher fidelity output.

Parameters
[in]instanceThe instance associated with this resource.

Definition at line 47 of file audio_config.cc.

References pp::InstanceHandle::pp_instance().

uint32_t pp::AudioConfig::sample_frame_count ( ) const
inline

Getter function for returning the internal sample frame count.

Returns
A uint32_t containing the sample frame count.

Definition at line 122 of file audio_config.h.

Referenced by AudioConfig().

PP_AudioSampleRate pp::AudioConfig::sample_rate ( ) const
inline

Getter function for returning the internal PP_AudioSampleRate enum.

Returns
The PP_AudioSampleRate enum.

Definition at line 117 of file audio_config.h.

Referenced by AudioConfig(), and RecommendSampleFrameCount().


The documentation for this class was generated from the following files: