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 |
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.
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 2D stereo audio, and positional audio emitters that simulate positional audio relative to the camera position to create a 3D audio effect.
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;
function initialize()
{
audio = scene.getObjectByName("test");
clock = new Clock();
clock.start();
time = 0;
}
function update()
{
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();
}
}
The example bellow shows how to controll a positional audio object. When the mouse left button is pressed the sound starts playing, and when it is pressed again it stops. To try this example in the editor you can download the project file or open it on the Web Editor.