forked from Pissandshittium/pissandshittium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initialize sampleRate in AudioWorkletGlobalScope upon construction
This CL changes how |sampleRate| in AudioWorkletGlobalScope is updated. Previously, the sample rate was updated when the first processor was created, thus accessing the sample rate in the class definition phase gives 0 value. With this CL, the sample rate is initialized as soon as the global scope is created, before the script is loaded/parsed. Bug: 815313 Test: http/tests/webaudio/audio-worklet/global-sample-rate.html Change-Id: I994ee70c10ed93618b28c7d29df42b5d458c74f8 Reviewed-on: https://chromium-review.googlesource.com/935747 Commit-Queue: Hongchan Choi <hongchan@chromium.org> Reviewed-by: Raymond Toy <rtoy@chromium.org> Cr-Commit-Position: refs/heads/master@{#539254}
- Loading branch information
Showing
11 changed files
with
118 additions
and
20 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
third_party/WebKit/LayoutTests/http/tests/webaudio/audio-worklet/global-sample-rate.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title> | ||
Test sampleRate in AudioWorkletGlobalScope | ||
</title> | ||
<script src="../../resources/testharness.js"></script> | ||
<script src="../../resources/testharnessreport.js"></script> | ||
<script src="../../../webaudio-resources/audit.js"></script> | ||
<script src="audio-worklet-common.js"></script> | ||
</head> | ||
<body> | ||
<script id="layout-test-code"> | ||
// TODO(hongchan): remove this assertion when AudioWorklet shipped. | ||
assertAudioWorklet(); | ||
|
||
let audit = Audit.createTaskRunner(); | ||
|
||
let sampleRate = 48000; | ||
let renderLength = 512; | ||
let context = new OfflineAudioContext(1, renderLength, sampleRate); | ||
|
||
// Without rendering the context, attempt to access |sampleRate| in the | ||
// global scope as soon as it is created. | ||
audit.define( | ||
'Query |sampleRate| upon AudioWorkletGlobalScope construction', | ||
(task, should) => { | ||
let onePoleFilterNode = | ||
new AudioWorkletNode(context, 'one-pole-filter'); | ||
let frequencyParam = onePoleFilterNode.parameters.get('frequency'); | ||
|
||
should(frequencyParam.maxValue, | ||
'frequencyParam.maxValue') | ||
.beEqualTo(0.5 * context.sampleRate); | ||
|
||
task.done(); | ||
}); | ||
|
||
context.audioWorklet.addModule('one-pole-processor.js').then(() => { | ||
audit.run(); | ||
}); | ||
</script> | ||
</body> | ||
</html> |
49 changes: 49 additions & 0 deletions
49
third_party/WebKit/LayoutTests/http/tests/webaudio/audio-worklet/one-pole-processor.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/** | ||
* @class OnePoleFilter | ||
* @extends AudioWorkletProcessor | ||
* | ||
* A simple One-pole filter. | ||
*/ | ||
|
||
class OnePoleFilter extends AudioWorkletProcessor { | ||
|
||
// This gets evaluated as soon as the global scope is created. | ||
static get parameterDescriptors() { | ||
return [{ | ||
name: 'frequency', | ||
defaultValue: 250, | ||
minValue: 0, | ||
maxValue: 0.5 * sampleRate | ||
}]; | ||
} | ||
|
||
constructor() { | ||
super(); | ||
this.updateCoefficientsWithFrequency_(250); | ||
} | ||
|
||
updateCoefficientsWithFrequency_(frequency) { | ||
this.b1_ = Math.exp(-2 * Math.PI * frequency / sampleRate); | ||
this.a0_ = 1.0 - this.b1_; | ||
this.z1_ = 0; | ||
} | ||
|
||
process(inputs, outputs, parameters) { | ||
let input = inputs[0]; | ||
let output = outputs[0]; | ||
let frequency = parameters.frequency; | ||
for (let channel = 0; channel < output.length; ++channel) { | ||
let inputChannel = input[channel]; | ||
let outputChannel = output[channel]; | ||
for (let i = 0; i < outputChannel.length; ++i) { | ||
this.updateCoefficientsWithFrequency_(frequency[i]); | ||
this.z1_ = inputChannel[i] * this.a0_ + this.z1_ * this.b1_; | ||
outputChannel[i] = this.z1_; | ||
} | ||
} | ||
|
||
return true; | ||
} | ||
} | ||
|
||
registerProcessor('one-pole-filter', OnePoleFilter); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters