Skip to content

Commit f34abcb

Browse files
committed
docs(audioWorklets): fix broken bit crusher
1 parent d8c29bd commit f34abcb

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed

docs/audioWorklets/bitCrusher.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@ class BitCrusher extends AudioWorkletProcessor {
1818
}
1919

2020
process([input], [output], parameters) {
21-
const bitDepth = parameters.bitDepth;
22-
const frequencyReduction = parameters.frequencyReduction;
21+
const bitDepth = parameters.bitDepth[0];
22+
const frequencyReduction = parameters.frequencyReduction[0];
2323
for (let channel = 0; channel < input.length; channel++) {
2424
const inputChannel = input[channel];
2525
const outputChannel = output[channel];
2626
for (let i = 0; i < inputChannel.length; ++i) {
27-
const step = Math.pow(0.5, bitDepth[i]);
28-
this.phase += frequencyReduction[i];
27+
this.phase += frequencyReduction;
2928
if (this.phase >= 1) {
29+
const step = Math.pow(0.5, bitDepth);
3030
this.phase -= 1;
3131
this.lastSampleValue =
3232
step * Math.floor(inputChannel[i] / step + 0.5);

docs/index.html

+11-10
Original file line numberDiff line numberDiff line change
@@ -631,20 +631,21 @@ <h2>AudioWorklet bit crusher</h2>
631631
this.phase = 0
632632
}
633633

634-
process ([input], [output], parameters) {
635-
const bitDepth = parameters.bitDepth
636-
const frequencyReduction = parameters.frequencyReduction
634+
process([input], [output], parameters) {
635+
const bitDepth = parameters.bitDepth[0];
636+
const frequencyReduction = parameters.frequencyReduction[0];
637637
for (let channel = 0; channel &lt; input.length; channel++) {
638-
const inputChannel = input[channel]
639-
const outputChannel = output[channel]
638+
const inputChannel = input[channel];
639+
const outputChannel = output[channel];
640640
for (let i = 0; i &lt; inputChannel.length; ++i) {
641-
const step = Math.pow(0.5, bitDepth[i])
642-
this.phase += frequencyReduction[i]
641+
this.phase += frequencyReduction;
643642
if (this.phase >= 1) {
644-
this.phase -= 1
645-
this.lastSampleValue = step * Math.floor(inputChannel[i] / step + 0.5)
643+
const step = Math.pow(0.5, bitDepth);
644+
this.phase -= 1;
645+
this.lastSampleValue =
646+
step * Math.floor(inputChannel[i] / step + 0.5);
646647
}
647-
outputChannel[i] = this.lastSampleValue
648+
outputChannel[i] = this.lastSampleValue;
648649
}
649650
}
650651

0 commit comments

Comments
 (0)