Skip to content

Commit

Permalink
feat: option to pass in the number of input channels to Panner
Browse files Browse the repository at this point in the history
fixes #609
  • Loading branch information
tambien committed Jan 30, 2020
1 parent 3c9dfff commit d966735
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
15 changes: 15 additions & 0 deletions Tone/component/channel/Panner.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,20 @@ describe("Panner", () => {
expect(r[0]).to.be.closeTo(0.707, 0.01);
});
});

it("can chain two panners when channelCount is 2", () => {
return Offline(() => {
const panner1 = new Panner({
channelCount: 2,
}).toDestination();
const panner0 = new Panner(-1).connect(panner1);
new Signal(1).connect(panner0);
}, 0.1, 2).then((buffer) => {
const l = buffer.toArray()[0];
const r = buffer.toArray()[1];
expect(l[0]).to.be.closeTo(1, 0.01);
expect(r[0]).to.be.closeTo(0, 0.01);
});
});
});
});
4 changes: 3 additions & 1 deletion Tone/component/channel/Panner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { readOnly } from "../../core/util/Interface";

interface TonePannerOptions extends ToneAudioNodeOptions {
pan: AudioRange;
channelCount: number;
}

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

// initial value
Expand All @@ -65,6 +66,7 @@ export class Panner extends ToneAudioNode<TonePannerOptions> {
static getDefaults(): TonePannerOptions {
return Object.assign(ToneAudioNode.getDefaults(), {
pan: 0,
channelCount: 1,
});
}

Expand Down

0 comments on commit d966735

Please sign in to comment.