mirror of
https://github.com/Tonejs/Tone.js
synced 2024-11-16 00:27:58 +00:00
merging functionality from 'dev'
changes were made to .js files which are no longer there. moving functionality to .ts files
This commit is contained in:
parent
22396a8942
commit
1792ff1d05
4 changed files with 29 additions and 23 deletions
|
@ -39,7 +39,7 @@ describe("AmplitudeEnvelope", () => {
|
||||||
const osc = new Oscillator().start(0).connect(ampEnv);
|
const osc = new Oscillator().start(0).connect(ampEnv);
|
||||||
ampEnv.triggerAttack(0);
|
ampEnv.triggerAttack(0);
|
||||||
ampEnv.triggerAttack(0.3);
|
ampEnv.triggerAttack(0.3);
|
||||||
}, "ampEnvelope2.wav");
|
}, "ampEnvelope2.wav", 0.004);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("matches a file with ripple attack/release", () => {
|
it("matches a file with ripple attack/release", () => {
|
||||||
|
@ -57,7 +57,7 @@ describe("AmplitudeEnvelope", () => {
|
||||||
ampEnv.triggerRelease(0.7);
|
ampEnv.triggerRelease(0.7);
|
||||||
ampEnv.triggerAttack(1);
|
ampEnv.triggerAttack(1);
|
||||||
ampEnv.triggerRelease(1.6);
|
ampEnv.triggerRelease(1.6);
|
||||||
}, "ampEnvelope3.wav");
|
}, "ampEnvelope3.wav", 0.002);
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
|
@ -8,23 +8,6 @@ describe("Envelope", () => {
|
||||||
|
|
||||||
BasicTests(Envelope);
|
BasicTests(Envelope);
|
||||||
|
|
||||||
// context("API", function(){
|
|
||||||
|
|
||||||
// APITest.constructor(Envelope, {
|
|
||||||
// "attack" : "Time=",
|
|
||||||
// "decay" : "Time=",
|
|
||||||
// release : "Time=",
|
|
||||||
// "sustain" : "NormalRange=",
|
|
||||||
// "attackCurve" : ["linear", "exponential"],
|
|
||||||
// "releaseCurve" : ["linear", "exponential"],
|
|
||||||
// "decayCurve" : ["linear", "exponential"]
|
|
||||||
// });
|
|
||||||
// APITest.constructor(Envelope, ["Time=", "Time=", "NormalRange=", "Time="]);
|
|
||||||
|
|
||||||
// APITest.method(Envelope, "triggerAttack", ["Time=", "NormalRange="]);
|
|
||||||
// APITest.method(Envelope, "triggerRelease", ["Time="]);
|
|
||||||
// });
|
|
||||||
|
|
||||||
context("Envelope", () => {
|
context("Envelope", () => {
|
||||||
|
|
||||||
it("has an output connections", () => {
|
it("has an output connections", () => {
|
||||||
|
@ -289,6 +272,21 @@ describe("Envelope", () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("can retrigger a short attack at the same time as previous release", () => {
|
||||||
|
return Offline(() => {
|
||||||
|
const env = new Envelope(0.001, 0.1, 0.5);
|
||||||
|
env.attackCurve = "linear";
|
||||||
|
env.toMaster();
|
||||||
|
env.triggerAttack(0);
|
||||||
|
env.triggerRelease(0.4);
|
||||||
|
env.triggerAttack(0.4);
|
||||||
|
}, 0.6).then(buffer => {
|
||||||
|
expect(buffer.getValueAtTime(0.4)).be.closeTo(0.5, 0.01);
|
||||||
|
expect(buffer.getValueAtTime(0.40025)).be.closeTo(0.75, 0.01);
|
||||||
|
expect(buffer.getValueAtTime(0.4005)).be.closeTo(1, 0.01);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it("is silent before and after triggering", () => {
|
it("is silent before and after triggering", () => {
|
||||||
const e = {
|
const e = {
|
||||||
attack : 0.001,
|
attack : 0.001,
|
||||||
|
|
|
@ -304,9 +304,14 @@ implements AbstractParam<Type> {
|
||||||
}
|
}
|
||||||
|
|
||||||
exponentialApproachValueAtTime(value: Type, time: Time, rampTime: Time): this {
|
exponentialApproachValueAtTime(value: Type, time: Time, rampTime: Time): this {
|
||||||
const timeConstant = Math.log(this.toSeconds(rampTime) + 1) / Math.log(200);
|
|
||||||
time = this.toSeconds(time);
|
time = this.toSeconds(time);
|
||||||
return this.setTargetAtTime(value, time, timeConstant);
|
rampTime = this.toSeconds(rampTime);
|
||||||
|
const timeConstant = Math.log(rampTime + 1) / Math.log(200);
|
||||||
|
this.setTargetAtTime(value, time, timeConstant);
|
||||||
|
// at 90% start a linear ramp to the final value
|
||||||
|
this.cancelAndHoldAtTime(time + rampTime * 0.9);
|
||||||
|
this.linearRampToValueAtTime(value, time + rampTime);
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
setTargetAtTime(value: Type, startTime: Time, timeConstant: Positive): this {
|
setTargetAtTime(value: Type, startTime: Time, timeConstant: Positive): this {
|
||||||
|
|
|
@ -200,9 +200,12 @@ export class Sampler extends Instrument<SamplerOptions> {
|
||||||
const midi = new FrequencyClass(this.context, note).toMidi();
|
const midi = new FrequencyClass(this.context, note).toMidi();
|
||||||
// find the note
|
// find the note
|
||||||
if (this._activeSources.has(midi) && (this._activeSources.get(midi) as ToneBufferSource[]).length) {
|
if (this._activeSources.has(midi) && (this._activeSources.get(midi) as ToneBufferSource[]).length) {
|
||||||
const source = (this._activeSources.get(midi) as ToneBufferSource[]).shift() as ToneBufferSource;
|
const sources = this._activeSources.get(midi) as ToneBufferSource[];
|
||||||
time = this.toSeconds(time);
|
time = this.toSeconds(time);
|
||||||
source.stop(time);
|
sources.forEach(source => {
|
||||||
|
source.stop(time);
|
||||||
|
});
|
||||||
|
this._activeSources.set(midi, []);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return this;
|
return this;
|
||||||
|
|
Loading…
Reference in a new issue