Skip to content

Commit d966735

Browse files
committed
feat: option to pass in the number of input channels to Panner
fixes #609
1 parent 3c9dfff commit d966735

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

Tone/component/channel/Panner.test.ts

+15
Original file line numberDiff line numberDiff line change
@@ -67,5 +67,20 @@ describe("Panner", () => {
6767
expect(r[0]).to.be.closeTo(0.707, 0.01);
6868
});
6969
});
70+
71+
it("can chain two panners when channelCount is 2", () => {
72+
return Offline(() => {
73+
const panner1 = new Panner({
74+
channelCount: 2,
75+
}).toDestination();
76+
const panner0 = new Panner(-1).connect(panner1);
77+
new Signal(1).connect(panner0);
78+
}, 0.1, 2).then((buffer) => {
79+
const l = buffer.toArray()[0];
80+
const r = buffer.toArray()[1];
81+
expect(l[0]).to.be.closeTo(1, 0.01);
82+
expect(r[0]).to.be.closeTo(0, 0.01);
83+
});
84+
});
7085
});
7186
});

Tone/component/channel/Panner.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { readOnly } from "../../core/util/Interface";
66

77
interface TonePannerOptions extends ToneAudioNodeOptions {
88
pan: AudioRange;
9+
channelCount: number;
910
}
1011

1112
/**
@@ -55,7 +56,7 @@ export class Panner extends ToneAudioNode<TonePannerOptions> {
5556
// this is necessary for standardized-audio-context
5657
// doesn't make any difference for the native AudioContext
5758
// https://github.com/chrisguttandin/standardized-audio-context/issues/647
58-
this._panner.channelCount = 1;
59+
this._panner.channelCount = options.channelCount;
5960
this._panner.channelCountMode = "explicit";
6061

6162
// initial value
@@ -65,6 +66,7 @@ export class Panner extends ToneAudioNode<TonePannerOptions> {
6566
static getDefaults(): TonePannerOptions {
6667
return Object.assign(ToneAudioNode.getDefaults(), {
6768
pan: 0,
69+
channelCount: 1,
6870
});
6971
}
7072

0 commit comments

Comments
 (0)