Data Fields


Detailed Description

The PPB_Audio interface contains pointers to several functions for handling audio resources.

Refer to the Audio chapter in the Developer's Guide for information on using this interface. Please see descriptions for each PPB_Audio and PPB_AudioConfig function for more details. A C example using PPB_Audio and PPB_AudioConfig follows.

Example:

 void audio_callback(void* sample_buffer,
                     uint32_t buffer_size_in_bytes,
                     void* user_data) {
   ... quickly fill in the buffer with samples and return to caller ...
  }

 ...Assume the application has cached the audio configuration interface in
 audio_config_interface and the audio interface in
 audio_interface...

 uint32_t count = audio_config_interface->RecommendSampleFrameCount(
     PP_AUDIOSAMPLERATE_44100, 4096);
 PP_Resource pp_audio_config = audio_config_interface->CreateStereo16Bit(
     pp_instance, PP_AUDIOSAMPLERATE_44100, count);
 PP_Resource pp_audio = audio_interface->Create(pp_instance, pp_audio_config,
     audio_callback, NULL);
 audio_interface->StartPlayback(pp_audio);

 ...audio_callback() will now be periodically invoked on a separate thread...

Field Documentation

PP_Resource(* PPB_Audio::Create)(PP_Instance instance, PP_Resource config, PPB_Audio_Callback audio_callback, void *user_data)

Create() creates an audio resource.

No sound will be heard until StartPlayback() is called. The callback is called with the buffer address and given user data whenever the buffer needs to be filled. From within the callback, you should not call PPB_Audio functions. The callback will be called on a different thread than the one which created the interface. For performance-critical applications (i.e. low-latency audio), the callback should avoid blocking or calling functions that can obtain locks, such as malloc. The layout and the size of the buffer passed to the audio callback will be determined by the device configuration and is specified in the AudioConfig documentation.

Parameters:
[in]instanceA PP_Instance identifying one instance of a module.
[in]configA PP_Resource corresponding to an audio config resource.
[in]audio_callbackA PPB_Audio_Callback callback function that the browser calls when it needs more samples to play.
[in]user_dataA pointer to user data used in the callback function.
Returns:
A PP_Resource containing the audio resource if successful or 0 if the configuration cannot be honored or the callback is null.

GetCurrrentConfig() returns an audio config resource for the given audio resource.

Parameters:
[in]configA PP_Resource corresponding to an audio resource.
Returns:
A PP_Resource containing the audio config resource if successful.

IsAudio() determines if the provided resource is an audio resource.

Parameters:
[in]resourceA PP_Resource corresponding to a generic resource.
Returns:
A PP_Bool containing containing PP_TRUE if the given resource is an Audio resource, otherwise PP_FALSE.

StartPlayback() starts the playback of the audio resource and begins periodically calling the callback.

Parameters:
[in]configA PP_Resource corresponding to an audio resource.
Returns:
A PP_Bool containing PP_TRUE if successful, otherwise PP_FALSE. Also returns PP_TRUE (and be a no-op) if called while playback is already in progress.

StopPlayback() stops the playback of the audio resource.

Parameters:
[in]configA PP_Resource corresponding to an audio resource.
Returns:
A PP_Bool containing PP_TRUE if successful, otherwise PP_FALSE. Also returns PP_TRUE (and is a no-op) if called while playback is already stopped. If a callback is in progress, StopPlayback() will block until the callback completes.

The documentation for this struct was generated from the following file:
This site uses cookies to deliver and enhance the quality of its services and to analyze traffic. If you agree, cookies are also used to serve advertising and to personalize the content and advertisements that you see. Learn more about our use of cookies.