File tree 2 files changed +15
-14
lines changed
2 files changed +15
-14
lines changed Original file line number Diff line number Diff line change @@ -18,15 +18,15 @@ class BitCrusher extends AudioWorkletProcessor {
18
18
}
19
19
20
20
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 ] ;
23
23
for ( let channel = 0 ; channel < input . length ; channel ++ ) {
24
24
const inputChannel = input [ channel ] ;
25
25
const outputChannel = output [ channel ] ;
26
26
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 ;
29
28
if ( this . phase >= 1 ) {
29
+ const step = Math . pow ( 0.5 , bitDepth ) ;
30
30
this . phase -= 1 ;
31
31
this . lastSampleValue =
32
32
step * Math . floor ( inputChannel [ i ] / step + 0.5 ) ;
Original file line number Diff line number Diff line change @@ -631,20 +631,21 @@ <h2>AudioWorklet bit crusher</h2>
631
631
this.phase = 0
632
632
}
633
633
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];
637
637
for (let channel = 0; channel < input.length; channel++) {
638
- const inputChannel = input[channel]
639
- const outputChannel = output[channel]
638
+ const inputChannel = input[channel];
639
+ const outputChannel = output[channel];
640
640
for (let i = 0; i < inputChannel.length; ++i) {
641
- const step = Math.pow(0.5, bitDepth[i])
642
- this.phase += frequencyReduction[i]
641
+ this.phase += frequencyReduction;
643
642
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);
646
647
}
647
- outputChannel[i] = this.lastSampleValue
648
+ outputChannel[i] = this.lastSampleValue;
648
649
}
649
650
}
650
651
You can’t perform that action at this time.
0 commit comments