This section discusses:
Add the following script commands to the Weaver script:
preloadinstrument
-preloads the instrument that will play back the audio.
enableaudiomask
-specifies a mask that enables specific audio channels at setup.
Example 1: Initializing the streaming application for audio.
/* If the stream has audio, then do some additional initializations.
*/
if ( fStreamHasAudio )
{
/* Preload audio instrument templates, if any are specified
*/
if ( ctx->hdr.preloadInstList != 0 )
{
ctlBlock.loadTemplates.tagListPtr = ctx->hdr.preloadInstList;
status = DSControl( ctx->messageItem, NULL, ctx->streamCBPtr,
SNDS_CHUNK_TYPE, kSAudioCtlOpLoadTemplates, &ctlBlock );
if ( status != 0 )
goto CLEANUP;
}
/* Enable any audio channels whose enable bit is set.
* NOTE: Channel zero is enabled by default, so we don't check it.*/
for ( channelNum = 1; channelNum < 32; channelNum++ )
{
/* If the bit corresponding to the channel number is set,
* then tell the audio subscriber to enable that channel.
*/
if ( ctx->hdr.enableAudioChan & (1L << channelNum) )
{
status = DSSetChannel( ctx->messageItem, NULL, ctx->streamCBPtr,
SNDS_CHUNK_TYPE, channelNum, CHAN_ENABLED );
CHECK_DS_RESULT( "DSSetChannel", status );
if ( status != 0 )
goto CLEANUP;
}
}
/* Set the audio clock to use the selected channel */
ctlBlock.clock.channelNumber = ctx->hdr.audioClockChan;
status = DSControl( ctx->messageItem, NULL, ctx->streamCBPtr,
SNDS_CHUNK_TYPE, kSAudioCtlOpSetClockChan, &ctlBlock );
CHECK_DS_RESULT( "DSControl - setting audio clock chan", status );
}