Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/api/en/audio/Audio.html
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ <h3>[property:Boolean autoplay]</h3>
<h3>[property:AudioContext context]</h3>
<p>The [link:https://developer.mozilla.org/en-US/docs/Web/API/AudioContext AudioContext] of the [page:AudioListener listener] given in the constructor.</p>

<h3>[property:Number detune]</h3>
<p>Modify pitch, measured in cents. +/- 100 is a semitone. +/- 1200 is an octave. Default is *0*.</p>

<h3>[property:Array filters]</h3>
<p>Represents an array of [link:https://developer.mozilla.org/en-US/docs/Web/API/BiquadFilterNode BiquadFilterNodes]. Can be used to apply a variety of low-order filters to create more complex sound effects. Filters are set via [page:Audio.setFilter] or [page:Audio.setFilters].</p>

Expand Down
3 changes: 3 additions & 0 deletions docs/api/zh/audio/Audio.html
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ <h3>[property:Boolean autoplay]</h3>
<h3>[property:AudioContext context]</h3>
<p>构造函数中传入[page:AudioListener listener]的[link:https://developer.mozilla.org/en-US/docs/Web/API/AudioContext AudioContext].</p>

<h3>[property:Number detune]</h3>
<p>TODO</p>

<h3>[property:Array filters]</h3>
<p>表示[link:https://developer.mozilla.org/en-US/docs/Web/API/BiquadFilterNode BiquadFilterNodes]的数组. 可以使用多种不同的低阶filters去创建复杂的音效. filters可以通过 [page:Audio.setFilter] 或者 [page:Audio.setFilters]设置.</p>

Expand Down
24 changes: 23 additions & 1 deletion src/audio/Audio.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ function Audio( listener ) {
this.autoplay = false;

this.buffer = null;
this.detune = 0;
this.loop = false;
this.startTime = 0;
this.offset = 0;
Expand Down Expand Up @@ -94,6 +95,7 @@ Audio.prototype = Object.assign( Object.create( Object3D.prototype ), {
var source = this.context.createBufferSource();

source.buffer = this.buffer;
source.detune.value = this.detune;
source.loop = this.loop;
source.onended = this.onEnded.bind( this );
source.playbackRate.setValueAtTime( this.playbackRate, this.startTime );
Expand Down Expand Up @@ -222,6 +224,26 @@ Audio.prototype = Object.assign( Object.create( Object3D.prototype ), {

},

setDetune: function ( value ) {

this.detune = value;

if ( this.isPlaying === true ) {

this.source.detune.setTargetAtTime( this.detune, this.context.currentTime, 0.01 );

}

return this;

},

getDetune: function () {

return this.detune;

},

getFilter: function () {

return this.getFilters()[ 0 ];
Expand All @@ -247,7 +269,7 @@ Audio.prototype = Object.assign( Object.create( Object3D.prototype ), {

if ( this.isPlaying === true ) {

this.source.playbackRate.setValueAtTime( this.playbackRate, this.context.currentTime );
this.source.playbackRate.setTargetAtTime( this.playbackRate, this.context.currentTime, 0.01 );

}

Expand Down