Skip to content

Commit

Permalink
Merge pull request #12773 from Mugen87/dev4
Browse files Browse the repository at this point in the history
Docs: Update Audio Entities
  • Loading branch information
mrdoob authored Nov 29, 2017
2 parents 311f502 + 113fbee commit a2dbfc0
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 25 deletions.
11 changes: 7 additions & 4 deletions docs/api/audio/Audio.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,21 @@ <h1>[name]</h1>

<h2>Example</h2>

<div>[example:misc_sound misc / sound ]</div>
<div>
[example:webaudio_sandbox webaudio / sandbox ]</br>
[example:webaudio_visualizer webaudio / visualizer ]
</div>

<code>
//Create an AudioListener and add it to the camera
// create an AudioListener and add it to the camera
var listener = new THREE.AudioListener();
camera.add( listener );

// create a global audio source
var sound = new THREE.Audio( listener );

// load a sound and set it as the Audio object's buffer
var audioLoader = new THREE.AudioLoader();

//Load a sound and set it as the Audio object's buffer
audioLoader.load( 'sounds/ambient.ogg', function( buffer ) {
sound.setBuffer( buffer );
sound.setLoop( true );
Expand Down
17 changes: 10 additions & 7 deletions docs/api/audio/AudioAnalyser.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,30 +21,33 @@ <h1>[name]</h1>

<h2>Example</h2>

<div>[example:misc_sound misc / sound ]</div>
<div>
[example:webaudio_sandbox webaudio / sandbox ]</br>
[example:webaudio_visualizer webaudio / visualizer ]
</div>

<code>
//Create an AudioListener and add it to the camera
// create an AudioListener and add it to the camera
var listener = new THREE.AudioListener();
camera.add( listener );

// create an Audio source
var sound = new THREE.Audio( listener );

// load a sound and set it as the Audio object's buffer
var audioLoader = new THREE.AudioLoader();

//Load a sound and set it as the Audio object's buffer
audioLoader.load( 'sounds/ambient.ogg', function( buffer ) {
sound.setBuffer( buffer );
sound.setLoop(true);
sound.setVolume(0.5);
sound.play();
});

//Create an AudioAnalyser, passing in the sound and desired fftSize
// create an AudioAnalyser, passing in the sound and desired fftSize
var analyser = new THREE.AudioAnalyser( sound, 32 );

//Get the average frequency of the sound
analyser.getAverageFrequency();
// get the average frequency of the sound
var data = analyser.getAverageFrequency();
</code>


Expand Down
19 changes: 11 additions & 8 deletions docs/api/audio/AudioListener.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,30 @@
<h1>[name]</h1>

<div class="desc">
Create a non-positional ( global ) audio object.<br /><br />

This uses the [link:https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API Web Audio API].

The [name] represents a virtual [link:https://developer.mozilla.org/de/docs/Web/API/AudioListener listener] of the all positional and non-positional audio effects in the scene.</br>
A three.js application usually creates a single instance of [name]. It is a mandatory construtor parameter for audios entities like [page:Audio Audio] and [page:PositionalAudio PositionalAudio].</br>
In most cases, the listener object is a child of the camera. So the 3D transformation of the camera represents the 3D transformation of the listener.
</div>


<h2>Example</h2>

<div>[example:misc_sound misc / sound ]</div>
<div>
[example:webaudio_sandbox webaudio / sandbox ]</br>
[example:webaudio_timing webaudio / timing ]</br>
[example:webaudio_visualizer webaudio / visualizer ]
</div>

<code>
//Create an AudioListener and add it to the camera
// create an AudioListener and add it to the camera
var listener = new THREE.AudioListener();
camera.add( listener );

// create a global audio source
var sound = new THREE.Audio( listener );

// load a sound and set it as the Audio object's buffer
var audioLoader = new THREE.AudioLoader();

//Load a sound and set it as the Audio object's buffer
audioLoader.load( 'sounds/ambient.ogg', function( buffer ) {
sound.setBuffer( buffer );
sound.setLoop(true);
Expand Down
16 changes: 10 additions & 6 deletions docs/api/audio/PositionalAudio.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,30 +21,34 @@ <h1>[name]</h1>

<h2>Example</h2>

<div>[example:misc_sound misc / sound ]</div>
<div>
[example:webaudio_sandbox webaudio / sandbox ]</br>
[example:webaudio_timing webaudio / timing ]
</div>

<code>
//Create an AudioListener and add it to the camera
// create an AudioListener and add it to the camera
var listener = new THREE.AudioListener();
camera.add( listener );

//Create the PositionalAudio object (passing in the listener)
// create the PositionalAudio object (passing in the listener)
var sound = new THREE.PositionalAudio( listener );

//Load a sound and set it as the PositionalAudio object's buffer
// load a sound and set it as the PositionalAudio object's buffer
var audioLoader = new THREE.AudioLoader();
audioLoader.load( 'sounds/song.ogg', function( buffer ) {
sound.setBuffer( buffer );
sound.setRefDistance( 20 );
sound.play();
});

//Create an object for the sound to play from
// create an object for the sound to play from
var sphere = new THREE.SphereGeometry( 20, 32, 16 );
var material = new THREE.MeshPhongMaterial( { color: 0xff2200 } );
var mesh = new THREE.Mesh( sphere, material );
scene.add( mesh );

//Finally add the sound to the mesh
// finally add the sound to the mesh
mesh.add( sound );
</code>

Expand Down

0 comments on commit a2dbfc0

Please sign in to comment.