CrossBrowdy - Basic tutorial

Audio

Speaker

The CB_Speaker static class provides a higher-level layer to manage audio easily.

With this static class you can manage audio files (including groups of sprites), sound effects, music composition, processing, synthesizing, etc.

Note that, most of the times, it is recommended to deal with audio files using always the CB_Speaker static class which can contain a CB_AudioFileSpritesPool object (mainly using the CB_Speaker.setAudioFileSpritesPool and the CB_Speaker.getAudioFileSpritesPool functions). The CB_AudioFileSpritesPool class uses audio files cache and provides multiple sprites groups management as well as many other advanced methods. Here is an example:


	//Sets an internal CB_AudioFileSpritesPool object:
	CB_Speaker.setAudioFileSpritesPool(audioFileSpritesPool); //The parameter must be a CB_AudioFileSpritesPool object.
	
	//Gets the current internal CB_AudioFileSpritesPool object:
	var audioFileSpritesPool = CB_Speaker.getAudioFileSpritesPool();
	if (audioFileSpritesPool !== null)
	{
		//Do things with it...
	}

You can read more about the CB_AudioFileSpritesPool class in the Audio sprites pool topic.

Here are some examples of management with the CB_Speaker class:


	//Returns the volume sanitized (it does not allow values greater than 100 or lower than 0):
	var volume = CB_Speaker.sanitizeVolume(-20); //Returns 0.
	var volume_2 = CB_Speaker.sanitizeVolume(50); //Returns 50.
	var volume_3 = CB_Speaker.sanitizeVolume(130); //Returns 100.
	
	//Returns the current volume:
	var volumeCurrent = CB_Speaker.getVolume();
	
	//Sets the given volume:
	CB_Speaker.setVolume(80);
	
	//Mutes the speaker:
	CB_Speaker.mute();
	
	//Unmutes the speaker:
	CB_Speaker.unmute();

The functions above will affect the volume of the internal CB_AudioFileSpritesPool object (if any).

Here is an example managing sound effects:


	//Sound effects:
	var jsfxObject = CB_Speaker.getJsfxObject(); //Gets the 'jsfx' object.
	if (jsfxObject !== null)
	{
		//Do things with it...
	}

You can read more about it in the Sound FX topic.

Here is an example managing music composition:


	//Music composition:
	var bandJSObject = CB_Speaker.getBandJSObject(); //Gets a new 'BandJS' object.
	if (bandJSObject !== null)
	{
		//Do things with it...
	}

You can read more about it in the Music composition topic.

Here is an example managing processing and synthesizing:


	//Processing and synthesizing audio:
	var timbreJSObject = CB_Speaker.getTimbreJSObject(); //Gets the 'T' object.
	if (timbreJSObject !== null)
	{
		//Do things with it...
	}

You can read more about it in the Processing and synthesizing topic.

Check the API documentation to read more about the CB_Speaker static class.

Go back to Guides & Tutorials

« PrevReturnNext »
CrossBrowdy by Joan Alba Maldonado