Plugins:PepperAudioAPI: Difference between revisions

Jump to navigation Jump to search
Line 79: Line 79:
Regardless of callback vs. push model, first the Pepper audio interface must be acquired.
Regardless of callback vs. push model, first the Pepper audio interface must be acquired.


<tt>
<pre>
NPPepperExtensions *pepper;<br>
NPPepperExtensions *pepper;
NPAudio *audio = NULL;<br>
NPAudio *audio = NULL;
/* Get PEPPER extensions */<br>
/* Get PEPPER extensions */
NPERR ret = NPN_GetValue(instance, NPNVPepperExtensions, &pepper);<br>
NPERR ret = NPN_GetValue(instance, NPNVPepperExtensions, &pepper);
if (NPERR_NO_ERROR == ret) {<br>
if (NPERR_NO_ERROR == ret) {
/* successfully obtained Pepper extensions, now acquire audio... */<br>
/* successfully obtained Pepper extensions, now acquire audio... */
audio = pepper->acquireDevice(NPAudioDeviceID);<br>
audio = pepper->acquireDevice(NPAudioDeviceID);
} else {<br>
} else {
/* Pepper extensions are not available */<br>
/* Pepper extensions are not available */
}<br>
}
/* check for acquisition of audio device interface */<br>
/* check for acquisition of audio device interface */
if (NULL != audio) {<br>
if (NULL != audio) {
/* Pepper audio device interface is available */<br>
/* Pepper audio device interface is available */
...
...
</tt>
</pre>


Once an interface to the audio device is acquired, an application can query capabilities of the device, and from there, create a configuration (a set of capabilities.) In this simple example, the application picks 44.1kHz, stereo output using int16 sample types. It uses query Capability to retrieve a recommended sample frame count for the output buffer.
Once an interface to the audio device is acquired, an application can query capabilities of the device, and from there, create a configuration (a set of capabilities.) In this simple example, the application picks 44.1kHz, stereo output using int16 sample types. It uses query Capability to retrieve a recommended sample frame count for the output buffer.


<tt>
<pre>
...<br>
/* fill out request, use sample buffer size from configuration */<br>
NPAudioConfig request;<br>
NPAudioConfig config;<br>
int32 ret;<br>
request.sampleRate = NPAudioSampleRate44100Hz;<br>
request.sampleType = NPAudioSampleTypeInt16;<br>
ret = audio->queryCapability(npp,<br>
NPAudioQuerySampleFrameCount44100Hz, &request.sampleFrameCount);<br>
request.outputChannelMap = NPAudioChannelStereo;<br>
request.inputChannelMap = NPAudioChannelNone;<br>
request.flags = 0;<br>
request.callback = NULL;<br>
request.userData = NULL;<br>
ret = audio->queryConfig(npp, &request, &config);<br>
if (NPERR_NO_ERROR == ret) {<br>
/* config struct now contains a valid audio device config */<br>
...
...
</tt>
/* fill out request, use sample buffer size from configuration */
NPAudioConfig request;
NPAudioConfig config;
int32 ret;
request.sampleRate = NPAudioSampleRate44100Hz;
request.sampleType = NPAudioSampleTypeInt16;
ret = audio->queryCapability(npp,
NPAudioQuerySampleFrameCount44100Hz, &request.sampleFrameCount);
request.outputChannelMap = NPAudioChannelStereo;
request.inputChannelMap = NPAudioChannelNone;
request.flags = 0;
request.callback = NULL;
request.userData = NULL;
ret = audio->queryConfig(npp, &request, &config);
if (NPERR_NO_ERROR == ret) {
/* config struct now contains a valid audio device config */
...
</pre>
 


This example uses a very standard audio device configuration. When requesting less common configurations, an application should be prepared to work with the configuration returned by queryConfig(), which may end up being different than the requested configuration. For example, a device might return that it is capable of emitting audio at 96kHz. It could also return that it is capable of 5.1 channel output. However, when the application requests a configuration of 5.1 channel output at 96kHz, query Config may return back that in this case, the device is only capable of 48kHz playback over 5.1 channels. The application then has to decide, take the 5.1 output at 48kHz, or try another configuration,
This example uses a very standard audio device configuration. When requesting less common configurations, an application should be prepared to work with the configuration returned by queryConfig(), which may end up being different than the requested configuration. For example, a device might return that it is capable of emitting audio at 96kHz. It could also return that it is capable of 5.1 channel output. However, when the application requests a configuration of 5.1 channel output at 96kHz, query Config may return back that in this case, the device is only capable of 48kHz playback over 5.1 channels. The application then has to decide, take the 5.1 output at 48kHz, or try another configuration,
11

edits

Navigation menu