Skip to content

Commit daaa152

Browse files
authored
Merge pull request #15345 from Mugen87/dev19
Audio: Added support for AudioBufferSourceNode.detune
2 parents 36e2f63 + a3e9397 commit daaa152

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

docs/api/en/audio/Audio.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ <h3>[property:Boolean autoplay]</h3>
6262
<h3>[property:AudioContext context]</h3>
6363
<p>The [link:https://developer.mozilla.org/en-US/docs/Web/API/AudioContext AudioContext] of the [page:AudioListener listener] given in the constructor.</p>
6464

65+
<h3>[property:Number detune]</h3>
66+
<p>Modify pitch, measured in cents. +/- 100 is a semitone. +/- 1200 is an octave. Default is *0*.</p>
67+
6568
<h3>[property:Array filters]</h3>
6669
<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>
6770

docs/api/zh/audio/Audio.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ <h3>[property:Boolean autoplay]</h3>
6262
<h3>[property:AudioContext context]</h3>
6363
<p>构造函数中传入[page:AudioListener listener]的[link:https://developer.mozilla.org/en-US/docs/Web/API/AudioContext AudioContext].</p>
6464

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

src/audio/Audio.js

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ function Audio( listener ) {
2020
this.autoplay = false;
2121

2222
this.buffer = null;
23+
this.detune = 0;
2324
this.loop = false;
2425
this.startTime = 0;
2526
this.offset = 0;
@@ -94,6 +95,7 @@ Audio.prototype = Object.assign( Object.create( Object3D.prototype ), {
9495
var source = this.context.createBufferSource();
9596

9697
source.buffer = this.buffer;
98+
source.detune.value = this.detune;
9799
source.loop = this.loop;
98100
source.onended = this.onEnded.bind( this );
99101
source.playbackRate.setValueAtTime( this.playbackRate, this.startTime );
@@ -222,6 +224,26 @@ Audio.prototype = Object.assign( Object.create( Object3D.prototype ), {
222224

223225
},
224226

227+
setDetune: function ( value ) {
228+
229+
this.detune = value;
230+
231+
if ( this.isPlaying === true ) {
232+
233+
this.source.detune.setTargetAtTime( this.detune, this.context.currentTime, 0.01 );
234+
235+
}
236+
237+
return this;
238+
239+
},
240+
241+
getDetune: function () {
242+
243+
return this.detune;
244+
245+
},
246+
225247
getFilter: function () {
226248

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

248270
if ( this.isPlaying === true ) {
249271

250-
this.source.playbackRate.setValueAtTime( this.playbackRate, this.context.currentTime );
272+
this.source.playbackRate.setTargetAtTime( this.playbackRate, this.context.currentTime, 0.01 );
251273

252274
}
253275

0 commit comments

Comments
 (0)