QUICK NAVIGATOR
PRODUCTS
TECHNOLOGIES
DEVELOPMENT TOOLS
* News
* Java Media Framework
* Intel Animation for Java
* Intel Spatial Audio for Java
* Runtime Software License
* SDK Software License
* System Requirements
* Download Area
* Documentation Online
* Gallery
* General FAQ
* Support Information

[INTEL NAVIGATION HEADER]

Intel Spatial Audio for Java* Package Tutorial

Lesson 6: Advanced Controls II
Synchronization, Notification, and Scalable Rendering

In this applet, the listener is located in the center of the path crossed by the sound source, represented by a purple ball. Playback cycles through the four sound sources, prompted by the event generated when each sound source completes its playback. Try to hear the differences in how the sound sources are rendered according to their creation flags and processor budgets. Study the source code to note how the events are handled.

You can edit the HTML file to specify a different sound file or a different icon to represent the sound source.

Here is the source for the applet on this page, called AdvancedControls2.

Goal: This lesson covers the use of additional advanced controls, including:

Synchronization

Two cached sound sources can have their playback synchronized so that any call to setPlaybackState() applied to one member of the group applies simultaneously to all members of the group. To create a synchronization group, specify any nonzero value for the groupId member parameter when creating a sound source. All sound sources with the same groupId automatically belong to the same synchronization group. Note that in this applet, soundSource1 and soundSource2 belong to a synchronization group with groupId = 1.

To keep a group of sound sources synchronized, make their data sources the same length, turn Doppler off, and set the pitch adjustment to the default (1.0).

Notification

If you specify a value for the eventArg and target parameters when creating a cached sound source, an AWT event will be generated when the cached sound source finishes playback. The event will be directed to the AWT Component specified in the target parameter, and will have the Event.id value SoundSource.PLAYBACK_EVENT and the Event.arg value specified in the eventArg parameter. In an applet context, the target Component is usually the applet itself.

The applet on this page uses this notification to cycle through playback of the four sound sources (the first two belong to the same synchronization group and play together). It specifies a String eventArg for each during creation, and catches the events in the handleEvent() method:

public boolean handleEvent(Event evt) {
switch(evt.id) {
case SoundSource.PLAYBACK_EVENT:
System.out.println("Got an event!");
if (evt.arg     == "event1") {
	System.out.println("EVENT 1");
	soundSource2.setPlayState(MediaState.AUDIO_PLAY, 3, 0.0f);
	return true;
}
if (evt.arg     == "event2") {
	System.out.println("EVENT 2");
	soundSource3.setPlayState(MediaState.AUDIO_PLAY, 1, 0.1f);
	return true;
}
if (evt.arg     == "event3") {
	System.out.println("EVENT 3");
	soundSource4.setPlayState(MediaState.AUDIO_PLAY, 1, 0.2f);
	return true;
}
if (evt.arg     == "event4") {
	System.out.println("EVENT 4");
	soundSource1.setPlayState(MediaState.AUDIO_PLAY, 2, 0.0f);
	return true;
}
} // switch
return false;
}

Scalable Rendering

In some applications, or at certain times, the quality of the audio spatialization may be very important; at other times, you may want to devote your processor resources to other tasks, such as graphics rendering. You can dynamically set a processing budget for an Environment by calling Environment.setModel() with the desired cpuBudget value. RenderOptions.MODERATE_BUDGET indicates that the best possible audio localization should be performed, RenderOptions.MIN_BUDGET indicates that minimal resources should be devoted to localization, and RenderOptions.LOW_BUDGET, the default, requests that a moderate budget be allowed.

In the applet on this page, we request the best possible audio localization:

try { 
	env = SpatialAudio.createEnvironment();
	EnvironmentModel model = env.getModel();
	...
	model.cpuBudget = RenderOptions.MODERATE_BUDGET;
	env.setModel`(model);
	...
} catch (SpatialAudioException e) {
	...
}

The environment's processor budget will be applied by default to all sound sources in that environment. However, you may want to give more resources to some sound sources — for instance, one that represents a plane actively flying overhead — than to others, such as one that is essentially ambient or unmoving. You can override the environment's processor budget for individual sound sources by specifying one of the values described above as the parameter to its setCpuBudget() method. In addition, you can limit the types of rendering that will be applied to a sound source at creation time. The first sound source in the applet opts out of almost every rendering option. Try to hear the difference between its rendering and that of the other sound sources in the applet.

soundSource1 = env.createCachedSoundSource(	RenderOptions.NO_DOPPLER +
						RenderOptions.NO_REVERB +
						RenderOptions.NO_SPATIALIZE +
						RenderOptions.NO_ATTENUATE +
						docBase + soundName1,
						1,
						"event1", 
						this,
						null);

Note the the RenderOptions values can be combined. NO_DOPPLER and NO_REVERB specify that no Doppler effects or reverberation should ever be applied to this sound source, regardless of the environment settings. NO_SPATIALIZE indicates that the sound should not be localized in space; distance attenuation will still occur unless NO_ATTENUATE is also flagged. In this case, the sound source is simply mixed.

Advanced Media Controls

Additional parameters can be passed in the setPlayState() method for cached sound sources to specify how many times the sound should loop over its data, and to specify an offset from the beginning of the data source during the first loop of playback. This line of code causes the sound source to loop twice, starting 0.15 seconds into the data on the first loop:

soundSource1.setPlayState(MediaState.AUDIO_PLAY, 2, 0.15f);

Previous Lesson Tutorial Contents Next Lesson

 

This page was last updated on Feb 11th, 1997.

Legal Stuff

Free Web Hosting