Back

Audio

nunuStudio uses WebAdio to provide a fully featured audio engine, with support for effects, positional audio, analysis tools etc. To use audio elements the host must support WebAudio since there is no fallback for hosts without this API available.

More information about the WebAudio API can be found here.

Audio file format support depends on the host, but the following table can be used as a reference.

Format Chorme Firefox Edge Safari
MP3 Yes Yes Yes Yes
FLAC No Yes No No
OGG Yes Yes Yes No
WAV Yes Yes Yes Yes
WMA No No No No

Load Audio Files

Its possible to load Audio files by selecting the import options in the asset explorer or by dragging audio files into the asset explorer directly.

Creating a audio emitter

To create a new audio emitter simply select the desired type of emitter from the toolbar, or drag the audio file to the scene editor, this will create a normal audio emitter by default.

there are 2 types of audio emitters in nunuStudio, normal emitters that play unmodified 2D stereo audio, and positional audio emitters that automatically balance the sound volume in the left and right channel relative to the camera position to create a 3D audio effect.

Controlling a audio emitter

Its possible to control a audio emitter using a script, the example bellow gets the audio emitter object, plays it on initialization and after 5 starts lowering its volume, after 10 seconds plays the audio again.

var audio;
var time, clock;

this.initialize = function()
{
	audio = scene.getObjectByName("test");
	
	clock = new Clock();
	clock.start();
	
	time = 0;
};

this.update = function()
{
	time += clock.getDelta();
	
	if(time > 5)
	{
		audio.setVolume(audio.volume - 0.01);
	}
	if(audio.volume < 0.1)
	{
		audio.pause();
	}
	
	if(time > 10)
	{
		audio.setVolume(1.0);
		audio.play();
	}
};